Project

General

Profile

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

    
7

    
8
  // TODO Genus UUID.
9

    
10
const CDM_NAME_PAGE_AUTOREDIRECT = 'cdm_name_page_autoredirect';
11

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

    
17
  define('CDM_SUB_TREE_FILTER_UUID', 'cdm_sub_tree_filter_uuid');
18

    
19
  define('NO_SORT', -1);
20
  define('SORT_HIERARCHICAL', 9);
21

    
22
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
23

    
24
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
25
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
26

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

    
40
  define('CDM_SEARCH_BLAST_SERVICE_URI', 'http://bgbm-import:9001/api/sequence');
41
  define('CDM_SEARCH_BLAST_ENABLED', 0);
42
  define('CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK', 'cdm_registration_presistent_identifier_as_link');
43

    
44
  /* annotationTypeKeys */
45
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
46
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
47
    $annotationTypeKeys = array_flip($annotationTypeKeys);
48

    
49
    // Technical annotation are off by default.
50
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
51
    $annotationTypeKeys = array_flip($annotationTypeKeys);
52
    // Additional value for the NULL case.
53
    $annotationTypeKeys[] = 'NULL_VALUE';
54
  }
55

    
56
  define('ANNOTATION_TYPES_VISIBLE', 'annotations_types_as_footnotes');
57
  define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
58

    
59
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
60
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
61
    'enabled' => 0,
62
    'key_format' => 'ALPHA'
63
  )));
64

    
65
  /* taxonRelationshipTypes */
66
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(
67
    array(
68
      UUID_MISAPPLIED_NAME_FOR => UUID_MISAPPLIED_NAME_FOR,
69
      UUID_PROPARTE_MISAPPLIEDNAME_FOR => UUID_PROPARTE_MISAPPLIEDNAME_FOR,
70
      UUID_PARTIAL_MISAPPLIEDNAME_FOR => UUID_PARTIAL_MISAPPLIEDNAME_FOR,
71
      UUID_PROPARTE_SYNONYM_FOR => UUID_PROPARTE_SYNONYM_FOR,
72
      UUID_PARTIAL_SYNONYM_FOR => UUID_PARTIAL_SYNONYM_FOR,
73
      UUID_INVALID_DESIGNATION_FOR => UUID_INVALID_DESIGNATION_FOR
74
    )
75
  ));
76

    
77

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

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

    
123

    
124
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
125

    
126
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
127
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
128
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
129
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
130
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
131

    
132
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
133
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
134
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
135
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
136

    
137
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
138
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
139

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

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

    
172

    
173
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
174
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
175
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
176
  array(
177
    'general' => null,
178
    'synonymy' => null,
179
    'images' => null,
180
    'specimens' => null,
181
    'keys' => null,
182
    'experts' => null,
183
  )
184
));
185

    
186
$taxon_tab_options = get_taxon_tabs_list();
187
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
188

    
189
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
190

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

    
201
}
202

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

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

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

    
380
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
381

    
382
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
383
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
384
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
385

    
386
/* Gallery variables. */
387
$gallery_settings = array(
388
    "cdm_dataportal_show_taxon_thumbnails" => 1,
389
    "cdm_dataportal_show_synonym_thumbnails" => 0,
390
    "cdm_dataportal_show_thumbnail_captions" => 1,
391
    "cdm_dataportal_media_maxextend" => 120,
392
    "cdm_dataportal_media_cols" => 3,
393
    "cdm_dataportal_media_maxRows" => 1,
394
);
395

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

    
409
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
410
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
411
  'media_representation_details_enabled' => 0
412
)));
413

    
414
/**
415
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
416
 * the synonymy.
417
 *
418
 * @var string
419
 */
420
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
421

    
422
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES', 'cdm_name_relationship_types');
423
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT', serialize(
424
    array(
425
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
426
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
427
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
428
    )
429
  )
430
);
431

    
432
define('CDM_NAME_RELATIONSHIP_LIST_TYPES', 'cdm_name_relationship_list_types');
433

    
434

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

    
456
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
457
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
458
      array(
459
      'filter_rules' => array(
460
        'statusOrderPreference' => 0,
461
        'subAreaPreference' => 0,
462
      ),
463
      'hiddenAreaMarkerType' => array()
464
     )
465
));
466

    
467
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
468
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
469
  "level_0" => array(
470
    'label_suffix' => ':',
471
    'status_glue' => '',
472
    'item_glue' => ' ',
473
    'item_group_prefix' => '',
474
    'item_group_postfix' => ''
475
  ),
476
  "level_1" => array(
477
    'label_suffix' => '',
478
    'status_glue' => '‒ ', // '&#8210; '
479
    'item_glue' => '; ',
480
    'item_group_prefix' => ', ',
481
    'item_group_postfix' => ''
482
  ),
483
  "level_2" => array(
484
    'label_suffix' => '',
485
    'status_glue' => '‒ ', // '&#8210; '
486
    'item_glue' => ', ',
487
    'item_group_prefix' => ' (',
488
    'item_group_postfix' => ')'
489
  )
490
)));
491

    
492
/**
493
 * Constant for the drupal variable key distribution_map_visibility
494
 *
495
 * possible values:
496
 *  - never
497
 *  - automatic
498
 *  - always
499
 */
500
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
501
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
502

    
503
/**
504
 * Constant for the drupal variable key specimen_map_visibility
505
 *
506
 * possible values:
507
 *  - never
508
 *  - automatic
509
 *  - always
510
 */
511
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
512
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
513

    
514
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
515
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
516
    array(
517
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
518
        'includeOccurrences' => 0,
519
        'includeTaxonNameDescriptions' => 0
520
     )
521
  ));
522

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

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

    
598
    // unserialize if nessecary
599
    if(!is_array($default)){
600
      $default = unserialize($default);
601
    }
602
    $variable = variable_get($variable_name, array());
603
    $result = drupal_array_merge_deep($default, $variable);
604
    return $result;
605
}
606

    
607
/**
608
 * @todo document this function.
609
 */
610
function getGallerySettings($gallery_config_form_name) {
611
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
612
}
613

    
614
/**
615
 * Returns the string representation of the default tab.
616
 *
617
 * @param bool $returnTabIndex
618
 *   Defaults to FALSE, if set true this function will return the index number
619
 *   of the default tab. (used to supply default values to form elements).
620
 */
621
function get_default_taxon_tab($returnTabIndex = FALSE) {
622

    
623
  global $user;
624
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
625
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
626
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
627
  // Get the user value if the used has chosen to overwrite the system settings.
628
  $user_tab_on = variable_get($user_tab_active, FALSE);
629
  if ($user_tab_on) {
630
    $user_value = variable_get($user_tab, 0);
631
    $index_value = $user_value;
632
    // Get the system value.
633
  }
634
  else {
635
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
636
    $index_value = $system_value;
637
  }
638

    
639
  // Return the index value or the string representation.
640
  if ($returnTabIndex) {
641
    return $index_value;
642
  }
643
  else {
644
    return ($values[$index_value]);
645
  }
646
}
647

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

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

    
719
  // ---- DEFAULTS settings
720

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

    
747
  // will be used as preset in the settings
748
  $other_themes_default = array(
749
    'DEFAULT' => array(
750
      'as_list' => 'div',
751
      'link_to_reference' => 0,
752
      'link_to_name_used_in_source' => 1,
753
      'sources_as_content' => 0,
754
      'sources_as_content_to_bibliography' => 0,
755
      'sort_elements' => NO_SORT,
756
      'glue' => '',
757
      'element_tag' => NULL
758
    ),
759
    UUID_CITATION => array(
760
      'as_list' => 'div',
761
      'link_to_reference' => 0,
762
      'link_to_name_used_in_source' => 0,
763
      'sources_as_content' => 1,
764
      'sources_as_content_to_bibliography' => 0,
765
      'sort_elements' => SORT_ASC,
766
      'glue' => '',
767
      'element_tag' => 'div'
768
    ),
769
    UUID_DISTRIBUTION => array(
770
      'as_list' => 'div', // currently ignored
771
      'link_to_reference' => 0,
772
      'link_to_name_used_in_source' => 0,
773
      'sources_as_content' => 0,
774
      'sources_as_content_to_bibliography' => 0,
775
      'sort_elements' => NO_SORT, // will cause ...
776
      'glue' => '',
777
      'element_tag' => 'div',
778
      'special' => array()
779
    ),
780
    UUID_COMMON_NAME => 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' => 'span'
789
    ),
790
  );
791

    
792
  // ---- Special DEFAULTS for existing portals
793
  // TODO:
794
  // this can be removed once the feature block
795
  // settings have been deployed for the first time to these portals
796

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

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

    
884
  $cyprus_default = $cichorieae_default;
885
  $cyprus_default[UUID_DISTRIBUTION] = array(
886
    'as_list' => 'div', // currently ignored
887
    'link_to_reference' => 0,
888
    'link_to_name_used_in_source' => 0,
889
    'sources_as_content' => 0,
890
    'sources_as_content_to_bibliography' => 0,
891
    'sort_elements' => NO_SORT, // will cause ...
892
    'glue' => ' ',
893
    'element_tag' => 'div',
894
    'special' => array()
895
  );
896

    
897
  $default_theme = variable_get('theme_default', NULL);
898

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

    
923
  // ---- END of DEFAULTS
924

    
925
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
926

    
927
  $feature_block_setting = null;
928

    
929
  if (isset($saved_settings[$feature_uuid])) {
930
    $feature_block_setting = $saved_settings[$feature_uuid];
931
  }
932
  else if (isset($settings_for_theme[$feature_uuid])) {
933
    $feature_block_setting = $settings_for_theme[$feature_uuid];
934
  }
935
  else if (isset($settings_for_theme['DEFAULT'])) {
936
    $feature_block_setting = $settings_for_theme['DEFAULT'];
937
  }
938

    
939
  // now merge the default and specific settings
940
  $settings_to_merge = array($default['DEFAULT']);
941
  if(is_array($saved_settings)){
942
    $settings_to_merge[] = $saved_settings['DEFAULT'];
943
  }
944
  if(isset($feature_block_setting)){
945
    $settings_to_merge[] = $feature_block_setting;
946
  }
947
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
948

    
949
  return $feature_block_setting;
950
}
951

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

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

    
1008
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
1009
    'title' => 'Cache',
1010
    'description' => 'Cache',
1011
    'access arguments' => array('administer cdm_dataportal'),
1012
    'page callback' => 'drupal_get_form',
1013
    'page arguments' => array('cdm_settings_cache'),
1014
    'weight' => 10,
1015
    'type' => MENU_LOCAL_TASK,
1016
  );
1017

    
1018
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
1019
    'title' => 'Geo & Map',
1020
    'description' => 'Geo & Map',
1021
    'access arguments' => array('administer cdm_dataportal'),
1022
    'page callback' => 'drupal_get_form',
1023
    'page arguments' => array('cdm_settings_geo'),
1024
    'weight' => 1,
1025
    'type' => MENU_LOCAL_TASK,
1026
  );
1027

    
1028
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
1029
    'title' => 'Layout',
1030
    'description' => 'Configure and adjust the layout of your DataPortal ',
1031
    'access arguments' => array('administer cdm_dataportal'),
1032
    'page callback' => 'drupal_get_form',
1033
    'page arguments' => array('cdm_settings_layout'),
1034
    'weight' => 2,
1035
    'type' => MENU_LOCAL_TASK,
1036
  );
1037

    
1038
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
1039
    'title' => 'Taxon page',
1040
    'description' => 'Configure and adjust the layout of your DataPortal ',
1041
    'access arguments' => array('administer cdm_dataportal'),
1042
    'page callback' => 'drupal_get_form',
1043
    'page arguments' => array('cdm_settings_layout_taxon'),
1044
    'weight' => 1,
1045
    'type' => MENU_LOCAL_TASK,
1046
  );
1047
  $items['admin/config/cdm_dataportal/settings/layout/name-page'] = array(
1048
    'title' => 'Name page',
1049
    'description' => 'Configure and adjust the layout of your DataPortal ',
1050
    'access arguments' => array('administer cdm_dataportal'),
1051
    'page callback' => 'drupal_get_form',
1052
    'page arguments' => array('cdm_settings_layout_name_page'),
1053
    'weight' => 1,
1054
    'type' => MENU_LOCAL_TASK,
1055
  );
1056
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1057
    'title' => 'Search',
1058
    'description' => 'Configure and adjust the layout of your DataPortal ',
1059
    'access arguments' => array('administer cdm_dataportal'),
1060
    'page callback' => 'drupal_get_form',
1061
    'page arguments' => array('cdm_settings_layout_search'),
1062
    'weight' => 2,
1063
    'type' => MENU_LOCAL_TASK,
1064
  );
1065

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

    
1076
}
1077

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1222
  $form['sub_tree_filter'] = array(
1223
    '#type' => 'fieldset',
1224
    '#title' => t('Subtree filter'),
1225
    '#collapsible' => FALSE,
1226
    '#collapsed' => TRUE,
1227
    '#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.'),
1228
  );
1229

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

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

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

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

    
1282
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1283
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1284
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1285
      '#type' => 'checkboxes',
1286
      '#title' => t('Included Classifications') . ':',
1287
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1288
      '#options' => cdm_get_taxontrees_as_options(),
1289
      '#description' => t('Only the checked classifications will be available in the classification chooser.'),
1290
  );
1291

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

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

    
1326
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1327
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1328
      '#type' => 'checkboxes',
1329
      '#title' => 'Filter rules',
1330
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1331
      '#options' => array(
1332
          'statusOrderPreference' => 'Status order preference rule',
1333
          'subAreaPreference' => 'Sub area preference rule'
1334
      ),
1335
  );
1336

    
1337
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1338
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1339
      '#type' => 'checkboxes',
1340
      '#title' => 'Hide marked area filter',
1341
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1342
      '#options' => $marker_type_options,
1343
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1344
  );
1345

    
1346
  $form['aggregation'] = array(
1347
      '#type' => 'fieldset',
1348
      '#title' => t('Aggregation of data'),
1349
      '#collapsible' => FALSE,
1350
      '#description' => 'This section covers the different aspects of aggregating information.
1351
          <p>
1352
          </p>',
1353
  );
1354

    
1355
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1356
      '#type' => 'checkboxes',
1357
      '#title' => 'Taxon media filter',
1358
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1359
      '#options' => array(
1360
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1361
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1362
          'includeOccurrences' => 'Media related to specimens and occurrences',
1363
      ),
1364
      '#description' => 'This filter configures which images should be taken into account.',
1365
  );
1366

    
1367
  $form['aggregation']['notice'] = array(
1368
      '#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
1369
          want to make use of the caching capabilities of the dataportal.',
1370
  );
1371

    
1372
  $form['aggregation']['media_aggregation'] = array(
1373
      '#type' => 'fieldset',
1374
      '#title' => t('Media aggregation'),
1375
      '#collapsible' => FALSE,
1376
      '#collapsed' => TRUE,
1377
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1378

    
1379
  );
1380
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1381
      '#type' => 'select',
1382
      '#title' => t('Aggregation of taxon pictures') . ':',
1383
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1384
      '#options' => array(
1385
          0 => "Show only pictures of the current taxon",
1386
          1 => "Include pictures of taxonomic children",
1387
      ),
1388
      '#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."),
1389
  );
1390

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

    
1405
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1406
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1407

    
1408
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1409
      '#type' => 'checkboxes',
1410
      '#title' => t('Direct'),
1411
      '#options' => $taxonRelationshipTypeOptions,
1412
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1413
  );
1414
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1415
      '#type' => 'checkboxes',
1416
      '#title' => t('Invers'),
1417
      '#options' => $taxonRelationshipTypeOptions,
1418
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1419
  );
1420

    
1421
  $form['drupal_integration'] = array(
1422
    '#type' => 'fieldset',
1423
    '#attributes' => array('class'=> array('clearfix')),
1424
    '#title' => t('Drupal integration'),
1425
    '#collapsible' => FALSE,
1426
    '#collapsed' => FALSE,
1427
    '#tree' => FALSE
1428
  );
1429

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

    
1439

    
1440

    
1441
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1442
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1443
    <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>',
1444
  );
1445
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1446
    '#type' => 'submit',
1447
    '#value' => t('Drop all cdm nodes'),
1448
    '#submit' => array('drop_all_cdm_nodes_submit')
1449
  );
1450

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

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

    
1480
  // Comment @WA: D7 form api does not support reset buttons,
1481
  // so to mimic the D5 reset button we add one like this.
1482
  $form['actions']['reset'] = array(
1483
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1484
    '#weight' => 1000,
1485
  );
1486

    
1487
  $form['#submit'][] = 'cdm_settings_general_submit';
1488

    
1489
  return system_settings_form($form);
1490
}
1491

    
1492
/**
1493
 * Submit callback; drops all cdm nodes.
1494
 *
1495
 * @ingroup forms
1496
 */
1497
function drop_all_cdm_nodes_submit($form, &$form_state) {
1498
  cdm_delete_all_cdm_nodes();
1499
  drupal_set_message(t('All cdm nodes dropped.'));
1500
}
1501

    
1502

    
1503
/**
1504
 * LAYOUT settings
1505
 *
1506
 * @return array
1507
 *   The form structure.
1508
 */
1509
function cdm_settings_layout() {
1510

    
1511
  $form = array();
1512

    
1513
  $form['about'] = array(
1514
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1515
      layout. If you want to configure the specific sites layout visit the
1516
      respective configuration site for taxon, search or media.') . '</p>',
1517
  );
1518

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

    
1530
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1531
    '#type' => 'checkbox',
1532
    '#title' => t('Do not show footnotes'),
1533
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1534
    '#description' => t('Check this if you do not want to show any footnotes'),
1535
  );
1536

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

    
1544
  $form['annotations'] = array(
1545
    '#type' => 'fieldset',
1546
    '#title' => t('Annotations'),
1547
    '#collapsible' => FALSE,
1548
    '#collapsed' => FALSE,
1549
    '#description' => t('This sections allows configuring global settings regarding annotations and thus will affect annotations dispayed as footnote and others.'),
1550
  );
1551

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

    
1564

    
1565
  // ---- original source --- //
1566
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1567
      '#type' => 'fieldset',
1568
      '#tree' => TRUE,
1569
      '#title' => t('Source Citations'),
1570
      '#collapsible' => FALSE,
1571
      '#collapsed' => FALSE,
1572
  );
1573

    
1574
  $bibliography_settings = get_bibliography_settings(true);
1575

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

    
1587
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1588
    '#type' => 'select',
1589
    '#title' => t('The format of the key numerals'),
1590
    '#default_value' => $bibliography_settings['key_format'],
1591
    '#options' => array('latin' => 'Latin',
1592
      'ROMAN' => 'Roman (upper case)',
1593
      'roman' => 'Roman (lower case)',
1594
      'ALPHA'=> 'Alphabet (upper case)',
1595
      'alpha' => 'Alphabet (lower case)')
1596
  );
1597

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

    
1612
  // --- Name page autoredirect feature --- //
1613
  $form['name_page'] = array(
1614
    '#type' => 'fieldset',
1615
    '#title' => t('Name page'),
1616
    '#collapsible' => FALSE,
1617
    '#collapsed' => FALSE,
1618
  );
1619
  $form['name_page'][CDM_NAME_PAGE_AUTOREDIRECT] = array(
1620
    '#type' => 'checkbox',
1621
    '#title' => 'Always redirect to taxon',
1622
    '#default_value' => variable_get(CDM_NAME_PAGE_AUTOREDIRECT, 0),
1623
    '#description' => t('By checking this option you can globally enable the redirection behavior of the name page. 
1624
    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. 
1625
    This option allows to enable this behavior also for contexts in which the redirection normally is not active.'),
1626
  );
1627

    
1628
  // --- Registrations --- //
1629
  $form['registrations'] = array(
1630
    '#type' => 'fieldset',
1631
    '#title' => t('Registrations'),
1632
    '#collapsible' => FALSE,
1633
    '#collapsed' => FALSE,
1634
  );
1635
  $form['registrations']['cdm_registration_presistent_identifier_as_link'] = array(
1636
    '#type' => 'checkbox',
1637
    '#title' => t('Use the persistent http identifier as link'),
1638
    '#default_value' => variable_get('cdm_registration_presistent_identifier_as_link', 0),
1639
    '#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.'),
1640
  );
1641

    
1642
  // ---- Taxon Name Rendering --- //
1643
  $form['taxon_name'] = array(
1644
      '#type' => 'fieldset',
1645
      '#title' => t('Taxon name display'),
1646
      '#collapsible' => TRUE,
1647
      '#collapsed' => TRUE,
1648
      '#description' => t('The display of taxon names is configured by two parts.
1649
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1650
          The name parts are defined in the <stong>part definitions</strong>'),
1651
  );
1652

    
1653
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1654
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1655
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1656
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1657

    
1658
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1659
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1660
    $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.)';
1661
  } else if($is_custom_part_definition){
1662
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1663
  } else  {
1664
    $which_version_message = '(These are the default part definition.)';
1665
  }
1666

    
1667
  $diff_viewer_markup = '';
1668
  if($is_custom_part_definition){
1669
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1670
  }
1671

    
1672
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1673
    . $which_version_message
1674
    . '</div>'
1675
    . $diff_viewer_markup;
1676

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

    
1766
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1767
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1768
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1769
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1770
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1771

    
1772
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1773
    $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.)';
1774
  } else if($is_custom_render_template){
1775
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1776
  } else {
1777
    $which_version_message = '(These are the default render templates.)';
1778
  }
1779

    
1780
  $diff_viewer_markup = '';
1781
  if($is_custom_render_template){
1782
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1783
  }
1784

    
1785
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1786
    . $which_version_message
1787
    . '</div>'
1788
    . $diff_viewer_markup;
1789

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

    
1830
  // @WA: D7 form api does not support reset buttons,
1831
  // so to mimic the D5 reset button we add one like this.
1832
  $form['actions']['reset'] = array(
1833
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1834
    '#weight' => 1000,
1835
  );
1836

    
1837
  $form['#submit'] = array('submit_json_as_php_array');
1838
  // #json_elements especially defined for submit_json_as_php_array()
1839
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1840
  return system_settings_form($form);
1841
}
1842

    
1843

    
1844
/**
1845
 * @param $form_name
1846
 * @param $form_title
1847
 * @param $collapsed
1848
 * @param string $form_description
1849
 *   The description for the fieldset of the gallery setting.
1850
 * @return mixed
1851
 */
1852
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1853
  $form[$form_name] = array(
1854
    '#type' => 'fieldset',
1855
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1856
    '#collapsible' => TRUE,
1857
    '#collapsed' => $collapsed,
1858
    '#tree' => TRUE,
1859
    '#description' => $form_description,
1860
  );
1861

    
1862
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1863
  $gallery_settings = variable_get($form_name, $default_values);
1864
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1865
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1866
    /*
1867
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1868
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1869
    '#type' => 'textfield',
1870
    '#title' => t('Search Page Size'),
1871
    '#default_value' => $test,
1872
    '#description' => t('Number of Names to display per page in search results.')
1873
    );
1874
    */
1875
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1876
      '#type' => 'checkbox',
1877
      '#title' => t('Show media thumbnails for accepted taxa'),
1878
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1879
    );
1880

    
1881
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1882
      '#type' => 'checkbox',
1883
      '#title' => t('Show media thumbnails for synonyms'),
1884
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1885
      '#description' => '',
1886
    );
1887
  }
1888

    
1889
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1890
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1891
    '#type' => 'checkbox',
1892
    '#title' => t('Show captions under thumbnails'),
1893
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1894
    '#description' => '',
1895
  );
1896

    
1897
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1898
    '#type' => 'textfield',
1899
    '#title' => t('Thumbnail size (max of width or height)') . ':',
1900
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1901
    '#description' => t('The maximum extend in either dimension, width or height, in pixels for the thumbnail images in the gallery.'),
1902
  );
1903

    
1904
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1905
    '#type' => 'textfield',
1906
    '#title' => t('Number of columns') . ':',
1907
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1908
    '#description' => t('Group the thumbnails in columns: select how many
1909
      columns the gallery should display.'),
1910
  );
1911

    
1912
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1913
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1914
      '#type' => 'textfield',
1915
      '#title' => t('Maximum number of rows') . ':',
1916
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1917
      '#description' => t('You can group the thumbnails in rows, select in how
1918
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1919
        If you want an unlimited number of rows please set to 0.'),
1920
    );
1921
  }
1922

    
1923
  return $form;
1924
}
1925

    
1926
/**
1927
 * @return array
1928
 *   The form structure.
1929
 */
1930
function cdm_settings_layout_taxon() {
1931
  $collapsed = FALSE;
1932
  $form = array();
1933

    
1934
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1935

    
1936
  // --------- TABBED TAXON ------- //
1937
  $form['taxon_tabs'] = array(
1938
    '#type' => 'fieldset',
1939
    '#title' => t('Taxon tabs'),
1940
    '#collapsible' => TRUE,
1941
    '#collapsed' => TRUE,
1942
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
1943
  );
1944

    
1945
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1946
    '#type' => 'checkbox',
1947
    '#title' => t('Tabbed taxon page'),
1948
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1949
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1950
  );
1951

    
1952
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
1953
    '#type' => 'checkbox',
1954
    '#title' => t('Synonymy as tab'),
1955
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
1956
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
1957
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
1958
  );
1959

    
1960
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1961
    '#type' => 'checkboxes',
1962
    '#title' => t('Section/Tab visibility') . ':',
1963
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1964
    '#options' => get_taxon_options_list()
1965
  );
1966

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

    
1989
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1990
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1991
    '#title'  => 'Section/Tab label override',
1992
    '#type' => 'fieldset',
1993
    '#collapsible' => false,
1994
    '#tree' => true,
1995
    '#description' => 'Setting a label for a section/tab will override the default label. 
1996
      Please enter the label text in the default language of the portal.'
1997
  );
1998
  foreach (get_taxon_tabs_list() as $label) {
1999
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
2000
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
2001
      '#title' => $label,
2002
      '#type'  => 'textfield',
2003
      '#default_value' => $taxon_tabs_labels[$key]
2004
    );
2005
  }
2006

    
2007
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
2008
    '#type' => 'select',
2009
    '#title' => t('Default tab to display') . ':',
2010
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
2011
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
2012
    '#description' => t('<p>Select the default tab to display when visiting a
2013
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
2014
      <strong>Note:</strong> After performing a search and clicking in any
2015
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
2016
      taxon and not the above selected tab.'),
2017
  );
2018

    
2019
  /* ======  TAXON_PROFILE ====== */
2020
  $form['taxon_profile'] = array(
2021
    '#type' => 'fieldset',
2022
    '#title' => t('Taxon profile (tab)'),
2023
    '#description' => t('<p>This section covers the settings related to the taxon
2024
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
2025
    '#collapsible' => TRUE,
2026
    '#collapsed' => TRUE,
2027
  );
2028

    
2029
  // ---- PROFILE PICTURE ----//
2030

    
2031
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
2032
    '#type' => 'fieldset',
2033
    '#tree' => TRUE,
2034
    '#title' => t('Taxon profile picture'),
2035
    '#collapsible' => TRUE,
2036
    '#collapsed' => FALSE,
2037
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
2038
  );
2039

    
2040
  //FIXME migrate variables:
2041
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
2042
  // FIXME
2043
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
2044

    
2045
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
2046

    
2047
  /*
2048
   * 'show' => 1,
2049
   * 'maxextend' => 184,
2050
   * 'media_uri_query' => ''
2051
   * 'custom_placeholder_image_on' => 1,
2052
   * 'custom_placeholder_image_fid' => ''
2053
   */
2054
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
2055
    '#type' => 'checkbox',
2056
    '#title' => t('Enable profile picture'),
2057
    '#description' => t('Show the profile picture.'),
2058
    '#default_value' => $taxon_profile_image_settings['show'],
2059
  );
2060

    
2061
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
2062
      '#type' => 'textfield',
2063
      '#tree' => TRUE,
2064
      '#title' => t('Profile picture maximum extend'),
2065
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
2066
      '#field_suffix' => 'px',
2067
      '#maxlength' => 4,
2068
      '#size' => 4,
2069
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
2070
  );
2071

    
2072
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
2073
      '#type' => 'textfield',
2074
      '#tree' => TRUE,
2075
      '#title' => t('Additional URI query parameter'),
2076
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
2077
      '#maxlength' => 1024,
2078
      '#size' => 60,
2079
      '#description' => t('Additional query parameters to be used when requesting for the  
2080
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
2081
            The query parameters will be appended to the uri of the media representation part
2082
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
2083
  );
2084

    
2085
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2086
    '#type' => 'checkbox',
2087
    '#title' => t('Show the placeholder image'),
2088
    '#description' => t("A placeholder image will be shown if no taxon profile picture is available."),
2089
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2090
  );
2091

    
2092
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2093
      '#type' => 'checkbox',
2094
      '#title' => t('Use a custom placeholder image'),
2095
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2096
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2097
  );
2098

    
2099
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2100
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2101
        '#type' => 'managed_file',
2102
        '#title' => t('Custom placeholder image file'),
2103
        '#progress_indicator' => 'bar',
2104
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2105
    //       '#name' => 'custom_placeholder_image',
2106
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2107
    );
2108

    
2109
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2110
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2111
      $url = file_create_url($profile_image_file->uri);
2112
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2113
                '#type' => 'item',
2114
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2115
      );
2116
    }
2117
  } else {
2118
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2119
      '#type' => 'hidden',
2120
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2121
    );
2122
  }
2123

    
2124
  $options = cdm_vocabulary_as_option(UUID_RANK, null, true);
2125
  array_unshift($options, '-- DISABLED --');
2126
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2127
    '#type' => 'select',
2128
    '#title' => t('Hide profile picture for higher ranks') . ':',
2129
    '#default_value' => variable_get('image_hide_rank', '0'),
2130
    '#options' => $options,
2131
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2132
  );
2133

    
2134
  // -- MEDIA THUMBNAILS -- //
2135
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2136
  $form_title = 'Taxon Profile Images';
2137
  $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>';
2138
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2139

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

    
2168
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2169
  $profile_feature_tree = get_profile_feature_tree();
2170

    
2171
  if (isset($profile_feature_tree->root->childNodes)) {
2172

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

    
2215

    
2216
    $feature_list_layout_settings_disabled = FALSE;
2217

    
2218
    // creating helper object to retrieve the default settings
2219
    $featureNode = new stdClass();
2220
    $featureNode->term = new stdClass();
2221
    $featureNode->term->uuid="DEFAULT";
2222
    $featureNode->term->representation_L10n = "Default";
2223
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2224

    
2225
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2226

    
2227
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2228

    
2229
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2230
        $subform_id = $featureNode->term->uuid;
2231
        $feature_block_setting = get_feature_block_settings($featureNode->term->uuid);
2232

    
2233
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2234

    
2235
        $form_feature_block_layout[$subform_id] = array(
2236
          '#type' => 'fieldset',
2237
          '#tree' => TRUE,
2238
          '#title' => $featureNode->term->representation_L10n,
2239
          '#collapsible' => FALSE,
2240
          '#collapsed' => FALSE,
2241
        );
2242
        if($featureNode->term->uuid == "DEFAULT"){
2243
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2244
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2245
          references</em> and <em>names in source</em> is only possible in the defaults';
2246
        }
2247

    
2248
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2249
          '#type' => 'select',
2250
          '#title' => 'List type',
2251
          '#default_value' => $feature_block_setting['as_list'],
2252
          '#options' => array(
2253
            'div' => 'not as list',
2254
            'ul' => 'bullet list',
2255
            'ol' => 'numbered list',
2256
            'dl' => 'definition list'
2257
          ),
2258
        );
2259

    
2260
        if($featureNode->term->uuid == "DEFAULT"){
2261
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2262
            '#type' => 'checkbox',
2263
            '#title' => t('Link to reference'),
2264
            '#default_value' => $feature_block_setting['link_to_reference'],
2265
          );
2266

    
2267
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2268
            '#type' => 'checkbox',
2269
            '#title' => 'Link to name used in source',
2270
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2271
          );
2272
        }
2273

    
2274
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2275
          '#type' => 'checkbox',
2276
          '#title' => 'Sources as content',
2277
          '#default_value' => $feature_block_setting['sources_as_content'],
2278
        );
2279

    
2280
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2281
          '#type' => 'checkbox',
2282
          '#title' => 'Put sources also as content to bibliography',
2283
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2284
        );
2285

    
2286
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2287
          '#type' => 'select',
2288
          '#title' => t('Sort elements'),
2289
          '#default_value' => $feature_block_setting['sort_elements'],
2290
          '#options' => array(
2291
            NO_SORT => 'No sorting',
2292
            SORT_ASC => 'Ascending',
2293
            SORT_DESC => 'Descending',
2294
            SORT_HIERARCHICAL => 'Hierarchical'
2295
          ),
2296
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2297
          <dl>
2298
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2299
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2300
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2301
          <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>
2302
          </dl>',
2303
        );
2304

    
2305
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2306
          '#type' => 'select',
2307
          '#title' => t('Element tag'),
2308
          '#options' => array(
2309
            'span' => 'span',
2310
            'div' => 'div',
2311
            'p' => 'p'
2312
          ),
2313
          '#default_value' => $feature_block_setting['element_tag'],
2314
        );
2315
        $form_feature_block_layout[$subform_id]['glue'] = array(
2316
          '#type' => 'textfield',
2317
          '#title' => t('Element glue'),
2318
          '#default_value' => $feature_block_setting['glue'],
2319
          '#size' => 10
2320
      );
2321

    
2322
      }
2323
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2324
    }
2325
  }
2326

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

    
2352

    
2353

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

    
2372
  );
2373

    
2374
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2375

    
2376
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2377
    '#type' => 'checkbox',
2378
    '#title' => t('Condensed distribution'),
2379
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2380
    '#description' => 'This option enables the display of a very compact representation
2381
    of the distribution which includes also information on the status.',
2382
  );
2383

    
2384
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2385
    '#type' => 'select',
2386
    '#title' => t('Condensed distribution recipe'),
2387
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2388
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2389
    '#description' => 'Recipe for creating the condensed distribution.',
2390
  );
2391

    
2392
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2393
    '#type' => 'textfield',
2394
    '#title' => t('Condensed distribution info path'),
2395
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2396
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2397
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2398
  );
2399

    
2400

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

    
2418
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2419
    '#type' => 'fieldset',
2420
    '#tree' => true,
2421
    '#title' => t('Distribution hierarchy style')
2422
  );
2423

    
2424
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2425
  foreach(array_keys($hierarchy_styles) as $level) {
2426
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2427
      '#type' => 'fieldset',
2428
      '#tree' => true,
2429
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2430
      '#attributes' => array('class' => array('fieldset-float'))
2431
    );
2432
    foreach ($hierarchy_styles[$level] as $key => $value) {
2433
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2434
        '#type' => 'textfield',
2435
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2436
        '#default_value' => $hierarchy_styles[$level][$key],
2437
        '#maxlength' => 4,
2438
        '#size' => 4
2439
      );
2440
    }
2441
  }
2442

    
2443
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2444
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2445
    '#type' => 'checkboxes',
2446
    '#title' => 'Omit area levels',
2447
    '#options' => $level_options,
2448
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2449
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2450
    Areas which belong to the selected area levels will be hidden in the portal.',
2451
  );
2452

    
2453
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2454
    '#type' => 'checkbox',
2455
    '#title' => t('Show TextData elements on top of the map'),
2456
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2457
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2458
      elements on top of the map. Otherwise all <code>TextData</code>
2459
      distribution elements will be listed below the other area elements.
2460
      This option is useful if you need to have descriptive texts for each
2461
      distribution map.'),
2462
  );
2463

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

    
2491
AbsenceTerm
2492
a	absent
2493
f	reported in error
2494
nf	native: reported in error
2495
if	introduced: reported in error
2496
cf	cultivated: reported in error
2497
ne	native: formerly native
2498
ie	introduced: formerly introduced
2499

    
2500
</pre>'),
2501
  );
2502

    
2503

    
2504
  /* ====== SYNONYMY ====== */
2505
  $form['taxon_synonymy'] = array(
2506
    '#type' => 'fieldset',
2507
    '#title' => t('Taxon synonymy (tab)'),
2508
    '#collapsible' => TRUE,
2509
    '#collapsed' => TRUE,
2510
    '#description' => t('This section covers the settings related to the taxon
2511
      <strong>synonymy</strong> tab.'),
2512
  );
2513

    
2514
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2515
    '#type' => 'checkbox',
2516
    '#title' => t('Accepted taxon on top of the synonymy'),
2517
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2518
    '#description' => t('If checked, the first homotypic taxon is a repetition
2519
      of the accepted taxon most likely with the full nomenclatural reference, 
2520
      depending on the ' . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout') . '.'),
2521
  );
2522

    
2523
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE] = array(
2524
    '#type' => 'checkbox',
2525
    '#title' => t('Secundum referenence as separate line above the accepted taxon.'),
2526
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE, 0),
2527
    '#description' => t('You may want to remove the <code>"secReferencePart": true,</code> entry from <code>"accepted_taxon.taxon_page_synonymy"{</code> the in the '
2528
      . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout')
2529
      . ' (Only applicable when the "Show accepted taxon on top of the synonymy" option above is enabled.)'),
2530
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE)
2531
  );
2532

    
2533
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL] = array(
2534
    '#type' => 'textfield',
2535
    '#description' => 'Label for the secundum referenence.',
2536
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT),
2537
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', 0)
2538
    );
2539

    
2540
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2541
    '#type' => 'checkbox',
2542
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2543
      coming from a synonym link.'),
2544
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2545
    '#description' => t('Check this if after doing a search and clicking on a
2546
      synonym you want to see the "accept of" text for the accepted synonym.'),
2547
  );
2548

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

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

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

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

    
2582
  $name_relationship_type_options = cdm_vocabulary_as_option(
2583
      UUID_NAME_RELATIONSHIP_TYPE,
2584
      '_cdm_relationship_type_term_label_callback',
2585
      false,
2586
      array('uuid' => '/' .UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM . '|'
2587
        . UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM . '|'
2588
        . UUID_NAMERELATIONSHIPTYPE_CONSERVED_AGAINST . '|'
2589
        . UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR . '|'
2590
        . UUID_NAMERELATIONSHIPTYPE_MISSPELLING . '|'
2591
        . UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT . '/' )
2592
  );
2593
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_INLINE_TYPES] = array(
2594
    '#type' => 'checkboxes',
2595
    '#title' => t('Name relationship types') . ':',
2596
    '#description' => 'This setting only affects specific types of name relations which are displayed appended to scientific name. 
2597
    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') . '.',
2598
    '#options' => $name_relationship_type_options,
2599
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT)),
2600
  );
2601

    
2602
  // ====== SPECIMENS ====== //
2603
  $form['taxon_specimens'] = array(
2604
    '#type' => 'fieldset',
2605
    '#title' => t('Taxon specimens (tab)'),
2606
    '#collapsible' => TRUE,
2607
    '#collapsed' => TRUE,
2608
    '#description' => t('This section covers the settings related to the taxon
2609
      <strong>specimens</strong> tab.'),
2610
  );
2611

    
2612
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2613

    
2614
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2615
    '#type' => 'checkbox',
2616
    '#title' => t('Show specimen derivatives in a compressed table'),
2617
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2618
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2619
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2620
  );
2621

    
2622
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2623
      '#type' => 'textfield',
2624
      '#title' => t('Number of records per page') . ':',
2625
      '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2626
  );
2627

    
2628
    $form['taxon_specimens']['cdm_dataportal_specimen_derivate_tree'] = array(
2629
        '#type' => 'checkbox',
2630
        '#title' => t('Show specimen derivatives in a tree view'),
2631
        '#default_value' => variable_get('cdm_dataportal_specimen_derivate_tree', CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE),
2632
        '#description' => t('If checked, the specimen will be listed in a tree view.'),
2633
    );
2634

    
2635

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

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

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

    
2674
  // Comment @WA: D7 form api does not support reset buttons,
2675
  // so to mimic the D5 reset button we add one like this.
2676
  $form['actions']['reset'] = array(
2677
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2678
    '#weight' => 1000,
2679
  );
2680
  return system_settings_form($form);
2681
}
2682

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

    
2702
/**
2703
 * @return array
2704
 *   The form structure.
2705
 */
2706
function cdm_settings_layout_search() {
2707

    
2708
  $form = array();
2709

    
2710
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2711

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

    
2723
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2724
      '#type' => 'checkbox',
2725
      '#title' => t('Ignore the chosen classification in simple search'),
2726
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2727
      '#description' => t('The simple search, which can be executed via the search block,
2728
          will by default search on the classification selected in the classification browser
2729
          selector. Set the tick if you want your portal to search on all classifications.'),
2730
  );
2731

    
2732
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2733
    '#type' => 'checkbox',
2734
    '#title' => t('Run simple search with free-text search backend.'),
2735
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2736
    '#description' => t('The simple search uses by default another search
2737
      backend as the advances search. By checking this option the simple search can be
2738
      configured to also use the free-text search backend.'),
2739
  );
2740

    
2741
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2742
    '#type' => 'checkbox',
2743
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2744
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2745
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2746
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2747
  );
2748

    
2749
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2750
    '#type' => 'textfield',
2751
    '#title' => t('Results per page') . ':',
2752
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2753
    '#description' => t('Number of results to display per page.'),
2754
  );
2755

    
2756
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2757
    '#type' => 'checkbox',
2758
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2759
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2760
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2761
  );
2762

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

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

    
2780
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2781
  );
2782

    
2783
    $form['blast_search_settings'] = array(
2784
        '#type' => 'fieldset',
2785
        '#title' => t('Blast Search'),
2786
        '#collapsible' => TRUE,
2787
        '#collapsed' => TRUE,
2788
        '#description' => t('<p>To perform blast searchs
2789
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2790
         where they can write the text to be searched. You can find Drupal block configuration
2791
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p>
2792
         <p>To perform a blast search a blast database for the cdm instance is needed.</p> '),
2793
    );
2794

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

    
2800
        '#description' => t('Activate the blast search for this portal, this works only with an existing blast database!'),
2801
    );
2802
    $form['blast_search_settings'][CDM_SEARCH_BLAST_SERVICE_URI] = array(
2803
        '#type' => 'textfield',
2804
        '#title' => t('Webservice URL for blast search') . ':',
2805
        '#default_value' => variable_get(CDM_SEARCH_BLAST_SERVICE_URI, 'http://130.133.70.28:9001/api/sequence'),
2806

    
2807
        '#description' => t('Enter the webservice URL for blast search'),
2808
    );
2809

    
2810
  // --- SEARCH TAXA GALLERY ---- //
2811
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2812
  $collapsed = FALSE;
2813
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2814
  $form_title = 'Taxa Search thumbnails';
2815
  $form_description = 'Search results may show thumbnails. ';
2816
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2817

    
2818
  // Comment @WA: D7 form api does not support reset buttons,
2819
  // so to mimic the D5 reset button we add one like this.
2820
  $form['actions']['reset'] = array(
2821
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2822
    '#weight' => 1000,
2823
  );
2824
  return system_settings_form($form);
2825
}
2826

    
2827

    
2828
/**
2829
 * @return array
2830
 *   The form structure.
2831
 */
2832
function cdm_settings_layout_name_page()
2833
{
2834

    
2835
  $form = array();
2836

    
2837

    
2838
  $form['name_relations'] = array(
2839
    '#type' => 'fieldset',
2840
    '#title' => t('Name relationship listings'),
2841
    '#collapsible' => FALSE,
2842
    '#collapsed' => FALSE
2843
  );
2844

    
2845
  $name_relationship_type_options = cdm_vocabulary_as_option(
2846
    UUID_NAME_RELATIONSHIP_TYPE,
2847
    '_cdm_relationship_type_term_label_callback',
2848
    false
2849
  );
2850
  $form['name_relations'][CDM_NAME_RELATIONSHIP_LIST_TYPES] = array(
2851
    '#type' => 'checkboxes',
2852
    '#title' => t('Name relationship types') . ':',
2853
    '#description' => 'This setting only affects specific types of name relations which are displayed as list. Another representations 
2854
    is the inline style used in the synonymy which may show a different (reduced) set of name relations. 
2855
    The according settings can be adjusted in the ' . l('taxon page settings section synonmy', 'admin/config/cdm_dataportal/settings/layout/taxon') . '.',
2856
    '#options' => $name_relationship_type_options,
2857
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_LIST_TYPES, cdm_vocabulary_as_defaults(UUID_NAME_RELATIONSHIP_TYPE)),
2858
  );
2859

    
2860

    
2861

    
2862
  return system_settings_form($form);
2863
}
2864

    
2865
/**
2866
 * @return array
2867
 *   The form structure.
2868
 */
2869
function cdm_settings_layout_media() {
2870

    
2871
  $form = array();
2872

    
2873
  $form['media_settings'] = array(
2874
    '#type' => 'fieldset',
2875
    '#title' => t('Media settings'),
2876
    '#collapsible' => FALSE,
2877
    '#collapsed' => FALSE,
2878
    '#description' => 'This section covers layout settings for media pages.'
2879
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2880
  );
2881

    
2882
  $form['media_settings']['image_gallery_viewer'] = array(
2883
    '#type' => 'select',
2884
    '#title' => t('Image viewer') . ':',
2885
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2886
    '#options' => array(
2887
      'default' => t('Standard image viewer'),
2888
      'fsi' => t('FSI viewer (requires FSI server!)'),
2889
    ),
2890
  );
2891

    
2892
  // --- STANDARD_IMAGE_VIEWER ---- //
2893
  if(variable_get('image_gallery_viewer', 'default') == 'default') {
2894
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2895
      '#type' => 'fieldset',
2896
      '#tree' => true,
2897
      '#title' => t('Standard image viewer settings'),
2898
      '#collapsible' => FALSE,
2899
      '#collapsed' => FALSE,
2900
      );
2901

    
2902
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2903
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2904
      '#type' => 'checkbox',
2905
      '#title' => 'Show media representations',
2906
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2907

    
2908
    );
2909
  }
2910

    
2911

    
2912
  // @WA: D7 form api does not support reset buttons,
2913
  // so to mimic the D5 reset button we add one like this.
2914
  $form['actions']['reset'] = array(
2915
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2916
    '#weight' => 1000,
2917
  );
2918
  return system_settings_form($form);
2919
}
2920

    
2921
/**
2922
 * GEOSERVICE and Map settings.
2923
 *
2924
 *  @return array
2925
 *   The form structure.
2926
 */
2927
function cdm_settings_geo($form, &$form_state) {
2928

    
2929
  $current_geoserver_settings = get_edit_map_service_settings();
2930
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2931

    
2932

    
2933
  $form = array();
2934

    
2935
  $dummy_distribution_query = NULL;
2936
  if($map_distribution['map_type'] != 1){
2937
    // we need to apply a dummy query since the map service requires for image maps
2938
    // at least as and ad to be defined
2939
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2940
  }
2941

    
2942
  $form['map_preview'] = array(
2943
      '#type' => 'fieldset',
2944
      '#tree' => FALSE,
2945
      '#title' => t('Map preview'),
2946
      '#collapsible' => FALSE,
2947
      '#description' => 'The preview of the map'
2948
       . ($dummy_distribution_query != null ?
2949
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2950
           '.<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.')
2951
  );
2952
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2953
    'move' => "this.cdmOpenlayersMap.printInfo",
2954
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2955
  ), true // resizable
2956
  );
2957

    
2958
  /*
2959
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2960
  );
2961
  */
2962

    
2963
  /*
2964
   * GEO SERVER
2965
   */
2966
  $form['edit_map_server'] = array(
2967
    '#type' => 'fieldset',
2968
    '#tree' => true,
2969
    '#title' => t('EDIT map service'),
2970
    '#collapsible' => TRUE,
2971
    '#collapsed' => TRUE,
2972
    '#description' => t('Configuration and selection of your geo server.
2973
      The Geo Server is responsible for generating the maps.'),
2974
  );
2975

    
2976
  $form['edit_map_server']['base_uri'] = array(
2977
    '#type' => 'select',
2978
    '#title' => t('EDIT map service') . ':',
2979
    '#default_value' => $current_geoserver_settings['base_uri'],
2980
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2981
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2982
  );
2983
  $form['edit_map_server']['version'] = array(
2984
      '#type' => 'select',
2985
      '#title' => t('Version') . ':',
2986
      '#default_value' => $current_geoserver_settings['version'],
2987
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2988
      '#description' => t('The version of the EDIT map services'),
2989
  );
2990

    
2991
  /*
2992
   * MAP SETTINGS
2993
   */
2994

    
2995
  $form[CDM_MAP_DISTRIBUTION] = array(
2996
    '#type' => 'fieldset',
2997
    '#tree' => TRUE,
2998
    '#title' => t('Maps settings'),
2999
    '#collapsible' => TRUE,
3000
    '#collapsed' => TRUE,
3001
    '#description' => t('General configuration for all map types.'),
3002
  );
3003

    
3004
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
3005
    '#type' => 'radios',
3006
    '#title' => 'Map types',
3007
    '#options' => array(
3008
      1 => "OpenLayers dynamic map viewer",
3009
      0 => "Plain image",
3010
    ),
3011
    '#default_value' => $map_distribution['map_type'],
3012
    '#description' => 'Two different map types are available :
3013
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
3014
      which allows zooming and panning. If enabled you can configure the default layer
3015
      (background of your maps) below.</li>
3016
      <li><em>Plain image</em>: The map will be static non interactive
3017
      image.</li></ul>',
3018
  );
3019
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
3020

    
3021
  /*
3022
   * settings for the distribution map are used also for specimens map!!!!
3023
   */
3024

    
3025
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
3026
      '#type' => 'textfield',
3027
      '#title' => 'Aspect ratio',
3028
      '#default_value' => $map_distribution['aspect_ratio'],
3029
      '#maxlength' => 4,
3030
      '#size' => 4,
3031
      '#element_validate' => array('element_validate_number'),
3032
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
3033
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
3034
      width by the height:</br>
3035
      <pre>aspect ratio = w / h</pre>
3036
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
3037
      for a square map use <strong>1</strong>.',
3038
  );
3039

    
3040
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
3041
    '#type' => 'textfield',
3042
    '#title' => 'Bounding box',
3043
    '#default_value' => $map_distribution['bbox'],
3044
    '#description' =>
3045
      '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. 
3046
      For the whole world use Use <code>-180,-90,180,90</code>" for EPSG:4326 layers, for Web Mercator maps Open Street Map or 
3047
      Google maps the maximum bounds of the world are <code>-27395030.933594,-13697515.466797,27395030.933594,13697515.466797</code>.
3048
      Leave <strong>empty</strong> to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
3049
      <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.
3050
      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
3051
      below the map from where you can copy the bbox string.</p>',
3052
  );
3053

    
3054
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
3055
    '#type' => 'select',
3056
    '#title' => 'Max zoom level',
3057
    '#default_value' => $map_distribution['maxZoom'],
3058
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
3059
  );
3060

    
3061
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
3062
    '#type' => 'checkbox',
3063
    '#title' => 'Display area labels',
3064
    '#default_value' => $map_distribution['show_labels'],
3065
    '#description' => t('The map will show name labels of the areas'),
3066
  );
3067

    
3068
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
3069
    '#type' => 'textfield',
3070
    '#title' => 'Map caption',
3071
    '#default_value' => $map_distribution['caption'],
3072
    '#description' => t('The caption will be shown below the map.'),
3073
  );
3074

    
3075
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
3076
    '#type' => 'textfield',
3077
    '#title' => 'Distribution layer opacity',
3078
    '#default_value' => $map_distribution['distribution_opacity'],
3079
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
3080
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
3081
  );
3082

    
3083
  // --- Plain Image Settings --- //
3084
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
3085
    '#type' => 'fieldset',
3086
    '#title' => 'Plain image map settings',
3087
    '#tree' => TRUE,
3088
    '#collapsible' => TRUE,
3089
    '#collapsed' => $open_layers_is_enabled,
3090
    '#description' => 'The settings in this section are still expertimental
3091
      and can only be used with the EDIT map service version 1.1 or above.',
3092
  );
3093
  $edit_mapserver_version = get_edit_map_service_version_number();
3094
  if ($edit_mapserver_version < 1.1) {
3095
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
3096
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
3097
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
3098
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
3099
  }
3100

    
3101
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
3102
    '#type' => 'textfield',
3103
    '#title' => 'Width',
3104
    '#default_value' => $map_distribution['image_map']['width'],
3105
    '#maxlength' => 4,
3106
    '#size' => 4,
3107
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
3108
  );
3109

    
3110
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
3111
    '#type' => 'textfield',
3112
    '#title' => 'Background layer',
3113
    '#default_value' => $map_distribution['image_map']['base_layer'],
3114
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
3115
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
3116
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
3117
    )),
3118
  );
3119

    
3120
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3121
    '#type' => 'textfield',
3122
    '#title' => 'Background color',
3123
    '#default_value' => $map_distribution['image_map']['bg_color'],
3124
  );
3125

    
3126
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3127
    '#type' => 'textfield',
3128
    '#title' => 'Background layer style',
3129
     // Only line color by now.
3130
    '#default_value' => $map_distribution['image_map']['layer_style'],
3131
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3132
  );
3133

    
3134
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3135
      '#type' => 'textfield',
3136
      '#title' => 'Projection',
3137
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3138
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3139
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3140
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3141
  );
3142

    
3143

    
3144
  // --- OpenLayers Settings --- //
3145
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3146
    '#type' => 'fieldset',
3147
    '#title' => 'OpenLayers settings',
3148
    '#tree' => TRUE,
3149
    '#collapsible' => TRUE,
3150
    '#collapsed' => !$open_layers_is_enabled,
3151
    '#description' => '',
3152
  );
3153

    
3154

    
3155
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3156
      '#type' => 'checkbox',
3157
      '#title' => 'Display outside max extent',
3158
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3159
      '#description' => t('Allows the map to display parts of the layers which are outside
3160
         the max extent if the aspect ratio of the map and of the baselayer
3161
         are not equal.'),
3162
  );
3163

    
3164

    
3165
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3166
      '#type' => 'checkbox',
3167
      '#title' => 'Show Layer Switcher',
3168
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3169
      '#description' => 'The Layer Switcher control displays a table of contents
3170
      for the map.  This allows the user interface to switch between
3171
      base layers and to show or hide overlays.  By default the switcher is
3172
      shown minimized on the right edge of the map, the user may expand it
3173
      by clicking on the handle.',
3174
  );
3175

    
3176
  if (!$open_layers_is_enabled) {
3177
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3178
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3179
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3180
  }
3181

    
3182
  // The default layer must always be enabled
3183
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3184
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3185

    
3186
  $baselayer_options = array(
3187
    /*
3188
   NOTICE: must correspond to the layers defined in
3189
   js/openlayers_,ap.js#getLayersByName()
3190
   */
3191
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3192
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3193
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3194
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3195
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3196
    // all others EPSG:900913
3197
    'mapnik' => 'OpenStreetMap (mapnik)',
3198
    'stamen_terrain' => 'Stamen Terrain',
3199
    'open_topomap' => 'OpenTopoMap',
3200
    // map quest is no longer free. it is required to sign up for a test plan.
3201
    // 'mapquest_open' => "MapQuest",
3202
    // 'mapquest_sat' => "MapQuest Sattelite",
3203
    'groadmap' => 'Google Roadmap',
3204
    'gsatellite' => 'Google Satellite',
3205
    'ghybrid' => 'Google Hybrid',
3206
    'gterrain' => 'Google Terrain',
3207
//     'veroad' => 'Virtual Earth Roads',
3208
//     'veaer' => 'Virtual Earth Aerial',
3209
//     'vehyb' => 'Virtual Earth Hybrid',
3210
    // 'yahoo' => 'Yahoo Street',
3211
    // 'yahoosat' => 'Yahoo Satellite',
3212
    // 'yahoohyb' => 'Yahoo Hybrid',
3213
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3214
  );
3215

    
3216
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3217
    '#type' => 'checkboxes_preferred',
3218
    '#title' => 'Base Layers',
3219
    '#options' => $baselayer_options,
3220
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3221
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3222
  );
3223

    
3224
  $google_maps_api_key = null;
3225
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3226
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3227
  }
3228
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3229
    '#type' => 'textfield',
3230
    '#title' => 'Google Maps API Key',
3231
    '#default_value' => $google_maps_api_key,
3232
    '#description' => 'In order to use any of the Google map layers you need to provide 
3233
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3234
  );
3235

    
3236
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3237
    $map_distribution['openlayers']['custom_wms_base_layer'],
3238
    'Custom WMS base layer',
3239
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3240
    true // add projection settings
3241
    );
3242

    
3243
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3244
    $map_distribution['openlayers']['wms_overlay_layer'],
3245
    'WMS overlay layer',
3246
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3247
                You can actually combine multiple layers for this overlay. 
3248
                For details please refer to the wms query parameter <code>Layers</code> .'
3249
  );
3250

    
3251
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3252
    '#type' => 'checkbox',
3253
    '#title' => 'Enable overlay layer',
3254
    '#weight' => -100,
3255
    '#default_value' => isset($map_distribution['openlayers']['wms_overlay_layer']['is_enabled']) && $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3256
  );
3257

    
3258
  /*
3259
   * Map Legend
3260
   */
3261
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3262
    '#type' => 'fieldset',
3263
    '#title' => 'Map legend',
3264
    '#tree' => TRUE,
3265
    '#collapsible' => TRUE,
3266
    '#collapsed' => TRUE,
3267
    '#description' => 'Configure the maps legend.',
3268
  );
3269

    
3270
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3271
    '#type' => 'checkbox',
3272
    '#title' => 'Display a map legend',
3273
    '#default_value' => $map_distribution['legend']['show'],
3274
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3275
  );
3276

    
3277
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3278
    '#type' => 'textfield',
3279
    '#title' => 'Legend opacity',
3280
    '#default_value' => $map_distribution['legend']['opacity'],
3281
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3282
                         to 0.0 will be not much visible.',
3283
  );
3284

    
3285
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3286
    '#type' => 'textfield',
3287
    '#title' => 'Font size',
3288
    '#default_value' => $map_distribution['legend']['font_size'],
3289
    '#description' => 'Font size in pixels.',
3290
  );
3291

    
3292
  $fontStyles = array(
3293
    0 => "plane",
3294
    1 => "italic",
3295
  );
3296
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3297
    '#type' => 'select',
3298
    '#title' => 'Available font styles',
3299
    '#default_value' => $map_distribution['legend']['font_style'],
3300
    '#options' => $fontStyles,
3301
    '#description' => 'Select a font style for the map legend.',
3302
  );
3303

    
3304
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3305
    '#type' => 'textfield',
3306
    '#title' => 'Icon width',
3307
    '#default_value' => $map_distribution['legend']['icon_width'],
3308
    '#description' => 'Legend icon width in pixels.',
3309
  );
3310
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3311
    '#type' => 'textfield',
3312
    '#title' => 'Icon height',
3313
    '#default_value' => $map_distribution['legend']['icon_height'],
3314
    '#description' => 'Legend icon height in pixels.',
3315
  );
3316

    
3317
  // @WA: D7 form api does not support reset buttons,
3318
  // so to mimic the D5 reset button we add one like this.
3319
  $form['actions']['reset'] = array(
3320
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3321
    '#weight' => 1000,
3322
  );
3323

    
3324
  return system_settings_form($form);
3325
}
3326

    
3327
/**
3328
 * @param $default_settings
3329
 * @param $title
3330
 * @param $description
3331
 * @param bool $add_projection_settings
3332
 * @return array
3333
 */
3334
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3335
{
3336
  $form_elements = array(
3337
    '#type' => 'fieldset',
3338
    '#title' => $title,
3339
    '#tree' => TRUE,
3340
    '#collapsible' => FALSE,
3341
    '#collapsed' => FALSE,
3342
    '#description' => $description,
3343
  );
3344

    
3345
  $form_elements['name'] = array(
3346
    '#type' => 'textfield',
3347
    '#title' => 'Layer name',
3348
    '#default_value' => $default_settings['name'],
3349
    '#description' => 'A arbitrary name for the layer.',
3350
  );
3351
  $form_elements['url'] = array(
3352
    '#type' => 'textfield',
3353
    '#title' => 'WMS url',
3354
    '#default_value' => $default_settings['url'],
3355
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3356
  );
3357
  $form_elements['untiled'] = array(
3358
    '#type' => 'checkbox',
3359
    '#title' => 'Untiled',
3360
    '#default_value' => $default_settings['untiled'],
3361
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3362
  );
3363
  $form_elements['params'] = array(
3364
    '#type' => 'textarea',
3365
    '#title' => 'WMS parameters',
3366
    '#element_validate' => array('form_element_validate_json'),
3367
    '#default_value' => $default_settings['params'],
3368
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3369
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3370
      . '), entered in valid JSON. For example:
3371
<pre> {
3372
  "Layers": "topp:em_tiny_jan2003",
3373
  "Format": "image/png",
3374
  "BGCOLOR": "0xe0faff"
3375
}
3376
</pre>
3377
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3378
  );
3379

    
3380
  if($add_projection_settings){
3381

    
3382
    $form_elements['projection'] = array(
3383
      '#type' => 'textfield',
3384
      '#title' => 'Projection',
3385
      '#default_value' => $default_settings['projection'],
3386
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
3387
    );
3388
    $form_elements['proj4js_def'] = array(
3389
      '#type' => 'textfield',
3390
      '#maxlength' => 256,
3391
      '#title' => 'proj4js definition',
3392
      '#default_value' => $default_settings['proj4js_def'],
3393
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
3394
              The definitions for
3395
              EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
3396
              EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
3397
              are already predefined and must NOT be added here again.  If your dont know the defintion of your desired projection,
3398
              go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
3399
              choose to display the proj4js definition string.
3400
              <h5>Quick Reference on the common proj4js definition parameters:</h5>
3401
              <pre>
3402
  +a         Semimajor radius of the ellipsoid axis
3403
  +alpha     ? Used with Oblique Mercator and possibly a few others
3404
  +axis      Axis orientation (new in 4.8.0)
3405
  +b         Semiminor radius of the ellipsoid axis
3406
  +datum     Datum name (see `proj -ld`)
3407
  +ellps     Ellipsoid name (see `proj -le`)
3408
  +k         Scaling factor (old name)
3409
  +k_0       Scaling factor (new name)
3410
  +lat_0     Latitude of origin
3411
  +lat_1     Latitude of first standard parallel
3412
  +lat_2     Latitude of second standard parallel
3413
  +lat_ts    Latitude of true scale
3414
  +lon_0     Central meridian
3415
  +lonc      ? Longitude used with Oblique Mercator and possibly a few others
3416
  +lon_wrap  Center longitude to use for wrapping (see below)
3417
  +nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
3418
  +no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
3419
  +over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
3420
  +pm        Alternate prime meridian (typically a city name, see below)
3421
  +proj      Projection name (see `proj -l`)
3422
  +south     Denotes southern hemisphere UTM zone
3423
  +to_meter  Multiplier to convert map units to 1.0m
3424
  +towgs84   3 or 7 term datum transform parameters (see below)
3425
  +units     meters, US survey feet, etc.
3426
  +vto_meter vertical conversion to meters.
3427
  +vunits    vertical units.
3428
  +x_0       False easting
3429
  +y_0       False northing
3430
  +zone      UTM zone
3431
              </pre>
3432
            For the full reference please refer to <a href="http://proj4.org/parameters.html">http://proj4.org/parameters.html</a>.'
3433
    );
3434
    $form_elements['max_extent'] = array(
3435
      '#type' => 'textfield',
3436
      '#title' => 'Maximum extent',
3437
      '#default_value' => $default_settings['max_extent'],
3438
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
3439
    );
3440
    $form_elements['units'] = array(
3441
      '#type' => 'textfield',
3442
      '#title' => 'Units',
3443
      '#default_value' => $default_settings['units'],
3444
      '#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.'
3445
    );
3446

    
3447
  }
3448
  return $form_elements;
3449
}
3450

    
3451

    
3452
/**
3453
 * @return array
3454
 *   The form structure.
3455
 */
3456
function cdm_settings_cache() {
3457

    
3458
  $form = array();
3459

    
3460
  $form['cache_settings'] = array(
3461
    '#type' => 'fieldset',
3462
    '#title' => t('Cache Settings'),
3463
    '#collapsible' => FALSE,
3464
    '#collapsed' => FALSE,
3465
    '#description' => t('<p>When caching is enabled all single taxon sites are
3466
      stored in an internal drupal cache doing the portal response of taxa pages
3467
      faster. This is possible because the sites are loaded from the cache and
3468
      are not created from scratch.</p>'),
3469
  );
3470

    
3471
  $form['cache_settings']['cdm_webservice_cache'] = array(
3472
    '#type' => 'checkbox',
3473
    '#title' => t('<strong>Enable caching</strong>'),
3474
    '#options' => cdm_help_general_cache(),
3475
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3476
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3477
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3478
       application the changes will be not visible till the cache is erased.
3479
       Therefore developers should deactived this feature when they are working
3480
       on the CDM Dataportal Module.</p>'),
3481
  );
3482

    
3483
  $form['cache_settings']['cdm_run_cache'] = array(
3484
    '#markup' => cdm_view_cache_site(),
3485
  );
3486

    
3487
  // @WA: D7 form api does not support reset buttons,
3488
  // so to mimic the D5 reset button we add one like this.
3489
  $form['actions']['reset'] = array(
3490
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3491
    '#weight' => 1000,
3492
  );
3493
  return system_settings_form($form);
3494
}
3495

    
3496
/**
3497
 * Walk and cache all taxon pages.
3498
 */
3499
function cdm_view_cache_site() {
3500

    
3501
  $out = '';
3502

    
3503
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3504

    
3505
  $request_params = array();
3506
  $request_params['class'] = "Taxon";
3507

    
3508
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3509
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3510
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3511

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

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

    
3521
  // Comment @WA: A form within a form is not valid html and not needed here.
3522
  // Also, it would be recommended just to include this part of the form in the
3523
  // rest of the form array in cdm_settings_cache().
3524
  // $out .= '<form id="cache_site">';
3525
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3526
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3527
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3528
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3529
  // $out .= '</form>';
3530
  $out .= '</div>';
3531
  /*
3532
  foreach($taxonPager->records as $taxon){
3533
    cdm_dataportal_taxon_view($uuid);
3534
  }
3535
  */
3536
  return $out;
3537
}
3538

    
3539

    
3540
function cdm_settings_layout_taxon_submit($form, &$form_state){
3541
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3542
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3543
    if(is_object($file)){
3544
      $file->status = FILE_STATUS_PERMANENT;
3545
      file_save($file);
3546
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3547
    }
3548
  }
3549
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3550
  $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]);
3551
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3552
  if($tab_lables_modified || $tabs_enabled_modified){
3553
    // we first need to set the variable to persist the changes setting
3554
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3555
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3556
    menu_rebuild();
3557
  }
3558
}
3559

    
3560
function cdm_settings_layout_search_submit($form, &$form_state){
3561
  // the visibility of media thumbnails also affects the ui of the search results
3562
  // so reset the according session variable
3563
  //    1. in order to give the user immediate
3564
  //       feedback on potential setting changes
3565
  //    2. let refresh the default if it has changed
3566
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3567
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3568
  }
3569
}
3570

    
3571
/**
3572
 * Form validation handler for cdm_settings_general
3573
 *
3574
 * @param $form
3575
 * @param $form_state
3576
 */
3577
function cdm_settings_general_validate($form, &$form_state) {
3578

    
3579
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3580
    $form_state['values']['cdm_webservice_url'] .= '/';
3581
  }
3582

    
3583
}
3584

    
3585
/**
3586
 * Form submit handler for settings general.
3587
 *
3588
 * tasks performed:
3589
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3590
 *
3591
 * @param $form
3592
 * @param $form_state
3593
 */
3594
function cdm_settings_general_submit($form, &$form_state){
3595
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3596
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3597
  unset($_SESSION['cdm_login']);
3598
}
3599

    
3600
/**
3601
 * Form validation handler for cdm_settings_cache
3602
 */
3603
function cdm_settings_cache_validate($form, &$form_state) {
3604
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3605
    cache_clear_all(NULL, 'cache_cdm_ws');
3606
    // Better clear secref_cache since I can not be sure if the cache has not
3607
    // be used during this response.
3608
    cdm_api_secref_cache_clear();
3609
  }
3610

    
3611
}
3612

    
3613
/**
3614
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3615
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3616
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3617
 *  - version: the version, e.g.: v1.1
3618
 *
3619
 * @return array
3620
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3621
 */
3622
function get_edit_map_service_settings() {
3623

    
3624
  $settings = variable_get('edit_map_server', array(
3625
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3626
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3627
      )
3628
  );
3629

    
3630
  return $settings;
3631
}
3632

    
3633
/**
3634
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3635
 *
3636
 * @return string
3637
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3638
 */
3639
function get_edit_map_service_full_uri() {
3640
  $settings = get_edit_map_service_settings();
3641
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3642
}
3643

    
3644

    
3645
/**
3646
 * Returns the version number of the currently selected edit mapserver as a float
3647
 *
3648
 * @return float
3649
 *   The version number of the currently selected edit mapserver as a float.
3650
 *   Returns 0 on error.
3651
 */
3652
function get_edit_map_service_version_number() {
3653

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

    
3656
  $settings = get_edit_map_service_settings();
3657
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3658
  if (isset($matches[1])) {
3659
    // Convert string to float.
3660
    $version = 1 + $matches[1][0] - 1;
3661
    return $version;
3662
  }
3663
  else {
3664
    // Report error.
3665
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3666
        array(
3667
          '!version' => $settings['version'],
3668
          'warning')
3669
        )
3670
      );
3671
    return 0;
3672
  }
3673
}
3674

    
3675
/**
3676
 * Returns the array of selected items in a options array
3677
 *
3678
 * @param array $options
3679
 *   An options array as generated by a form element like checkoxes, select ...,
3680
 */
3681
function get_selection($options) {
3682
  $selection = array();
3683
  foreach ($options as $key=>$val) {
3684
    if (!empty($val)) {
3685
      $selection[] = $val;
3686
    }
3687
  }
3688
  return $selection;
3689
}
3690

    
3691

    
3692
/**
3693
 * Implements hook_element_info().
3694
 *
3695
 * Allows modules to declare their own Form API element types and specify their default values.
3696
 *
3697
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3698
 */
3699
function cdm_dataportal_element_info() {
3700
  $type['checkboxes_preferred'] = array(
3701
    '#input' => TRUE,
3702
    '#process' => array('checkboxes_preferred_expand'),
3703
    '#after_build' => array('checkboxes_preferred_after_build'),
3704
    '#theme' => array('checkboxes_preferred'),
3705
    // '#theme_wrapper' => array('form_element'),
3706
  );
3707
  return $type;
3708
}
3709

    
3710
/**
3711
 * #process callback function for the custom form element type 'checkbox_preferred'
3712
 *
3713
 *
3714
 */
3715
function checkboxes_preferred_expand($element, &$form_state, $form) {
3716

    
3717
  // First of all create checkboxes for each of the elements
3718
  $element = form_process_checkboxes($element);
3719

    
3720
  // compose the element name
3721
  $parents = array();
3722
  array_deep_copy($element['#parents'], $parents);
3723
  $parents[count($parents) -1 ] .= '_preferred';
3724
  $element_name = $parents[0];
3725
  for ($i=1; $i < count($parents); $i++){
3726
    $element_name .= '[' . $parents[$i] . ']';
3727
  }
3728

    
3729
  $children = element_children($element);
3730

    
3731
  $element['table_start'] = array(
3732
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3733
    '#weight' => -1,
3734
  );
3735

    
3736
  // prepare first part each of the table rows which contains the row label
3737
  $weight = 0;
3738
  foreach ($children as $key) {
3739
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3740
    $element[$key]['#weight'] = $weight;
3741
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3742
    $element[$key]['#suffix'] = '</td>';
3743
    unset($element[$key]['#title']);
3744
    $weight += 2;
3745
  }
3746
  $weight = 0;
3747

    
3748
  // add a radio button to each of the checkboxes, the
3749
  // check boxes have already been created at the beginning
3750
  // of this function
3751
  if (count($element['#options']) > 0) {
3752
    foreach ($element['#options'] as $key => $choice) {
3753
      if (!isset($element[$key . '_preferred'])) {
3754
        $element[$key . '_preferred'] = array(
3755
          '#type' => 'radio',
3756
          '#name' => $element_name,
3757
          '#return_value' => check_plain($key),
3758
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3759
          '#attributes' => $element['#attributes'],
3760
          '#parents' => $element['#parents'],
3761
          // '#spawned' => TRUE,
3762
          '#weight' => $weight + 1,
3763
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3764
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3765
        );
3766
      }
3767
      $weight += 2;
3768
    }
3769
  }
3770

    
3771
  // end the table
3772
  $element['table_end'] = array(
3773
    '#markup' => '</table>',
3774
    '#weight' => $weight++,
3775
  );
3776

    
3777
  return $element;
3778
}
3779

    
3780
/**
3781
 * Theme function for the custom form field 'checkboxes_preferred'.
3782
 */
3783
function theme_checkboxes_preferred($variables) {
3784
  $element = $variables['element'];
3785
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3786
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3787
  $out .= drupal_render_children($element);
3788
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3789
  $out .= '</div>';
3790
  return $out;
3791
}
3792

    
3793
/**
3794
 * Callback for checkboxes preferred for widget which will
3795
 * be called after the form or element is built. The call
3796
 * back is configured in the form element by setting it as
3797
 * #after_build parameter.
3798
 *
3799
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3800
 *
3801
 * @param $element
3802
 *   Nested array of form elements that comprise the form.
3803
 * @param $form_state
3804
 *   A keyed array containing the current state of the form.
3805
 *   This includes the current persistent storage data for the form.
3806
 *   Additional information, like the sanitized $_POST data,
3807
 *   is also accumulated here in $form_state['input']
3808
 *
3809
 * @return the modified form array
3810
 */
3811
function checkboxes_preferred_after_build($element, &$form_state) {
3812

    
3813
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3814

    
3815
  if ($_POST && count($_POST) > 0) {
3816
    // TODO use  $form_state['input'] instead of POST !!!
3817
    // First pass of form processing.
3818
    $parents = array();
3819
    array_deep_copy($element['#parents'], $parents);
3820
    $parents[count($parents) - 1] .= '_preferred';
3821
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3822
    $element['#value']['PREFERRED'] = $preferred_layer;
3823
//     $form_state[$parent_id] = $element['#value'];
3824
//     $form_state['values']['baselayers'] = $element['#value'];
3825
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3826
    $form_state_element_values = $element['#value'];
3827
  }
3828
  else {
3829
    // Second pass of form processing.
3830
    $preferred_layer = $element['#value']['PREFERRED'];
3831
  }
3832

    
3833
  // Also set the chosen value (not sure if this is good Drupal style ....).
3834
  foreach ($children = element_children($element) as $key) {
3835
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3836
      $element[$key]['#value'] = $preferred_layer;
3837
    }
3838
  }
3839
  // The default layer must always be enabled.
3840
  $element[$preferred_layer]['#value'] = $preferred_layer;
3841

    
3842
  return $element;
3843
}
3844

    
3845
function radios_prepare_options_suffix(&$elements){
3846

    
3847
  $childrenKeys = element_children($elements);
3848
  foreach($childrenKeys as $key){
3849
    if(!is_array($elements[$key]['#theme_wrappers'])){
3850
      $elements[$key]['#theme_wrappers'] = array();
3851
    }
3852
    if(isset($elements['#options_suffixes'][$key])){
3853
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3854
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3855
    }
3856
  }
3857
  return $elements;
3858

    
3859
}
3860

    
3861
/**
3862
 * TODO
3863
 * @param unknown $variables
3864
 */
3865
function theme_radio_options_suffix($variables) {
3866
  $element = $variables['element'];
3867
  if(isset($element['#options_suffix'])) {
3868
    $element['#children'] .= $element['#options_suffix'];
3869
  }
3870
  return $element['#children'];
3871
}
3872

    
3873

    
3874
/**
3875
 * Element validate callback for text field and arrays containing json.
3876
 *
3877
 * @param $element
3878
 *   The form element to validate
3879
 * @param $form_state
3880
 *   A keyed array containing the current state of the form.
3881
 * @param $form
3882
 *   Nested array of form elements that comprise the form.
3883
 */
3884
function form_element_validate_json($element, &$form_state, $form) {
3885
   if (!empty($element['#value'])) {
3886
     json_decode($element['#value']);
3887
     if(json_last_error() != JSON_ERROR_NONE){
3888
       form_error($element,
3889
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3890
         . l('JSONLint', 'http://jsonlint.com/')
3891
       );
3892
     }
3893
   }
3894
}
3895

    
3896
/**
3897
 * Form submission handler for textareas and textfields containing JSON.
3898
 *
3899
 * The contained JSON will be converted into an php array
3900
 * or object and will be stored in the variables as such.
3901
 *
3902
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3903
 *
3904
 * @param $form
3905
 *   Nested array of form elements that comprise the form.
3906
 * @param $form_state
3907
 *   A keyed array containing the current state of the form.
3908
 *
3909
 */
3910
function submit_json_as_php_array($form, &$form_state) {
3911
  if (is_array($form['#json_elements'])) {
3912
    foreach ($form['#json_elements'] as $element){
3913
      if (trim($form_state['values'][$element])) {
3914
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3915
      } else {
3916
        $form_state['values'][$element] = NULL;
3917
      }
3918
    }
3919
  }
3920
}
(18-18/18)