Project

General

Profile

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

    
7

    
8
  // TODO Genus UUID.
9

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

    
15
  define('CDM_SUB_TREE_FILTER_UUID', 'cdm_sub_tree_filter_uuid');
16

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

    
20
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
21

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

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

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

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

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

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

    
66

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

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

    
112

    
113
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
114

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

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

    
126
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
127
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
128

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

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

    
161

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

    
175
$taxon_tab_options = get_taxon_tabs_list();
176
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
177

    
178
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
179

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

    
190
}
191

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

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

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

    
369
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
370

    
371
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
372
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
373
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
374

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
704
  // ---- DEFAULTS settings
705

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

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

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

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

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

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

    
882
  $default_theme = variable_get('theme_default', NULL);
883

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

    
908
  // ---- END of DEFAULTS
909

    
910
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
911

    
912
  $feature_block_setting = null;
913

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

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

    
934
  return $feature_block_setting;
935
}
936

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

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

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

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

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

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

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

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

    
1075
}
1076

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1438

    
1439

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

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

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

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

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

    
1488
  return system_settings_form($form);
1489
}
1490

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

    
1501

    
1502
/**
1503
 * LAYOUT settings
1504
 * @return
1505
 *   todo
1506
 */
1507
function cdm_settings_layout() {
1508

    
1509
  $form = array();
1510

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

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

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

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

    
1542
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1543
  // Additional option for the NULL case.
1544
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1545
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1546
    '#type' => 'checkboxes',
1547
    '#title' => t('Annotation types as footnotes'),
1548
    '#description' => t("Only annotations of the selected type will be displayed
1549
       as footnotes. You may want to turn 'technical annotations' off."),
1550
    '#options' => $annotationTypeOptions,
1551
  );
1552
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1553
  if (!empty($annotationsTypesAsFootnotes)) {
1554
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1555
  }
1556

    
1557
  // ---- original source --- //
1558
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1559
      '#type' => 'fieldset',
1560
      '#tree' => TRUE,
1561
      '#title' => t('Source Citations'),
1562
      '#collapsible' => FALSE,
1563
      '#collapsed' => FALSE,
1564
  );
1565

    
1566
  $bibliography_settings = get_bibliography_settings(true);
1567

    
1568
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1569
      '#type' => 'checkbox',
1570
      '#title' => t('Original Source in bibliography'),
1571
      '#default_value' => $bibliography_settings['enabled'],
1572
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1573
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1574
       into the bibliography also depends on the settings in the ' .
1575
        l("Taxon profile feature block settings", "settings/layout/taxon") .
1576
        '. 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.'),
1577
  );
1578

    
1579
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1580
    '#type' => 'select',
1581
    '#title' => t('The format of the key numerals'),
1582
    '#default_value' => $bibliography_settings['key_format'],
1583
    '#options' => array('latin' => 'Latin',
1584
      'ROMAN' => 'Roman (upper case)',
1585
      'roman' => 'Roman (lower case)',
1586
      'ALPHA'=> 'Alphabet (upper case)',
1587
      'alpha' => 'Alphabet (lower case)')
1588
  );
1589

    
1590
  // --- Advanced Search --- //
1591
  $form['asearch'] = array(
1592
      '#type' => 'fieldset',
1593
      '#title' => t('Advanced search'),
1594
      '#collapsible' => FALSE,
1595
      '#collapsed' => FALSE,
1596
  );
1597
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1598
      '#type' => 'checkbox',
1599
      '#title' => t('Show advanced search link'),
1600
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1601
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1602
  );
1603

    
1604
  // ---- Taxon Name Rendering --- //
1605
  $form['taxon_name'] = array(
1606
      '#type' => 'fieldset',
1607
      '#title' => t('Taxon name display'),
1608
      '#collapsible' => TRUE,
1609
      '#collapsed' => TRUE,
1610
      '#description' => t('The display of taxon names is configured by two parts.
1611
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1612
          The name parts are defined in the <stong>part definitions</strong>'),
1613
  );
1614

    
1615
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1616
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1617
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1618
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1619

    
1620
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1621
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1622
    $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.)';
1623
  } else if($is_custom_part_definition){
1624
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1625
  } else  {
1626
    $which_version_message = '(These are the default part definition.)';
1627
  }
1628

    
1629
  $diff_viewer_markup = '';
1630
  if($is_custom_part_definition){
1631
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1632
  }
1633

    
1634
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1635
    . $which_version_message
1636
    . '</div>'
1637
    . $diff_viewer_markup;
1638

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

    
1728
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1729
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1730
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1731
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1732
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1733

    
1734
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1735
    $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.)';
1736
  } else if($is_custom_render_template){
1737
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1738
  } else {
1739
    $which_version_message = '(These are the default render templates.)';
1740
  }
1741

    
1742
  $diff_viewer_markup = '';
1743
  if($is_custom_render_template){
1744
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1745
  }
1746

    
1747
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1748
    . $which_version_message
1749
    . '</div>'
1750
    . $diff_viewer_markup;
1751

    
1752
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1753
      '#type' => 'textarea',
1754
      '#title' => t('Name render templates'),
1755
      '#element_validate' => array('form_element_validate_json'),
1756
      '#default_value' =>  $current_render_templates_json,
1757
      '#description' => '
1758
          <p>' . $which_version_message . '</p>
1759
          <p>
1760
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1761
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1762
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1763
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1764
          The following render Path keys are currently recognized:
1765
          <ul>
1766
            <li>list_of_taxa</li>
1767
            <li>acceptedFor</li>
1768
            <li>homonym</li>
1769
            <li>taxon_page_synonymy</li>
1770
            <li>typedesignations</li>
1771
            <li>taxon_page_title</li>
1772
            <li>polytomousKey</li>
1773
            <li>na: name + authorship</li>
1774
            <li>nar:name + authorship + reference</li>
1775
            <li>#DEFAULT</li>
1776
          </ul>
1777
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1778
          array element should be a comma separated list of render paths, without any whitespace!.
1779
          </p>
1780
          <p>
1781
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1782
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1783
          <p>
1784
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1785
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1786
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1787
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1788
          links if the paramters $nameLink or $refenceLink are given to the name render function
1789
          (this is hard coded and cannot be configured here).',
1790
  );
1791

    
1792
  // @WA: D7 form api does not support reset buttons,
1793
  // so to mimic the D5 reset button we add one like this.
1794
  $form['actions']['reset'] = array(
1795
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1796
    '#weight' => 1000,
1797
  );
1798

    
1799
  $form['#submit'] = array('submit_json_as_php_array');
1800
  // #json_elements especially defined for submit_json_as_php_array()
1801
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1802
  return system_settings_form($form);
1803
}
1804

    
1805

    
1806
/**
1807
 * @param $form_name
1808
 * @param $form_title
1809
 * @param $collapsed
1810
 * @param string $form_description
1811
 *   The description for the fieldset of the gallery setting.
1812
 * @return mixed
1813
 */
1814
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1815
  $form[$form_name] = array(
1816
    '#type' => 'fieldset',
1817
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1818
    '#collapsible' => TRUE,
1819
    '#collapsed' => $collapsed,
1820
    '#tree' => TRUE,
1821
    '#description' => $form_description,
1822
  );
1823

    
1824
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1825
  $gallery_settings = variable_get($form_name, $default_values);
1826
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1827
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1828
    /*
1829
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1830
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1831
    '#type' => 'textfield',
1832
    '#title' => t('Search Page Size'),
1833
    '#default_value' => $test,
1834
    '#description' => t('Number of Names to display per page in search results.')
1835
    );
1836
    */
1837
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1838
      '#type' => 'checkbox',
1839
      '#title' => t('Show media thumbnails for accepted taxa'),
1840
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1841
    );
1842

    
1843
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1844
      '#type' => 'checkbox',
1845
      '#title' => t('Show media thumbnails for synonyms'),
1846
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1847
      '#description' => '',
1848
    );
1849
  }
1850

    
1851
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1852
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1853
    '#type' => 'checkbox',
1854
    '#title' => t('Show captions under thumbnails'),
1855
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1856
    '#description' => '',
1857
  );
1858

    
1859
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1860
    '#type' => 'textfield',
1861
    '#title' => t('Thumbnail size') . ':',
1862
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1863
    '#description' => t('Select the size of each individual thumbnail.'),
1864
  );
1865

    
1866
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1867
    '#type' => 'textfield',
1868
    '#title' => t('Number of columns') . ':',
1869
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1870
    '#description' => t('Group the thumbnails in columns: select how many
1871
      columns the gallery should display.'),
1872
  );
1873

    
1874
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1875
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1876
      '#type' => 'textfield',
1877
      '#title' => t('Maximum number of rows') . ':',
1878
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1879
      '#description' => t('You can group the thumbnails in rows, select in how
1880
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1881
        If you want an unlimited number of rows please set to 0.'),
1882
    );
1883
  }
1884

    
1885
  return $form;
1886
}
1887

    
1888
/**
1889
 * @todo document this function.
1890
 */
1891
function cdm_settings_layout_taxon() {
1892
  $collapsed = FALSE;
1893
  $form = array();
1894

    
1895
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1896

    
1897
  // --------- TABBED TAXON ------- //
1898
  $form['taxon_tabs'] = array(
1899
    '#type' => 'fieldset',
1900
    '#title' => t('Taxon tabs'),
1901
    '#collapsible' => TRUE,
1902
    '#collapsed' => TRUE,
1903
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
1904
  );
1905

    
1906
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1907
    '#type' => 'checkbox',
1908
    '#title' => t('Tabbed taxon page'),
1909
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1910
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1911
  );
1912

    
1913
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
1914
    '#type' => 'checkbox',
1915
    '#title' => t('Synonymy as tab'),
1916
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
1917
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
1918
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
1919
  );
1920

    
1921
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1922
    '#type' => 'checkboxes',
1923
    '#title' => t('Section/Tab visibility') . ':',
1924
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1925
    '#options' => get_taxon_options_list()
1926
  );
1927

    
1928
  // WEIGHT
1929
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1930
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1931
    '#title'  => 'Section/Tab order',
1932
    '#type' => 'fieldset',
1933
    '#collapsible' => false,
1934
    '#tree' => true,
1935
    '#description' => 'The weight value defines the order of the section/tab.'
1936
  );
1937
  // Weights range from -delta to +delta, so delta should be at least half
1938
  // of the amount of tabs present.
1939
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1940
  foreach (get_taxon_tabs_list() as $label) {
1941
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1942
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1943
        '#title' => $label,
1944
        '#type'  => 'weight',
1945
        '#default_value' => $taxon_tabs_weights[$key],
1946
        '#delta' => $tab_weight_delta
1947
    );
1948
  }
1949

    
1950
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1951
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1952
    '#title'  => 'Section/Tab label override',
1953
    '#type' => 'fieldset',
1954
    '#collapsible' => false,
1955
    '#tree' => true,
1956
    '#description' => 'Setting a label for a section/tab will override the default label. 
1957
      Please enter the label text in the default language of the portal.'
1958
  );
1959
  foreach (get_taxon_tabs_list() as $label) {
1960
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1961
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1962
      '#title' => $label,
1963
      '#type'  => 'textfield',
1964
      '#default_value' => $taxon_tabs_labels[$key]
1965
    );
1966
  }
1967

    
1968
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1969
    '#type' => 'select',
1970
    '#title' => t('Default tab to display') . ':',
1971
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1972
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1973
    '#description' => t('<p>Select the default tab to display when visiting a
1974
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1975
      <strong>Note:</strong> After performing a search and clicking in any
1976
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1977
      taxon and not the above selected tab.'),
1978
  );
1979

    
1980
  /* ======  TAXON_PROFILE ====== */
1981
  $form['taxon_profile'] = array(
1982
    '#type' => 'fieldset',
1983
    '#title' => t('Taxon profile (tab)'),
1984
    '#description' => t('<p>This section covers the settings related to the taxon
1985
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1986
    '#collapsible' => TRUE,
1987
    '#collapsed' => TRUE,
1988
  );
1989

    
1990
  // ---- PROFILE PICTURE ----//
1991

    
1992
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1993
    '#type' => 'fieldset',
1994
    '#tree' => TRUE,
1995
    '#title' => t('Taxon profile picture'),
1996
    '#collapsible' => TRUE,
1997
    '#collapsed' => FALSE,
1998
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1999
  );
2000

    
2001
  //FIXME migrate variables:
2002
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
2003
  // FIXME
2004
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
2005

    
2006
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
2007

    
2008
  /*
2009
   * 'show' => 1,
2010
   * 'maxextend' => 184,
2011
   * 'media_uri_query' => ''
2012
   * 'custom_placeholder_image_on' => 1,
2013
   * 'custom_placeholder_image_fid' => ''
2014
   */
2015
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
2016
    '#type' => 'checkbox',
2017
    '#title' => t('Enable profile picture'),
2018
    '#description' => t('Show the profile picture.'),
2019
    '#default_value' => $taxon_profile_image_settings['show'],
2020
  );
2021

    
2022
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
2023
      '#type' => 'textfield',
2024
      '#tree' => TRUE,
2025
      '#title' => t('Profile picture maximum extend'),
2026
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
2027
      '#field_suffix' => 'px',
2028
      '#maxlength' => 4,
2029
      '#size' => 4,
2030
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
2031
  );
2032

    
2033
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
2034
      '#type' => 'textfield',
2035
      '#tree' => TRUE,
2036
      '#title' => t('Additional URI query parameter'),
2037
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
2038
      '#maxlength' => 1024,
2039
      '#size' => 60,
2040
      '#description' => t('Additional query parameters to be used when requesting for the  
2041
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
2042
            The query parameters will be appended to the uri of the media representation part
2043
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
2044
  );
2045

    
2046
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2047
    '#type' => 'checkbox',
2048
    '#title' => t('Show the placeholder image'),
2049
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
2050
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2051
  );
2052

    
2053
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2054
      '#type' => 'checkbox',
2055
      '#title' => t('Use a custom placeholder image'),
2056
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2057
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2058
  );
2059

    
2060
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2061
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2062
        '#type' => 'managed_file',
2063
        '#title' => t('Custom placeholder image file'),
2064
        '#progress_indicator' => 'bar',
2065
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2066
    //       '#name' => 'custom_placeholder_image',
2067
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2068
    );
2069

    
2070
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2071
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2072
      $url = file_create_url($profile_image_file->uri);
2073
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2074
                '#type' => 'item',
2075
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2076
      );
2077
    }
2078
  } else {
2079
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2080
      '#type' => 'hidden',
2081
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2082
    );
2083
  }
2084

    
2085
  $options = cdm_vocabulary_as_option(UUID_RANK, null, true);
2086
  array_unshift($options, '-- DISABLED --');
2087
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2088
    '#type' => 'select',
2089
    '#title' => t('Hide profile picture for higher ranks') . ':',
2090
    '#default_value' => variable_get('image_hide_rank', '0'),
2091
    '#options' => $options,
2092
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2093
  );
2094

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

    
2101
  // ---- FEATURE TREE BLOCKS ---- //
2102
  $form['taxon_profile']['feature_blocks'] = array(
2103
    '#type' => 'fieldset',
2104
    '#title' => t('Feature Blocks'),
2105
    '#collapsible' => TRUE,
2106
    '#collapsed' => FALSE,
2107
    '#description' => t("This section covers settings related to the taxon's
2108
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2109
      features such as description, distribution, common names"),
2110
  );
2111
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2112
  $profile_feature_tree = get_profile_feature_tree();
2113
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2114
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2115
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2116
  }
2117
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2118
    '#type' => 'radios',
2119
    '#title' => t('Taxon profile feature tree') . ':',
2120
    '#default_value' => $profile_feature_tree_uuid,
2121
    '#options' =>  $featureTrees['options'],
2122
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2123
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2124
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
2125
      profile page.'
2126
    ),
2127
  );
2128

    
2129
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2130
  $profile_feature_tree = get_profile_feature_tree();
2131

    
2132
  if (isset($profile_feature_tree->root->childNodes)) {
2133

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

    
2176

    
2177
    $feature_list_layout_settings_disabled = FALSE;
2178

    
2179
    // creating helper object to retrieve the default settings
2180
    $featureNode = new stdClass();
2181
    $featureNode->feature = new stdClass();
2182
    $featureNode->feature->uuid="DEFAULT";
2183
    $featureNode->feature->representation_L10n = "Default";
2184
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2185

    
2186
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2187

    
2188
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2189

    
2190
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2191
        $subform_id = $featureNode->feature->uuid;
2192
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2193

    
2194
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2195

    
2196
        $form_feature_block_layout[$subform_id] = array(
2197
          '#type' => 'fieldset',
2198
          '#tree' => TRUE,
2199
          '#title' => $featureNode->feature->representation_L10n,
2200
          '#collapsible' => FALSE,
2201
          '#collapsed' => FALSE,
2202
        );
2203
        if($featureNode->feature->uuid == "DEFAULT"){
2204
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2205
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2206
          references</em> and <em>names in source</em> is only possible in the defaults';
2207
        }
2208

    
2209
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2210
          '#type' => 'select',
2211
          '#title' => 'List type',
2212
          '#default_value' => $feature_block_setting['as_list'],
2213
          '#options' => array(
2214
            'div' => 'not as list',
2215
            'ul' => 'bullet list',
2216
            'ol' => 'numbered list',
2217
            'dl' => 'definition list'
2218
          ),
2219
        );
2220

    
2221
        if($featureNode->feature->uuid == "DEFAULT"){
2222
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2223
            '#type' => 'checkbox',
2224
            '#title' => t('Link to reference'),
2225
            '#default_value' => $feature_block_setting['link_to_reference'],
2226
          );
2227

    
2228
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2229
            '#type' => 'checkbox',
2230
            '#title' => 'Link to name used in source',
2231
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2232
          );
2233
        }
2234

    
2235
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2236
          '#type' => 'checkbox',
2237
          '#title' => 'Sources as content',
2238
          '#default_value' => $feature_block_setting['sources_as_content'],
2239
        );
2240

    
2241
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2242
          '#type' => 'checkbox',
2243
          '#title' => 'Put sources also as content to bibliography',
2244
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2245
        );
2246

    
2247
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2248
          '#type' => 'select',
2249
          '#title' => t('Sort elements'),
2250
          '#default_value' => $feature_block_setting['sort_elements'],
2251
          '#options' => array(
2252
            NO_SORT => 'No sorting',
2253
            SORT_ASC => 'Ascending',
2254
            SORT_DESC => 'Descending',
2255
            SORT_HIERARCHICAL => 'Hierarchical'
2256
          ),
2257
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2258
          <dl>
2259
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2260
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2261
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2262
          <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>
2263
          </dl>',
2264
        );
2265

    
2266
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2267
          '#type' => 'select',
2268
          '#title' => t('Element tag'),
2269
          '#options' => array(
2270
            'span' => 'span',
2271
            'div' => 'div',
2272
            'p' => 'p'
2273
          ),
2274
          '#default_value' => $feature_block_setting['element_tag'],
2275
        );
2276
        $form_feature_block_layout[$subform_id]['glue'] = array(
2277
          '#type' => 'textfield',
2278
          '#title' => t('Element glue'),
2279
          '#default_value' => $feature_block_setting['glue'],
2280
          '#size' => 10
2281
      );
2282

    
2283
      }
2284
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2285
    }
2286
  }
2287

    
2288
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2289
  $form['taxon_profile']['structured_description_featuretree'] = array(
2290
    '#type' => 'fieldset',
2291
    '#title' => t('Structured Description Feature Tree'),
2292
    '#collapsible' => TRUE,
2293
    '#collapsed' => FALSE,
2294
  );
2295
  $featureTrees = cdm_get_featureTrees_as_options();
2296
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2297
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2298
    $profile_feature_tree_uuid = NULL;
2299
  }
2300
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2301
    '#type' => 'radios',
2302
    '#title' => t('Natural language representation of structured descriptions') . ':',
2303
    '#default_value' => $profile_feature_tree_uuid,
2304
    '#options' => $featureTrees['options'],
2305
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2306
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2307
    '#description' => t('Taxon descriptions can be stored in a highly structured
2308
      form. The feature tree selected here will be used to generate textual
2309
      representation in natural language.'
2310
    ),
2311
  );
2312

    
2313

    
2314

    
2315
  // ---- DISTRIBUTION LAYOUT ---- //
2316
  $form['taxon_profile']['distribution_layout'] = array(
2317
    '#title' => t('Distribution'),
2318
    '#collapsible' => TRUE,
2319
    '#collapsed' => FALSE,
2320
    '#type' => 'fieldset',
2321
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2322
        Map settings regarding the geometry, layers, etc are found in the '
2323
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2324
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2325
      . l(
2326
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2327
        array('fragment' => 'edit-feature-block-settings')
2328
      )
2329
      . ' More general settings regrading the filtering of Distributions are found at '
2330
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2331
      . '. (These settings here will be merged in future releases into the feature block settings)',
2332

    
2333
  );
2334

    
2335
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2336

    
2337
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2338
    '#type' => 'checkbox',
2339
    '#title' => t('Condensed distribution'),
2340
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2341
    '#description' => 'This option enables the display of a very compact representation
2342
    of the distribution which includes also information on the status.',
2343
  );
2344

    
2345
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2346
    '#type' => 'select',
2347
    '#title' => t('Condensed distribution recipe'),
2348
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2349
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2350
    '#description' => 'Recipe for creating the condensed distribution.',
2351
  );
2352

    
2353
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2354
    '#type' => 'textfield',
2355
    '#title' => t('Condensed distribution info path'),
2356
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2357
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2358
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2359
  );
2360

    
2361

    
2362
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2363
    '#type' => 'radios',
2364
    '#title' => t('Display mode') . ':',
2365
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2366
    '#options' => array(
2367
      'FLAT_ALPHA' => t('Flat list'),
2368
      'TREE' => t('Hierarchically ordered'),
2369
    ),
2370
    '#description' => 'Taxon distribution information is displayed with
2371
    focus on the area of the distribution. The list of areas can either be shown
2372
    as flat list ordered alphabetically or in the hierarchical of the parent
2373
    area and subarea relationship. Fall back areas areas with no Distribution data
2374
    are hidden from the area hierarchy so that their sub areas will move one level up.
2375
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2376
    ' for details on the <em>Marked area filter</em>.',
2377
  );
2378

    
2379
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2380
    '#type' => 'fieldset',
2381
    '#tree' => true,
2382
    '#title' => t('Distribution hierarchy style')
2383
  );
2384

    
2385
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2386
  foreach(array_keys($hierarchy_styles) as $level) {
2387
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2388
      '#type' => 'fieldset',
2389
      '#tree' => true,
2390
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2391
      '#attributes' => array('class' => array('fieldset-float'))
2392
    );
2393
    foreach ($hierarchy_styles[$level] as $key => $value) {
2394
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2395
        '#type' => 'textfield',
2396
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2397
        '#default_value' => $hierarchy_styles[$level][$key],
2398
        '#maxlength' => 4,
2399
        '#size' => 4
2400
      );
2401
    }
2402
  }
2403

    
2404
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2405
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2406
    '#type' => 'checkboxes',
2407
    '#title' => 'Omit area levels',
2408
    '#options' => $level_options,
2409
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2410
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2411
    Areas which belong to the selected area levels will be hidden in the portal.',
2412
  );
2413

    
2414
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2415
    '#type' => 'checkbox',
2416
    '#title' => t('Show TextData elements on top of the map'),
2417
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2418
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2419
      elements on top of the map. Otherwise all <code>TextData</code>
2420
      distribution elements will be listed below the other area elements.
2421
      This option is useful if you need to have descriptive texts for each
2422
      distribution map.'),
2423
  );
2424

    
2425
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2426
      '#type' => 'textarea',
2427
      '#title' => t('Custom status colors'),
2428
      '#element_validate' => array('form_element_validate_json'),
2429
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2430
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2431
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2432
          reference list of the idInVocabulary values of absence and presence terms:
2433
<pre>
2434
Presence Term
2435
p	present
2436
pd	present: doubtfully present
2437
n	native
2438
nq	native: presence questionable
2439
nd	native: doubtfully native
2440
c	cultivated
2441
i	introduced
2442
iq	introduced: presence questionable
2443
id	introduced: doubtfully introduced (perhaps cultivated only)
2444
ip	introduced: uncertain degree of naturalisation
2445
ia	introduced: adventitious (casual)
2446
in	introduced: naturalized
2447
ic	introduced: cultivated
2448
e	endemic for the relevant area
2449
na	naturalised
2450
iv	invasive
2451

    
2452
AbsenceTerm
2453
a	absent
2454
f	reported in error
2455
nf	native: reported in error
2456
if	introduced: reported in error
2457
cf	cultivated: reported in error
2458
ne	native: formerly native
2459
ie	introduced: formerly introduced
2460

    
2461
</pre>'),
2462
  );
2463

    
2464

    
2465
  /* ====== SYNONYMY ====== */
2466
  $form['taxon_synonymy'] = array(
2467
    '#type' => 'fieldset',
2468
    '#title' => t('Taxon synonymy (tab)'),
2469
    '#collapsible' => TRUE,
2470
    '#collapsed' => TRUE,
2471
    '#description' => t('This section covers the settings related to the taxon
2472
      <strong>synonymy</strong> tab.'),
2473
  );
2474

    
2475
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2476
    '#type' => 'checkbox',
2477
    '#title' => t('Show accepted taxon on top of the synonymy'),
2478
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2479
    '#description' => t('If checked, the first homotypic taxon is a repetition
2480
      of the accepted taxon most likely with the full nomenclatural reference
2481
      (depending on the currently chosen theme).'),
2482
  );
2483

    
2484
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2485
    '#type' => 'checkbox',
2486
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2487
      coming from a synonym link.'),
2488
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2489
    '#description' => t('Check this if after doing a search and clicking on a
2490
      synonym you want to see the "accept of" text for the accepted synonym.'),
2491
  );
2492

    
2493
  /* === currently unused ===
2494
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2495
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2496
    '#type' => 'checkboxes',
2497
    '#title' => t('Display name relationships') . ':',
2498
    '#default_value' => variable_get('name_relationships_to_show', 0),
2499
    '#options' => $nameRelationshipTypeOptions,
2500
    '#description' => t('Select the name relationships you want to show for the
2501
      accepted taxa.'),
2502
  );
2503
 */
2504

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

    
2512
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2513
    '#type' => 'checkbox',
2514
    '#title' => t('Show taxon relations ships of accepted taxon'),
2515
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2516
    '#description' => t('If this option is enabled the synonymy will show the
2517
      below selected taxon relationships of accepted taxa.'),
2518
  );
2519

    
2520
  $taxon_relationship_type_options = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2521
  $taxon_relationship_type_defaults = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
2522
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2523
    '#type' => 'checkboxes',
2524
    '#title' => t('Taxon relationship types') . ':',
2525
    '#description' => t('Only taxon relationships of the selected type will be
2526
      displayed'),
2527
    '#options' => $taxon_relationship_type_options,
2528
    '#default_value' => $taxon_relationship_type_defaults,
2529
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2530
  );
2531

    
2532
  $form['taxon_synonymy']['name_relations'] = array(
2533
    '#type' => 'fieldset',
2534
    '#title' => t('Name relationships'),
2535
    '#collapsible' => FALSE,
2536
    '#collapsed' => FALSE
2537
  );
2538

    
2539
  $name_relationship_type_options = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2540
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2541
    '#type' => 'checkboxes',
2542
    '#title' => t('Name relationship types') . ':',
2543
    '#description' => t('Only name relationships of the selected type will be
2544
      displayed'),
2545
    '#options' => $name_relationship_type_options,
2546
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2547
  );
2548

    
2549
  // ====== SPECIMENS ====== //
2550
  $form['taxon_specimens'] = array(
2551
    '#type' => 'fieldset',
2552
    '#title' => t('Taxon specimens (tab)'),
2553
    '#collapsible' => TRUE,
2554
    '#collapsed' => TRUE,
2555
    '#description' => t('This section covers the settings related to the taxon
2556
      <strong>specimens</strong> tab.'),
2557
  );
2558

    
2559
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2560

    
2561
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2562
    '#type' => 'checkbox',
2563
    '#title' => t('Show specimen derivatives in a compressed table'),
2564
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2565
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2566
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2567
  );
2568

    
2569
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2570
      '#type' => 'textfield',
2571
      '#title' => t('Number of records per page') . ':',
2572
      '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2573
  );
2574

    
2575
    $form['taxon_specimens']['cdm_dataportal_specimen_derivate_tree'] = array(
2576
        '#type' => 'checkbox',
2577
        '#title' => t('Show specimen derivatives in a tree view'),
2578
        '#default_value' => variable_get('cdm_dataportal_specimen_derivate_tree', CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE),
2579
        '#description' => t('If checked, the specimen will be listed in a tree view.'),
2580
    );
2581

    
2582

    
2583
    $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2584
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2585
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2586
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2587
  }
2588
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2589
    '#type' => 'radios',
2590
    '#title' => t('Specimen description feature tree') . ':',
2591
    '#default_value' => $profile_feature_tree_uuid,
2592
    '#options' =>  $featureTrees['options'],
2593
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2594
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2595
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2596
    ),
2597
  );
2598

    
2599
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2600
  $form_title = t('Specimen media');
2601
  $form_description = t('Specimens may have media which is displayed at the
2602
     Specimen tab/section as a gallery. It is possible to configure the
2603
     thumbnails gallery here, however for configuring how a single media should
2604
     be displayed please go to !url.</p>',
2605
     array(
2606
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2607
     ));
2608
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2609

    
2610
  // --- MEDIA GALLERY ---- //
2611
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2612
  $form_title = 'Media gallery (tab)';
2613
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2614
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2615
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2616
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2617
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2618
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2619
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2620

    
2621
  // Comment @WA: D7 form api does not support reset buttons,
2622
  // so to mimic the D5 reset button we add one like this.
2623
  $form['actions']['reset'] = array(
2624
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2625
    '#weight' => 1000,
2626
  );
2627
  return system_settings_form($form);
2628
}
2629

    
2630
/**
2631
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2632
 *
2633
 * @param $map_id
2634
 * @param $form
2635
 * @return mixed
2636
 */
2637
function _cdm_map_visibility_setting($map_id)
2638
{
2639
  return array(
2640
    '#type' => 'select',
2641
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2642
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2643
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2644
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2645
        The map also can forced to show up <b>always</b> or <b>never</b>."
2646
  );
2647
}
2648

    
2649
/**
2650
 * @todo document this function.
2651
 */
2652
function cdm_settings_layout_search() {
2653

    
2654
  $form = array();
2655

    
2656
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2657

    
2658
  $form['search_settings'] = array(
2659
    '#type' => 'fieldset',
2660
    '#title' => t('Taxa Search'),
2661
    '#collapsible' => FALSE,
2662
    '#collapsed' => FALSE,
2663
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2664
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2665
         where they can write the text to be searched. You can find Drupal block configuration
2666
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2667
  );
2668

    
2669
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2670
      '#type' => 'checkbox',
2671
      '#title' => t('Ignore the chosen classification in simple search'),
2672
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2673
      '#description' => t('The simple search, which can be executed via the search block,
2674
          will by default search on the classification selected in the classification browser
2675
          selector. Set the tick if you want your portal to search on all classifications.'),
2676
  );
2677

    
2678
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2679
    '#type' => 'checkbox',
2680
    '#title' => t('Run simple search with free-text search backend.'),
2681
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2682
    '#description' => t('The simple search uses by default another search
2683
      backend as the advances search. By checking this option the simple search can be
2684
      configured to also use the free-text search backend.'),
2685
  );
2686

    
2687
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2688
    '#type' => 'checkbox',
2689
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2690
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2691
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2692
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2693
  );
2694

    
2695
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2696
    '#type' => 'textfield',
2697
    '#title' => t('Results per page') . ':',
2698
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2699
    '#description' => t('Number of results to display per page.'),
2700
  );
2701

    
2702
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2703
    '#type' => 'checkbox',
2704
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2705
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2706
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2707
  );
2708

    
2709
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2710
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2711
      '#type' => 'checkboxes',
2712
      '#title' => 'Search mode',
2713
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2714
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2715
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2716
          defaults set here.',
2717
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2718
      '#default_value' => $search_mode_default
2719
      );
2720

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

    
2726
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2727
  );
2728

    
2729
  // --- SEARCH TAXA GALLERY ---- //
2730
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2731
  $collapsed = FALSE;
2732
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2733
  $form_title = 'Taxa Search thumbnails';
2734
  $form_description = 'Search results may show thumbnails. ';
2735
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2736

    
2737
  // Comment @WA: D7 form api does not support reset buttons,
2738
  // so to mimic the D5 reset button we add one like this.
2739
  $form['actions']['reset'] = array(
2740
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2741
    '#weight' => 1000,
2742
  );
2743
  return system_settings_form($form);
2744
}
2745

    
2746
/**
2747
 * @todo document this function.
2748
 */
2749
function cdm_settings_layout_media() {
2750

    
2751
  $form = array();
2752

    
2753
  $form['media_settings'] = array(
2754
    '#type' => 'fieldset',
2755
    '#title' => t('Media settings'),
2756
    '#collapsible' => FALSE,
2757
    '#collapsed' => FALSE,
2758
    '#description' => 'This section covers layout settings for media pages.'
2759
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2760
  );
2761

    
2762
  $form['media_settings']['image_gallery_viewer'] = array(
2763
    '#type' => 'select',
2764
    '#title' => t('Image viewer') . ':',
2765
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2766
    '#options' => array(
2767
      'default' => t('Standard image viewer'),
2768
      'fsi' => t('FSI viewer (requires FSI server!)'),
2769
    ),
2770
  );
2771

    
2772
  // --- STANDARD_IMAGE_VIEWER ---- //
2773
  if(variable_get('image_gallery_viewer', 'default') == 'default') {
2774
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2775
      '#type' => 'fieldset',
2776
      '#tree' => true,
2777
      '#title' => t('Standard image viewer settings'),
2778
      '#collapsible' => FALSE,
2779
      '#collapsed' => FALSE,
2780
      );
2781

    
2782
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2783
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2784
      '#type' => 'checkbox',
2785
      '#title' => 'Show media representations',
2786
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2787

    
2788
    );
2789
  }
2790

    
2791

    
2792
  // @WA: D7 form api does not support reset buttons,
2793
  // so to mimic the D5 reset button we add one like this.
2794
  $form['actions']['reset'] = array(
2795
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2796
    '#weight' => 1000,
2797
  );
2798
  return system_settings_form($form);
2799
}
2800

    
2801
/**
2802
 * GEOSERVICE and Map settings.
2803
 */
2804
function cdm_settings_geo($form, &$form_state) {
2805

    
2806
  $current_geoserver_settings = get_edit_map_service_settings();
2807
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2808

    
2809

    
2810
  $form = array();
2811

    
2812
  $dummy_distribution_query = NULL;
2813
  if($map_distribution['map_type'] != 1){
2814
    // we need to apply a dummy query since the map service requires for image maps
2815
    // at least as and ad to be defined
2816
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2817
  }
2818

    
2819
  $form['map_preview'] = array(
2820
      '#type' => 'fieldset',
2821
      '#tree' => FALSE,
2822
      '#title' => t('Map preview'),
2823
      '#collapsible' => FALSE,
2824
      '#description' => 'The preview of the map'
2825
       . ($dummy_distribution_query != null ?
2826
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2827
           '.<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.')
2828
  );
2829
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2830
    'move' => "this.cdmOpenlayersMap.printInfo",
2831
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2832
  ), true // resizable
2833
  );
2834

    
2835
  /*
2836
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2837
  );
2838
  */
2839

    
2840
  /*
2841
   * GEO SERVER
2842
   */
2843
  $form['edit_map_server'] = array(
2844
    '#type' => 'fieldset',
2845
    '#tree' => true,
2846
    '#title' => t('EDIT map service'),
2847
    '#collapsible' => TRUE,
2848
    '#collapsed' => TRUE,
2849
    '#description' => t('Configuration and selection of your geo server.
2850
      The Geo Server is responsible for generating the maps.'),
2851
  );
2852

    
2853
  $form['edit_map_server']['base_uri'] = array(
2854
    '#type' => 'select',
2855
    '#title' => t('EDIT map service') . ':',
2856
    '#default_value' => $current_geoserver_settings['base_uri'],
2857
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2858
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2859
  );
2860
  $form['edit_map_server']['version'] = array(
2861
      '#type' => 'select',
2862
      '#title' => t('Version') . ':',
2863
      '#default_value' => $current_geoserver_settings['version'],
2864
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2865
      '#description' => t('The version of the EDIT map services'),
2866
  );
2867

    
2868
  /*
2869
   * MAP SETTINGS
2870
   */
2871

    
2872
  $form[CDM_MAP_DISTRIBUTION] = array(
2873
    '#type' => 'fieldset',
2874
    '#tree' => TRUE,
2875
    '#title' => t('Maps settings'),
2876
    '#collapsible' => TRUE,
2877
    '#collapsed' => TRUE,
2878
    '#description' => t('General configuration for all map types.'),
2879
  );
2880

    
2881
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2882
    '#type' => 'radios',
2883
    '#title' => 'Map types',
2884
    '#options' => array(
2885
      1 => "OpenLayers dynamic map viewer",
2886
      0 => "Plain image",
2887
    ),
2888
    '#default_value' => $map_distribution['map_type'],
2889
    '#description' => 'Two different map types are available :
2890
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2891
      which allows zooming and panning. If enabled you can configure the default layer
2892
      (background of your maps) below.</li>
2893
      <li><em>Plain image</em>: The map will be static non interactive
2894
      image.</li></ul>',
2895
  );
2896
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2897

    
2898
  /*
2899
   * settings for the distribution map are used also for specimens map!!!!
2900
   */
2901

    
2902
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2903
      '#type' => 'textfield',
2904
      '#title' => 'Aspect ratio',
2905
      '#default_value' => $map_distribution['aspect_ratio'],
2906
      '#maxlength' => 4,
2907
      '#size' => 4,
2908
      '#element_validate' => array('element_validate_number'),
2909
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2910
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2911
      width by the height:</br>
2912
      <pre>aspect ratio = w / h</pre>
2913
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2914
      for a square map use <strong>1</strong>.',
2915
  );
2916

    
2917
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2918
    '#type' => 'textfield',
2919
    '#title' => 'Bounding box',
2920
    '#default_value' => $map_distribution['bbox'],
2921
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2922
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2923
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2924
      <strong>TIP:</strong> You can use the map preview above to choose the <span class="map-extent-bbox"><strong>map extent bbox</strong> in <strong class="degree-value"">degree</strong></span> from the map.
2925
      (Maybe you need to change the map base layer to OpeLayers.)
2926
      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
2927
      below the map from where you can copy the bbox string.</p>'),
2928
  );
2929

    
2930
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
2931
    '#type' => 'select',
2932
    '#title' => 'Max zoom level',
2933
    '#default_value' => $map_distribution['maxZoom'],
2934
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
2935
  );
2936

    
2937
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2938
    '#type' => 'checkbox',
2939
    '#title' => 'Display area labels',
2940
    '#default_value' => $map_distribution['show_labels'],
2941
    '#description' => t('The map will show name labels of the areas'),
2942
  );
2943

    
2944
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2945
    '#type' => 'textfield',
2946
    '#title' => 'Map caption',
2947
    '#default_value' => $map_distribution['caption'],
2948
    '#description' => t('The caption will be shown below the map.'),
2949
  );
2950

    
2951
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2952
    '#type' => 'textfield',
2953
    '#title' => 'Distribution layer opacity',
2954
    '#default_value' => $map_distribution['distribution_opacity'],
2955
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2956
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2957
  );
2958

    
2959
  // --- Plain Image Settings --- //
2960
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2961
    '#type' => 'fieldset',
2962
    '#title' => 'Plain image map settings',
2963
    '#tree' => TRUE,
2964
    '#collapsible' => TRUE,
2965
    '#collapsed' => $open_layers_is_enabled,
2966
    '#description' => 'The settings in this section are still expertimental
2967
      and can only be used with the EDIT map service version 1.1 or above.',
2968
  );
2969
  $edit_mapserver_version = get_edit_map_service_version_number();
2970
  if ($edit_mapserver_version < 1.1) {
2971
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2972
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2973
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2974
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2975
  }
2976

    
2977
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2978
    '#type' => 'textfield',
2979
    '#title' => 'Width',
2980
    '#default_value' => $map_distribution['image_map']['width'],
2981
    '#maxlength' => 4,
2982
    '#size' => 4,
2983
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2984
  );
2985

    
2986
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2987
    '#type' => 'textfield',
2988
    '#title' => 'Background layer',
2989
    '#default_value' => $map_distribution['image_map']['base_layer'],
2990
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2991
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2992
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2993
    )),
2994
  );
2995

    
2996
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2997
    '#type' => 'textfield',
2998
    '#title' => 'Background color',
2999
    '#default_value' => $map_distribution['image_map']['bg_color'],
3000
  );
3001

    
3002
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3003
    '#type' => 'textfield',
3004
    '#title' => 'Background layer style',
3005
     // Only line color by now.
3006
    '#default_value' => $map_distribution['image_map']['layer_style'],
3007
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3008
  );
3009

    
3010
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3011
      '#type' => 'textfield',
3012
      '#title' => 'Projection',
3013
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3014
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3015
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3016
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3017
  );
3018

    
3019

    
3020
  // --- OpenLayers Settings --- //
3021
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3022
    '#type' => 'fieldset',
3023
    '#title' => 'OpenLayers settings',
3024
    '#tree' => TRUE,
3025
    '#collapsible' => TRUE,
3026
    '#collapsed' => !$open_layers_is_enabled,
3027
    '#description' => '',
3028
  );
3029

    
3030

    
3031
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3032
      '#type' => 'checkbox',
3033
      '#title' => 'Display outside max extent',
3034
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3035
      '#description' => t('Allows the map to display parts of the layers which are outside
3036
         the max extent if the aspect ratio of the map and of the baselayer
3037
         are not equal.'),
3038
  );
3039

    
3040

    
3041
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3042
      '#type' => 'checkbox',
3043
      '#title' => 'Show Layer Switcher',
3044
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3045
      '#description' => 'The Layer Switcher control displays a table of contents
3046
      for the map.  This allows the user interface to switch between
3047
      base layers and to show or hide overlays.  By default the switcher is
3048
      shown minimized on the right edge of the map, the user may expand it
3049
      by clicking on the handle.',
3050
  );
3051

    
3052
  if (!$open_layers_is_enabled) {
3053
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3054
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3055
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3056
  }
3057

    
3058
  // The default layer must always be enabled
3059
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3060
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3061

    
3062
  $baselayer_options = array(
3063
    /*
3064
   NOTICE: must correspond to the layers defined in
3065
   js/openlayers_,ap.js#getLayersByName()
3066
   */
3067
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3068
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3069
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3070
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3071
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3072
    // all others EPSG:900913
3073
    'mapnik' => 'OpenStreetMap (mapnik)',
3074
    'stamen_terrain' => 'Stamen Terrain',
3075
    'open_topomap' => 'OpenTopoMap',
3076
    // map quest is no longer free. it is required to sign up for a test plan.
3077
    // 'mapquest_open' => "MapQuest",
3078
    // 'mapquest_sat' => "MapQuest Sattelite",
3079
    'groadmap' => 'Google Roadmap',
3080
    'gsatellite' => 'Google Satellite',
3081
    'ghybrid' => 'Google Hybrid',
3082
    'gterrain' => 'Google Terrain',
3083
//     'veroad' => 'Virtual Earth Roads',
3084
//     'veaer' => 'Virtual Earth Aerial',
3085
//     'vehyb' => 'Virtual Earth Hybrid',
3086
    // 'yahoo' => 'Yahoo Street',
3087
    // 'yahoosat' => 'Yahoo Satellite',
3088
    // 'yahoohyb' => 'Yahoo Hybrid',
3089
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3090
  );
3091

    
3092
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3093
    '#type' => 'checkboxes_preferred',
3094
    '#title' => 'Base Layers',
3095
    '#options' => $baselayer_options,
3096
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3097
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3098
  );
3099

    
3100
  $google_maps_api_key = null;
3101
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3102
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3103
  }
3104
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3105
    '#type' => 'textfield',
3106
    '#title' => 'Google Maps API Key',
3107
    '#default_value' => $google_maps_api_key,
3108
    '#description' => 'In order to use any of the Google map layers you need to provide 
3109
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3110
  );
3111

    
3112
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3113
    $map_distribution['openlayers']['custom_wms_base_layer'],
3114
    'Custom WMS base layer',
3115
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3116
    true // add projection settings
3117
    );
3118

    
3119
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3120
    $map_distribution['openlayers']['wms_overlay_layer'],
3121
    'WMS overlay layer',
3122
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3123
                You can actually combine multiple layers for this overlay. 
3124
                For details please refer to the wms query parameter <code>Layers</code> .'
3125
  );
3126

    
3127
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3128
    '#type' => 'checkbox',
3129
    '#title' => 'Enable overlay layer',
3130
    '#weight' => -100,
3131
    '#default_value' => $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3132
  );
3133

    
3134
  /*
3135
   * Map Legend
3136
   */
3137
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3138
    '#type' => 'fieldset',
3139
    '#title' => 'Map legend',
3140
    '#tree' => TRUE,
3141
    '#collapsible' => TRUE,
3142
    '#collapsed' => TRUE,
3143
    '#description' => 'Configure the maps legend.',
3144
  );
3145

    
3146
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3147
    '#type' => 'checkbox',
3148
    '#title' => 'Display a map legend',
3149
    '#default_value' => $map_distribution['legend']['show'],
3150
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3151
  );
3152

    
3153
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3154
    '#type' => 'textfield',
3155
    '#title' => 'Legend opacity',
3156
    '#default_value' => $map_distribution['legend']['opacity'],
3157
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3158
                         to 0.0 will be not much visible.',
3159
  );
3160

    
3161
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3162
    '#type' => 'textfield',
3163
    '#title' => 'Font size',
3164
    '#default_value' => $map_distribution['legend']['font_size'],
3165
    '#description' => 'Font size in pixels.',
3166
  );
3167

    
3168
  $fontStyles = array(
3169
    0 => "plane",
3170
    1 => "italic",
3171
  );
3172
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3173
    '#type' => 'select',
3174
    '#title' => 'Available font styles',
3175
    '#default_value' => $map_distribution['legend']['font_style'],
3176
    '#options' => $fontStyles,
3177
    '#description' => 'Select a font style for the map legend.',
3178
  );
3179

    
3180
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3181
    '#type' => 'textfield',
3182
    '#title' => 'Icon width',
3183
    '#default_value' => $map_distribution['legend']['icon_width'],
3184
    '#description' => 'Legend icon width in pixels.',
3185
  );
3186
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3187
    '#type' => 'textfield',
3188
    '#title' => 'Icon height',
3189
    '#default_value' => $map_distribution['legend']['icon_height'],
3190
    '#description' => 'Legend icon height in pixels.',
3191
  );
3192

    
3193
  // @WA: D7 form api does not support reset buttons,
3194
  // so to mimic the D5 reset button we add one like this.
3195
  $form['actions']['reset'] = array(
3196
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3197
    '#weight' => 1000,
3198
  );
3199

    
3200
  return system_settings_form($form);
3201
}
3202

    
3203
/**
3204
 * @param $default_settings
3205
 * @param $title
3206
 * @param $description
3207
 * @param bool $add_projection_settings
3208
 * @return array
3209
 */
3210
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3211
{
3212
  $form_elements = array(
3213
    '#type' => 'fieldset',
3214
    '#title' => $title,
3215
    '#tree' => TRUE,
3216
    '#collapsible' => FALSE,
3217
    '#collapsed' => FALSE,
3218
    '#description' => $description,
3219
  );
3220

    
3221
  $form_elements['name'] = array(
3222
    '#type' => 'textfield',
3223
    '#title' => 'Layer name',
3224
    '#default_value' => $default_settings['name'],
3225
    '#description' => 'A arbitrary name for the layer.',
3226
  );
3227
  $form_elements['url'] = array(
3228
    '#type' => 'textfield',
3229
    '#title' => 'WMS url',
3230
    '#default_value' => $default_settings['url'],
3231
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3232
  );
3233
  $form_elements['untiled'] = array(
3234
    '#type' => 'checkbox',
3235
    '#title' => 'Untiled',
3236
    '#default_value' => $default_settings['untiled'],
3237
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3238
  );
3239
  $form_elements['params'] = array(
3240
    '#type' => 'textarea',
3241
    '#title' => 'WMS parameters',
3242
    '#element_validate' => array('form_element_validate_json'),
3243
    '#default_value' => $default_settings['params'],
3244
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3245
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3246
      . '), entered in valid JSON. For example:
3247
<pre> {
3248
  "Layers": "topp:em_tiny_jan2003",
3249
  "Format": "image/png",
3250
  "BGCOLOR": "0xe0faff"
3251
}
3252
</pre>
3253
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3254
  );
3255

    
3256
  if($add_projection_settings){
3257

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

    
3323
  }
3324
  return $form_elements;
3325
}
3326

    
3327

    
3328
/**
3329
 * @todo document this function.
3330
 */
3331
function cdm_settings_cache() {
3332

    
3333
  $form = array();
3334

    
3335
  $form['cache_settings'] = array(
3336
    '#type' => 'fieldset',
3337
    '#title' => t('Cache Settings'),
3338
    '#collapsible' => FALSE,
3339
    '#collapsed' => FALSE,
3340
    '#description' => t('<p>When caching is enabled all single taxon sites are
3341
      stored in an internal drupal cache doing the portal response of taxa pages
3342
      faster. This is possible because the sites are loaded from the cache and
3343
      are not created from scratch.</p>'),
3344
  );
3345

    
3346
  $form['cache_settings']['cdm_webservice_cache'] = array(
3347
    '#type' => 'checkbox',
3348
    '#title' => t('<strong>Enable caching</strong>'),
3349
    '#options' => cdm_help_general_cache(),
3350
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3351
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3352
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3353
       application the changes will be not visible till the cache is erased.
3354
       Therefore developers should deactived this feature when they are working
3355
       on the CDM Dataportal Module.</p>'),
3356
  );
3357

    
3358
  $form['cache_settings']['cdm_run_cache'] = array(
3359
    '#markup' => cdm_view_cache_site(),
3360
  );
3361

    
3362
  // @WA: D7 form api does not support reset buttons,
3363
  // so to mimic the D5 reset button we add one like this.
3364
  $form['actions']['reset'] = array(
3365
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3366
    '#weight' => 1000,
3367
  );
3368
  return system_settings_form($form);
3369
}
3370

    
3371
/**
3372
 * Walk and cache all taxon pages.
3373
 */
3374
function cdm_view_cache_site() {
3375

    
3376
  $out = '';
3377

    
3378
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3379

    
3380
  $request_params = array();
3381
  $request_params['class'] = "Taxon";
3382

    
3383
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3384
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3385
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3386

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

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

    
3396
  // Comment @WA: A form within a form is not valid html and not needed here.
3397
  // Also, it would be recommended just to include this part of the form in the
3398
  // rest of the form array in cdm_settings_cache().
3399
  // $out .= '<form id="cache_site">';
3400
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3401
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3402
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3403
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3404
  // $out .= '</form>';
3405
  $out .= '</div>';
3406
  /*
3407
  foreach($taxonPager->records as $taxon){
3408
    cdm_dataportal_taxon_view($uuid);
3409
  }
3410
  */
3411
  return $out;
3412
}
3413

    
3414

    
3415
function cdm_settings_layout_taxon_submit($form, &$form_state){
3416
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3417
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3418
    if(is_object($file)){
3419
      $file->status = FILE_STATUS_PERMANENT;
3420
      file_save($file);
3421
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3422
    }
3423
  }
3424
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3425
  $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]);
3426
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3427
  if($tab_lables_modified || $tabs_enabled_modified){
3428
    // we first need to set the variable to persist the changes setting
3429
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3430
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3431
    menu_rebuild();
3432
  }
3433
}
3434

    
3435
function cdm_settings_layout_search_submit($form, &$form_state){
3436
  // the visibility of media thumbnails also affects the ui of the search results
3437
  // so reset the according session variable
3438
  //    1. in order to give the user immediate
3439
  //       feedback on potential setting changes
3440
  //    2. let refresh the default if it has changed
3441
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3442
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3443
  }
3444
}
3445

    
3446
/**
3447
 * Form validation handler for cdm_settings_general
3448
 *
3449
 * @param $form
3450
 * @param $form_state
3451
 */
3452
function cdm_settings_general_validate($form, &$form_state) {
3453

    
3454
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3455
    $form_state['values']['cdm_webservice_url'] .= '/';
3456
  }
3457

    
3458
}
3459

    
3460
/**
3461
 * Form submit handler for settings general.
3462
 *
3463
 * tasks performed:
3464
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3465
 *
3466
 * @param $form
3467
 * @param $form_state
3468
 */
3469
function cdm_settings_general_submit($form, &$form_state){
3470
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3471
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3472
  unset($_SESSION['cdm_login']);
3473
}
3474

    
3475
/**
3476
 * Form validation handler for cdm_settings_cache
3477
 */
3478
function cdm_settings_cache_validate($form, &$form_state) {
3479
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3480
    cache_clear_all(NULL, 'cache_cdm_ws');
3481
    // Better clear secref_cache since I can not be sure if the cache has not
3482
    // be used during this response.
3483
    cdm_api_secref_cache_clear();
3484
  }
3485

    
3486
}
3487

    
3488
/**
3489
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3490
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3491
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3492
 *  - version: the version, e.g.: v1.1
3493
 *
3494
 * @return array
3495
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3496
 */
3497
function get_edit_map_service_settings() {
3498

    
3499
  $settings = variable_get('edit_map_server', array(
3500
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3501
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3502
      )
3503
  );
3504

    
3505
  return $settings;
3506
}
3507

    
3508
/**
3509
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3510
 *
3511
 * @return string
3512
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3513
 */
3514
function get_edit_map_service_full_uri() {
3515
  $settings = get_edit_map_service_settings();
3516
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3517
}
3518

    
3519

    
3520
/**
3521
 * Returns the version number of the currently selected edit mapserver as a float
3522
 *
3523
 * @return float
3524
 *   The version number of the currently selected edit mapserver as a float.
3525
 *   Returns 0 on error.
3526
 */
3527
function get_edit_map_service_version_number() {
3528

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

    
3531
  $settings = get_edit_map_service_settings();
3532
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3533
  if (isset($matches[1])) {
3534
    // Convert string to float.
3535
    $version = 1 + $matches[1][0] - 1;
3536
    return $version;
3537
  }
3538
  else {
3539
    // Report error.
3540
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3541
        array(
3542
          '!version' => $settings['version'],
3543
          'warning')
3544
        )
3545
      );
3546
    return 0;
3547
  }
3548
}
3549

    
3550
/**
3551
 * Returns the array of selected items in a options array
3552
 *
3553
 * @param array $options
3554
 *   An options array as generated by a form element like checkoxes, select ...,
3555
 */
3556
function get_selection($options) {
3557
  $selection = array();
3558
  foreach ($options as $key=>$val) {
3559
    if (!empty($val)) {
3560
      $selection[] = $val;
3561
    }
3562
  }
3563
  return $selection;
3564
}
3565

    
3566

    
3567
/**
3568
 * Implements hook_element_info().
3569
 *
3570
 * Allows modules to declare their own Form API element types and specify their default values.
3571
 *
3572
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3573
 */
3574
function cdm_dataportal_element_info() {
3575
  $type['checkboxes_preferred'] = array(
3576
    '#input' => TRUE,
3577
    '#process' => array('checkboxes_preferred_expand'),
3578
    '#after_build' => array('checkboxes_preferred_after_build'),
3579
    '#theme' => array('checkboxes_preferred'),
3580
    // '#theme_wrapper' => array('form_element'),
3581
  );
3582
  return $type;
3583
}
3584

    
3585
/**
3586
 * #process callback function for the custom form element type 'checkbox_preferred'
3587
 *
3588
 *
3589
 */
3590
function checkboxes_preferred_expand($element, &$form_state, $form) {
3591

    
3592
  // First of all create checkboxes for each of the elements
3593
  $element = form_process_checkboxes($element);
3594

    
3595
  // compose the element name
3596
  $parents = array();
3597
  array_deep_copy($element['#parents'], $parents);
3598
  $parents[count($parents) -1 ] .= '_preferred';
3599
  $element_name = $parents[0];
3600
  for ($i=1; $i < count($parents); $i++){
3601
    $element_name .= '[' . $parents[$i] . ']';
3602
  }
3603

    
3604
  $children = element_children($element);
3605

    
3606
  $element['table_start'] = array(
3607
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3608
    '#weight' => -1,
3609
  );
3610

    
3611
  // prepare first part each of the table rows which contains the row label
3612
  $weight = 0;
3613
  foreach ($children as $key) {
3614
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3615
    $element[$key]['#weight'] = $weight;
3616
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3617
    $element[$key]['#suffix'] = '</td>';
3618
    unset($element[$key]['#title']);
3619
    $weight += 2;
3620
  }
3621
  $weight = 0;
3622

    
3623
  // add a radio button to each of the checkboxes, the
3624
  // check boxes have already been created at the beginning
3625
  // of this function
3626
  if (count($element['#options']) > 0) {
3627
    foreach ($element['#options'] as $key => $choice) {
3628
      if (!isset($element[$key . '_preferred'])) {
3629
        $element[$key . '_preferred'] = array(
3630
          '#type' => 'radio',
3631
          '#name' => $element_name,
3632
          '#return_value' => check_plain($key),
3633
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3634
          '#attributes' => $element['#attributes'],
3635
          '#parents' => $element['#parents'],
3636
          // '#spawned' => TRUE,
3637
          '#weight' => $weight + 1,
3638
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3639
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3640
        );
3641
      }
3642
      $weight += 2;
3643
    }
3644
  }
3645

    
3646
  // end the table
3647
  $element['table_end'] = array(
3648
    '#markup' => '</table>',
3649
    '#weight' => $weight++,
3650
  );
3651

    
3652
  return $element;
3653
}
3654

    
3655
/**
3656
 * Theme function for the custom form field 'checkboxes_preferred'.
3657
 */
3658
function theme_checkboxes_preferred($variables) {
3659
  $element = $variables['element'];
3660
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3661
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3662
  $out .= drupal_render_children($element);
3663
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3664
  $out .= '</div>';
3665
  return $out;
3666
}
3667

    
3668
/**
3669
 * Callback for checkboxes preferred for widget which will
3670
 * be called after the form or element is built. The call
3671
 * back is configured in the form element by setting it as
3672
 * #after_build parameter.
3673
 *
3674
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3675
 *
3676
 * @param $element
3677
 *   Nested array of form elements that comprise the form.
3678
 * @param $form_state
3679
 *   A keyed array containing the current state of the form.
3680
 *   This includes the current persistent storage data for the form.
3681
 *   Additional information, like the sanitized $_POST data,
3682
 *   is also accumulated here in $form_state['input']
3683
 *
3684
 * @return the modified form array
3685
 */
3686
function checkboxes_preferred_after_build($element, &$form_state) {
3687

    
3688
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3689

    
3690
  if ($_POST && count($_POST) > 0) {
3691
    // TODO use  $form_state['input'] instead of POST !!!
3692
    // First pass of form processing.
3693
    $parents = array();
3694
    array_deep_copy($element['#parents'], $parents);
3695
    $parents[count($parents) - 1] .= '_preferred';
3696
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3697
    $element['#value']['PREFERRED'] = $preferred_layer;
3698
//     $form_state[$parent_id] = $element['#value'];
3699
//     $form_state['values']['baselayers'] = $element['#value'];
3700
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3701
    $form_state_element_values = $element['#value'];
3702
  }
3703
  else {
3704
    // Second pass of form processing.
3705
    $preferred_layer = $element['#value']['PREFERRED'];
3706
  }
3707

    
3708
  // Also set the chosen value (not sure if this is good Drupal style ....).
3709
  foreach ($children = element_children($element) as $key) {
3710
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3711
      $element[$key]['#value'] = $preferred_layer;
3712
    }
3713
  }
3714
  // The default layer must always be enabled.
3715
  $element[$preferred_layer]['#value'] = $preferred_layer;
3716

    
3717
  return $element;
3718
}
3719

    
3720
function radios_prepare_options_suffix(&$elements){
3721

    
3722
  $childrenKeys = element_children($elements);
3723
  foreach($childrenKeys as $key){
3724
    if(!is_array($elements[$key]['#theme_wrappers'])){
3725
      $elements[$key]['#theme_wrappers'] = array();
3726
    }
3727
    if(isset($elements['#options_suffixes'][$key])){
3728
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3729
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3730
    }
3731
  }
3732
  return $elements;
3733

    
3734
}
3735

    
3736
/**
3737
 * TODO
3738
 * @param unknown $variables
3739
 */
3740
function theme_radio_options_suffix($variables) {
3741
  $element = $variables['element'];
3742
  if(isset($element['#options_suffix'])) {
3743
    $element['#children'] .= $element['#options_suffix'];
3744
  }
3745
  return $element['#children'];
3746
}
3747

    
3748

    
3749
/**
3750
 * Element validate callback for text field and arrays containing json.
3751
 *
3752
 * @param $element
3753
 *   The form element to validate
3754
 * @param $form_state
3755
 *   A keyed array containing the current state of the form.
3756
 * @param $form
3757
 *   Nested array of form elements that comprise the form.
3758
 */
3759
function form_element_validate_json($element, &$form_state, $form) {
3760
   if (!empty($element['#value'])) {
3761
     json_decode($element['#value']);
3762
     if(json_last_error() != JSON_ERROR_NONE){
3763
       form_error($element,
3764
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3765
         . l('JSONLint', 'http://jsonlint.com/')
3766
       );
3767
     }
3768
   }
3769
}
3770

    
3771
/**
3772
 * Form submission handler for textareas and textfields containing JSON.
3773
 *
3774
 * The contained JSON will be converted into an php array
3775
 * or object and will be stored in the variables as such.
3776
 *
3777
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3778
 *
3779
 * @param $form
3780
 *   Nested array of form elements that comprise the form.
3781
 * @param $form_state
3782
 *   A keyed array containing the current state of the form.
3783
 *
3784
 */
3785
function submit_json_as_php_array($form, &$form_state) {
3786
  if (is_array($form['#json_elements'])) {
3787
    foreach ($form['#json_elements'] as $element){
3788
      if (trim($form_state['values'][$element])) {
3789
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3790
      } else {
3791
        $form_state['values'][$element] = NULL;
3792
      }
3793
    }
3794
  }
3795
}
(18-18/18)