Project

General

Profile

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

    
7

    
8
  // TODO Genus UUID.
9

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

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

    
18
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
19

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

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

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

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

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

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

    
63

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

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

    
109

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

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

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

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

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

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

    
158

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

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

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

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

    
187
}
188

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
701
  // ---- DEFAULTS settings
702

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

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

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

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

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

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

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

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

    
905
  // ---- END of DEFAULTS
906

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

    
909
  $feature_block_setting = null;
910

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

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

    
931
  return $feature_block_setting;
932
}
933

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

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

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

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

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

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

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

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

    
1072
}
1073

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

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

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

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

    
1118
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1119
    '#type' => 'markup',
1120
    '#markup' => '<b>Debug CDM Web Service:</b> Debugging web services is possible via the ' . l('CDM web service debug block', 'admin/structure/block/manage/cdm_api/cdm_ws_debug/configure')
1121
      . ' visible only for administrators',
1122
  );
1123

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1340
  $form['aggregation']['notice'] = array(
1341
      '#markup' => '<strong>NOTICE:</strong> The below aggregation settings can slow down the data portal, so you may want to sensibly apply these setting and you may also
1342
          want to make use of the caching capabilities of the dataportal.',
1343
  );
1344

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

    
1352
  );
1353
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1354
      '#type' => 'select',
1355
      '#title' => t('Aggregation of taxon pictures') . ':',
1356
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1357
      '#options' => array(
1358
          0 => "Show only pictures of the current taxon",
1359
          1 => "Include pictures of taxonomic children",
1360
      ),
1361
      '#description' => t("Choose whether to include the images of the taxonomic children. This will affect the <em>Images</em> tab and image tumbnails like in the search results."),
1362
  );
1363

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

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

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

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

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

    
1412

    
1413

    
1414
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1415
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1416
    <div class="description">Using this button, you will lose all content associated with the cdm drupal nodes which is stored in the drupal data base.</div>',
1417
  );
1418
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1419
    '#type' => 'submit',
1420
    '#value' => t('Drop all cdm nodes'),
1421
    '#submit' => array('drop_all_cdm_nodes_submit')
1422
  );
1423

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

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

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

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

    
1462
  return system_settings_form($form);
1463
}
1464

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

    
1475

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

    
1483
  $form = array();
1484

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

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

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

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

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

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

    
1540
  $bibliography_settings = get_bibliography_settings(true);
1541

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

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

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

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

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

    
1594
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1595
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1596
    $which_version_message = '(These are the old default part definition from before EDIT platform release 3.8.0, you may want to reset these by clearing the text area and and submitting the form.)';
1597
  } else if($is_custom_part_definition){
1598
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1599
  } else  {
1600
    $which_version_message = '(These are the default part definition.)';
1601
  }
1602

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

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

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

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

    
1708
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1709
    $which_version_message = '(These are the old default render templates from before EDIT platform release 3.8.0, you may want to reset these by clearing the text area and and submitting the form.)';
1710
  } else if($is_custom_render_template){
1711
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1712
  } else {
1713
    $which_version_message = '(These are the default render templates.)';
1714
  }
1715

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

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

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

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

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

    
1779

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

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

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

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

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

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

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

    
1859
  return $form;
1860
}
1861

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2150

    
2151
    $feature_list_layout_settings_disabled = FALSE;
2152

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

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

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

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

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

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

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

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

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

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

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

    
2221
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2222
          '#type' => 'select',
2223
          '#title' => t('Sort elements'),
2224
          '#default_value' => $feature_block_setting['sort_elements'],
2225
          '#options' => array(
2226
            NO_SORT => 'No sorting',
2227
            SORT_ASC => 'Ascending',
2228
            SORT_DESC => 'Descending',
2229
            SORT_HIERARCHICAL => 'Hierarchical'
2230
          ),
2231
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2232
          <dl>
2233
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2234
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2235
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2236
          <dr><dt>Hierarchical</dt><dd>Use the order of items and their hierarchy. This is not possible for all feature and item types.</dd></dr>
2237
          </dl>',
2238
        );
2239

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

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

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

    
2287

    
2288

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

    
2307
  );
2308

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

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

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

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

    
2335

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

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

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

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

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

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

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

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

    
2438

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2615
/**
2616
 * @todo document this function.
2617
 */
2618
function cdm_settings_layout_search() {
2619

    
2620
  $form = array();
2621

    
2622
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2623

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

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

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

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

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

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

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

    
2692
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2693
  );
2694

    
2695
  // --- SEARCH TAXA GALLERY ---- //
2696
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2697
  $collapsed = FALSE;
2698
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2699
  $form_title = 'Taxa Search thumbnails';
2700
  $form_description = 'Search results may show thumbnails. ';
2701
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2702

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

    
2712
/**
2713
 * @todo document this function.
2714
 */
2715
function cdm_settings_layout_media() {
2716

    
2717
  $form = array();
2718

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

    
2728
  $form['media_settings']['image_gallery_viewer'] = array(
2729
    '#type' => 'select',
2730
    '#title' => t('Image viewer') . ':',
2731
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2732
    '#options' => array(
2733
      'default' => t('Standard image viewer'),
2734
      'fsi' => t('FSI viewer (requires FSI server!)'),
2735
    ),
2736
  );
2737

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

    
2748
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2749
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2750
      '#type' => 'checkbox',
2751
      '#title' => 'Show media representations',
2752
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2753

    
2754
    );
2755
  }
2756

    
2757

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

    
2767
/**
2768
 * GEOSERVICE and Map settings.
2769
 */
2770
function cdm_settings_geo($form, &$form_state) {
2771

    
2772
  $current_geoserver_settings = get_edit_map_service_settings();
2773
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2774

    
2775

    
2776
  $form = array();
2777

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

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

    
2801
  /*
2802
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2803
  );
2804
  */
2805

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

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

    
2834
  /*
2835
   * MAP SETTINGS
2836
   */
2837

    
2838
  $form[CDM_MAP_DISTRIBUTION] = array(
2839
    '#type' => 'fieldset',
2840
    '#tree' => TRUE,
2841
    '#title' => t('Maps settings'),
2842
    '#collapsible' => TRUE,
2843
    '#collapsed' => TRUE,
2844
    '#description' => t('General configuration for all map types.'),
2845
  );
2846

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

    
2864
  /*
2865
   * settings for the distribution map are used also for specimens map!!!!
2866
   */
2867

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

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

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

    
2903
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2904
    '#type' => 'checkbox',
2905
    '#title' => 'Display area labels',
2906
    '#default_value' => $map_distribution['show_labels'],
2907
    '#description' => t('The map will show name labels of the areas'),
2908
  );
2909

    
2910
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2911
    '#type' => 'textfield',
2912
    '#title' => 'Map caption',
2913
    '#default_value' => $map_distribution['caption'],
2914
    '#description' => t('The caption will be shown below the map.'),
2915
  );
2916

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

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

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

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

    
2962
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2963
    '#type' => 'textfield',
2964
    '#title' => 'Background color',
2965
    '#default_value' => $map_distribution['image_map']['bg_color'],
2966
  );
2967

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

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

    
2985

    
2986
  // --- OpenLayers Settings --- //
2987
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2988
    '#type' => 'fieldset',
2989
    '#title' => 'OpenLayers settings',
2990
    '#tree' => TRUE,
2991
    '#collapsible' => TRUE,
2992
    '#collapsed' => !$open_layers_is_enabled,
2993
    '#description' => '',
2994
  );
2995

    
2996

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

    
3006

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

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

    
3024
  // The default layer must always be enabled
3025
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3026
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3027

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

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

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

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

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

    
3093
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3094
    '#type' => 'checkbox',
3095
    '#title' => 'Enable overlay layer',
3096
    '#weight' => -100,
3097
    '#default_value' => $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3098
  );
3099

    
3100
  /*
3101
   * Map Legend
3102
   */
3103
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3104
    '#type' => 'fieldset',
3105
    '#title' => 'Map legend',
3106
    '#tree' => TRUE,
3107
    '#collapsible' => TRUE,
3108
    '#collapsed' => TRUE,
3109
    '#description' => 'Configure the maps legend.',
3110
  );
3111

    
3112
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3113
    '#type' => 'checkbox',
3114
    '#title' => 'Display a map legend',
3115
    '#default_value' => $map_distribution['legend']['show'],
3116
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3117
  );
3118

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

    
3127
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3128
    '#type' => 'textfield',
3129
    '#title' => 'Font size',
3130
    '#default_value' => $map_distribution['legend']['font_size'],
3131
    '#description' => 'Font size in pixels.',
3132
  );
3133

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

    
3146
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3147
    '#type' => 'textfield',
3148
    '#title' => 'Icon width',
3149
    '#default_value' => $map_distribution['legend']['icon_width'],
3150
    '#description' => 'Legend icon width in pixels.',
3151
  );
3152
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3153
    '#type' => 'textfield',
3154
    '#title' => 'Icon height',
3155
    '#default_value' => $map_distribution['legend']['icon_height'],
3156
    '#description' => 'Legend icon height in pixels.',
3157
  );
3158

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

    
3166
  return system_settings_form($form);
3167
}
3168

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

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

    
3222
  if($add_projection_settings){
3223

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

    
3289
  }
3290
  return $form_elements;
3291
}
3292

    
3293

    
3294
/**
3295
 * @todo document this function.
3296
 */
3297
function cdm_settings_cache() {
3298

    
3299
  $form = array();
3300

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

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

    
3324
  $form['cache_settings']['cdm_run_cache'] = array(
3325
    '#markup' => cdm_view_cache_site(),
3326
  );
3327

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

    
3337
/**
3338
 * Walk and cache all taxon pages.
3339
 */
3340
function cdm_view_cache_site() {
3341

    
3342
  $out = '';
3343

    
3344
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3345

    
3346
  $request_params = array();
3347
  $request_params['class'] = "Taxon";
3348

    
3349
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3350
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3351
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3352

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

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

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

    
3380

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

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

    
3412
/**
3413
 * Form validation handler for cdm_settings_general
3414
 *
3415
 * @param $form
3416
 * @param $form_state
3417
 */
3418
function cdm_settings_general_validate($form, &$form_state) {
3419

    
3420
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3421
    $form_state['values']['cdm_webservice_url'] .= '/';
3422
  }
3423

    
3424
}
3425

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

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

    
3452
}
3453

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

    
3465
  $settings = variable_get('edit_map_server', array(
3466
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3467
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3468
      )
3469
  );
3470

    
3471
  return $settings;
3472
}
3473

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

    
3485

    
3486
/**
3487
 * Returns the version number of the currently selected edit mapserver as a float
3488
 *
3489
 * @return float
3490
 *   The version number of the currently selected edit mapserver as a float.
3491
 *   Returns 0 on error.
3492
 */
3493
function get_edit_map_service_version_number() {
3494

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

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

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

    
3532

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

    
3551
/**
3552
 * #process callback function for the custom form element type 'checkbox_preferred'
3553
 *
3554
 *
3555
 */
3556
function checkboxes_preferred_expand($element, &$form_state, $form) {
3557

    
3558
  // First of all create checkboxes for each of the elements
3559
  $element = form_process_checkboxes($element);
3560

    
3561
  // compose the element name
3562
  $parents = array();
3563
  array_deep_copy($element['#parents'], $parents);
3564
  $parents[count($parents) -1 ] .= '_preferred';
3565
  $element_name = $parents[0];
3566
  for ($i=1; $i < count($parents); $i++){
3567
    $element_name .= '[' . $parents[$i] . ']';
3568
  }
3569

    
3570
  $children = element_children($element);
3571

    
3572
  $element['table_start'] = array(
3573
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3574
    '#weight' => -1,
3575
  );
3576

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

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

    
3612
  // end the table
3613
  $element['table_end'] = array(
3614
    '#markup' => '</table>',
3615
    '#weight' => $weight++,
3616
  );
3617

    
3618
  return $element;
3619
}
3620

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

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

    
3654
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3655

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

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

    
3683
  return $element;
3684
}
3685

    
3686
function radios_prepare_options_suffix(&$elements){
3687

    
3688
  $childrenKeys = element_children($elements);
3689
  foreach($childrenKeys as $key){
3690
    if(!is_array($elements[$key]['#theme_wrappers'])){
3691
      $elements[$key]['#theme_wrappers'] = array();
3692
    }
3693
    if(isset($elements['#options_suffixes'][$key])){
3694
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3695
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3696
    }
3697
  }
3698
  return $elements;
3699

    
3700
}
3701

    
3702
/**
3703
 * TODO
3704
 * @param unknown $variables
3705
 */
3706
function theme_radio_options_suffix($variables) {
3707
  $element = $variables['element'];
3708
  if(isset($element['#options_suffix'])) {
3709
    $element['#children'] .= $element['#options_suffix'];
3710
  }
3711
  return $element['#children'];
3712
}
3713

    
3714

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

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