Project

General

Profile

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

    
7

    
8
const FEATURE_BLOCK_WEIGHT_INCREMENT = 2;
9
const PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS = 'AGGREGATION_DESCRIPTIONS';
10
const PSEUDO_FEATURE_BIBLIOGRAPHY = 'BIBLIOGRAPHY';
11
const PSEUDO_FEATURE_NUMBER_OF_TAXA = 'NUMBER_OF_TAXA';
12

    
13
const CDM_NAME_PAGE_AUTOREDIRECT = 'cdm_name_page_autoredirect';
14

    
15
const CDM_NAME_PAGE_SECTION_TAXA = 'cdm_name_page_section_taxa';
16
const CDM_NAME_PAGE_SECTION_TAXA_DEFAULT = 1;
17

    
18
const CDM_MEDIA_GALLERY_VIEWER = 'image_gallery_viewer';
19
const CDM_MEDIA_GALLERY_VIEWER_DEFAULT = 'universalviewer';
20
const CDM_MEDIA_GALLERY_VIEWER_SIMPLE = 'default';
21

    
22
const CDM_ADDITIONAL_MEDIA_COPYRIGHT = 'cdm_additional_media_copyright';
23

    
24
const CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES = 'cdm_taxonpage_taxon_node_show_status';
25
define('TAXONTREE_RANKLIMIT', 'cdm_taxontree_ranklimit');
26
define('TAXONTREE_RANKLIMIT_DEFAULT', 0);
27
  define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
28
  define('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
29

    
30
  define('CDM_SUB_TREE_FILTER_UUID', 'cdm_sub_tree_filter_uuid');
31

    
32
  define('NO_SORT', -1);
33
  define('SORT_HIERARCHICAL', 9);
34

    
35
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
36

    
37
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
38
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
39
 const CDM_DATAPORTAL_NOMREF_IN_TITLE = 'cdm_dataportal_nomref_in_title';
40
 const CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT =  1;
41
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
42
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE', 50);
43
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 0);
44
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
45
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE', 'cdm_synonymy_accepted_taxon_sec_separate');
46
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL', 'cdm_synonymy_accepted_taxon_sec_separate_label');
47
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT', 'Source');
48
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
49
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
50
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
51
  define('CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE', 0);
52

    
53
  define('CDM_SEARCH_BLAST_SERVICE_URI', 'http://bgbm-import:9001/api/sequence');
54
  define('CDM_SEARCH_BLAST_ENABLED', 0);
55
  define('CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK', 'cdm_registration_presistent_identifier_as_link');
56

    
57
  /* annotationTypeKeys */
58
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
59
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
60
    $annotationTypeKeys = array_flip($annotationTypeKeys);
61

    
62
    // Technical annotation are off by default.
63
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
64
    $annotationTypeKeys = array_flip($annotationTypeKeys);
65
    // Additional value for the NULL case.
66
    $annotationTypeKeys[] = 'NULL_VALUE';
67
  }
68

    
69
  const ANNOTATION_TYPES_VISIBLE = 'annotations_types_as_footnotes';
70
  define('ANNOTATION_TYPES_VISIBLE_DEFAULT', serialize($annotationTypeKeys));
71

    
72
/* extensionTypeKeys */
73
$extensionTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_EXTENSION_TYPE));
74
if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $extensionTypeKeys)) {
75
  // Additional value for the NULL case.
76
  $extensionTypeKeys[] = 'NULL_VALUE';
77
}
78
const EXTENSION_TYPES_VISIBLE = 'extension_types_visible';
79
define('EXTENSION_TYPES_VISIBLE_DEFAULT', serialize([]));
80

    
81
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
82
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
83
    'enabled' => 0,
84
    'key_format' => 'ALPHA'
85
  )));
86

    
87
  /* taxonRelationshipTypes */
88
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(
89
    array(
90
      UUID_MISAPPLIED_NAME_FOR => UUID_MISAPPLIED_NAME_FOR,
91
      UUID_PROPARTE_MISAPPLIEDNAME_FOR => UUID_PROPARTE_MISAPPLIEDNAME_FOR,
92
      UUID_PARTIAL_MISAPPLIEDNAME_FOR => UUID_PARTIAL_MISAPPLIEDNAME_FOR,
93
      UUID_PROPARTE_SYNONYM_FOR => UUID_PROPARTE_SYNONYM_FOR,
94
      UUID_PARTIAL_SYNONYM_FOR => UUID_PARTIAL_SYNONYM_FOR,
95
      UUID_INVALID_DESIGNATION_FOR => UUID_INVALID_DESIGNATION_FOR
96
    )
97
  ));
98

    
99

    
100
  /* ---- MAP SETTING CONSTANTS ---- */
101
  /**
102
   * @var array of URIs eg. http://edit.africamuseum.be"
103
   *   An options array
104
   */
105
  define('EDIT_MAPSERVER_URI', serialize(
106
      array(
107
        'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)'
108
      )
109
    )
110
  );
111
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
112
  /**
113
   * @var array of versions eg. "v1.2"
114
   *   An options array
115
   */
116
  define('EDIT_MAPSERVER_VERSION', serialize(
117
      array(
118
//        'v1' => 'v1' ,           // no longer recommended
119
//        'v1.1' => 'v1.1',        // no longer recommended
120
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
121
        'v1.2' => 'v1.2',
122
        'v1.3_dev' => 'v1.3_dev (not recommended)',
123
        'v1.4_dev' => 'v1.4_dev (experimental features)'
124
      )
125
    )
126
  );
127
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
128
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
129

    
130
    // --- Taxon profile settings --- /
131
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
132
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
133
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
134
      array(
135
          'show' => 0,
136
          'maxextend' => 184,
137
          'media_uri_query' => '',
138
          'custom_placeholder_enabled' => 1,
139
          'custom_placeholder_image_on' => 0,
140
          'custom_placeholder_image_fid' => ''
141
      )
142
    )
143
  );
144

    
145

    
146
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
147

    
148
define('CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS', 'cdm_pseudo_feature_block_weights');
149
define('CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT', serialize(
150
  [
151
    PSEUDO_FEATURE_NUMBER_OF_TAXA => 0 - FEATURE_BLOCK_WEIGHT_INCREMENT,
152
    PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS => 100,
153
    PSEUDO_FEATURE_BIBLIOGRAPHY => 102
154
  ]
155
));
156

    
157
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
158
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
159
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
160
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
161
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
162

    
163
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
164
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
165
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
166
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
167

    
168
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
169
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
170

    
171
/**
172
 * Returns the array of implemented taxon page tabs.
173
 * The array has fixed integer keys which must not be changed.
174
 */
175
function get_taxon_tabs_list() {
176
  $opts = array(
177
    0 => 'General',
178
    1 => 'Synonymy',
179
    2 => 'Images',
180
    3 => 'Specimens',
181
    4 => 'Keys',
182
    5 => 'Experts',
183
  );
184
  if(variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) !== 1){
185
    // skip the Synonymy if it is shown in  the general tab
186
    unset($opts[1]);
187
  }
188
  return $opts;
189
}
190

    
191
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
192
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
193
  array(
194
    'general' => '-3',
195
    'synonymy' => '-2',
196
    'images' => '0',
197
    'specimens' => '1',
198
    'keys' => '3',
199
    'experts' => '5',
200
    )
201
));
202

    
203

    
204
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
205
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
206
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
207
  array(
208
    'general' => null,
209
    'synonymy' => null,
210
    'images' => null,
211
    'specimens' => null,
212
    'keys' => null,
213
    'experts' => null,
214
  )
215
));
216

    
217
$taxon_tab_options = get_taxon_tabs_list();
218
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
219

    
220
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
221

    
222
/**
223
 * @todo document this function.
224
 */
225
function get_taxon_options_list() {
226
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
227
  foreach ($taxon_tab_options as $key => $value) {
228
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
229
  }
230
  return $taxon_tab_options;
231

    
232
}
233

    
234
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
235
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
236
    array(
237
      'ZoologicalName' => array(
238
        'namePart' => array('name' => TRUE),
239
        'nameAuthorPart' => array('name' => TRUE),
240
        'referencePart' => array('authors' => TRUE),
241
        'microreferencePart' => array('microreference' => TRUE),
242
        'secReferencePart' => array('secReference' => TRUE,),
243
        'statusPart' => array('status' => TRUE),
244
        'descriptionPart' => array('description' => TRUE),
245
      ),
246
      'BotanicalName'=> array(
247
        'namePart' => array('name' => TRUE),
248
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
249
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
250
        'secReferencePart' => array('secReference' => 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
       'secReferencePart' => array(
267
         'secReference' => TRUE,
268
       ),
269
       'microreferencePart' => array(
270
          'microreference' => TRUE,
271
        ),
272
       'statusPart' => array(
273
          'status' => TRUE,
274
        ),
275
       'descriptionPart' => array(
276
          'description' => TRUE,
277
        ),
278
      )
279
    )
280
  )
281
);
282
define('CDM_PART_DEFINITIONS_DEFAULT_PRE_380', serialize(
283
    array(
284
      'ZoologicalName' => array(
285
        'namePart' => array('name' => TRUE),
286
        'nameAuthorPart' => array('name' => TRUE),
287
        'referencePart' => array('authors' => TRUE),
288
        'microreferencePart' => array('microreference' => TRUE),
289
        'statusPart' => array('status' => TRUE),
290
        'descriptionPart' => array('description' => TRUE),
291
      ),
292
      'BotanicalName'=> array(
293
        'namePart' => array('name' => TRUE),
294
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
295
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
296
        'referenceYearPart' => array('reference.year' => TRUE),
297
        'statusPart' => array('status' => TRUE),
298
        'descriptionPart' => array('description' => TRUE),
299
      ),
300
      '#DEFAULT' => array(
301
        'namePart' => array(
302
          'name' => TRUE
303
        ),
304
        'nameAuthorPart' => array(
305
          'name' => TRUE,
306
          'authors' => TRUE
307
        ),
308
        'referencePart' => array(
309
          'reference' => TRUE
310
        ),
311
        'microreferencePart' => array(
312
          'microreference' => TRUE,
313
        ),
314
        'statusPart' => array(
315
          'status' => TRUE,
316
        ),
317
        'descriptionPart' => array(
318
          'description' => TRUE,
319
        ),
320
      )
321
    )
322
  )
323
  );
324

    
325
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
326
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
327
  array (
328
    'taxon_page_title,polytomousKey'=> array(
329
        'namePart' => array('#uri' => TRUE),
330
      ),
331
    'not_in_current_classification' => array(
332
     'nameAuthorPart' => TRUE,
333
     'referencePart' => TRUE,
334
     'statusPart' => TRUE,
335
     'secReferencePart' => TRUE,
336
    ),
337
    'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy,name_page,registration_page'=> array(
338
      'nameAuthorPart' => array('#uri' => TRUE),
339
      'referencePart' => TRUE,
340
      'descriptionPart' => TRUE,
341
      'statusPart' => TRUE,
342
    ),
343
    'related_taxon.other_taxon_relationship.taxon_relationships.taxon_page_synonymy'=> array(
344
      'nameAuthorPart' => array('#uri' => TRUE),
345
      'referencePart' => TRUE,
346
      'descriptionPart' => TRUE,
347
      'statusPart' => TRUE,
348
      'secReferencePart' => TRUE,
349
    ),
350
    'related_taxon.misapplied_name_for.taxon_relationships.taxon_page_synonymy' => array(
351
      'nameAuthorPart' => array('#uri' => TRUE),
352
      'referencePart' => TRUE,
353
      'descriptionPart' => TRUE,
354
      'statusPart' => TRUE,
355
      /* no sec ref in this case, misapplied names are
356
       * de-duplicated and the sec ref is shown as footnote */
357
    ),
358
    'homonym'=> array(
359
        'nameAuthorPart' => array('#uri' => TRUE),
360
        'referenceYearPart' => TRUE,
361
        'statusPart' => TRUE,
362
    ),
363
    'acceptedFor,typedesignations,list_of_taxa' => array(
364
        'nameAuthorPart' => array('#uri' => TRUE),
365
        'referencePart' => TRUE,
366
      ),
367
    '#DEFAULT' => array(
368
        'nameAuthorPart' => array('#uri' => TRUE),
369
        'referencePart' => TRUE,
370
     )
371
  )
372
));
373
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
374
  array (
375
    'taxon_page_title,polytomousKey'=> array(
376
      'namePart' => array('#uri' => TRUE),
377
    ),
378
    'taxon_page_synonymy,related_taxon'=> array(
379
      'nameAuthorPart' => array('#uri' => TRUE),
380
      'referencePart' => TRUE,
381
      'statusPart' => TRUE,
382
      'descriptionPart' => TRUE,
383
    ),
384
    'homonym'=> array(
385
      'nameAuthorPart' => array('#uri' => TRUE),
386
      'referenceYearPart' => TRUE,
387
    ),
388
    'acceptedFor,typedesignations,list_of_taxa' => array(
389
      'nameAuthorPart' => array('#uri' => TRUE),
390
      'referencePart' => TRUE,
391
    ),
392
    '#DEFAULT' => array(
393
      'nameAuthorPart' => array('#uri' => TRUE),
394
      'referencePart' => TRUE,
395
    )
396
  )
397
));
398

    
399
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
400
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
401
    // to unset a default enntry set the value to 0
402
    array(
403
      'doTaxa'=>'doTaxa',
404
      'doSynonyms' => 'doSynonyms',
405
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
406
      'doMisappliedNames' => 'doMisappliedNames'
407
    )
408
  )
409
);
410

    
411
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
412

    
413
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
414
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
415
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
416

    
417
/* Gallery variables. */
418
$gallery_settings = array(
419
    "cdm_dataportal_show_taxon_thumbnails" => 1,
420
    "cdm_dataportal_show_synonym_thumbnails" => 0,
421
    "cdm_dataportal_show_thumbnail_captions" => 1,
422
    "cdm_dataportal_media_maxextend" => 120,
423
    "cdm_dataportal_media_cols" => 3,
424
    "cdm_dataportal_media_maxRows" => 1,
425
);
426

    
427
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
428
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
429
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
430
define('CDM_DATAPORTAL_TYPE_SPECIMEN_GALLERY_NAME', 'type_specimen_gallery');
431
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
432
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
433
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
434
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
435
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
436
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
437
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
438
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
439

    
440
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
441
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
442
  'media_representation_details_enabled' => 0
443
)));
444

    
445
/**
446
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
447
 * the synonymy.
448
 *
449
 * @var string
450
 */
451
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
452

    
453
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES', 'cdm_name_relationship_types');
454
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT', serialize(
455
    array(
456
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
457
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
458
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
459
    )
460
  )
461
);
462

    
463
define('CDM_NAME_RELATIONSHIP_LIST_TYPES', 'cdm_name_relationship_list_types');
464

    
465

    
466
/**
467
 * The drupal variable for the configuration of the information aggregation along
468
 * the taxon relation ships. The mapped array is associative and holds two elements:
469
 *    - direct: the uuids of the taxon relationship types to take into account in invers
470
 *      direction.
471
 *    - invers: the uuids of the taxon relationship types to take into account in direct
472
 *      direction.
473
 *
474
 * @var String
475
 */
476
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
477
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
478
    array(
479
        'direct'=>array(),
480
        'invers'=>array()
481
     )
482
   ));
483
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
484
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
485
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
486

    
487
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
488
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
489
      array(
490
      'filter_rules' => array(
491
        'statusOrderPreference' => 0,
492
        'subAreaPreference' => 0,
493
      ),
494
      'hiddenAreaMarkerType' => array()
495
     )
496
));
497

    
498
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
499
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
500
  "level_0" => array(
501
    'label_suffix' => ':',
502
    'status_glue' => '',
503
    'item_glue' => ' ',
504
    'item_group_prefix' => '',
505
    'item_group_postfix' => ''
506
  ),
507
  "level_1" => array(
508
    'label_suffix' => '',
509
    'status_glue' => '‒ ', // '&#8210; '
510
    'item_glue' => '; ',
511
    'item_group_prefix' => ', ',
512
    'item_group_postfix' => ''
513
  ),
514
  "level_2" => array(
515
    'label_suffix' => '',
516
    'status_glue' => '‒ ', // '&#8210; '
517
    'item_glue' => ', ',
518
    'item_group_prefix' => ' (',
519
    'item_group_postfix' => ')'
520
  )
521
)));
522

    
523
/**
524
 * Constant for the drupal variable key distribution_map_visibility
525
 *
526
 * possible values:
527
 *  - never
528
 *  - automatic
529
 *  - always
530
 */
531
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
532
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
533

    
534
/**
535
 * Constant for the drupal variable key specimen_map_visibility
536
 *
537
 * possible values:
538
 *  - never
539
 *  - automatic
540
 *  - always
541
 */
542
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
543
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
544

    
545
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
546
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
547
    array(
548
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
549
        'includeOccurrences' => 0,
550
        'includeTaxonNameDescriptions' => 0
551
     )
552
  ));
553

    
554
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
555
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
556
  // needs to be merged with user setting by drupal_array_merge_deep()
557
  // 'width' => 512, // optimum size for OSM layers is 512
558
  // 'height' => 512 / 2, // optimum size for OSM layers 256
559
  'aspect_ratio' => 2,
560
  'bbox' => '', // empty to allow automatic zooming to extend
561
  'maxZoom' => 15, // corresponds to the default in cdm_openlayers_map.defaults
562
  'show_labels' => FALSE,
563
  'caption' => '',
564
  'distribution_opacity' => '0.5',
565
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
566
  'image_map' => array(
567
    'base_layer' => '', // none, formerly this was cyprusdivs
568
    'bg_color' => '1874CD',
569
    'layer_style' => 'ffffff,606060,,',
570
  ),
571
  'openlayers' => array(
572
    'base_layers' =>  array(
573
      // A layer MUST NOT BE SET in the defaults,
574
      // otherwise it can not be overidden by the user settings:
575
      // 'mapproxy_vmap0' => 'mapproxy_vmap0',
576
      // it is sufficient to define the preferred layer,
577
      // since it will automatically be enabled:
578
      'PREFERRED' => 'mapproxy_vmap0'),
579
    'custom_wms_base_layer' => array(
580
      'name' => NULL,
581
      'url' => NULL,
582
      'params' =>  NULL,
583
      'projection' => NULL,
584
      'proj4js_def' => NULL,
585
      'max_extent' => NULL,
586
      'units' => NULL,
587
      'untiled' => FALSE
588
    ),
589
    'wms_overlay_layer' => array(
590
      'name' => NULL,
591
      'url' => NULL,
592
      'params' =>  NULL,
593
      'untiled' => FALSE
594
    ),
595
    'show_layer_switcher' => TRUE,
596
    'display_outside_max_extent' => FALSE,
597
    'google_maps_api_key' => NULL,
598
  ),
599
  'legend' => array(
600
    'show' => TRUE,
601
    'opacity' => '0.5',
602
    'font_size' => 10,
603
    'font_style' => FALSE,
604
    'icon_width' => 35,
605
    'icon_height' => 15
606
  )
607
)));
608

    
609
/**
610
 * Merges the named array variable with the array of defaults.
611
 *
612
 * IMPORTANT: The array keys must be strings. When the keys are integers
613
 * the merging will not take place for these entities. Number keyed entities
614
 * are just appended to the result array.
615
 *
616
 * @param string $variable_name
617
 *     The variable name
618
 * @param string | array $default
619
 *     The array containing the default values either as array or serialized as string.
620
 *     Unserialization is cared for if necessary
621
 * @return array
622
 *     The merged array as returned by drupal_array_merge_deep()
623
 *
624
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
625
 * TODO force $default being an array
626
 */
627
function get_array_variable_merged($variable_name, $default){
628

    
629
    // unserialize if nessecary
630
    if(!is_array($default)){
631
      $default = unserialize($default);
632
    }
633
    $variable = variable_get($variable_name, array());
634
    $result = drupal_array_merge_deep($default, $variable);
635
    return $result;
636
}
637

    
638
/**
639
 * @todo document this function.
640
 */
641
function getGallerySettings($gallery_config_form_name) {
642
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
643
}
644

    
645
/**
646
 * Returns the string representation of the default tab.
647
 *
648
 * @param bool $returnTabIndex
649
 *   Defaults to FALSE, if set true this function will return the index number
650
 *   of the default tab. (used to supply default values to form elements).
651
 */
652
function get_default_taxon_tab($returnTabIndex = FALSE) {
653

    
654
  global $user;
655
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
656
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
657
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
658
  // Get the user value if the used has chosen to overwrite the system settings.
659
  $user_tab_on = variable_get($user_tab_active, FALSE);
660
  if ($user_tab_on) {
661
    $user_value = variable_get($user_tab, 0);
662
    $index_value = $user_value;
663
    // Get the system value.
664
  }
665
  else {
666
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
667
    $index_value = $system_value;
668
  }
669

    
670
  // Return the index value or the string representation.
671
  if ($returnTabIndex) {
672
    return $index_value;
673
  }
674
  else {
675
    return ($values[$index_value]);
676
  }
677
}
678

    
679
/**
680
 * Provides the feature block settings for a specific feature which matches the $feature_uuid parameter.
681
 *
682
 * In case specifically configured settings array, like these which are stored in the drupal variables, is missing
683
 * one or more fields these fields are taken from the default. That is the specific settings are always merges
684
 * with the default.
685
 *
686
 * Note: These settings only apply to feature blocks which do not have a special rendering
687
 * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
688
 * 'special' element of the settings
689
 *
690
 * @param $feature_uuid
691
 *   The uuid string representation of the feature to return the settings for
692
 *
693
 * @return array
694
 *  an associative array of settings, with the following fields:
695
 *    - as_list: string
696
 *        this setting will be used in compose_feature_block_wrap_elements() as $enclosing_tag
697
 *        possible values are:
698
 *          div: not as list,
699
 *          ul: as bullet list,
700
 *          ol: as numbered list,
701
 *          dl: as definition list
702
 *        The tag used for the inner element, thus depends on the value of this field. The
703
 *        inner tag name can be retrieved by the function cdm_feature_block_element_tag_name()
704
 *    - link_to_reference: boolean,
705
 *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
706
 *    - link_to_name_used_in_source": boolean
707
 *        whether to show name in source information as link which will point to the according name page
708
 *    - sources_as_content (boolean)
709
 *        TRUE (int: 1):
710
 *          1. If element is of the CDM type TextData and the text is not empty the source references will be
711
 *             appended in brackets like "text (source references)". If the original source has name in source
712
 *             information it will be appended to the citation string,
713
 *             like : "(citation, as name in source; citation, as name in source)"
714
 *          2. if the text of the TextData is empty, the original source citations are the only content
715
 *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
716
 *             prepended to the citation string like: "name in source: citation"
717
 *        FALSE (int: 0):
718
 *          Original sources are put into the bibliography(=references) pseudo feature block. If the original source
719
 *          citations are the only content, the resulting feature block content would only consist of footnotes.
720
 *          In this case the display of the respective feature block is suppressed.
721
 *          TODO if the bibliography is not enabled the sources will be treated as footnotes like annotations,
722
 *               in future however they will in this case be shown in a separate references section for each
723
 *               feature block.
724
 *    - sources_as_content_to_bibliography  (boolean)
725
 *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
726
 *        in the bibliography.
727
 *    - sort_elements
728
 *        whether and how to sort the elements
729
 *        possible values are the constants SORT_ASC, SORT_DESC, NULL,
730
 *        some feature types (Distribution) also support: SORT_HIERARCHICAL (
731
 *        TODO option to exclude levels, put in special?,
732
 *        TODO make use of this setting in compose_feature_block_wrap_elements())
733
 *    - element_tag
734
 *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
735
 *        possible values are span | div. the proper inner tag name can be retrieved by the function
736
 *        cdm_feature_block_element_tag_name()
737
 *    - special: array()
738
 *        an array with further settings, this field can be used for special
739
 *        settings for specialized rendering like for distributions
740
 *  }
741
 *
742
 */
743
function get_feature_block_settings($feature_uuid = 'DEFAULT') {
744
  // the default must conform to the default parameter values of
745
  // compose_feature_block_wrap_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
746
  // compose_description_element_text_data() : asListElement = NULL
747

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

    
750
  // ---- DEFAULTS settings
751

    
752
  // only needed as final option, when the settings are not having a default
753
  $default = array(
754
    'DEFAULT' => array(
755
      'as_list' => 'div',
756
      'link_to_reference' => 0,
757
      'link_to_name_used_in_source' => 1,
758
      'sources_as_content' => 0,
759
      'sources_as_content_to_bibliography' => 0,
760
      'sort_elements' => NO_SORT,
761
      'glue' => '',
762
      'element_tag' => NULL
763
    ),
764
    // settings for pseudo feature bibliography
765
    // only hard coded here
766
    'BIBLIOGRAPHY' => array(
767
      'as_list' => 'div',
768
      'link_to_reference' => 0,
769
      'link_to_name_used_in_source' => 1,
770
      'sources_as_content' => 0,
771
      'sources_as_content_to_bibliography' => 0,
772
      'sort_elements' => NO_SORT,
773
      'glue' => '',
774
      'element_tag' => NULL
775
    )
776
  );
777

    
778
  // will be used as preset in the settings
779
  $other_themes_default = array(
780
    'DEFAULT' => array(
781
      'as_list' => 'div',
782
      'link_to_reference' => 0,
783
      'link_to_name_used_in_source' => 1,
784
      'sources_as_content' => 0,
785
      'sources_as_content_to_bibliography' => 0,
786
      'sort_elements' => NO_SORT,
787
      'glue' => '',
788
      'element_tag' => NULL
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_DISTRIBUTION => array(
801
      'as_list' => 'div', // currently ignored
802
      'link_to_reference' => 0,
803
      'link_to_name_used_in_source' => 0,
804
      'sources_as_content' => 0,
805
      'sources_as_content_to_bibliography' => 0,
806
      'sort_elements' => NO_SORT, // will cause ...
807
      'glue' => '',
808
      'element_tag' => 'div',
809
      'special' => array()
810
    ),
811
    UUID_COMMON_NAME => array(
812
      'as_list' => 'div',
813
      'link_to_reference' => 0,
814
      'link_to_name_used_in_source' => 1,
815
      'sources_as_content' => 0,
816
      'sources_as_content_to_bibliography' => 0,
817
      'sort_elements' => NO_SORT,
818
      'glue' => '',
819
      'element_tag' => 'span'
820
    ),
821
  );
822

    
823
  // ---- Special DEFAULTS for existing portals
824
  // TODO:
825
  // this can be removed once the feature block
826
  // settings have been deployed for the first time to these portals
827

    
828
  $cichorieae_default = array(
829
    'DEFAULT' => array(
830
      'as_list' => 'div',
831
      'link_to_reference' => 1,
832
      'link_to_name_used_in_source' => 1,
833
      'sources_as_content' => 1,
834
      'sources_as_content_to_bibliography' => 0,
835
      'sort_elements' => NO_SORT,
836
      'glue' => '',
837
      'element_tag' => 'div'
838
    ),
839
    UUID_CITATION => array(
840
      'as_list' => 'div',
841
      'link_to_reference' => 0,
842
      'link_to_name_used_in_source' => 0,
843
      'sources_as_content' => 1,
844
      'sources_as_content_to_bibliography' => 0,
845
      'sort_elements' => SORT_ASC,
846
      'glue' => '',
847
      'element_tag' => 'div'
848
    ),
849
    UUID_CHROMOSOMES_NUMBERS => array(
850
      'as_list' => 'ul',
851
      'link_to_reference' => 1,
852
      'link_to_name_used_in_source' => 1,
853
      'sources_as_content' => 1,
854
      'sources_as_content_to_bibliography' => 0,
855
      'sort_elements' => NO_SORT,
856
      'glue' => '',
857
      'element_tag' => 'div'
858
    ),
859
    UUID_CHROMOSOMES => array(
860
      'as_list' => 'ul',
861
      'link_to_reference' => 0,
862
      'link_to_name_used_in_source' => 1,
863
      'sources_as_content' => 1,
864
      'sources_as_content_to_bibliography' => 0,
865
      'sort_elements' => NO_SORT,
866
      'glue' => '',
867
      'element_tag' => 'div'
868
    ),
869
    UUID_COMMON_NAME => array(
870
      'as_list' => 'div',
871
      'link_to_reference' => 0,
872
      'link_to_name_used_in_source' => 1,
873
      'sources_as_content' => 0,
874
      'sources_as_content_to_bibliography' => 0,
875
      'sort_elements' => NO_SORT,
876
      'glue' => '',
877
      'element_tag' => 'span'
878
    ),
879
  );
880

    
881
  $palmweb_default = array(
882
    'DEFAULT' => array(
883
      'as_list' => 'ul',
884
      'link_to_reference' => 1,
885
      'link_to_name_used_in_source' => 1,
886
      'sources_as_content' => 1,
887
      'sources_as_content_to_bibliography' => 1,
888
      'sort_elements' => NO_SORT,
889
      'glue' => '',
890
      'element_tag' => NULL
891
    ),
892
    UUID_CITATION => array(
893
      'as_list' => 'ul',
894
      'link_to_reference' => 1,
895
      'link_to_name_used_in_source' => 1,
896
      'sources_as_content' => 0,
897
      'sources_as_content_to_bibliography' => 1,
898
      'sort_elements' => SORT_ASC,
899
      'glue' => '',
900
      'element_tag' => 'div'
901
    ),
902
    UUID_DISTRIBUTION => array(
903
      'as_list' => 'div', // currently ignored
904
      'link_to_reference' => 1,
905
      'link_to_name_used_in_source' => 1,
906
      'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
907
      'sources_as_content_to_bibliography' => 1,
908
      'sort_elements' => NO_SORT, // will cause ...
909
      'glue' => ', ',
910
      'element_tag' => 'span',
911
      'special' => array()
912
    ),
913
  );
914

    
915
  $cyprus_default = $cichorieae_default;
916
  $cyprus_default[UUID_DISTRIBUTION] = array(
917
    'as_list' => 'div', // currently ignored
918
    'link_to_reference' => 0,
919
    'link_to_name_used_in_source' => 0,
920
    'sources_as_content' => 0,
921
    'sources_as_content_to_bibliography' => 0,
922
    'sort_elements' => NO_SORT, // will cause ...
923
    'glue' => ' ',
924
    'element_tag' => 'div',
925
    'special' => array()
926
  );
927

    
928
  $default_theme = variable_get('theme_default', NULL);
929

    
930
  switch ($default_theme) {
931
    case 'garland_cichorieae':
932
      $settings_for_theme = $cichorieae_default;
933
      break;
934
    case 'cyprus':
935
      // cyprus: no longer used in production,
936
      // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
937
      $settings_for_theme = $cyprus_default;
938
      break;
939
    case 'flore_afrique_centrale':
940
    case 'flora_malesiana':
941
    case 'flore_gabon':
942
      $settings_for_theme = $cichorieae_default;
943
      $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
944
      break;
945
    case 'palmweb_2':
946
      $settings_for_theme = $palmweb_default;
947
      break;
948
    default:
949
      $settings_for_theme = $other_themes_default;
950
  }
951
  // add pseudo feature settings
952
  $settings_for_theme['BIBLIOGRAPHY'] = $default['BIBLIOGRAPHY'];
953

    
954
  // ---- END of DEFAULTS
955

    
956
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
957

    
958
  $feature_block_setting = null;
959

    
960
  if (isset($saved_settings[$feature_uuid])) {
961
    $feature_block_setting = $saved_settings[$feature_uuid];
962
  }
963
  else if (isset($settings_for_theme[$feature_uuid])) {
964
    $feature_block_setting = $settings_for_theme[$feature_uuid];
965
  }
966
  else if (isset($settings_for_theme['DEFAULT'])) {
967
    $feature_block_setting = $settings_for_theme['DEFAULT'];
968
  }
969

    
970
  // now merge the default and specific settings
971
  $settings_to_merge = array($default['DEFAULT']);
972
  if(is_array($saved_settings)){
973
    $settings_to_merge[] = $saved_settings['DEFAULT'];
974
  }
975
  if(isset($feature_block_setting)){
976
    $settings_to_merge[] = $feature_block_setting;
977
  }
978
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
979

    
980
  return $feature_block_setting;
981
}
982

    
983
/**
984
 * returns the current setting for the original source bibliography
985
 *
986
 * Caches internally
987
 *
988
 * @return array
989
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
990
 *   - 'enabled': 1|0
991
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
992
 */
993
function get_bibliography_settings($clear_cache = false){
994
  static $bibliography_settings = null;
995
  if(!$bibliography_settings || $clear_cache){
996
    $bibliography_settings = get_array_variable_merged(
997
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
998
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
999
    );
1000
  }
1001
  return $bibliography_settings;
1002
}
1003

    
1004
/**
1005
 * @todo Please document this function.
1006
 * @see http://drupal.org/node/1354
1007
 */
1008
function cdm_dataportal_menu_admin(&$items) {
1009
  // Display section on admin/config page.
1010
  $items['admin/config/cdm_dataportal'] = array(
1011
    'title' => 'CDM Dataportal',
1012
    'description' => 'Settings for the CDM DataPortal.',
1013
    'position' => 'right',
1014
    'weight' => 10,
1015
    'page callback' => 'system_admin_menu_block_page',
1016
    'access arguments' => array('administer cdm_dataportal'),
1017
    'file' => 'system.admin.inc',
1018
    'file path' => drupal_get_path('module', 'system'),
1019
  );
1020
  $items['admin/config/cdm_dataportal/settings'] = array(
1021
    'title' => 'Settings',
1022
    'description' => 'Settings for the CDM DataPortal.',
1023
    'weight' => 0,
1024
    'page callback' => 'drupal_get_form',
1025
    'page arguments' => array('cdm_settings_general'),
1026
    'access arguments' => array('administer cdm_dataportal'),
1027
    'type' => MENU_NORMAL_ITEM,
1028
  );
1029
  $items['admin/config/cdm_dataportal/settings/general'] = array(
1030
    'title' => 'General',
1031
    'description' => 'General',
1032
    'weight' => 0,
1033
    'page callback' => 'drupal_get_form',
1034
    'page arguments' => array('cdm_settings_general'),
1035
    'access arguments' => array('administer cdm_dataportal'),
1036
    'type' => MENU_DEFAULT_LOCAL_TASK,
1037
  );
1038

    
1039
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
1040
    'title' => 'Cache',
1041
    'description' => 'Cache',
1042
    'access arguments' => array('administer cdm_dataportal'),
1043
    'page callback' => 'drupal_get_form',
1044
    'page arguments' => array('cdm_settings_cache'),
1045
    'weight' => 10,
1046
    'type' => MENU_LOCAL_TASK,
1047
  );
1048

    
1049
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
1050
    'title' => 'Geo & Map',
1051
    'description' => 'Geo & Map',
1052
    'access arguments' => array('administer cdm_dataportal'),
1053
    'page callback' => 'drupal_get_form',
1054
    'page arguments' => array('cdm_settings_geo'),
1055
    'weight' => 1,
1056
    'type' => MENU_LOCAL_TASK,
1057
  );
1058

    
1059
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
1060
    'title' => 'Layout',
1061
    'description' => 'Configure and adjust the layout of your DataPortal ',
1062
    'access arguments' => array('administer cdm_dataportal'),
1063
    'page callback' => 'drupal_get_form',
1064
    'page arguments' => array('cdm_settings_layout'),
1065
    'weight' => 2,
1066
    'type' => MENU_LOCAL_TASK,
1067
  );
1068

    
1069
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
1070
    'title' => 'Taxon page',
1071
    'description' => 'Configure and adjust the layout of your DataPortal ',
1072
    'access arguments' => array('administer cdm_dataportal'),
1073
    'page callback' => 'drupal_get_form',
1074
    'page arguments' => array('cdm_settings_layout_taxon'),
1075
    'weight' => 1,
1076
    'type' => MENU_LOCAL_TASK,
1077
  );
1078
  $items['admin/config/cdm_dataportal/settings/layout/name-page'] = array(
1079
    'title' => 'Name page',
1080
    'description' => 'Configure and adjust the layout of your DataPortal ',
1081
    'access arguments' => array('administer cdm_dataportal'),
1082
    'page callback' => 'drupal_get_form',
1083
    'page arguments' => array('cdm_settings_layout_name_page'),
1084
    'weight' => 1,
1085
    'type' => MENU_LOCAL_TASK,
1086
  );
1087
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1088
    'title' => 'Search',
1089
    'description' => 'Configure and adjust the layout of your DataPortal ',
1090
    'access arguments' => array('administer cdm_dataportal'),
1091
    'page callback' => 'drupal_get_form',
1092
    'page arguments' => array('cdm_settings_layout_search'),
1093
    'weight' => 2,
1094
    'type' => MENU_LOCAL_TASK,
1095
  );
1096

    
1097
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1098
    'title' => 'Media',
1099
    'description' => 'Configure and adjust the layout of your DataPortal ',
1100
    'access arguments' => array('administer cdm_dataportal'),
1101
    'page callback' => 'drupal_get_form',
1102
    'page arguments' => array('cdm_settings_layout_media'),
1103
    'weight' => 3,
1104
    'type' => MENU_LOCAL_TASK,
1105
  );
1106

    
1107
}
1108

    
1109
/**
1110
 * @todo document this function.
1111
 */
1112
function cdm_help_general_cache() {
1113
  $form = array();
1114
  $form['cache_help'] = array(
1115
    '#type' => 'fieldset',
1116
    '#title' => t('Help'),
1117
    '#collapsible' => TRUE,
1118
    '#collapsed' => TRUE,
1119
  );
1120
  $form['cache_help']['test'] = array('#value' => t('probando'));
1121
  return drupal_render($form);
1122
  $res = array();
1123
  $res['default'] = drupal_render($help);
1124
  return $res;
1125
}
1126

    
1127
/**
1128
 * Configures the settings form for the CDM-API module.
1129
 *
1130
 * @return array
1131
 *   Drupal settings form.
1132
 */
1133
function cdm_settings_general() {
1134

    
1135
  $form['cdm_webservice'] = array(
1136
    '#type' => 'fieldset',
1137
    '#title' => t('CDM Server'),
1138
    '#collapsible' => FALSE,
1139
    '#collapsed' => FALSE,
1140
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1141
        CDM data base to the web via RESTful web services and thus is the source of the data
1142
        to be displayed by a CDM DataPotal.'),
1143
  );
1144

    
1145
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1146
    '#type' => 'textfield',
1147
    '#title' => t('CDM web service URL') . ':',
1148
    '#description' => t('This is the URL to the CDM-Server exposing your data
1149
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1150
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1151
  );
1152

    
1153
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1154
    '#type' => 'markup',
1155
    '#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')
1156
      . ' visible only for administrators',
1157
  );
1158

    
1159
  $form['cdm_webservice']['freetext_index'] = array(
1160
    '#type' => 'fieldset',
1161
    '#title' => t('Freetext index'),
1162
    '#collapsible' => FALSE,
1163
    '#collapsed' => FALSE,
1164
  );
1165

    
1166
  // Check the cdmserver port number and display a waring if it is not port 80
1167
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1168
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1169
    $form['cdm_webservice']['freetext_index']['message'] = array(
1170
      '#markup' => "<div class=\"description\">"
1171
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1172
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1173
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1174
          array('!port' => $portNumberMatch[1][0])
1175
        )
1176
      . "</div>",
1177
    );
1178
  };
1179

    
1180
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1181
  $trigger_link_options = array(
1182
    'attributes' => array(
1183
      'class' => 'index-trigger'
1184
    ),
1185
  );
1186
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1187
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1188
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1189
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1190
      ))
1191
    . '<div id="index-progress"></div></div>',
1192
  );
1193

    
1194
  $form['cdm_webservice']['freetext_index']['cdm_login'] = array(
1195
    // this must not be stored, it is only used by the _add_js_cdm_ws_progressbar
1196
    '#type' => 'textfield',
1197
    '#title' => t('Login'),
1198
    '#description' => t('Your cdm user credentials in the following form: <code>user:password</code>')
1199
  );
1200
  drupal_add_js('
1201
        jQuery(document).ready(function() {
1202
             jQuery("#edit-cdm-login").change(function (e) {
1203
                var login = jQuery(e.target).val();
1204
                jQuery("#edit-freetext-index .index-trigger").each(function(index){
1205
                   var url = jQuery(this).attr("href");
1206
                   url = url.replace(/:\/\/[^@]+@|:\/\//, "://" + login + "@");
1207
                   jQuery(this).attr("href", url);
1208
                });
1209
            });
1210
        });
1211
      ',
1212
    array(
1213
      'type' => 'inline',
1214
      'scope' => 'footer'
1215
    )
1216
  );
1217
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1218

    
1219
  $form['cdm_webservice']['proxy'] = array(
1220
    '#type' => 'fieldset',
1221
    '#title' => t('Proxy'),
1222
    '#collapsible' => TRUE,
1223
    '#collapsed' => TRUE,
1224
  );
1225

    
1226
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1227
    '#type' => 'textfield',
1228
    '#title' => t('Proxy URL') . ':',
1229
    '#description' => t('If this proxy url is set the cdm api tries
1230
    to connect the web service over the given proxy server.
1231
    Otherwise proxy usage is deactivated.'),
1232
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1233
  );
1234

    
1235
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1236
    '#type' => 'textfield',
1237
    '#title' => t('Proxy port') . ':',
1238
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1239
  );
1240

    
1241
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1242
    '#type' => 'textfield',
1243
    '#title' => t('Login') . ':',
1244
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1245
  );
1246

    
1247
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1248
    '#type' => 'textfield',
1249
    '#title' => t('Password') . ':',
1250
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1251
  );
1252

    
1253
  $form['sub_tree_filter'] = array(
1254
    '#type' => 'fieldset',
1255
    '#title' => t('Subtree filter'),
1256
    '#collapsible' => FALSE,
1257
    '#collapsed' => TRUE,
1258
    '#description' => t('The Data Portal can be restricted to the taxa which belong to a specific classification subtree. Other taxa will not be shown or accessible otherwise.'),
1259
  );
1260

    
1261
  $sub_tree_filter_uuid_value = variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE);
1262
  $taxon_node_info = '';
1263
  if($sub_tree_filter_uuid_value){
1264
    $taxon_node_dto = cdm_ws_get(CDM_WS_TAXONNODE, array($sub_tree_filter_uuid_value));
1265
    if($taxon_node_dto){
1266
      $taxon_node_info = " Current taxon node: <strong>" . cdm_tagged_text_to_markup($taxon_node_dto->taggedTitle) . " [" . $taxon_node_dto->treeIndex . "]</strong>";
1267
    }
1268
  }
1269
  $form['sub_tree_filter'][CDM_SUB_TREE_FILTER_UUID] = array(
1270
    '#type' => 'textfield',
1271
    '#title' => t('Taxon Node UUID') . ':',
1272
    '#default_value' => variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE),
1273
    '#description' => "The uuid of the TaxonNode entity to be used as filter." . $taxon_node_info
1274
  );
1275

    
1276
  // TODO: settings are still incomplete, compare with
1277
  // trunk/dataportal/inc/config_default.php.inc.
1278
  $form['taxon_tree'] = array(
1279
    '#type' => 'fieldset',
1280
    '#title' => t('Taxon Tree'),
1281
    '#collapsible' => FALSE,
1282
    '#collapsed' => TRUE,
1283
    '#description' => t('<p>When you explore your collection, you can navigate
1284
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1285
      able to navigate through your collection the
1286
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1287
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1288
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1289
      </a></p>'),
1290
  );
1291

    
1292
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1293
    '#type' => 'select',
1294
    '#title' => t('Default classification') . ':',
1295
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1296
    '#options' => cdm_get_taxontrees_as_options(),
1297
    '#description' => t('The default taxa classification to be used in the whole portal. 
1298
      This affects most obviously the classification browser and the search in case it is restricted 
1299
      to a specific classification. See also <i>Included Classifications</i> below.'),
1300
  );
1301

    
1302
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1303
    '#type' => 'select',
1304
    '#title' => t('Rank of highest displayed taxon') . ':',
1305
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1306
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1307
    '#options' => cdm_vocabulary_as_option(UUID_RANK, null, true),
1308
    '#description' => t('This is the rank of the highest displayed taxon in the
1309
      <em>taxon tree</em>. You can select here which rank should be at the top
1310
      level of the tree structure.'),
1311
  );
1312

    
1313
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1314
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1315
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1316
      '#type' => 'checkboxes',
1317
      '#title' => t('Included Classifications') . ':',
1318
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1319
      '#options' => cdm_get_taxontrees_as_options(),
1320
      '#description' => t('Only the checked classifications will be available in the classification chooser.'),
1321
  );
1322

    
1323
  $form['distribution'] = array(
1324
      '#type' => 'fieldset',
1325
      '#title' => t('Distributions'),
1326
      '#collapsible' => FALSE,
1327
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1328
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1329
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1330
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1331
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1332
          '<p>
1333
          </p>',
1334
  );
1335

    
1336
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1337
      '#type' => 'fieldset',
1338
      '#title' => 'Distribution filter',
1339
      '#collapsible' => FALSE,
1340
      '#collapsed' => FALSE,
1341
      '#tree' => TRUE,
1342
      '#description' => 'The Distribution filter offers the following options
1343
      <ul>
1344
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1345
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1346
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1347
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1348
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1349
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1350
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1351
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1352
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1353
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1354
      </ul>'
1355
  );
1356

    
1357
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1358
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1359
      '#type' => 'checkboxes',
1360
      '#title' => 'Filter rules',
1361
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1362
      '#options' => array(
1363
          'statusOrderPreference' => 'Status order preference rule',
1364
          'subAreaPreference' => 'Sub area preference rule'
1365
      ),
1366
  );
1367

    
1368
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1369
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1370
      '#type' => 'checkboxes',
1371
      '#title' => 'Hide marked area filter',
1372
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1373
      '#options' => $marker_type_options,
1374
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1375
  );
1376

    
1377
  $form['aggregation'] = array(
1378
      '#type' => 'fieldset',
1379
      '#title' => t('Aggregation of data'),
1380
      '#collapsible' => FALSE,
1381
      '#description' => 'This section covers the different aspects of aggregating information.
1382
          <p>
1383
          </p>',
1384
  );
1385

    
1386
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1387
      '#type' => 'checkboxes',
1388
      '#title' => 'Taxon media filter',
1389
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1390
      '#options' => array(
1391
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1392
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1393
          'includeOccurrences' => 'Media related to specimens and occurrences',
1394
      ),
1395
      '#description' => 'This filter configures which images should be taken into account.',
1396
  );
1397

    
1398
  $form['aggregation']['notice'] = array(
1399
      '#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
1400
          want to make use of the caching capabilities of the dataportal.',
1401
  );
1402

    
1403
  $form['aggregation']['media_aggregation'] = array(
1404
      '#type' => 'fieldset',
1405
      '#title' => t('Media aggregation'),
1406
      '#collapsible' => FALSE,
1407
      '#collapsed' => TRUE,
1408
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1409

    
1410
  );
1411
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1412
      '#type' => 'select',
1413
      '#title' => t('Aggregation of taxon pictures') . ':',
1414
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1415
      '#options' => array(
1416
          0 => "Show only pictures of the current taxon",
1417
          1 => "Include pictures of taxonomic children",
1418
      ),
1419
      '#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."),
1420
  );
1421

    
1422
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1423
      '#type' => 'fieldset',
1424
      '#attributes' => array('class' => array('clearfix')),
1425
      '#title' => t('Aggregation via taxon relationsships'),
1426
      '#collapsible' => TRUE,
1427
      '#collapsed' => TRUE,
1428
      '#tree' => TRUE,
1429
      '#description' => t('Information on taxa will be aggregated along the below chosen
1430
          taxon relation ships. This will affect images and occurrences (specimens).
1431
          Taxon relation ships are directed and point form one taxon to another. The taxon
1432
          relationships to be taken into accunt can therefore configured for the direct direction
1433
          and for the inverse.'),
1434
  );
1435

    
1436
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1437
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1438

    
1439
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1440
      '#type' => 'checkboxes',
1441
      '#title' => t('Direct'),
1442
      '#options' => $taxonRelationshipTypeOptions,
1443
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1444
  );
1445
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1446
      '#type' => 'checkboxes',
1447
      '#title' => t('Invers'),
1448
      '#options' => $taxonRelationshipTypeOptions,
1449
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1450
  );
1451

    
1452
  $form['drupal_integration'] = array(
1453
    '#type' => 'fieldset',
1454
    '#attributes' => array('class'=> array('clearfix')),
1455
    '#title' => t('Drupal integration'),
1456
    '#collapsible' => FALSE,
1457
    '#collapsed' => FALSE,
1458
    '#tree' => FALSE
1459
  );
1460

    
1461
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1462
    '#type' => 'checkbox',
1463
    '#title' => 'Create drupal nodes',
1464
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1465
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1466
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1467
    cdm pages it is required that drupal nodes are created and stored in the database.'
1468
  );
1469

    
1470

    
1471

    
1472
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1473
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1474
    <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>',
1475
  );
1476
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1477
    '#type' => 'submit',
1478
    '#value' => t('Drop all cdm nodes'),
1479
    '#submit' => array('drop_all_cdm_nodes_submit')
1480
  );
1481

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

    
1486
    // ----------------------
1487
  $form['cdm_js_devel_mode'] = array(
1488
      '#type' => 'checkbox',
1489
      '#title' => 'Java-script developer mode',
1490
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1491
      '#description' => 'In production envirionments the java script libraries
1492
      the cdm_dataportal is making use of are compressed and optimized. This
1493
      is good for performance but a caveat if you need to debug java-script. When the
1494
      java-script developer mode is enabled the uncompressed and commented developer
1495
      versions of java-script libraries will be used where possible.
1496
      <br/><strong>Do not use this option in production!</strong>'
1497
  );
1498
  // ----------------------
1499
  $form['cdm_debug_mode'] = array(
1500
      '#type' => 'checkbox',
1501
      '#title' => 'CDM page debug mode',
1502
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1503
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1504
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1505
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1506
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1507
      The log is written by the drupal devel module function <code>dd()</code>.
1508
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1509
  );
1510

    
1511
  // Comment @WA: D7 form api does not support reset buttons,
1512
  // so to mimic the D5 reset button we add one like this.
1513
  $form['actions']['reset'] = array(
1514
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1515
    '#weight' => 1000,
1516
  );
1517

    
1518
  $form['#submit'][] = 'cdm_settings_general_submit';
1519

    
1520
  return system_settings_form($form);
1521
}
1522

    
1523
/**
1524
 * Submit callback; drops all cdm nodes.
1525
 *
1526
 * @ingroup forms
1527
 */
1528
function drop_all_cdm_nodes_submit($form, &$form_state) {
1529
  cdm_delete_all_cdm_nodes();
1530
  drupal_set_message(t('All cdm nodes dropped.'));
1531
}
1532

    
1533

    
1534
/**
1535
 * LAYOUT settings
1536
 *
1537
 * @return array
1538
 *   The form structure.
1539
 */
1540
function cdm_settings_layout() {
1541

    
1542
  $form = array();
1543

    
1544
  $form['about'] = array(
1545
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1546
      layout. If you want to configure the specific sites layout visit the
1547
      respective configuration site for taxon, search or media.') . '</p>',
1548
  );
1549

    
1550
  // ---- footnotes --- //
1551
  $form['footnotes'] = array(
1552
    '#type' => 'fieldset',
1553
    '#title' => t('Footnotes'),
1554
    '#collapsible' => FALSE,
1555
    '#collapsed' => FALSE,
1556
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1557
      media or distribution areas may have annotations or footnotes. When the
1558
      footnotes are enabled they will be visible (if they exist).'),
1559
  );
1560

    
1561
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1562
    '#type' => 'checkbox',
1563
    '#title' => t('Do not show footnotes'),
1564
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1565
    '#description' => t('Check this if you do not want to show any footnotes'),
1566
  );
1567

    
1568
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1569
    '#type' => 'checkbox',
1570
    '#title' => t('Do not show annotation footnotes'),
1571
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1572
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1573
  );
1574

    
1575
  $form['annotations'] = array(
1576
    '#type' => 'fieldset',
1577
    '#title' => t('Annotations'),
1578
    '#collapsible' => FALSE,
1579
    '#collapsed' => FALSE,
1580
    '#description' => t('This sections allows configuring global settings regarding annotations and thus will affect annotations dispayed as footnote and others.'),
1581
  );
1582

    
1583
  $annotation_type_options = cdm_terms_by_type_as_option('AnnotationType');
1584
  // Additional option for the NULL case.
1585
  $annotation_type_options['NULL_VALUE'] = t('untyped');
1586
  $annotations_types_visible = variable_get(ANNOTATION_TYPES_VISIBLE, unserialize(EXTENSION_TYPES_VISIBLE_DEFAULT));
1587
  $form['annotations'][ANNOTATION_TYPES_VISIBLE] = array(
1588
    '#type' => 'checkboxes',
1589
    '#title' => t('Visbility of annotation types'),
1590
    '#description' => t("Only annotations of the selected type will be displayed. You may want to turn 'technical annotations' off."),
1591
    '#options' => $annotation_type_options,
1592
    '#default_value' => $annotations_types_visible
1593
  );
1594

    
1595
  $form['extensions'] = array(
1596
    '#type' => 'fieldset',
1597
    '#title' => t('Extensions'),
1598
    '#collapsible' => FALSE,
1599
    '#collapsed' => FALSE,
1600
    '#description' => t('This sections allows configuring global settings regarding the data type extensions.'),
1601
  );
1602

    
1603
  $extension_type_options = cdm_terms_by_type_as_option('ExtensionType');
1604
  $extension_types_visible = variable_get(EXTENSION_TYPES_VISIBLE, unserialize(EXTENSION_TYPES_VISIBLE_DEFAULT));
1605
  $form['extensions'][EXTENSION_TYPES_VISIBLE] = array(
1606
    '#type' => 'checkboxes',
1607
    '#title' => t('Visbility of extension types'),
1608
    '#description' => t("Only extensions of the selected type will be displayed."),
1609
    '#options' => $extension_type_options,
1610
    '#default_value' => $extension_types_visible
1611
  );
1612

    
1613

    
1614
  // ---- original source --- //
1615
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1616
      '#type' => 'fieldset',
1617
      '#tree' => TRUE,
1618
      '#title' => t('Source Citations'),
1619
      '#collapsible' => FALSE,
1620
      '#collapsed' => FALSE,
1621
  );
1622

    
1623
  $bibliography_settings = get_bibliography_settings(true);
1624

    
1625
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1626
      '#type' => 'checkbox',
1627
      '#title' => t('Original Source in bibliography'),
1628
      '#default_value' => $bibliography_settings['enabled'],
1629
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1630
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1631
       into the bibliography also depends on the settings in the ' .
1632
        l("Taxon profile feature block settings", "admin/config/cdm_dataportal/settings/layout/taxon") .
1633
        '. 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.'),
1634
  );
1635

    
1636
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1637
    '#type' => 'select',
1638
    '#title' => t('The format of the key numerals'),
1639
    '#default_value' => $bibliography_settings['key_format'],
1640
    '#options' => array('latin' => 'Latin',
1641
      'ROMAN' => 'Roman (upper case)',
1642
      'roman' => 'Roman (lower case)',
1643
      'ALPHA'=> 'Alphabet (upper case)',
1644
      'alpha' => 'Alphabet (lower case)')
1645
  );
1646

    
1647
  // --- Advanced Search --- //
1648
  $form['asearch'] = array(
1649
      '#type' => 'fieldset',
1650
      '#title' => t('Advanced search'),
1651
      '#collapsible' => FALSE,
1652
      '#collapsed' => FALSE,
1653
  );
1654
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1655
      '#type' => 'checkbox',
1656
      '#title' => t('Show advanced search link'),
1657
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1658
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1659
  );
1660

    
1661
  // --- Name page autoredirect feature --- //
1662
  $form['name_page'] = array(
1663
    '#type' => 'fieldset',
1664
    '#title' => t('Name page'),
1665
    '#collapsible' => FALSE,
1666
    '#collapsed' => FALSE,
1667
  );
1668
  $form['name_page'][CDM_NAME_PAGE_AUTOREDIRECT] = array(
1669
    '#type' => 'checkbox',
1670
    '#title' => 'Always redirect to taxon',
1671
    '#default_value' => variable_get(CDM_NAME_PAGE_AUTOREDIRECT, 0),
1672
    '#description' => t('By checking this option you can globally enable the redirection behavior of the name page. 
1673
    Depending on the context from which a user navigates to the name page the data portal chooses to show the name page or it redirects to the related taxon if there is only one. 
1674
    This option allows to enable this behavior also for contexts in which the redirection normally is not active.'),
1675
  );
1676

    
1677
  // --- Registrations --- //
1678
  $form['registrations'] = array(
1679
    '#type' => 'fieldset',
1680
    '#title' => t('Registrations'),
1681
    '#collapsible' => FALSE,
1682
    '#collapsed' => FALSE,
1683
  );
1684
  $form['registrations']['cdm_registration_presistent_identifier_as_link'] = array(
1685
    '#type' => 'checkbox',
1686
    '#title' => t('Use the persistent http identifier as link'),
1687
    '#default_value' => variable_get('cdm_registration_presistent_identifier_as_link', 0),
1688
    '#description' => t('Switch the portal from using the drupal path <code>registration/{url encoded persistent http identifier}</code> to using the persistent http identifier directly as link.'),
1689
  );
1690

    
1691
  // ---- Taxon Name Rendering --- //
1692
  $form['taxon_name'] = array(
1693
      '#type' => 'fieldset',
1694
      '#title' => t('Taxon name display'),
1695
      '#collapsible' => TRUE,
1696
      '#collapsed' => TRUE,
1697
      '#description' => t('The display of taxon names is configured by two parts.
1698
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1699
          The name parts are defined in the <stong>part definitions</strong>'),
1700
  );
1701

    
1702
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1703
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1704
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1705
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1706

    
1707
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1708
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1709
    $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.)';
1710
  } else if($is_custom_part_definition){
1711
      $which_version_message = '(This are custom part definitions, 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 part definition.)';
1714
  }
1715

    
1716
  $diff_viewer_markup = '';
1717
  if($is_custom_part_definition){
1718
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_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_PART_DEFINITIONS] = array(
1727
      '#type' => 'textarea',
1728
      '#title' => t('Part definitions'),
1729
      '#element_validate' => array('form_element_validate_json'),
1730
      '#default_value' =>  $current_part_definition_json,
1731
      '#description' => '
1732
          <p>' . $which_version_message . '</p>
1733
          <p>
1734
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1735
          </p>
1736
          <p>
1737
           A full taxon name plus additional information can consist of the following elements:
1738
          <ul>
1739
             <li>name: the taxon name inclugin rank nbut without author</li>
1740
             <li>authors:  The authors of a reference, also used in taxon names</li>
1741
             <li>reference: the nomenclatural reference,</li>
1742
             <li>microreference:  Volume, page number etc.</li>
1743
             <li>status:  The nomenclatural status of a name</li>
1744
             <li>description: name descriptions like protologues etc ...</li>
1745
          </ul>
1746
          </p>
1747
          <p>
1748
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1749
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1750
           The following parts can be formed and are recognized by the system:
1751
          <ul>
1752
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1753
            <li>authorshipPart: the author (for example: "L.")</li>
1754
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1755
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1756
               be combined when a link to the taxon is rendered.</li>
1757
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1758
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1759
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1760
            <li>statusPart: the nomenclatorical status</li>
1761
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1762
          </ul>
1763
          </p>
1764
          <p>
1765
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1766
           specific parts part definitions:
1767
          <ul>
1768
            <li>BotanicalName</li>
1769
            <li>ZoologicalName</li>
1770
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1771
          </ul>
1772
           An example:
1773
          <pre>
1774
           {
1775
            "ZoologicalName": {
1776
              "namePart": {
1777
                "name": true
1778
              },
1779
              "referencePart": {
1780
                "authors": true
1781
              },
1782
              "microreferencePart": {
1783
                "microreference": true
1784
              },
1785
              "statusPart": {
1786
                "status": true
1787
              },
1788
              "descriptionPart": {
1789
                "description": true
1790
              }
1791
            },
1792
            "BotanicalName": {
1793
              "namePart": {
1794
                "name": true,
1795
                "authors": true
1796
              },
1797
              "referencePart": {
1798
                "reference": true,
1799
                "microreference": true
1800
              },
1801
              "secReferencePart": {
1802
                "secReference": true
1803
              },
1804
              "statusPart": {
1805
                "status": true
1806
              },
1807
              "descriptionPart": {
1808
                "description": true
1809
              }
1810
            }
1811
          }
1812
           </pre>',
1813
  );
1814

    
1815
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1816
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1817
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1818
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1819
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1820

    
1821
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1822
    $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.)';
1823
  } else if($is_custom_render_template){
1824
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1825
  } else {
1826
    $which_version_message = '(These are the default render templates.)';
1827
  }
1828

    
1829
  $diff_viewer_markup = '';
1830
  if($is_custom_render_template){
1831
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1832
  }
1833

    
1834
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1835
    . $which_version_message
1836
    . '</div>'
1837
    . $diff_viewer_markup;
1838

    
1839
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1840
      '#type' => 'textarea',
1841
      '#title' => t('Name render templates'),
1842
      '#element_validate' => array('form_element_validate_json'),
1843
      '#default_value' =>  $current_render_templates_json,
1844
      '#description' => '
1845
          <p>' . $which_version_message . '</p>
1846
          <p>
1847
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1848
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1849
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1850
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1851
          The following render Path keys are currently recognized:
1852
          <ul>
1853
            <li>list_of_taxa</li>
1854
            <li>acceptedFor</li>
1855
            <li>homonym</li>
1856
            <li>taxon_page_synonymy</li>
1857
            <li>typedesignations</li>
1858
            <li>taxon_page_title</li>
1859
            <li>polytomousKey</li>
1860
            <li>na: name + authorship</li>
1861
            <li>nar:name + authorship + reference</li>
1862
            <li>#DEFAULT</li>
1863
          </ul>
1864
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1865
          array element should be a comma separated list of render paths, without any whitespace!.
1866
          </p>
1867
          <p>
1868
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1869
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1870
          <p>
1871
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1872
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1873
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1874
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1875
          links if the paramters $nameLink or $refenceLink are given to the name render function
1876
          (this is hard coded and cannot be configured here).',
1877
  );
1878

    
1879
  // @WA: D7 form api does not support reset buttons,
1880
  // so to mimic the D5 reset button we add one like this.
1881
  $form['actions']['reset'] = array(
1882
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1883
    '#weight' => 1000,
1884
  );
1885

    
1886
  $form['#submit'] = array('submit_json_as_php_array');
1887
  // #json_elements especially defined for submit_json_as_php_array()
1888
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1889
  return system_settings_form($form);
1890
}
1891

    
1892

    
1893
/**
1894
 * @param $form_name
1895
 * @param $form_title
1896
 * @param $collapsed
1897
 * @param string $form_description
1898
 *   The description for the fieldset of the gallery setting.
1899
 * @return mixed
1900
 */
1901
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1902
  $form[$form_name] = array(
1903
    '#type' => 'fieldset',
1904
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1905
    '#collapsible' => TRUE,
1906
    '#collapsed' => $collapsed,
1907
    '#tree' => TRUE,
1908
    '#description' => $form_description,
1909
  );
1910

    
1911
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1912
  $gallery_settings = variable_get($form_name, $default_values);
1913
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1914
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1915
    /*
1916
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1917
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1918
    '#type' => 'textfield',
1919
    '#title' => t('Search Page Size'),
1920
    '#default_value' => $test,
1921
    '#description' => t('Number of Names to display per page in search results.')
1922
    );
1923
    */
1924
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1925
      '#type' => 'checkbox',
1926
      '#title' => t('Show media thumbnails for accepted taxa'),
1927
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1928
    );
1929

    
1930
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1931
      '#type' => 'checkbox',
1932
      '#title' => t('Show media thumbnails for synonyms'),
1933
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1934
      '#description' => '',
1935
    );
1936
  }
1937

    
1938
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1939
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1940
    '#type' => 'checkbox',
1941
    '#title' => t('Show captions under thumbnails'),
1942
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1943
    '#description' => '',
1944
  );
1945

    
1946
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1947
    '#type' => 'textfield',
1948
    '#title' => t('Thumbnail size (max of width or height)') . ':',
1949
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1950
    '#description' => t('The maximum extend in either dimension, width or height, in pixels for the thumbnail images in the gallery.'),
1951
  );
1952

    
1953
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1954
    '#type' => 'textfield',
1955
    '#title' => t('Number of columns') . ':',
1956
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1957
    '#description' => t('Group the thumbnails in columns: select how many
1958
      columns the gallery should display.'),
1959
  );
1960

    
1961
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1962
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1963
      '#type' => 'textfield',
1964
      '#title' => t('Maximum number of rows') . ':',
1965
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1966
      '#description' => t('You can group the thumbnails in rows, select in how
1967
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1968
        If you want an unlimited number of rows please set to 0.'),
1969
    );
1970
  }
1971

    
1972
  return $form;
1973
}
1974

    
1975
/**
1976
 * @return array
1977
 *   The form structure.
1978
 */
1979
function cdm_settings_layout_taxon() {
1980
  $collapsed = FALSE;
1981
  $form = array();
1982

    
1983
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1984

    
1985
  // --------- TABBED TAXON ------- //
1986
  $form['taxon_node'] = array(
1987
    '#type' => 'fieldset',
1988
    '#title' => t('Taxon node'),
1989
    '#collapsible' => TRUE,
1990
    '#collapsed' => TRUE,
1991
    '#description' => 'Taxa are organized in a classification tree by taxon nodes. Display of taxon node related information like states can be manged here.'
1992
  );
1993
  $form['taxon_node'][CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES] = array(
1994
    '#type' => 'checkbox',
1995
    '#title' => t('Show taxon node states'),
1996
    '#default_value' => variable_get(CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES, 1),
1997
    '#description' => t('Show the taxon node states excluded, unplaced and placement doubtful.'),
1998
  );
1999

    
2000
  // --------- TABBED TAXON ------- //
2001
  $form['taxon_tabs'] = array(
2002
    '#type' => 'fieldset',
2003
    '#title' => t('Taxon tabs'),
2004
    '#collapsible' => TRUE,
2005
    '#collapsed' => TRUE,
2006
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
2007
  );
2008

    
2009
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
2010
    '#type' => 'checkbox',
2011
    '#title' => t('Tabbed taxon page'),
2012
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
2013
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
2014
  );
2015

    
2016
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
2017
    '#type' => 'checkbox',
2018
    '#title' => t('Synonymy as tab'),
2019
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
2020
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
2021
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
2022
  );
2023

    
2024
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
2025
    '#type' => 'checkboxes',
2026
    '#title' => t('Section/Tab visibility') . ':',
2027
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
2028
    '#options' => get_taxon_options_list()
2029
  );
2030

    
2031
  // WEIGHT
2032
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
2033
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
2034
    '#title'  => 'Section/Tab order',
2035
    '#type' => 'fieldset',
2036
    '#collapsible' => false,
2037
    '#tree' => true,
2038
    '#description' => 'The weight value defines the order of the section/tab.'
2039
  );
2040
  // Weights range from -delta to +delta, so delta should be at least half
2041
  // of the amount of tabs present.
2042
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
2043
  foreach (get_taxon_tabs_list() as $label) {
2044
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
2045
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
2046
        '#title' => $label,
2047
        '#type'  => 'weight',
2048
        '#default_value' => $taxon_tabs_weights[$key],
2049
        '#delta' => $tab_weight_delta
2050
    );
2051
  }
2052

    
2053
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
2054
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
2055
    '#title'  => 'Section/Tab label override',
2056
    '#type' => 'fieldset',
2057
    '#collapsible' => false,
2058
    '#tree' => true,
2059
    '#description' => 'Setting a label for a section/tab will override the default label. 
2060
      Please enter the label text in the default language of the portal.'
2061
  );
2062
  foreach (get_taxon_tabs_list() as $label) {
2063
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
2064
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
2065
      '#title' => $label,
2066
      '#type'  => 'textfield',
2067
      '#default_value' => $taxon_tabs_labels[$key]
2068
    );
2069
  }
2070

    
2071
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
2072
    '#type' => 'select',
2073
    '#title' => t('Default tab to display') . ':',
2074
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
2075
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
2076
    '#description' => t('<p>Select the default tab to display when visiting a
2077
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
2078
      <strong>Note:</strong> After performing a search and clicking in any
2079
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
2080
      taxon and not the above selected tab.'),
2081
  );
2082

    
2083
  /* ======  TAXON_PROFILE ====== */
2084
  $form['taxon_profile'] = array(
2085
    '#type' => 'fieldset',
2086
    '#title' => t('Taxon profile (tab)'),
2087
    '#description' => t('<p>This section covers the settings related to the taxon
2088
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
2089
    '#collapsible' => TRUE,
2090
    '#collapsed' => TRUE,
2091
  );
2092

    
2093
  // ---- PROFILE PICTURE ----//
2094

    
2095
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
2096
    '#type' => 'fieldset',
2097
    '#tree' => TRUE,
2098
    '#title' => t('Taxon profile picture'),
2099
    '#collapsible' => TRUE,
2100
    '#collapsed' => FALSE,
2101
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
2102
  );
2103

    
2104
  //FIXME migrate variables:
2105
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
2106
  // FIXME
2107
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
2108

    
2109
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
2110

    
2111
  /*
2112
   * 'show' => 1,
2113
   * 'maxextend' => 184,
2114
   * 'media_uri_query' => ''
2115
   * 'custom_placeholder_image_on' => 1,
2116
   * 'custom_placeholder_image_fid' => ''
2117
   */
2118
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
2119
    '#type' => 'checkbox',
2120
    '#title' => t('Enable profile picture'),
2121
    '#description' => t('Show the profile picture.'),
2122
    '#default_value' => $taxon_profile_image_settings['show'],
2123
  );
2124

    
2125
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
2126
      '#type' => 'textfield',
2127
      '#tree' => TRUE,
2128
      '#title' => t('Profile picture maximum extend'),
2129
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
2130
      '#field_suffix' => 'px',
2131
      '#maxlength' => 4,
2132
      '#size' => 4,
2133
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
2134
  );
2135

    
2136
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
2137
      '#type' => 'textfield',
2138
      '#tree' => TRUE,
2139
      '#title' => t('Additional URI query parameter'),
2140
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
2141
      '#maxlength' => 1024,
2142
      '#size' => 60,
2143
      '#description' => t('Additional query parameters to be used when requesting for the  
2144
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
2145
            The query parameters will be appended to the uri of the media representation part
2146
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
2147
  );
2148

    
2149
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2150
    '#type' => 'checkbox',
2151
    '#title' => t('Show the placeholder image'),
2152
    '#description' => t("A placeholder image will be shown if no taxon profile picture is available."),
2153
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2154
  );
2155

    
2156
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2157
      '#type' => 'checkbox',
2158
      '#title' => t('Use a custom placeholder image'),
2159
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2160
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2161
  );
2162

    
2163
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2164
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2165
        '#type' => 'managed_file',
2166
        '#title' => t('Custom placeholder image file'),
2167
        '#progress_indicator' => 'bar',
2168
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2169
    //       '#name' => 'custom_placeholder_image',
2170
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2171
    );
2172

    
2173
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2174
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2175
      $url = file_create_url($profile_image_file->uri);
2176
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2177
                '#type' => 'item',
2178
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2179
      );
2180
    }
2181
  } else {
2182
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2183
      '#type' => 'hidden',
2184
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2185
    );
2186
  }
2187

    
2188
  $options = cdm_vocabulary_as_option(UUID_RANK, null, true);
2189
  array_unshift($options, '-- DISABLED --');
2190
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2191
    '#type' => 'select',
2192
    '#title' => t('Hide profile picture for higher ranks') . ':',
2193
    '#default_value' => variable_get('image_hide_rank', '0'),
2194
    '#options' => $options,
2195
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2196
  );
2197

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

    
2204
  // ---- FEATURE TREE BLOCKS ---- //
2205
  $form['taxon_profile']['feature_blocks'] = array(
2206
    '#type' => 'fieldset',
2207
    '#title' => t('Feature Blocks'),
2208
    '#collapsible' => TRUE,
2209
    '#collapsed' => FALSE,
2210
    '#description' => t("This section covers settings related to the taxon's
2211
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2212
      features such as description, distribution, common names"),
2213
  );
2214
  $featureTrees = cdm_get_featureTrees_as_options(TRUE, TRUE);
2215
  $profile_feature_tree = get_profile_feature_tree();
2216
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2217
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2218
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2219
  }
2220
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2221
    '#type' => 'radios',
2222
    '#title' => t('Taxon profile feature tree') . ':',
2223
    '#default_value' => $profile_feature_tree_uuid,
2224
    '#options' =>  $featureTrees['options'],
2225
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2226
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2227
    '#description' => t('The Feature Tree selected defines the type and order 
2228
    of the according feature blocks visible in the taxon profile page. A feature block 
2229
    only is shown if any data for it is present. The block weight is shown after the feature label in brackets'
2230
    ),
2231
  );
2232

    
2233
  $pseudo_feature_weights = get_array_variable_merged(CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS, CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT);
2234
  $form['taxon_profile']['feature_blocks'][CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS] = array(
2235
    '#title'  => 'Pseudo feature block weight',
2236
    '#type' => 'fieldset',
2237
    '#collapsible' => false,
2238
    '#tree' => true,
2239
    '#description' => 'Weights for the pseudo feature blocks. The weight value defines the 
2240
    position in the list of blocks. The weight of normal feature is defined by the position 
2241
    of the according feature. Please see the specific feature details above to find the feature weight.'
2242
  );
2243
  foreach ([PSEUDO_FEATURE_NUMBER_OF_TAXA, PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS, PSEUDO_FEATURE_BIBLIOGRAPHY] as $ps_feature) {
2244
    $form['taxon_profile']['feature_blocks'][CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS][$ps_feature] = array(
2245
      '#title' => $ps_feature,
2246
      '#type'  => 'textfield',
2247
      '#element_validate' => array('element_validate_number'),
2248
      '#size' => 4,
2249
      '#default_value' => $pseudo_feature_weights[$ps_feature]
2250
    );
2251
  }
2252

    
2253

    
2254
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2255
  $profile_feature_tree = get_profile_feature_tree();
2256

    
2257
  if (isset($profile_feature_tree->root->childNodes)) {
2258

    
2259
    $form_feature_block_layout = array(
2260
      '#type' => 'fieldset',
2261
      '#tree' => true,
2262
      '#title' => t('Taxon profile feature block settings'),
2263
      '#collapsible' => TRUE,
2264
      '#collapsed' => FALSE,
2265
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2266
      A sub form for each of the the currently selected feature tree allows to configure each feature block individually.
2267
      The subforms have the following settings in common:<br />
2268
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2269
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2270
      <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>
2271
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2272
            <ol>
2273
            <li>If the element is a CDM TextData instance and if the text is not empty the source references will be
2274
                appended in brackets like "text (source references)". If the original source has name in source
2275
                information it will be appended to the citation string,
2276
                like : "(citation-A, as name-in-source-A; citation-B, as name-in-source-B)"</li>
2277
             <li>if the text of the TextData is empty, the original source citations are the only content
2278
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2279
                prepended to the citation string like: "name in source: citation"</li>
2280
            </ol>
2281
            <strong>If disabled:</strong><br />
2282
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2283
             citations are the only content, the resulting feature block content would only consist of footnotes.
2284
             In this case the display of the respective feature block is suppressed.</div>
2285
      </dl>
2286
      <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
2287
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2288
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2289
        . '</em></div>
2290
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2291
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2292
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2293
      <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>
2294
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2295
           cdm_feature_block_element_tag_name()</div>
2296
       <h6>Element glue:</h6><div>This string is used to concatenate individual items together. The glue is ignored when the items are displayed 
2297
           as list.<b>NOTE:</b>The glue is not yet fully implemented for all features and thus may not work as expected, see '
2298
           . l('#6831', 'https://dev.e-taxonomy.eu/redmine/issues/6831') . '</div>',
2299
    );
2300

    
2301

    
2302
    $feature_list_layout_settings_disabled = FALSE;
2303

    
2304
    // creating helper object to retrieve the default settings
2305
    $featureNode = new stdClass();
2306
    $featureNode->term = new stdClass();
2307
    $featureNode->term->uuid="DEFAULT";
2308
    $featureNode->term->representation_L10n = "Default";
2309
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2310

    
2311
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2312

    
2313
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2314

    
2315
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2316
        $subform_id = $featureNode->term->uuid;
2317
        $feature_block_setting = get_feature_block_settings($featureNode->term->uuid);
2318

    
2319
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2320

    
2321
        $form_feature_block_layout[$subform_id] = array(
2322
          '#type' => 'fieldset',
2323
          '#tree' => TRUE,
2324
          '#title' => $featureNode->term->representation_L10n,
2325
          '#collapsible' => FALSE,
2326
          '#collapsed' => FALSE,
2327
        );
2328
        if($featureNode->term->uuid == "DEFAULT"){
2329
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2330
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2331
          references</em> and <em>names in source</em> is only possible in the defaults';
2332
        }
2333

    
2334
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2335
          '#type' => 'select',
2336
          '#title' => 'List type',
2337
          '#default_value' => $feature_block_setting['as_list'],
2338
          '#options' => array(
2339
            'div' => 'not as list',
2340
            'ul' => 'bullet list',
2341
            'ol' => 'numbered list',
2342
            'dl' => 'definition list'
2343
          ),
2344
        );
2345

    
2346
        if($featureNode->term->uuid == "DEFAULT"){
2347
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2348
            '#type' => 'checkbox',
2349
            '#title' => t('Link to reference'),
2350
            '#default_value' => $feature_block_setting['link_to_reference'],
2351
          );
2352

    
2353
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2354
            '#type' => 'checkbox',
2355
            '#title' => 'Link to name used in source',
2356
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2357
          );
2358
        }
2359

    
2360
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2361
          '#type' => 'checkbox',
2362
          '#title' => 'Sources as content',
2363
          '#default_value' => $feature_block_setting['sources_as_content'],
2364
        );
2365

    
2366
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2367
          '#type' => 'checkbox',
2368
          '#title' => 'Put sources also as content to bibliography',
2369
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2370
        );
2371

    
2372
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2373
          '#type' => 'select',
2374
          '#title' => t('Sort elements'),
2375
          '#default_value' => $feature_block_setting['sort_elements'],
2376
          '#options' => array(
2377
            NO_SORT => 'No sorting',
2378
            SORT_ASC => 'Ascending',
2379
            SORT_DESC => 'Descending',
2380
            SORT_HIERARCHICAL => 'Hierarchical'
2381
          ),
2382
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2383
          <dl>
2384
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2385
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2386
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2387
          <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>
2388
          </dl>',
2389
        );
2390

    
2391
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2392
          '#type' => 'select',
2393
          '#title' => t('Element tag'),
2394
          '#options' => array(
2395
            'span' => 'span',
2396
            'div' => 'div',
2397
            'p' => 'p'
2398
          ),
2399
          '#default_value' => $feature_block_setting['element_tag'],
2400
        );
2401
        $form_feature_block_layout[$subform_id]['glue'] = array(
2402
          '#type' => 'textfield',
2403
          '#title' => t('Element glue'),
2404
          '#default_value' => $feature_block_setting['glue'],
2405
          '#size' => 10
2406
      );
2407

    
2408
      }
2409
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2410
    }
2411
  }
2412

    
2413
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2414
  $form['taxon_profile']['structured_description_featuretree'] = array(
2415
    '#type' => 'fieldset',
2416
    '#title' => t('Structured Description Feature Tree'),
2417
    '#collapsible' => TRUE,
2418
    '#collapsed' => FALSE,
2419
  );
2420
  $featureTrees = cdm_get_featureTrees_as_options();
2421
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2422
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2423
    $profile_feature_tree_uuid = NULL;
2424
  }
2425
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2426
    '#type' => 'radios',
2427
    '#title' => t('Natural language representation of structured descriptions') . ':',
2428
    '#default_value' => $profile_feature_tree_uuid,
2429
    '#options' => $featureTrees['options'],
2430
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2431
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2432
    '#description' => t('Taxon descriptions can be stored in a highly structured
2433
      form. The feature tree selected here will be used to generate textual
2434
      representation in natural language.'
2435
    ),
2436
  );
2437

    
2438

    
2439

    
2440
  // ---- DISTRIBUTION LAYOUT ---- //
2441
  $form['taxon_profile']['distribution_layout'] = array(
2442
    '#title' => t('Distribution'),
2443
    '#collapsible' => TRUE,
2444
    '#collapsed' => FALSE,
2445
    '#type' => 'fieldset',
2446
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2447
        Map settings regarding the geometry, layers, etc are found in the '
2448
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2449
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2450
      . l(
2451
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2452
        array('fragment' => 'edit-feature-block-settings')
2453
      )
2454
      . ' More general settings regrading the filtering of Distributions are found at '
2455
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2456
      . '. (These settings here will be merged in future releases into the feature block settings)',
2457

    
2458
  );
2459

    
2460
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2461

    
2462
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2463
    '#type' => 'checkbox',
2464
    '#title' => t('Condensed distribution'),
2465
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2466
    '#description' => 'This option enables the display of a very compact representation
2467
    of the distribution which includes also information on the status.',
2468
  );
2469

    
2470
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2471
    '#type' => 'select',
2472
    '#title' => t('Condensed distribution recipe'),
2473
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2474
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2475
    '#description' => 'Recipe for creating the condensed distribution.',
2476
  );
2477

    
2478
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2479
    '#type' => 'textfield',
2480
    '#title' => t('Condensed distribution info path'),
2481
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2482
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2483
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2484
  );
2485

    
2486

    
2487
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2488
    '#type' => 'radios',
2489
    '#title' => t('Display mode') . ':',
2490
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2491
    '#options' => array(
2492
      'FLAT_ALPHA' => t('Flat list'),
2493
      'TREE' => t('Hierarchically ordered'),
2494
    ),
2495
    '#description' => 'Taxon distribution information is displayed with
2496
    focus on the area of the distribution. The list of areas can either be shown
2497
    as flat list ordered alphabetically or in the hierarchical of the parent
2498
    area and subarea relationship. Fall back areas areas with no Distribution data
2499
    are hidden from the area hierarchy so that their sub areas will move one level up.
2500
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2501
    ' for details on the <em>Marked area filter</em>.',
2502
  );
2503

    
2504
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2505
    '#type' => 'fieldset',
2506
    '#tree' => true,
2507
    '#title' => t('Distribution hierarchy style')
2508
  );
2509

    
2510
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2511
  foreach(array_keys($hierarchy_styles) as $level) {
2512
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2513
      '#type' => 'fieldset',
2514
      '#tree' => true,
2515
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2516
      '#attributes' => array('class' => array('fieldset-float'))
2517
    );
2518
    foreach ($hierarchy_styles[$level] as $key => $value) {
2519
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2520
        '#type' => 'textfield',
2521
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2522
        '#default_value' => $hierarchy_styles[$level][$key],
2523
        '#maxlength' => 4,
2524
        '#size' => 4
2525
      );
2526
    }
2527
  }
2528

    
2529
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2530
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2531
    '#type' => 'checkboxes',
2532
    '#title' => 'Omit area levels',
2533
    '#options' => $level_options,
2534
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2535
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2536
    Areas which belong to the selected area levels will be hidden in the portal.',
2537
  );
2538

    
2539
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2540
    '#type' => 'checkbox',
2541
    '#title' => t('Show TextData elements on top of the map'),
2542
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2543
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2544
      elements on top of the map. Otherwise all <code>TextData</code>
2545
      distribution elements will be listed below the other area elements.
2546
      This option is useful if you need to have descriptive texts for each
2547
      distribution map.'),
2548
  );
2549

    
2550
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2551
      '#type' => 'textarea',
2552
      '#title' => t('Custom status colors'),
2553
      '#element_validate' => array('form_element_validate_json'),
2554
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2555
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2556
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2557
          reference list of the idInVocabulary values of absence and presence terms:
2558
<pre>
2559
Presence Term
2560
p	present
2561
pd	present: doubtfully present
2562
n	native
2563
nq	native: presence questionable
2564
nd	native: doubtfully native
2565
c	cultivated
2566
i	introduced
2567
iq	introduced: presence questionable
2568
id	introduced: doubtfully introduced (perhaps cultivated only)
2569
ip	introduced: uncertain degree of naturalisation
2570
ia	introduced: adventitious (casual)
2571
in	introduced: naturalized
2572
ic	introduced: cultivated
2573
e	endemic for the relevant area
2574
na	naturalised
2575
iv	invasive
2576

    
2577
AbsenceTerm
2578
a	absent
2579
f	reported in error
2580
nf	native: reported in error
2581
if	introduced: reported in error
2582
cf	cultivated: reported in error
2583
ne	native: formerly native
2584
ie	introduced: formerly introduced
2585

    
2586
</pre>'),
2587
  );
2588

    
2589

    
2590
  /* ====== SYNONYMY ====== */
2591
  $form['taxon_synonymy'] = array(
2592
    '#type' => 'fieldset',
2593
    '#title' => t('Taxon synonymy (tab)'),
2594
    '#collapsible' => TRUE,
2595
    '#collapsed' => TRUE,
2596
    '#description' => t('This section covers the settings related to the taxon
2597
      <strong>synonymy</strong> tab.'),
2598
  );
2599

    
2600
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2601
    '#type' => 'checkbox',
2602
    '#title' => t('Accepted taxon on top of the synonymy'),
2603
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT),
2604
    '#description' => t('If checked, the first homotypic taxon is a repetition
2605
      of the accepted taxon most likely with the full nomenclatural reference, 
2606
      depending on the ' . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout') . '.'),
2607
  );
2608

    
2609
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE] = array(
2610
    '#type' => 'checkbox',
2611
    '#title' => t('Secundum referenence as separate line above the accepted taxon.'),
2612
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE, 0),
2613
    '#description' => t('You may want to remove the <code>"secReferencePart": true,</code> entry from <code>"accepted_taxon.taxon_page_synonymy"{</code> the in the '
2614
      . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout')
2615
      . ' (Only applicable when the "Show accepted taxon on top of the synonymy" option above is enabled.)'),
2616
    '#disabled' =>  !variable_get(CDM_DATAPORTAL_NOMREF_IN_TITLE, CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT)
2617
  );
2618

    
2619
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL] = array(
2620
    '#type' => 'textfield',
2621
    '#description' => 'Label for the secundum referenence.',
2622
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT),
2623
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', 0)
2624
    );
2625

    
2626
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2627
    '#type' => 'checkbox',
2628
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2629
      coming from a synonym link.'),
2630
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2631
    '#description' => t('Check this if after doing a search and clicking on a
2632
      synonym you want to see the "accept of" text for the accepted synonym.'),
2633
  );
2634

    
2635
  $form['taxon_synonymy']['taxon_relations'] = array(
2636
    '#type' => 'fieldset',
2637
    '#title' => t('Taxon relationships'),
2638
    '#collapsible' => FALSE,
2639
    '#collapsed' => FALSE
2640
  );
2641

    
2642
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2643
    '#type' => 'checkbox',
2644
    '#title' => t('Show taxon relations ships of accepted taxon'),
2645
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2646
    '#description' => t('If this option is enabled the synonymy will show the
2647
      below selected taxon relationships of accepted taxa.'),
2648
  );
2649

    
2650
  $taxon_relationship_type_options = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2651
  $taxon_relationship_type_defaults = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
2652
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2653
    '#type' => 'checkboxes',
2654
    '#title' => t('Taxon relationship types') . ':',
2655
    '#description' => 'Only taxon relationships of the selected type will be displayed',
2656
    '#options' => $taxon_relationship_type_options,
2657
    '#default_value' => $taxon_relationship_type_defaults,
2658
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2659
  );
2660

    
2661
  $form['taxon_synonymy']['name_relations'] = array(
2662
    '#type' => 'fieldset',
2663
    '#title' => t('Name relationships'),
2664
    '#collapsible' => FALSE,
2665
    '#collapsed' => FALSE
2666
  );
2667

    
2668
  $name_relationship_type_options = cdm_vocabulary_as_option(
2669
      UUID_NAME_RELATIONSHIP_TYPE,
2670
      '_cdm_relationship_type_term_label_callback',
2671
      false,
2672
      array('uuid' => '/' .UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM . '|'
2673
        . UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM . '|'
2674
        . UUID_NAMERELATIONSHIPTYPE_CONSERVED_AGAINST . '|'
2675
        . UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR . '|'
2676
        . UUID_NAMERELATIONSHIPTYPE_MISSPELLING . '|'
2677
        . UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT . '/' )
2678
  );
2679
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_INLINE_TYPES] = array(
2680
    '#type' => 'checkboxes',
2681
    '#title' => t('Name relationship types') . ':',
2682
    '#description' => 'This setting only affects specific types of name relations which are displayed appended to scientific name. 
2683
    A full listing of all name relationships for a scientific name is provided by the taxon ' . l('name page', 'admin/config/cdm_dataportal/settings/layout/name-page') . '.',
2684
    '#options' => $name_relationship_type_options,
2685
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT)),
2686
  );
2687

    
2688
  // ====== SPECIMENS ====== //
2689
  $form['taxon_specimens'] = array(
2690
    '#type' => 'fieldset',
2691
    '#title' => t('Taxon specimens (tab)'),
2692
    '#collapsible' => TRUE,
2693
    '#collapsed' => TRUE,
2694
    '#description' => t('This section covers the settings related to the taxon
2695
      <strong>specimens</strong> tab.'),
2696
  );
2697

    
2698
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2699

    
2700
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2701
    '#type' => 'checkbox',
2702
    '#title' => t('Show specimen derivatives in a compressed table'),
2703
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2704
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2705
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2706
  );
2707

    
2708
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2709
      '#type' => 'textfield',
2710
      '#title' => t('Number of records per page') . ':',
2711
      '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2712
  );
2713

    
2714
    $form['taxon_specimens']['cdm_dataportal_specimen_derivate_tree'] = array(
2715
        '#type' => 'checkbox',
2716
        '#title' => t('Show specimen derivatives in a tree view'),
2717
        '#default_value' => variable_get('cdm_dataportal_specimen_derivate_tree', CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE),
2718
        '#description' => t('If checked, the specimen will be listed in a tree view.'),
2719
    );
2720

    
2721

    
2722
    $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2723
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2724
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2725
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2726
  }
2727
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2728
    '#type' => 'radios',
2729
    '#title' => t('Specimen description feature tree') . ':',
2730
    '#default_value' => $profile_feature_tree_uuid,
2731
    '#options' =>  $featureTrees['options'],
2732
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2733
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2734
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2735
    ),
2736
  );
2737

    
2738
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2739
  $form_title = t('Specimen media');
2740
  $form_description = t('Specimens may have media which is displayed at the
2741
     Specimen tab/section as a gallery. It is possible to configure the
2742
     thumbnails gallery here, however for configuring how a single media should
2743
     be displayed please go to !url.</p>',
2744
     array(
2745
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2746
     ));
2747
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2748

    
2749
  // --- MEDIA GALLERY ---- //
2750
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2751
  $form_title = 'Media gallery (tab)';
2752
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2753
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2754
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2755
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2756
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2757
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2758
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2759

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

    
2769
/**
2770
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2771
 *
2772
 * @param $map_id
2773
 * @param $form
2774
 * @return mixed
2775
 */
2776
function _cdm_map_visibility_setting($map_id)
2777
{
2778
  return array(
2779
    '#type' => 'select',
2780
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2781
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2782
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2783
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2784
        The map also can forced to show up <b>always</b> or <b>never</b>."
2785
  );
2786
}
2787

    
2788
/**
2789
 * @return array
2790
 *   The form structure.
2791
 */
2792
function cdm_settings_layout_search() {
2793

    
2794
  $form = array();
2795

    
2796
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2797

    
2798
  $form['search_settings'] = array(
2799
    '#type' => 'fieldset',
2800
    '#title' => t('Taxa Search'),
2801
    '#collapsible' => FALSE,
2802
    '#collapsed' => FALSE,
2803
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2804
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2805
         where they can write the text to be searched. You can find Drupal block configuration
2806
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2807
  );
2808

    
2809
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2810
      '#type' => 'checkbox',
2811
      '#title' => t('Ignore the chosen classification in simple search'),
2812
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2813
      '#description' => t('The simple search, which can be executed via the search block,
2814
          will by default search on the classification selected in the classification browser
2815
          selector. Set the tick if you want your portal to search on all classifications.'),
2816
  );
2817

    
2818
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2819
    '#type' => 'checkbox',
2820
    '#title' => t('Run simple search with free-text search backend.'),
2821
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2822
    '#description' => t('The simple search uses by default another search
2823
      backend as the advances search. By checking this option the simple search can be
2824
      configured to also use the free-text search backend.'),
2825
  );
2826

    
2827
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2828
    '#type' => 'checkbox',
2829
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2830
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2831
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2832
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2833
  );
2834

    
2835
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2836
    '#type' => 'textfield',
2837
    '#title' => t('Results per page') . ':',
2838
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2839
    '#description' => t('Number of results to display per page.'),
2840
  );
2841

    
2842
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2843
    '#type' => 'checkbox',
2844
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2845
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2846
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2847
  );
2848

    
2849
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2850
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2851
      '#type' => 'checkboxes',
2852
      '#title' => 'Search mode',
2853
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2854
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2855
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2856
          defaults set here.',
2857
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2858
      '#default_value' => $search_mode_default
2859
      );
2860

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

    
2866
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2867
  );
2868

    
2869
    $form['blast_search_settings'] = array(
2870
        '#type' => 'fieldset',
2871
        '#title' => t('Blast Search'),
2872
        '#collapsible' => TRUE,
2873
        '#collapsed' => TRUE,
2874
        '#description' => t('<p>To perform blast searchs
2875
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2876
         where they can write the text to be searched. You can find Drupal block configuration
2877
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p>
2878
         <p>To perform a blast search a blast database for the cdm instance is needed.</p> '),
2879
    );
2880

    
2881
    $form['blast_search_settings'][CDM_SEARCH_BLAST_ENABLED] = array(
2882
        '#type' => 'checkbox',
2883
        '#title' => t('Activate Blast search') . ':',
2884
        '#default_value' => variable_get(CDM_SEARCH_BLAST_ENABLED, 0), // '05b0dd06-30f8-477d-bf4c-30d9def56320' =>  Caucasia (Ab + Ar + Gg + Rf(CS)) (Cc)
2885

    
2886
        '#description' => t('Activate the blast search for this portal, this works only with an existing blast database!'),
2887
    );
2888
    $form['blast_search_settings'][CDM_SEARCH_BLAST_SERVICE_URI] = array(
2889
        '#type' => 'textfield',
2890
        '#title' => t('Webservice URL for blast search') . ':',
2891
        '#default_value' => variable_get(CDM_SEARCH_BLAST_SERVICE_URI, 'http://130.133.70.28:9001/api/sequence'),
2892

    
2893
        '#description' => t('Enter the webservice URL for blast search'),
2894
    );
2895

    
2896
  // --- SEARCH TAXA GALLERY ---- //
2897
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2898
  $collapsed = FALSE;
2899
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2900
  $form_title = 'Taxa Search thumbnails';
2901
  $form_description = 'Search results may show thumbnails. ';
2902
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2903

    
2904
  // Comment @WA: D7 form api does not support reset buttons,
2905
  // so to mimic the D5 reset button we add one like this.
2906
  $form['actions']['reset'] = array(
2907
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2908
    '#weight' => 1000,
2909
  );
2910
  return system_settings_form($form);
2911
}
2912

    
2913

    
2914
/**
2915
 * @return array
2916
 *   The form structure.
2917
 */
2918
function cdm_settings_layout_name_page()
2919
{
2920

    
2921
  $form = array();
2922

    
2923

    
2924
  $form['name_relations'] = array(
2925
    '#type' => 'fieldset',
2926
    '#title' => t('Name relationship listings'),
2927
    '#collapsible' => FALSE,
2928
    '#collapsed' => FALSE
2929
  );
2930

    
2931
  $name_relationship_type_options = cdm_vocabulary_as_option(
2932
    UUID_NAME_RELATIONSHIP_TYPE,
2933
    '_cdm_relationship_type_term_label_callback',
2934
    false
2935
  );
2936
  $form['name_relations'][CDM_NAME_RELATIONSHIP_LIST_TYPES] = array(
2937
    '#type' => 'checkboxes',
2938
    '#title' => t('Name relationship types') . ':',
2939
    '#description' => 'This setting only affects specific types of name relations which are displayed as list. Another representations 
2940
    is the inline style used in the synonymy which may show a different (reduced) set of name relations. 
2941
    The according settings can be adjusted in the ' . l('taxon page settings section synonmy', 'admin/config/cdm_dataportal/settings/layout/taxon') . '.',
2942
    '#options' => $name_relationship_type_options,
2943
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_LIST_TYPES, cdm_vocabulary_as_defaults(UUID_NAME_RELATIONSHIP_TYPE)),
2944
  );
2945

    
2946
  $form[CDM_NAME_PAGE_SECTION_TAXA] = array (
2947
    '#type' => 'checkbox',
2948
    '#title' => 'Show the associated taxa section',
2949
    '#default_value' => variable_get(CDM_NAME_PAGE_SECTION_TAXA, CDM_NAME_PAGE_SECTION_TAXA_DEFAULT)
2950

    
2951
  );
2952

    
2953
  return system_settings_form($form);
2954
}
2955

    
2956
/**
2957
 * @return array
2958
 *   The form structure.
2959
 */
2960
function cdm_settings_layout_media() {
2961

    
2962
  $form = array();
2963

    
2964
  $form['media_settings'] = array(
2965
    '#type' => 'fieldset',
2966
    '#title' => t('Media settings'),
2967
    '#collapsible' => FALSE,
2968
    '#collapsed' => FALSE,
2969
    '#description' => 'This section covers layout settings for media pages.'
2970
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2971
  );
2972

    
2973
  $form['media_settings'][CDM_MEDIA_GALLERY_VIEWER] = array(
2974
    '#type' => 'select',
2975
    '#title' => t('Image viewer') . ':',
2976
    '#default_value' => variable_get(CDM_MEDIA_GALLERY_VIEWER, CDM_MEDIA_GALLERY_VIEWER_DEFAULT),
2977
    '#options' => array(
2978
      CDM_MEDIA_GALLERY_VIEWER_DEFAULT => t('Universalviewer'),
2979
      'fsi' => t('FSI viewer (requires FSI server!)'),
2980
      'default' => t('Simple viewer'),
2981
    ),
2982
    '#description' => 'The <b>Universalviewer</b> is a feature rich image gallery and viewer which provides support
2983
            for mobile devices and thus is highly recommended over the other options.<br/>
2984
            <b>Simple viewer</b> combines a HTML gallery with a simple image viewer and only provides basic functionality 
2985
            and does not work well on mobile devices.<br />
2986
            <b>FSI Viewer</b> can only be used in conjunction with images served by an FSI server.'
2987
  );
2988

    
2989
  // --- STANDARD_IMAGE_VIEWER ---- //
2990
  if(variable_get(CDM_MEDIA_GALLERY_VIEWER, CDM_MEDIA_GALLERY_VIEWER_DEFAULT) == CDM_MEDIA_GALLERY_VIEWER_SIMPLE) {
2991
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2992
      '#type' => 'fieldset',
2993
      '#tree' => true,
2994
      '#title' => t('Standard image viewer settings'),
2995
      '#collapsible' => FALSE,
2996
      '#collapsed' => FALSE,
2997
      );
2998

    
2999
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
3000
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
3001
      '#type' => 'checkbox',
3002
      '#title' => 'Show media representations',
3003
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
3004
    );
3005

    
3006
  }
3007
  if(variable_get(CDM_MEDIA_GALLERY_VIEWER, 'default') == CDM_MEDIA_GALLERY_VIEWER_DEFAULT) {
3008
    $form['media_settings'][CDM_ADDITIONAL_MEDIA_COPYRIGHT] = [
3009
      '#type' => 'textarea',
3010
      '#title' => 'Additional media copyright statement',
3011
      '#default_value' => variable_get(CDM_ADDITIONAL_MEDIA_COPYRIGHT, NULL),
3012
      '#description' => 'This statement will be shown below the <b>Universal imgage viewer only</b>'
3013
    ];
3014
  }
3015

    
3016
  // @WA: D7 form api does not support reset buttons,
3017
  // so to mimic the D5 reset button we add one like this.
3018
  $form['actions']['reset'] = array(
3019
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3020
    '#weight' => 1000,
3021
  );
3022
  return system_settings_form($form);
3023
}
3024

    
3025
/**
3026
 * GEOSERVICE and Map settings.
3027
 *
3028
 *  @return array
3029
 *   The form structure.
3030
 */
3031
function cdm_settings_geo($form, &$form_state) {
3032

    
3033
  $current_geoserver_settings = get_edit_map_service_settings();
3034
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
3035

    
3036

    
3037
  $form = array();
3038

    
3039
  $dummy_distribution_query = NULL;
3040
  if($map_distribution['map_type'] != 1){
3041
    // we need to apply a dummy query since the map service requires for image maps
3042
    // at least as and ad to be defined
3043
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
3044
  }
3045

    
3046
  $form['map_preview'] = array(
3047
      '#type' => 'fieldset',
3048
      '#tree' => FALSE,
3049
      '#title' => t('Map preview'),
3050
      '#collapsible' => FALSE,
3051
      '#description' => 'The preview of the map'
3052
       . ($dummy_distribution_query != null ?
3053
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
3054
           '.<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.')
3055
  );
3056
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, NULL, $dummy_distribution_query, NULL, [
3057
    'move' => "this.cdmOpenlayersMap.printInfo",
3058
    '#execute' => "this.cdmOpenlayersMap.printInfo"
3059
  ], TRUE // resizable
3060
  );
3061

    
3062
  /*
3063
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
3064
  );
3065
  */
3066

    
3067
  /*
3068
   * GEO SERVER
3069
   */
3070
  $form['edit_map_server'] = array(
3071
    '#type' => 'fieldset',
3072
    '#tree' => true,
3073
    '#title' => t('EDIT map service'),
3074
    '#collapsible' => TRUE,
3075
    '#collapsed' => TRUE,
3076
    '#description' => t('Configuration and selection of your geo server.
3077
      The Geo Server is responsible for generating the maps.'),
3078
  );
3079

    
3080
  $form['edit_map_server']['base_uri'] = array(
3081
    '#type' => 'select',
3082
    '#title' => t('EDIT map service') . ':',
3083
    '#default_value' => $current_geoserver_settings['base_uri'],
3084
    '#options' => unserialize(EDIT_MAPSERVER_URI),
3085
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
3086
  );
3087
  $form['edit_map_server']['version'] = array(
3088
      '#type' => 'select',
3089
      '#title' => t('Version') . ':',
3090
      '#default_value' => $current_geoserver_settings['version'],
3091
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
3092
      '#description' => t('The version of the EDIT map services'),
3093
  );
3094

    
3095
  /*
3096
   * MAP SETTINGS
3097
   */
3098

    
3099
  $form[CDM_MAP_DISTRIBUTION] = array(
3100
    '#type' => 'fieldset',
3101
    '#tree' => TRUE,
3102
    '#title' => t('Maps settings'),
3103
    '#collapsible' => TRUE,
3104
    '#collapsed' => TRUE,
3105
    '#description' => t('General configuration for all map types.'),
3106
  );
3107

    
3108
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
3109
    '#type' => 'radios',
3110
    '#title' => 'Map types',
3111
    '#options' => array(
3112
      1 => "OpenLayers dynamic map viewer",
3113
      0 => "Plain image",
3114
    ),
3115
    '#default_value' => $map_distribution['map_type'],
3116
    '#description' => 'Two different map types are available :
3117
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
3118
      which allows zooming and panning. If enabled you can configure the default layer
3119
      (background of your maps) below.</li>
3120
      <li><em>Plain image</em>: The map will be static non interactive
3121
      image.</li></ul>',
3122
  );
3123
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
3124

    
3125
  /*
3126
   * settings for the distribution map are used also for specimens map!!!!
3127
   */
3128

    
3129
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
3130
      '#type' => 'textfield',
3131
      '#title' => 'Aspect ratio',
3132
      '#default_value' => $map_distribution['aspect_ratio'],
3133
      '#maxlength' => 4,
3134
      '#size' => 4,
3135
      '#element_validate' => array('element_validate_number'),
3136
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
3137
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
3138
      width by the height:</br>
3139
      <pre>aspect ratio = w / h</pre>
3140
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
3141
      for a square map use <strong>1</strong>.',
3142
  );
3143

    
3144
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
3145
    '#type' => 'textfield',
3146
    '#title' => 'Bounding box',
3147
    '#default_value' => $map_distribution['bbox'],
3148
    '#description' =>
3149
      'The bounding box (left, bottom, right, top) defines the area to be initially displayed in maps. The bbox must be given in coordinates of the projection of the chosen layer. 
3150
      For the whole world use Use <code>-180,-90,180,90</code>" for EPSG:4326 layers, for Web Mercator maps Open Street Map or 
3151
      Google maps the maximum bounds of the world are <code>-27395030.933594,-13697515.466797,27395030.933594,13697515.466797</code>.
3152
      Leave <strong>empty</strong> to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
3153
      <strong>TIP:</strong> You can use the map preview above to choose the <span class="map-extent-bbox"><strong class="layer-value">map extent bbox</strong></span> from the details information.
3154
      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
3155
      below the map from where you can copy the bbox string.</p>',
3156
  );
3157

    
3158
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
3159
    '#type' => 'select',
3160
    '#title' => 'Max zoom level',
3161
    '#default_value' => $map_distribution['maxZoom'],
3162
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
3163
  );
3164

    
3165
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
3166
    '#type' => 'checkbox',
3167
    '#title' => 'Display area labels',
3168
    '#default_value' => $map_distribution['show_labels'],
3169
    '#description' => t('The map will show name labels of the areas'),
3170
  );
3171

    
3172
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
3173
    '#type' => 'textfield',
3174
    '#title' => 'Map caption',
3175
    '#default_value' => $map_distribution['caption'],
3176
    '#description' => t('The caption will be shown below the map.'),
3177
  );
3178

    
3179
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
3180
    '#type' => 'textfield',
3181
    '#title' => 'Distribution layer opacity',
3182
    '#default_value' => $map_distribution['distribution_opacity'],
3183
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
3184
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
3185
  );
3186

    
3187
  // --- Plain Image Settings --- //
3188
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
3189
    '#type' => 'fieldset',
3190
    '#title' => 'Plain image map settings',
3191
    '#tree' => TRUE,
3192
    '#collapsible' => TRUE,
3193
    '#collapsed' => $open_layers_is_enabled,
3194
    '#description' => 'The settings in this section are still expertimental
3195
      and can only be used with the EDIT map service version 1.1 or above.',
3196
  );
3197
  $edit_mapserver_version = get_edit_map_service_version_number();
3198
  if ($edit_mapserver_version < 1.1) {
3199
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
3200
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
3201
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
3202
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
3203
  }
3204

    
3205
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
3206
    '#type' => 'textfield',
3207
    '#title' => 'Width',
3208
    '#default_value' => $map_distribution['image_map']['width'],
3209
    '#maxlength' => 4,
3210
    '#size' => 4,
3211
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
3212
  );
3213

    
3214
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
3215
    '#type' => 'textfield',
3216
    '#title' => 'Background layer',
3217
    '#default_value' => $map_distribution['image_map']['base_layer'],
3218
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
3219
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
3220
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
3221
    )),
3222
  );
3223

    
3224
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3225
    '#type' => 'textfield',
3226
    '#title' => 'Background color',
3227
    '#default_value' => $map_distribution['image_map']['bg_color'],
3228
  );
3229

    
3230
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3231
    '#type' => 'textfield',
3232
    '#title' => 'Background layer style',
3233
     // Only line color by now.
3234
    '#default_value' => $map_distribution['image_map']['layer_style'],
3235
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3236
  );
3237

    
3238
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3239
      '#type' => 'textfield',
3240
      '#title' => 'Projection',
3241
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3242
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3243
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3244
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3245
  );
3246

    
3247

    
3248
  // --- OpenLayers Settings --- //
3249
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3250
    '#type' => 'fieldset',
3251
    '#title' => 'OpenLayers settings',
3252
    '#tree' => TRUE,
3253
    '#collapsible' => TRUE,
3254
    '#collapsed' => !$open_layers_is_enabled,
3255
    '#description' => '',
3256
  );
3257

    
3258

    
3259
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3260
      '#type' => 'checkbox',
3261
      '#title' => 'Display outside max extent',
3262
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3263
      '#description' => t('Allows the map to display parts of the layers which are outside
3264
         the max extent if the aspect ratio of the map and of the baselayer
3265
         are not equal.'),
3266
  );
3267

    
3268

    
3269
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3270
      '#type' => 'checkbox',
3271
      '#title' => 'Show Layer Switcher',
3272
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3273
      '#description' => 'The Layer Switcher control displays a table of contents
3274
      for the map.  This allows the user interface to switch between
3275
      base layers and to show or hide overlays.  By default the switcher is
3276
      shown minimized on the right edge of the map, the user may expand it
3277
      by clicking on the handle.',
3278
  );
3279

    
3280
  if (!$open_layers_is_enabled) {
3281
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3282
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3283
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3284
  }
3285

    
3286
  // The default layer must always be enabled
3287
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3288
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3289

    
3290
  $baselayer_options = array(
3291
    /*
3292
   NOTICE: must correspond to the layers defined in
3293
   js/openlayers_,ap.js#getLayersByName()
3294
   */
3295
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3296
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3297
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3298
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3299
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3300
    // all others EPSG:900913
3301
    'mapnik' => 'OpenStreetMap (mapnik)',
3302
    'stamen_terrain' => 'Stamen Terrain',
3303
    'open_topomap' => 'OpenTopoMap',
3304
    // map quest is no longer free. it is required to sign up for a test plan.
3305
    // 'mapquest_open' => "MapQuest",
3306
    // 'mapquest_sat' => "MapQuest Sattelite",
3307
    'groadmap' => 'Google Roadmap',
3308
    'gsatellite' => 'Google Satellite',
3309
    'ghybrid' => 'Google Hybrid',
3310
    'gterrain' => 'Google Terrain',
3311
//     'veroad' => 'Virtual Earth Roads',
3312
//     'veaer' => 'Virtual Earth Aerial',
3313
//     'vehyb' => 'Virtual Earth Hybrid',
3314
    // 'yahoo' => 'Yahoo Street',
3315
    // 'yahoosat' => 'Yahoo Satellite',
3316
    // 'yahoohyb' => 'Yahoo Hybrid',
3317
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3318
  );
3319

    
3320
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3321
    '#type' => 'checkboxes_preferred',
3322
    '#title' => 'Base Layers',
3323
    '#options' => $baselayer_options,
3324
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3325
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3326
  );
3327

    
3328
  $google_maps_api_key = null;
3329
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3330
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3331
  }
3332
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3333
    '#type' => 'textfield',
3334
    '#title' => 'Google Maps API Key',
3335
    '#default_value' => $google_maps_api_key,
3336
    '#description' => 'In order to use any of the Google map layers you need to provide 
3337
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3338
  );
3339

    
3340
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3341
    $map_distribution['openlayers']['custom_wms_base_layer'],
3342
    'Custom WMS base layer',
3343
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3344
    true // add projection settings
3345
    );
3346

    
3347
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3348
    $map_distribution['openlayers']['wms_overlay_layer'],
3349
    'WMS overlay layer',
3350
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3351
                You can actually combine multiple layers for this overlay. 
3352
                For details please refer to the wms query parameter <code>Layers</code> .'
3353
  );
3354

    
3355
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3356
    '#type' => 'checkbox',
3357
    '#title' => 'Enable overlay layer',
3358
    '#weight' => -100,
3359
    '#default_value' => isset($map_distribution['openlayers']['wms_overlay_layer']['is_enabled']) && $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3360
  );
3361

    
3362
  /*
3363
   * Map Legend
3364
   */
3365
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3366
    '#type' => 'fieldset',
3367
    '#title' => 'Map legend',
3368
    '#tree' => TRUE,
3369
    '#collapsible' => TRUE,
3370
    '#collapsed' => TRUE,
3371
    '#description' => 'Configure the maps legend.',
3372
  );
3373

    
3374
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3375
    '#type' => 'checkbox',
3376
    '#title' => 'Display a map legend',
3377
    '#default_value' => $map_distribution['legend']['show'],
3378
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3379
  );
3380

    
3381
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3382
    '#type' => 'textfield',
3383
    '#title' => 'Legend opacity',
3384
    '#default_value' => $map_distribution['legend']['opacity'],
3385
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3386
                         to 0.0 will be not much visible.',
3387
  );
3388

    
3389
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3390
    '#type' => 'textfield',
3391
    '#title' => 'Font size',
3392
    '#default_value' => $map_distribution['legend']['font_size'],
3393
    '#description' => 'Font size in pixels.',
3394
  );
3395

    
3396
  $fontStyles = array(
3397
    0 => "plane",
3398
    1 => "italic",
3399
  );
3400
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3401
    '#type' => 'select',
3402
    '#title' => 'Available font styles',
3403
    '#default_value' => $map_distribution['legend']['font_style'],
3404
    '#options' => $fontStyles,
3405
    '#description' => 'Select a font style for the map legend.',
3406
  );
3407

    
3408
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3409
    '#type' => 'textfield',
3410
    '#title' => 'Icon width',
3411
    '#default_value' => $map_distribution['legend']['icon_width'],
3412
    '#description' => 'Legend icon width in pixels.',
3413
  );
3414
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3415
    '#type' => 'textfield',
3416
    '#title' => 'Icon height',
3417
    '#default_value' => $map_distribution['legend']['icon_height'],
3418
    '#description' => 'Legend icon height in pixels.',
3419
  );
3420

    
3421
  // @WA: D7 form api does not support reset buttons,
3422
  // so to mimic the D5 reset button we add one like this.
3423
  $form['actions']['reset'] = array(
3424
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3425
    '#weight' => 1000,
3426
  );
3427

    
3428
  return system_settings_form($form);
3429
}
3430

    
3431
/**
3432
 * @param $default_settings
3433
 * @param $title
3434
 * @param $description
3435
 * @param bool $add_projection_settings
3436
 * @return array
3437
 */
3438
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3439
{
3440
  $form_elements = array(
3441
    '#type' => 'fieldset',
3442
    '#title' => $title,
3443
    '#tree' => TRUE,
3444
    '#collapsible' => FALSE,
3445
    '#collapsed' => FALSE,
3446
    '#description' => $description,
3447
  );
3448

    
3449
  $form_elements['name'] = array(
3450
    '#type' => 'textfield',
3451
    '#title' => 'Layer name',
3452
    '#default_value' => $default_settings['name'],
3453
    '#description' => 'A arbitrary name for the layer.',
3454
  );
3455
  $form_elements['url'] = array(
3456
    '#type' => 'textfield',
3457
    '#title' => 'WMS url',
3458
    '#default_value' => $default_settings['url'],
3459
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3460
  );
3461
  $form_elements['untiled'] = array(
3462
    '#type' => 'checkbox',
3463
    '#title' => 'Untiled',
3464
    '#default_value' => $default_settings['untiled'],
3465
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3466
  );
3467
  $form_elements['params'] = array(
3468
    '#type' => 'textarea',
3469
    '#title' => 'WMS parameters',
3470
    '#element_validate' => array('form_element_validate_json'),
3471
    '#default_value' => $default_settings['params'],
3472
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3473
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3474
      . '), entered in valid JSON. For example:
3475
<pre> {
3476
  "Layers": "topp:em_tiny_jan2003",
3477
  "Format": "image/png",
3478
  "BGCOLOR": "0xe0faff"
3479
}
3480
</pre>
3481
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3482
  );
3483

    
3484
  if($add_projection_settings){
3485

    
3486
    $form_elements['projection'] = array(
3487
      '#type' => 'textfield',
3488
      '#title' => 'Projection',
3489
      '#default_value' => $default_settings['projection'],
3490
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
3491
    );
3492
    $form_elements['proj4js_def'] = array(
3493
      '#type' => 'textfield',
3494
      '#maxlength' => 256,
3495
      '#title' => 'proj4js definition',
3496
      '#default_value' => $default_settings['proj4js_def'],
3497
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
3498
              The definitions for
3499
              EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
3500
              EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
3501
              are already predefined and must NOT be added here again.  If your dont know the defintion of your desired projection,
3502
              go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
3503
              choose to display the proj4js definition string.
3504
              <h5>Quick Reference on the common proj4js definition parameters:</h5>
3505
              <pre>
3506
  +a         Semimajor radius of the ellipsoid axis
3507
  +alpha     ? Used with Oblique Mercator and possibly a few others
3508
  +axis      Axis orientation (new in 4.8.0)
3509
  +b         Semiminor radius of the ellipsoid axis
3510
  +datum     Datum name (see `proj -ld`)
3511
  +ellps     Ellipsoid name (see `proj -le`)
3512
  +k         Scaling factor (old name)
3513
  +k_0       Scaling factor (new name)
3514
  +lat_0     Latitude of origin
3515
  +lat_1     Latitude of first standard parallel
3516
  +lat_2     Latitude of second standard parallel
3517
  +lat_ts    Latitude of true scale
3518
  +lon_0     Central meridian
3519
  +lonc      ? Longitude used with Oblique Mercator and possibly a few others
3520
  +lon_wrap  Center longitude to use for wrapping (see below)
3521
  +nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
3522
  +no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
3523
  +over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
3524
  +pm        Alternate prime meridian (typically a city name, see below)
3525
  +proj      Projection name (see `proj -l`)
3526
  +south     Denotes southern hemisphere UTM zone
3527
  +to_meter  Multiplier to convert map units to 1.0m
3528
  +towgs84   3 or 7 term datum transform parameters (see below)
3529
  +units     meters, US survey feet, etc.
3530
  +vto_meter vertical conversion to meters.
3531
  +vunits    vertical units.
3532
  +x_0       False easting
3533
  +y_0       False northing
3534
  +zone      UTM zone
3535
              </pre>
3536
            For the full reference please refer to <a href="http://proj4.org/parameters.html">http://proj4.org/parameters.html</a>.'
3537
    );
3538
    $form_elements['max_extent'] = array(
3539
      '#type' => 'textfield',
3540
      '#title' => 'Maximum extent',
3541
      '#default_value' => $default_settings['max_extent'],
3542
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
3543
    );
3544
    $form_elements['units'] = array(
3545
      '#type' => 'textfield',
3546
      '#title' => 'Units',
3547
      '#default_value' => $default_settings['units'],
3548
      '#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.'
3549
    );
3550

    
3551
  }
3552
  return $form_elements;
3553
}
3554

    
3555

    
3556
/**
3557
 * @return array
3558
 *   The form structure.
3559
 */
3560
function cdm_settings_cache() {
3561

    
3562
  $form = array();
3563

    
3564
  $form['cache_settings'] = array(
3565
    '#type' => 'fieldset',
3566
    '#title' => t('Cache Settings'),
3567
    '#collapsible' => FALSE,
3568
    '#collapsed' => FALSE,
3569
    '#description' => t('<p>When caching is enabled all single taxon sites are
3570
      stored in an internal drupal cache doing the portal response of taxa pages
3571
      faster. This is possible because the sites are loaded from the cache and
3572
      are not created from scratch.</p>'),
3573
  );
3574

    
3575
  $form['cache_settings']['cdm_webservice_cache'] = array(
3576
    '#type' => 'checkbox',
3577
    '#title' => t('<strong>Enable caching</strong>'),
3578
    '#options' => cdm_help_general_cache(),
3579
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3580
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3581
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3582
       application the changes will be not visible till the cache is erased.
3583
       Therefore developers should deactived this feature when they are working
3584
       on the CDM Dataportal Module.</p>'),
3585
  );
3586

    
3587
  $form['cache_settings']['cdm_run_cache'] = array(
3588
    '#markup' => cdm_view_cache_site(),
3589
  );
3590

    
3591
  // @WA: D7 form api does not support reset buttons,
3592
  // so to mimic the D5 reset button we add one like this.
3593
  $form['actions']['reset'] = array(
3594
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3595
    '#weight' => 1000,
3596
  );
3597
  return system_settings_form($form);
3598
}
3599

    
3600
/**
3601
 * Walk and cache all taxon pages.
3602
 */
3603
function cdm_view_cache_site() {
3604

    
3605
  $out = '';
3606

    
3607
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3608

    
3609
  $request_params = array();
3610
  $request_params['class'] = "Taxon";
3611

    
3612
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3613
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3614
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3615

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

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

    
3625
  // Comment @WA: A form within a form is not valid html and not needed here.
3626
  // Also, it would be recommended just to include this part of the form in the
3627
  // rest of the form array in cdm_settings_cache().
3628
  // $out .= '<form id="cache_site">';
3629
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3630
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3631
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3632
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3633
  // $out .= '</form>';
3634
  $out .= '</div>';
3635
  /*
3636
  foreach($taxonPager->records as $taxon){
3637
    cdm_dataportal_taxon_view($uuid);
3638
  }
3639
  */
3640
  return $out;
3641
}
3642

    
3643

    
3644
function cdm_settings_layout_taxon_submit($form, &$form_state){
3645
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3646
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3647
    if(is_object($file)){
3648
      $file->status = FILE_STATUS_PERMANENT;
3649
      file_save($file);
3650
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3651
    }
3652
  }
3653
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3654
  $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]);
3655
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3656
  if($tab_lables_modified || $tabs_enabled_modified){
3657
    // we first need to set the variable to persist the changes setting
3658
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3659
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3660
    menu_rebuild();
3661
  }
3662
}
3663

    
3664
function cdm_settings_layout_search_submit($form, &$form_state){
3665
  // the visibility of media thumbnails also affects the ui of the search results
3666
  // so reset the according session variable
3667
  //    1. in order to give the user immediate
3668
  //       feedback on potential setting changes
3669
  //    2. let refresh the default if it has changed
3670
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3671
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3672
  }
3673
}
3674

    
3675
/**
3676
 * Form validation handler for cdm_settings_general
3677
 *
3678
 * @param $form
3679
 * @param $form_state
3680
 */
3681
function cdm_settings_general_validate($form, &$form_state) {
3682

    
3683
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3684
    $form_state['values']['cdm_webservice_url'] .= '/';
3685
  }
3686

    
3687
}
3688

    
3689
/**
3690
 * Form submit handler for settings general.
3691
 *
3692
 * tasks performed:
3693
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3694
 *
3695
 * @param $form
3696
 * @param $form_state
3697
 */
3698
function cdm_settings_general_submit($form, &$form_state){
3699
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3700
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3701
  unset($_SESSION['cdm_login']);
3702
}
3703

    
3704
/**
3705
 * Form validation handler for cdm_settings_cache
3706
 */
3707
function cdm_settings_cache_validate($form, &$form_state) {
3708
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3709
    cache_clear_all(NULL, 'cache_cdm_ws');
3710
    // Better clear secref_cache since I can not be sure if the cache has not
3711
    // be used during this response.
3712
    cdm_api_secref_cache_clear();
3713
  }
3714

    
3715
}