Project

General

Profile

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

    
7

    
8
  // TODO Genus UUID.
9

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

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

    
18
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
19

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

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

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

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

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

    
52
  /* taxonRelationshipTypes */
53
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
54

    
55

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

    
86
    // --- Taxon profile settings --- /
87
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
88
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
89
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
90
      array(
91
          'show' => 0,
92
          'maxextend' => 184,
93
          'media_uri_query' => '',
94
          'custom_placeholder_enabled' => 1,
95
          'custom_placeholder_image_on' => 0,
96
          'custom_placeholder_image_fid' => ''
97
      )
98
    )
99
  );
100

    
101

    
102
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
103

    
104
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
105
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
106
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
107
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
108
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
109

    
110
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
111
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
112
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
113
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
114

    
115
/**
116
 * Returns the array of implemented taxon page tabs.
117
 * The array has fixed integer keys which must not be changed.
118
 */
119
function get_taxon_tabs_list() {
120
  return array(
121
    0 => 'General',
122
    1 => 'Synonymy',
123
    2 => 'Images',
124
    3 => 'Specimens',
125
    4 => 'Keys',
126
    5 => 'Experts',
127
  );
128
}
129

    
130
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
131
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
132
  array(
133
    'general' => '-3',
134
    'synonymy' => '-2',
135
    'images' => '0',
136
    'specimens' => '1',
137
    'keys' => '3',
138
    'experts' => '5',
139
    )
140
));
141

    
142

    
143
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
144
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
145
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
146
  array(
147
    'general' => null,
148
    'synonymy' => null,
149
    'images' => null,
150
    'specimens' => null,
151
    'keys' => null,
152
    'experts' => null,
153
  )
154
));
155

    
156
$taxon_tab_options = get_taxon_tabs_list();
157
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
158

    
159
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
160

    
161
/**
162
 * @todo document this function.
163
 */
164
function get_taxon_options_list() {
165
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
166
  foreach ($taxon_tab_options as $key => $value) {
167
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
168
  }
169
  return $taxon_tab_options;
170

    
171
}
172

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

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

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

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

    
367
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
368
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
369

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

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

    
393
/**
394
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
395
 * the snonymy.
396
 *
397
 * @var string
398
 */
399
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
400

    
401
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
402
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
403
    array(
404
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
405
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
406
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
407
    )
408
  )
409
);
410

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

    
432
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
433
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
434
      array(
435
      'filter_rules' => array(
436
        'statusOrderPreference' => 0,
437
        'subAreaPreference' => 0,
438
      ),
439
      'hiddenAreaMarkerType' => array()
440
     )
441
));
442

    
443
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
444
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
445
  "level_0" => array(
446
    'label_suffix' => ':',
447
    'status_glue' => '',
448
    'item_glue' => ' ',
449
    'item_group_prefix' => '',
450
    'item_group_postfix' => ''
451
  ),
452
  "level_1" => array(
453
    'label_suffix' => '',
454
    'status_glue' => '‒ ', // '&#8210; '
455
    'item_glue' => '; ',
456
    'item_group_prefix' => ', ',
457
    'item_group_postfix' => ''
458
  ),
459
  "level_2" => array(
460
    'label_suffix' => '',
461
    'status_glue' => '‒ ', // '&#8210; '
462
    'item_glue' => ', ',
463
    'item_group_prefix' => ' (',
464
    'item_group_postfix' => ')'
465
  )
466
)));
467

    
468
/**
469
 * Constant for the drupal variable key distribution_map_visibility
470
 *
471
 * possible values:
472
 *  - never
473
 *  - automatic
474
 *  - always
475
 */
476
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
477
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
478

    
479
/**
480
 * Constant for the drupal variable key specimen_map_visibility
481
 *
482
 * possible values:
483
 *  - never
484
 *  - automatic
485
 *  - always
486
 */
487
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
488
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
489

    
490
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
491
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
492
    array(
493
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
494
        'includeOccurrences' => 0,
495
        'includeTaxonNameDescriptions' => 0
496
     )
497
  ));
498

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

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

    
574
    // unserialize if nessecary
575
    if(!is_array($default)){
576
      $default = unserialize($default);
577
    }
578
    $variable = variable_get($variable_name, array());
579
    $result = drupal_array_merge_deep($default, $variable);
580
    return $result;
581
}
582

    
583
/**
584
 * @todo document this function.
585
 */
586
function getGallerySettings($gallery_config_form_name) {
587
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
588
}
589

    
590
/**
591
 * Returns the string representation of the default tab.
592
 *
593
 * @param bool $returnTabIndex
594
 *   Defaults to FALSE, if set true this function will return the index number
595
 *   of the default tab. (used to supply default values to form elements).
596
 */
597
function get_default_taxon_tab($returnTabIndex = FALSE) {
598

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

    
615
  // Return the index value or the string representation.
616
  if ($returnTabIndex) {
617
    return $index_value;
618
  }
619
  else {
620
    return ($values[$index_value]);
621
  }
622
}
623

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

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

    
695
  // ---- DEFAULTS settings
696

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

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

    
768
  // ---- Special DEFAULTS for existing portals
769
  // TODO:
770
  // this can be removed once the feature block
771
  // settings have been deployed for the first time to these portals
772

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

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

    
860
  $cyprus_default = $cichorieae_default;
861
  $cyprus_default[UUID_DISTRIBUTION] = array(
862
    'as_list' => 'div', // currently ignored
863
    'link_to_reference' => 0,
864
    'link_to_name_used_in_source' => 0,
865
    'sources_as_content' => 0,
866
    'sources_as_content_to_bibliography' => 0,
867
    'sort_elements' => NO_SORT, // will cause ...
868
    'glue' => ' ',
869
    'element_tag' => 'div',
870
    'special' => array()
871
  );
872

    
873
  $default_theme = variable_get('theme_default', NULL);
874

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

    
899
  // ---- END of DEFAULTS
900

    
901
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
902

    
903
  $feature_block_setting = null;
904

    
905
  if (isset($saved_settings[$feature_uuid])) {
906
    $feature_block_setting = $saved_settings[$feature_uuid];
907
  }
908
  else if (isset($settings_for_theme[$feature_uuid])) {
909
    $feature_block_setting = $settings_for_theme[$feature_uuid];
910
  }
911
  else if (isset($settings_for_theme['DEFAULT'])) {
912
    $feature_block_setting = $settings_for_theme['DEFAULT'];
913
  }
914

    
915
  // now merge the default and specific settings
916
  $settings_to_merge = array($default['DEFAULT']);
917
  if(is_array($saved_settings)){
918
    $settings_to_merge[] = $saved_settings['DEFAULT'];
919
  }
920
  if(isset($feature_block_setting)){
921
    $settings_to_merge[] = $feature_block_setting;
922
  }
923
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
924

    
925
  return $feature_block_setting;
926
}
927

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

    
949
/**
950
 * @todo Please document this function.
951
 * @see http://drupal.org/node/1354
952
 */
953
function cdm_dataportal_menu_admin(&$items) {
954
  // Display section on admin/config page.
955
  $items['admin/config/cdm_dataportal'] = array(
956
    'title' => 'CDM Dataportal',
957
    'description' => 'Settings for the CDM DataPortal.',
958
    'position' => 'right',
959
    'weight' => 10,
960
    'page callback' => 'system_admin_menu_block_page',
961
    'access arguments' => array('administer cdm_dataportal'),
962
    'file' => 'system.admin.inc',
963
    'file path' => drupal_get_path('module', 'system'),
964
  );
965
  $items['admin/config/cdm_dataportal/settings'] = array(
966
    'title' => 'Settings',
967
    'description' => 'Settings for the CDM DataPortal.',
968
    'weight' => 0,
969
    'page callback' => 'drupal_get_form',
970
    'page arguments' => array('cdm_settings_general'),
971
    'access arguments' => array('administer cdm_dataportal'),
972
    'type' => MENU_NORMAL_ITEM,
973
  );
974
  $items['admin/config/cdm_dataportal/settings/general'] = array(
975
    'title' => 'General',
976
    'description' => 'General',
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_DEFAULT_LOCAL_TASK,
982
  );
983

    
984
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
985
    'title' => 'Cache',
986
    'description' => 'Cache',
987
    'access arguments' => array('administer cdm_dataportal'),
988
    'page callback' => 'drupal_get_form',
989
    'page arguments' => array('cdm_settings_cache'),
990
    'weight' => 10,
991
    'type' => MENU_LOCAL_TASK,
992
  );
993

    
994
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
995
    'title' => 'Geo & Map',
996
    'description' => 'Geo & Map',
997
    'access arguments' => array('administer cdm_dataportal'),
998
    'page callback' => 'drupal_get_form',
999
    'page arguments' => array('cdm_settings_geo'),
1000
    'weight' => 1,
1001
    'type' => MENU_LOCAL_TASK,
1002
  );
1003

    
1004
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
1005
    'title' => 'Layout',
1006
    'description' => 'Configure and adjust the layout of your DataPortal ',
1007
    'access arguments' => array('administer cdm_dataportal'),
1008
    'page callback' => 'drupal_get_form',
1009
    'page arguments' => array('cdm_settings_layout'),
1010
    'weight' => 2,
1011
    'type' => MENU_LOCAL_TASK,
1012
  );
1013

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

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

    
1056
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1057
    'title' => 'Media',
1058
    'description' => 'Configure and adjust the layout of your DataPortal ',
1059
    'access arguments' => array('administer cdm_dataportal'),
1060
    'page callback' => 'drupal_get_form',
1061
    'page arguments' => array('cdm_settings_layout_media'),
1062
    'weight' => 3,
1063
    'type' => MENU_LOCAL_TASK,
1064
  );
1065

    
1066
}
1067

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

    
1086
/**
1087
 * Configures the settings form for the CDM-API module.
1088
 *
1089
 * @return array
1090
 *   Drupal settings form.
1091
 */
1092
function cdm_settings_general() {
1093

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

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

    
1112
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1113
    '#type' => 'markup',
1114
    '#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')
1115
      . ' visible only for administrators',
1116
  );
1117

    
1118
  $form['cdm_webservice']['freetext_index'] = array(
1119
    '#type' => 'fieldset',
1120
    '#title' => t('Freetext index'),
1121
    '#collapsible' => FALSE,
1122
    '#collapsed' => FALSE,
1123
  );
1124

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

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

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

    
1178
    $form['cdm_webservice']['freetext_index']['cdm_dataportal_taxon_auto_suggest'] = array(
1179
        '#type' => 'checkbox',
1180
        '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
1181
        '#default_value' => variable_get('cdm_dataportal_taxon_auto_suggest', CDM_DATAPORTAL_TAXON_AUTO_SUGGEST),
1182
        '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
1183
        This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
1184
    );
1185

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

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

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

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

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

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

    
1236
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1237
    '#type' => 'select',
1238
    '#title' => t('Available classifications') . ':',
1239
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1240
    '#options' => cdm_get_taxontrees_as_options(),
1241
    '#description' => t('Select the default taxa classification for your
1242
      <em>taxon tree</em>, the other classifications will be also available but
1243
      with a manual user change.'),
1244
  );
1245

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1414

    
1415

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

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

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

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

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

    
1464
  return system_settings_form($form);
1465
}
1466

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

    
1477

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

    
1485
  $form = array();
1486

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

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

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

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

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

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

    
1542
  $bibliography_settings = get_bibliography_settings(true);
1543

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

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

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

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

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

    
1597
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1598
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1599
    $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.)';
1600
  } if($default_part_definitions_pre_480_json == $current_part_definition_json){
1601
    $which_version_message = '(These are the old default part definition from before EDIT platform release 4.8.0, you may want to reset these by clearing the text area and and submitting the form.)';
1602
  } else if($is_custom_part_definition){
1603
    if(isset($current_part_definition['ZoologicalName']) || isset($current_part_definition['BotanicalName']) || isset($current_part_definition['#DEFAULT'])){
1604
      // see also cdm_dataportal_requirements($phase)
1605
      $which_version_message = '(This are invalid custom part definitions from before EDIT platform release 4.8.0. Please use the diff function to review the changes and update the definition. 
1606
      Clearing the text area and and submitting the form will reset it to the default)';
1607
    } else {
1608
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1609
    }
1610
  } else  {
1611
    $which_version_message = '(These are the default part definition.)';
1612
  }
1613

    
1614
  $diff_viewer_markup = '';
1615
  if($is_custom_part_definition){
1616
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1617
  }
1618

    
1619
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1620
    . $which_version_message
1621
    . '</div>'
1622
    . $diff_viewer_markup;
1623

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

    
1713
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1714
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1715
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1716
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1717
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1718

    
1719
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1720
    $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.)';
1721
  } else if($is_custom_render_template){
1722
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1723
  } else {
1724
    $which_version_message = '(These are the default render templates.)';
1725
  }
1726

    
1727
  $diff_viewer_markup = '';
1728
  if($is_custom_render_template){
1729
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1730
  }
1731

    
1732
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1733
    . $which_version_message
1734
    . '</div>'
1735
    . $diff_viewer_markup;
1736

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

    
1777
  // @WA: D7 form api does not support reset buttons,
1778
  // so to mimic the D5 reset button we add one like this.
1779
  $form['actions']['reset'] = array(
1780
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1781
    '#weight' => 1000,
1782
  );
1783

    
1784
  $form['#submit'] = array('submit_json_as_php_array');
1785
  // #json_elements especially defined for submit_json_as_php_array()
1786
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1787
  return system_settings_form($form);
1788
}
1789

    
1790

    
1791
/**
1792
 * @param $form_name
1793
 * @param $form_title
1794
 * @param $collapsed
1795
 * @param string $form_description
1796
 *   The description for the fieldset of the gallery setting.
1797
 * @return mixed
1798
 */
1799
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1800
  $form[$form_name] = array(
1801
    '#type' => 'fieldset',
1802
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1803
    '#collapsible' => TRUE,
1804
    '#collapsed' => $collapsed,
1805
    '#tree' => TRUE,
1806
    '#description' => $form_description,
1807
  );
1808

    
1809
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1810
  $gallery_settings = variable_get($form_name, $default_values);
1811
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1812
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1813
    /*
1814
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1815
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1816
    '#type' => 'textfield',
1817
    '#title' => t('Search Page Size'),
1818
    '#default_value' => $test,
1819
    '#description' => t('Number of Names to display per page in search results.')
1820
    );
1821
    */
1822
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1823
      '#type' => 'checkbox',
1824
      '#title' => t('Show media thumbnails for accepted taxa'),
1825
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1826
    );
1827

    
1828
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1829
      '#type' => 'checkbox',
1830
      '#title' => t('Show media thumbnails for synonyms'),
1831
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1832
      '#description' => '',
1833
    );
1834
  }
1835

    
1836
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1837
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1838
    '#type' => 'checkbox',
1839
    '#title' => t('Show captions under thumbnails'),
1840
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1841
    '#description' => '',
1842
  );
1843

    
1844
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1845
    '#type' => 'textfield',
1846
    '#title' => t('Thumbnail size') . ':',
1847
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1848
    '#description' => t('Select the size of each individual thumbnail.'),
1849
  );
1850

    
1851
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1852
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1853
      '#type' => 'textfield',
1854
      '#title' => t('Number of columns') . ':',
1855
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1856
      '#description' => t('Group the thumbnails in columns: select how many
1857
        columns the gallery should display.'),
1858
    );
1859
  }
1860

    
1861
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1862
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1863
      '#type' => 'textfield',
1864
      '#title' => t('Maximum number of rows') . ':',
1865
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1866
      '#description' => t('You can group the thumbnails in rows, select in how
1867
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1868
        If you want an unlimited number of rows please set to 0.'),
1869
    );
1870
  }
1871

    
1872
  return $form;
1873
}
1874

    
1875
/**
1876
 * @todo document this function.
1877
 */
1878
function cdm_settings_layout_taxon() {
1879
  $collapsed = FALSE;
1880
  $form = array();
1881

    
1882
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1883

    
1884
  // --------- TABBED TAXON ------- //
1885
  $form['taxon_tabs'] = array(
1886
    '#type' => 'fieldset',
1887
    '#title' => t('Taxon tabs'),
1888
    '#collapsible' => TRUE,
1889
    '#collapsed' => TRUE,
1890
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1891
      be splitted in four diferent tabs; General, Synonymy, Images and
1892
      Specimens. If the taxon has no information for any of the tabs/sections
1893
      such tab will be not displayed.'),
1894
  );
1895

    
1896
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1897
    '#type' => 'checkbox',
1898
    '#title' => t('Tabbed taxon page'),
1899
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1900
    '#description' => t('<p>If selected split the taxon page into individual
1901
      tabs for description, images, synonymy and specimens. If not the taxon
1902
      data is rendered as a long single page without tabs.</p>'),
1903
  );
1904

    
1905
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1906
    '#type' => 'checkboxes',
1907
    '#title' => t('Tabs visibility options') . ':',
1908
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1909
    '#options' => get_taxon_options_list(),
1910
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1911
  );
1912

    
1913
  // WEIGHT
1914
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1915
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1916
    '#title'  => 'Tabs order',
1917
    '#type' => 'fieldset',
1918
    '#collapsible' => false,
1919
    '#tree' => true,
1920
    '#description' => 'The weight value defines the order of the tabs or of the respective content block on the 
1921
        taxon page when it is the tabless mode.'
1922
  );
1923
  // Weights range from -delta to +delta, so delta should be at least half
1924
  // of the amount of tabs present.
1925
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1926
  foreach (get_taxon_tabs_list() as $label) {
1927
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1928
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1929
        '#title' => $label,
1930
        '#type'  => 'weight',
1931
        '#default_value' => $taxon_tabs_weights[$key],
1932
        '#delta' => $tab_weight_delta
1933
    );
1934
  }
1935

    
1936
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1937
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1938
    '#title'  => 'Tab label override',
1939
    '#type' => 'fieldset',
1940
    '#collapsible' => false,
1941
    '#tree' => true,
1942
    '#description' => 'Setting a label for a tab will override the default label. 
1943
      Please enter the label text in the default language of the portal.'
1944
  );
1945
  foreach (get_taxon_tabs_list() as $label) {
1946
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1947
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1948
      '#title' => $label,
1949
      '#type'  => 'textfield',
1950
      '#default_value' => $taxon_tabs_labels[$key]
1951
    );
1952
  }
1953

    
1954
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1955
    '#type' => 'select',
1956
    '#title' => t('Default tab to display') . ':',
1957
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1958
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1959
    '#description' => t('<p>Select the default tab to display when visiting a
1960
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1961
      <strong>Note:</strong> After performing a search and clicking in any
1962
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1963
      taxon and not the above selected tab.'),
1964
  );
1965

    
1966
  /* ======  TAXON_PROFILE ====== */
1967
  $form['taxon_profile'] = array(
1968
    '#type' => 'fieldset',
1969
    '#title' => t('Taxon profile (tab)'),
1970
    '#description' => t('<p>This section covers the settings related to the taxon
1971
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1972
    '#collapsible' => TRUE,
1973
    '#collapsed' => TRUE,
1974
  );
1975

    
1976
  // ---- PROFILE PICTURE ----//
1977

    
1978
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1979
    '#type' => 'fieldset',
1980
    '#tree' => TRUE,
1981
    '#title' => t('Taxon profile picture'),
1982
    '#collapsible' => TRUE,
1983
    '#collapsed' => FALSE,
1984
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1985
  );
1986

    
1987
  //FIXME migrate variables:
1988
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1989
  // FIXME
1990
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1991

    
1992
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1993

    
1994
  /*
1995
   * 'show' => 1,
1996
   * 'maxextend' => 184,
1997
   * 'media_uri_query' => ''
1998
   * 'custom_placeholder_image_on' => 1,
1999
   * 'custom_placeholder_image_fid' => ''
2000
   */
2001
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
2002
    '#type' => 'checkbox',
2003
    '#title' => t('Enable profile picture'),
2004
    '#description' => t('Show the profile picture.'),
2005
    '#default_value' => $taxon_profile_image_settings['show'],
2006
  );
2007

    
2008
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
2009
      '#type' => 'textfield',
2010
      '#tree' => TRUE,
2011
      '#title' => t('Profile picture maximum extend'),
2012
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
2013
      '#field_suffix' => 'px',
2014
      '#maxlength' => 4,
2015
      '#size' => 4,
2016
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
2017
  );
2018

    
2019
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
2020
      '#type' => 'textfield',
2021
      '#tree' => TRUE,
2022
      '#title' => t('Additional URI query parameter'),
2023
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
2024
      '#maxlength' => 1024,
2025
      '#size' => 60,
2026
      '#description' => t('Additional query parameters to be used when requesting for the  
2027
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
2028
            The query parameters will be appended to the uri of the media representation part
2029
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
2030
  );
2031

    
2032
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2033
    '#type' => 'checkbox',
2034
    '#title' => t('Show the placeholder image'),
2035
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
2036
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2037
  );
2038

    
2039
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2040
      '#type' => 'checkbox',
2041
      '#title' => t('Use a custom placeholder image'),
2042
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2043
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2044
  );
2045

    
2046
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2047
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2048
        '#type' => 'managed_file',
2049
        '#title' => t('Custom placeholder image file'),
2050
        '#progress_indicator' => 'bar',
2051
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2052
    //       '#name' => 'custom_placeholder_image',
2053
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2054
    );
2055

    
2056
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2057
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2058
      $url = file_create_url($profile_image_file->uri);
2059
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2060
                '#type' => 'item',
2061
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2062
      );
2063
    }
2064
  } else {
2065
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2066
      '#type' => 'hidden',
2067
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2068
    );
2069
  }
2070

    
2071
  $options = cdm_rankVocabulary_as_option();
2072
  array_unshift($options, '-- DISABLED --');
2073
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2074
    '#type' => 'select',
2075
    '#title' => t('Hide profile picture for higher ranks') . ':',
2076
    '#default_value' => variable_get('image_hide_rank', '0'),
2077
    '#options' => $options,
2078
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2079
  );
2080

    
2081
  // -- MEDIA THUMBNAILS -- //
2082
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2083
  $form_title = 'Taxon Profile Images';
2084
  $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>';
2085
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2086

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

    
2115
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2116
  $profile_feature_tree = get_profile_feature_tree();
2117

    
2118
  if (isset($profile_feature_tree->root->childNodes)) {
2119

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

    
2159

    
2160
    $feature_list_layout_settings_disabled = FALSE;
2161

    
2162
    // creating helper object to retrieve the default settings
2163
    $featureNode = new stdClass();
2164
    $featureNode->feature = new stdClass();
2165
    $featureNode->feature->uuid="DEFAULT";
2166
    $featureNode->feature->representation_L10n = "Default";
2167
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2168

    
2169
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2170

    
2171
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2172

    
2173
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2174
        $subform_id = $featureNode->feature->uuid;
2175
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2176

    
2177
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2178

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

    
2192
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2193
          '#type' => 'select',
2194
          '#title' => 'List type',
2195
          '#default_value' => $feature_block_setting['as_list'],
2196
          '#options' => array(
2197
            'div' => 'not as list',
2198
            'ul' => 'bullet list',
2199
            'ol' => 'numbered list',
2200
            'dl' => 'definition list'
2201
          ),
2202
        );
2203

    
2204
        if($featureNode->feature->uuid == "DEFAULT"){
2205
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2206
            '#type' => 'checkbox',
2207
            '#title' => t('Link to reference'),
2208
            '#default_value' => $feature_block_setting['link_to_reference'],
2209
          );
2210

    
2211
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2212
            '#type' => 'checkbox',
2213
            '#title' => 'Link to name used in source',
2214
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2215
          );
2216
        }
2217

    
2218
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2219
          '#type' => 'checkbox',
2220
          '#title' => 'Sources as content',
2221
          '#default_value' => $feature_block_setting['sources_as_content'],
2222
        );
2223

    
2224
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2225
          '#type' => 'checkbox',
2226
          '#title' => 'Put sources also as content to bibliography',
2227
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2228
        );
2229

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

    
2249
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2250
          '#type' => 'select',
2251
          '#title' => t('Element tag'),
2252
          '#options' => array(
2253
            'span' => 'span',
2254
            'div' => 'div',
2255
            'p' => 'p'
2256
          ),
2257
          '#default_value' => $feature_block_setting['element_tag'],
2258
        );
2259
      }
2260
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2261
    }
2262
  }
2263

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

    
2289

    
2290

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

    
2309
  );
2310

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

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

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

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

    
2337

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

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

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

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

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

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

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

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

    
2440

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2550
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2551
    '#type' => 'checkbox',
2552
    '#title' => t('Show "Associated with" in specimen table.'),
2553
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2554
  );
2555

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

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

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

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

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

    
2622
/**
2623
 * @todo document this function.
2624
 */
2625
function cdm_settings_layout_search() {
2626

    
2627
  $form = array();
2628

    
2629
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2630

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

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

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

    
2660
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2661
    '#type' => 'textfield',
2662
    '#title' => t('Results per page') . ':',
2663
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2664
    '#description' => t('Number of results to display per page.'),
2665
  );
2666

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

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

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

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

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

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

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

    
2716
  $form = array();
2717

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

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

    
2737
  // --- MEDIA GALLERY ---- //
2738
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2739
  $form_title = 'Standard viewer';
2740
  $form_description = '<p>Configure the standard image viewer.</p><p><strong>Note:</strong> the image viewer should selected otherwise settings are not taking into account.</p>';
2741
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2742
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2743

    
2744
  // @WA: D7 form api does not support reset buttons,
2745
  // so to mimic the D5 reset button we add one like this.
2746
  $form['actions']['reset'] = array(
2747
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2748
    '#weight' => 1000,
2749
  );
2750
  return system_settings_form($form);
2751
}
2752

    
2753
/**
2754
 * GEOSERVICE and Map settings.
2755
 */
2756
function cdm_settings_geo($form, &$form_state) {
2757

    
2758
  $current_geoserver_settings = get_edit_map_service_settings();
2759
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2760

    
2761

    
2762
  $form = array();
2763

    
2764
  $dummy_distribution_query = NULL;
2765
  if($map_distribution['map_type'] != 1){
2766
    // we need to apply a dummy query since the map service requires for image maps
2767
    // at least as and ad to be defined
2768
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2769
  }
2770

    
2771
  $form['map_preview'] = array(
2772
      '#type' => 'fieldset',
2773
      '#tree' => FALSE,
2774
      '#title' => t('Map preview'),
2775
      '#collapsible' => FALSE,
2776
      '#description' => 'The preview of the map'
2777
       . ($dummy_distribution_query != null ?
2778
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2779
           '.<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.')
2780
  );
2781
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2782
    'move' => "this.cdmOpenlayersMap.printInfo",
2783
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2784
  ), true // resizable
2785
  );
2786

    
2787
  /*
2788
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2789
  );
2790
  */
2791

    
2792
  /*
2793
   * GEO SERVER
2794
   */
2795
  $form['edit_map_server'] = array(
2796
    '#type' => 'fieldset',
2797
    '#tree' => true,
2798
    '#title' => t('EDIT map service'),
2799
    '#collapsible' => TRUE,
2800
    '#collapsed' => TRUE,
2801
    '#description' => t('Configuration and selection of your geo server.
2802
      The Geo Server is responsible for generating the maps.'),
2803
  );
2804

    
2805
  $form['edit_map_server']['base_uri'] = array(
2806
    '#type' => 'select',
2807
    '#title' => t('EDIT map service') . ':',
2808
    '#default_value' => $current_geoserver_settings['base_uri'],
2809
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2810
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2811
  );
2812
  $form['edit_map_server']['version'] = array(
2813
      '#type' => 'select',
2814
      '#title' => t('Version') . ':',
2815
      '#default_value' => $current_geoserver_settings['version'],
2816
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2817
      '#description' => t('The version of the EDIT map services'),
2818
  );
2819

    
2820
  /*
2821
   * MAP SETTINGS
2822
   */
2823

    
2824
  $form[CDM_MAP_DISTRIBUTION] = array(
2825
    '#type' => 'fieldset',
2826
    '#tree' => TRUE,
2827
    '#title' => t('Maps settings'),
2828
    '#collapsible' => TRUE,
2829
    '#collapsed' => TRUE,
2830
    '#description' => t('General configuration for all map types.'),
2831
  );
2832

    
2833
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2834
    '#type' => 'radios',
2835
    '#title' => 'Map types',
2836
    '#options' => array(
2837
      1 => "OpenLayers dynamic map viewer",
2838
      0 => "Plain image",
2839
    ),
2840
    '#default_value' => $map_distribution['map_type'],
2841
    '#description' => 'Two different map types are available :
2842
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2843
      which allows zooming and panning. If enabled you can configure the default layer
2844
      (background of your maps) below.</li>
2845
      <li><em>Plain image</em>: The map will be static non interactive
2846
      image.</li></ul>',
2847
  );
2848
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2849

    
2850
  /*
2851
   * settings for the distribution map are used also for specimens map!!!!
2852
   */
2853

    
2854
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2855
      '#type' => 'textfield',
2856
      '#title' => 'Aspect ratio',
2857
      '#default_value' => $map_distribution['aspect_ratio'],
2858
      '#maxlength' => 4,
2859
      '#size' => 4,
2860
      '#element_validate' => array('element_validate_number'),
2861
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2862
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2863
      width by the height:</br>
2864
      <pre>aspect ratio = w / h</pre>
2865
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2866
      for a square map use <strong>1</strong>.',
2867
  );
2868

    
2869
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2870
    '#type' => 'textfield',
2871
    '#title' => 'Bounding box',
2872
    '#default_value' => $map_distribution['bbox'],
2873
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2874
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2875
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2876
      <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.
2877
      (Maybe you need to change the map base layer to OpeLayers.)
2878
      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
2879
      below the map from where you can copy the bbox string.</p>'),
2880
  );
2881

    
2882
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
2883
    '#type' => 'select',
2884
    '#title' => 'Max zoom level',
2885
    '#default_value' => $map_distribution['maxZoom'],
2886
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
2887
  );
2888

    
2889
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2890
    '#type' => 'checkbox',
2891
    '#title' => 'Display area labels',
2892
    '#default_value' => $map_distribution['show_labels'],
2893
    '#description' => t('The map will show name labels of the areas'),
2894
  );
2895

    
2896
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2897
    '#type' => 'textfield',
2898
    '#title' => 'Map caption',
2899
    '#default_value' => $map_distribution['caption'],
2900
    '#description' => t('The caption will be shown below the map.'),
2901
  );
2902

    
2903
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2904
    '#type' => 'textfield',
2905
    '#title' => 'Distribution layer opacity',
2906
    '#default_value' => $map_distribution['distribution_opacity'],
2907
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2908
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2909
  );
2910

    
2911
  // --- Plain Image Settings --- //
2912
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2913
    '#type' => 'fieldset',
2914
    '#title' => 'Plain image map settings',
2915
    '#tree' => TRUE,
2916
    '#collapsible' => TRUE,
2917
    '#collapsed' => $open_layers_is_enabled,
2918
    '#description' => 'The settings in this section are still expertimental
2919
      and can only be used with the EDIT map service version 1.1 or above.',
2920
  );
2921
  $edit_mapserver_version = get_edit_map_service_version_number();
2922
  if ($edit_mapserver_version < 1.1) {
2923
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2924
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2925
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2926
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2927
  }
2928

    
2929
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2930
    '#type' => 'textfield',
2931
    '#title' => 'Width',
2932
    '#default_value' => $map_distribution['image_map']['width'],
2933
    '#maxlength' => 4,
2934
    '#size' => 4,
2935
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2936
  );
2937

    
2938
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2939
    '#type' => 'textfield',
2940
    '#title' => 'Background layer',
2941
    '#default_value' => $map_distribution['image_map']['base_layer'],
2942
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2943
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2944
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2945
    )),
2946
  );
2947

    
2948
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2949
    '#type' => 'textfield',
2950
    '#title' => 'Background color',
2951
    '#default_value' => $map_distribution['image_map']['bg_color'],
2952
  );
2953

    
2954
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2955
    '#type' => 'textfield',
2956
    '#title' => 'Background layer style',
2957
     // Only line color by now.
2958
    '#default_value' => $map_distribution['image_map']['layer_style'],
2959
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2960
  );
2961

    
2962
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2963
      '#type' => 'textfield',
2964
      '#title' => 'Projection',
2965
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2966
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2967
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2968
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2969
  );
2970

    
2971

    
2972
  // --- OpenLayers Settings --- //
2973
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2974
    '#type' => 'fieldset',
2975
    '#title' => 'OpenLayers settings',
2976
    '#tree' => TRUE,
2977
    '#collapsible' => TRUE,
2978
    '#collapsed' => !$open_layers_is_enabled,
2979
    '#description' => '',
2980
  );
2981

    
2982

    
2983
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2984
      '#type' => 'checkbox',
2985
      '#title' => 'Display outside max extent',
2986
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2987
      '#description' => t('Allows the map to display parts of the layers which are outside
2988
         the max extent if the aspect ratio of the map and of the baselayer
2989
         are not equal.'),
2990
  );
2991

    
2992

    
2993
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2994
      '#type' => 'checkbox',
2995
      '#title' => 'Show Layer Switcher',
2996
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2997
      '#description' => 'The Layer Switcher control displays a table of contents
2998
      for the map.  This allows the user interface to switch between
2999
      base layers and to show or hide overlays.  By default the switcher is
3000
      shown minimized on the right edge of the map, the user may expand it
3001
      by clicking on the handle.',
3002
  );
3003

    
3004
  if (!$open_layers_is_enabled) {
3005
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3006
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3007
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3008
  }
3009

    
3010
  // The default layer must always be enabled
3011
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3012
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3013

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

    
3044
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3045
    '#type' => 'checkboxes_preferred',
3046
    '#title' => 'Base Layers',
3047
    '#options' => $baselayer_options,
3048
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3049
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3050
  );
3051

    
3052
  $google_maps_api_key = null;
3053
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3054
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3055
  }
3056
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3057
    '#type' => 'textfield',
3058
    '#title' => 'Google Maps API Key',
3059
    '#default_value' => $google_maps_api_key,
3060
    '#description' => 'In order to use any of the Google map layers you need to provide 
3061
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3062
  );
3063

    
3064
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3065
    $map_distribution['openlayers']['custom_wms_base_layer'],
3066
    'Custom WMS base layer',
3067
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3068
    true // add projection settings
3069
    );
3070

    
3071
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3072
    $map_distribution['openlayers']['wms_overlay_layer'],
3073
    'WMS overlay layer',
3074
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3075
                You can actually combine multiple layers for this overlay. 
3076
                For details please refer to the wms query parameter <code>Layers</code> .'
3077
  );
3078

    
3079
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3080
    '#type' => 'checkbox',
3081
    '#title' => 'Enable overlay layer',
3082
    '#weight' => -100,
3083
    '#default_value' => $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3084
  );
3085

    
3086
  /*
3087
   * Map Legend
3088
   */
3089
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3090
    '#type' => 'fieldset',
3091
    '#title' => 'Map legend',
3092
    '#tree' => TRUE,
3093
    '#collapsible' => TRUE,
3094
    '#collapsed' => TRUE,
3095
    '#description' => 'Configure the maps legend.',
3096
  );
3097

    
3098
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3099
    '#type' => 'checkbox',
3100
    '#title' => 'Display a map legend',
3101
    '#default_value' => $map_distribution['legend']['show'],
3102
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3103
  );
3104

    
3105
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3106
    '#type' => 'textfield',
3107
    '#title' => 'Legend opacity',
3108
    '#default_value' => $map_distribution['legend']['opacity'],
3109
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3110
                         to 0.0 will be not much visible.',
3111
  );
3112

    
3113
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3114
    '#type' => 'textfield',
3115
    '#title' => 'Font size',
3116
    '#default_value' => $map_distribution['legend']['font_size'],
3117
    '#description' => 'Font size in pixels.',
3118
  );
3119

    
3120
  $fontStyles = array(
3121
    0 => "plane",
3122
    1 => "italic",
3123
  );
3124
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3125
    '#type' => 'select',
3126
    '#title' => 'Available font styles',
3127
    '#default_value' => $map_distribution['legend']['font_style'],
3128
    '#options' => $fontStyles,
3129
    '#description' => 'Select a font style for the map legend.',
3130
  );
3131

    
3132
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3133
    '#type' => 'textfield',
3134
    '#title' => 'Icon width',
3135
    '#default_value' => $map_distribution['legend']['icon_width'],
3136
    '#description' => 'Legend icon width in pixels.',
3137
  );
3138
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3139
    '#type' => 'textfield',
3140
    '#title' => 'Icon height',
3141
    '#default_value' => $map_distribution['legend']['icon_height'],
3142
    '#description' => 'Legend icon height in pixels.',
3143
  );
3144

    
3145
  // @WA: D7 form api does not support reset buttons,
3146
  // so to mimic the D5 reset button we add one like this.
3147
  $form['actions']['reset'] = array(
3148
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3149
    '#weight' => 1000,
3150
  );
3151

    
3152
  return system_settings_form($form);
3153
}
3154

    
3155
/**
3156
 * @param $default_settings
3157
 * @param $title
3158
 * @param $description
3159
 * @param bool $add_projection_settings
3160
 * @return array
3161
 */
3162
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3163
{
3164
  $form_elements = array(
3165
    '#type' => 'fieldset',
3166
    '#title' => $title,
3167
    '#tree' => TRUE,
3168
    '#collapsible' => FALSE,
3169
    '#collapsed' => FALSE,
3170
    '#description' => $description,
3171
  );
3172

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

    
3208
  if($add_projection_settings){
3209

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

    
3275
  }
3276
  return $form_elements;
3277
}
3278

    
3279

    
3280
/**
3281
 * @todo document this function.
3282
 */
3283
function cdm_settings_cache() {
3284

    
3285
  $form = array();
3286

    
3287
  $form['cache_settings'] = array(
3288
    '#type' => 'fieldset',
3289
    '#title' => t('Cache Settings'),
3290
    '#collapsible' => FALSE,
3291
    '#collapsed' => FALSE,
3292
    '#description' => t('<p>When caching is enabled all single taxon sites are
3293
      stored in an internal drupal cache doing the portal response of taxa pages
3294
      faster. This is possible because the sites are loaded from the cache and
3295
      are not created from scratch.</p>'),
3296
  );
3297

    
3298
  $form['cache_settings']['cdm_webservice_cache'] = array(
3299
    '#type' => 'checkbox',
3300
    '#title' => t('<strong>Enable caching</strong>'),
3301
    '#options' => cdm_help_general_cache(),
3302
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3303
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3304
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3305
       application the changes will be not visible till the cache is erased.
3306
       Therefore developers should deactived this feature when they are working
3307
       on the CDM Dataportal Module.</p>'),
3308
  );
3309

    
3310
  $form['cache_settings']['cdm_run_cache'] = array(
3311
    '#markup' => cdm_view_cache_site(),
3312
  );
3313

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

    
3323
/**
3324
 * Walk and cache all taxon pages.
3325
 */
3326
function cdm_view_cache_site() {
3327

    
3328
  $out = '';
3329

    
3330
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3331

    
3332
  $request_params = array();
3333
  $request_params['class'] = "Taxon";
3334

    
3335
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3336
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3337
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3338

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

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

    
3348
  // Comment @WA: A form within a form is not valid html and not needed here.
3349
  // Also, it would be recommended just to include this part of the form in the
3350
  // rest of the form array in cdm_settings_cache().
3351
  // $out .= '<form id="cache_site">';
3352
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3353
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3354
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3355
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3356
  // $out .= '</form>';
3357
  $out .= '</div>';
3358
  /*
3359
  foreach($taxonPager->records as $taxon){
3360
    cdm_dataportal_taxon_view($uuid);
3361
  }
3362
  */
3363
  return $out;
3364
}
3365

    
3366

    
3367
function cdm_settings_layout_taxon_submit($form, &$form_state){
3368
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3369
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3370
    if(is_object($file)){
3371
      $file->status = FILE_STATUS_PERMANENT;
3372
      file_save($file);
3373
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3374
    }
3375
  }
3376
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3377
  $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]);
3378
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3379
  if($tab_lables_modified || $tabs_enabled_modified){
3380
    // we first need to set the variable to persist the changes setting
3381
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3382
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3383
    menu_rebuild();
3384
  }
3385
}
3386

    
3387
function cdm_settings_layout_search_submit($form, &$form_state){
3388
  // the visibility of media thumbnails also affects the ui of the search results
3389
  // so reset the according session variable
3390
  //    1. in order to give the user immediate
3391
  //       feedback on potential setting changes
3392
  //    2. let refresh the default if it has changed
3393
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3394
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3395
  }
3396
}
3397

    
3398
/**
3399
 * Form validation handler for cdm_settings_general
3400
 *
3401
 * @param $form
3402
 * @param $form_state
3403
 */
3404
function cdm_settings_general_validate($form, &$form_state) {
3405

    
3406
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3407
    $form_state['values']['cdm_webservice_url'] .= '/';
3408
  }
3409

    
3410
}
3411

    
3412
/**
3413
 * Form submit handler for settings general.
3414
 *
3415
 * tasks performed:
3416
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3417
 *
3418
 * @param $form
3419
 * @param $form_state
3420
 */
3421
function cdm_settings_general_submit($form, &$form_state){
3422
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3423
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3424
  unset($_SESSION['cdm_login']);
3425
}
3426

    
3427
/**
3428
 * Form validation handler for cdm_settings_cache
3429
 */
3430
function cdm_settings_cache_validate($form, &$form_state) {
3431
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3432
    cache_clear_all(NULL, 'cache_cdm_ws');
3433
    // Better clear secref_cache since I can not be sure if the cache has not
3434
    // be used during this response.
3435
    cdm_api_secref_cache_clear();
3436
  }
3437

    
3438
}
3439

    
3440
/**
3441
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3442
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3443
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3444
 *  - version: the version, e.g.: v1.1
3445
 *
3446
 * @return array
3447
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3448
 */
3449
function get_edit_map_service_settings() {
3450

    
3451
  $settings = variable_get('edit_map_server', array(
3452
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3453
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3454
      )
3455
  );
3456

    
3457
  return $settings;
3458
}
3459

    
3460
/**
3461
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3462
 *
3463
 * @return string
3464
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3465
 */
3466
function get_edit_map_service_full_uri() {
3467
  $settings = get_edit_map_service_settings();
3468
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3469
}
3470

    
3471

    
3472
/**
3473
 * Returns the version number of the currently selected edit mapserver as a float
3474
 *
3475
 * @return float
3476
 *   The version number of the currently selected edit mapserver as a float.
3477
 *   Returns 0 on error.
3478
 */
3479
function get_edit_map_service_version_number() {
3480

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

    
3483
  $settings = get_edit_map_service_settings();
3484
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3485
  if (isset($matches[1])) {
3486
    // Convert string to float.
3487
    $version = 1 + $matches[1][0] - 1;
3488
    return $version;
3489
  }
3490
  else {
3491
    // Report error.
3492
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3493
        array(
3494
          '!version' => $settings['version'],
3495
          'warning')
3496
        )
3497
      );
3498
    return 0;
3499
  }
3500
}
3501

    
3502
/**
3503
 * Returns the array of selected items in a options array
3504
 *
3505
 * @param array $options
3506
 *   An options array as generated by a form element like checkoxes, select ...,
3507
 */
3508
function get_selection($options) {
3509
  $selection = array();
3510
  foreach ($options as $key=>$val) {
3511
    if (!empty($val)) {
3512
      $selection[] = $val;
3513
    }
3514
  }
3515
  return $selection;
3516
}
3517

    
3518

    
3519
/**
3520
 * Implements hook_element_info().
3521
 *
3522
 * Allows modules to declare their own Form API element types and specify their default values.
3523
 *
3524
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3525
 */
3526
function cdm_dataportal_element_info() {
3527
  $type['checkboxes_preferred'] = array(
3528
    '#input' => TRUE,
3529
    '#process' => array('checkboxes_preferred_expand'),
3530
    '#after_build' => array('checkboxes_preferred_after_build'),
3531
    '#theme' => array('checkboxes_preferred'),
3532
    // '#theme_wrapper' => array('form_element'),
3533
  );
3534
  return $type;
3535
}
3536

    
3537
/**
3538
 * #process callback function for the custom form element type 'checkbox_preferred'
3539
 *
3540
 *
3541
 */
3542
function checkboxes_preferred_expand($element, &$form_state, $form) {
3543

    
3544
  // First of all create checkboxes for each of the elements
3545
  $element = form_process_checkboxes($element);
3546

    
3547
  // compose the element name
3548
  $parents = array();
3549
  array_deep_copy($element['#parents'], $parents);
3550
  $parents[count($parents) -1 ] .= '_preferred';
3551
  $element_name = $parents[0];
3552
  for ($i=1; $i < count($parents); $i++){
3553
    $element_name .= '[' . $parents[$i] . ']';
3554
  }
3555

    
3556
  $children = element_children($element);
3557

    
3558
  $element['table_start'] = array(
3559
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3560
    '#weight' => -1,
3561
  );
3562

    
3563
  // prepare first part each of the table rows which contains the row label
3564
  $weight = 0;
3565
  foreach ($children as $key) {
3566
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3567
    $element[$key]['#weight'] = $weight;
3568
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3569
    $element[$key]['#suffix'] = '</td>';
3570
    unset($element[$key]['#title']);
3571
    $weight += 2;
3572
  }
3573
  $weight = 0;
3574

    
3575
  // add a radio button to each of the checkboxes, the
3576
  // check boxes have already been created at the beginning
3577
  // of this function
3578
  if (count($element['#options']) > 0) {
3579
    foreach ($element['#options'] as $key => $choice) {
3580
      if (!isset($element[$key . '_preferred'])) {
3581
        $element[$key . '_preferred'] = array(
3582
          '#type' => 'radio',
3583
          '#name' => $element_name,
3584
          '#return_value' => check_plain($key),
3585
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3586
          '#attributes' => $element['#attributes'],
3587
          '#parents' => $element['#parents'],
3588
          // '#spawned' => TRUE,
3589
          '#weight' => $weight + 1,
3590
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3591
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3592
        );
3593
      }
3594
      $weight += 2;
3595
    }
3596
  }
3597

    
3598
  // end the table
3599
  $element['table_end'] = array(
3600
    '#markup' => '</table>',
3601
    '#weight' => $weight++,
3602
  );
3603

    
3604
  return $element;
3605
}
3606

    
3607
/**
3608
 * Theme function for the custom form field 'checkboxes_preferred'.
3609
 */
3610
function theme_checkboxes_preferred($variables) {
3611
  $element = $variables['element'];
3612
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3613
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3614
  $out .= drupal_render_children($element);
3615
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3616
  $out .= '</div>';
3617
  return $out;
3618
}
3619

    
3620
/**
3621
 * Callback for checkboxes preferred for widget which will
3622
 * be called after the form or element is built. The call
3623
 * back is configured in the form element by setting it as
3624
 * #after_build parameter.
3625
 *
3626
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3627
 *
3628
 * @param $element
3629
 *   Nested array of form elements that comprise the form.
3630
 * @param $form_state
3631
 *   A keyed array containing the current state of the form.
3632
 *   This includes the current persistent storage data for the form.
3633
 *   Additional information, like the sanitized $_POST data,
3634
 *   is also accumulated here in $form_state['input']
3635
 *
3636
 * @return the modified form array
3637
 */
3638
function checkboxes_preferred_after_build($element, &$form_state) {
3639

    
3640
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3641

    
3642
  if ($_POST && count($_POST) > 0) {
3643
    // TODO use  $form_state['input'] instead of POST !!!
3644
    // First pass of form processing.
3645
    $parents = array();
3646
    array_deep_copy($element['#parents'], $parents);
3647
    $parents[count($parents) - 1] .= '_preferred';
3648
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3649
    $element['#value']['PREFERRED'] = $preferred_layer;
3650
//     $form_state[$parent_id] = $element['#value'];
3651
//     $form_state['values']['baselayers'] = $element['#value'];
3652
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3653
    $form_state_element_values = $element['#value'];
3654
  }
3655
  else {
3656
    // Second pass of form processing.
3657
    $preferred_layer = $element['#value']['PREFERRED'];
3658
  }
3659

    
3660
  // Also set the chosen value (not sure if this is good Drupal style ....).
3661
  foreach ($children = element_children($element) as $key) {
3662
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3663
      $element[$key]['#value'] = $preferred_layer;
3664
    }
3665
  }
3666
  // The default layer must always be enabled.
3667
  $element[$preferred_layer]['#value'] = $preferred_layer;
3668

    
3669
  return $element;
3670
}
3671

    
3672
function radios_prepare_options_suffix(&$elements){
3673

    
3674
  $childrenKeys = element_children($elements);
3675
  foreach($childrenKeys as $key){
3676
    if(!is_array($elements[$key]['#theme_wrappers'])){
3677
      $elements[$key]['#theme_wrappers'] = array();
3678
    }
3679
    if(isset($elements['#options_suffixes'][$key])){
3680
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3681
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3682
    }
3683
  }
3684
  return $elements;
3685

    
3686
}
3687

    
3688
/**
3689
 * TODO
3690
 * @param unknown $variables
3691
 */
3692
function theme_radio_options_suffix($variables) {
3693
  $element = $variables['element'];
3694
  if(isset($element['#options_suffix'])) {
3695
    $element['#children'] .= $element['#options_suffix'];
3696
  }
3697
  return $element['#children'];
3698
}
3699

    
3700

    
3701
/**
3702
 * Element validate callback for text field and arrays containing json.
3703
 *
3704
 * @param $element
3705
 *   The form element to validate
3706
 * @param $form_state
3707
 *   A keyed array containing the current state of the form.
3708
 * @param $form
3709
 *   Nested array of form elements that comprise the form.
3710
 */
3711
function form_element_validate_json($element, &$form_state, $form) {
3712
   if (!empty($element['#value'])) {
3713
     json_decode($element['#value']);
3714
     if(json_last_error() != JSON_ERROR_NONE){
3715
       form_error($element,
3716
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3717
         . l('JSONLint', 'http://jsonlint.com/')
3718
       );
3719
     }
3720
   }
3721
}
3722

    
3723
/**
3724
 * Form submission handler for textareas and textfields containing JSON.
3725
 *
3726
 * The contained JSON will be converted into an php array
3727
 * or object and will be stored in the variables as such.
3728
 *
3729
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3730
 *
3731
 * @param $form
3732
 *   Nested array of form elements that comprise the form.
3733
 * @param $form_state
3734
 *   A keyed array containing the current state of the form.
3735
 *
3736
 */
3737
function submit_json_as_php_array($form, &$form_state) {
3738
  if (is_array($form['#json_elements'])) {
3739
    foreach ($form['#json_elements'] as $element){
3740
      if (trim($form_state['values'][$element])) {
3741
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3742
      } else {
3743
        $form_state['values'][$element] = NULL;
3744
      }
3745
    }
3746
  }
3747
}
(18-18/18)