Project

General

Profile

Download (150 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

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

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

    
102

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

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

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

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

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

    
143

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

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

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

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

    
172
}
173

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

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

    
339
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
340
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
341
    // to unset a default enntry set the value to 0
342
    array(
343
      'doTaxa'=>'doTaxa',
344
      'doSynonyms' => 'doSynonyms',
345
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
346
      'doMisappliedNames' => 'doMisappliedNames'
347
    )
348
  )
349
);
350

    
351
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
352

    
353
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
354
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
355

    
356
/* Gallery variables. */
357
$gallery_settings = array(
358
    "cdm_dataportal_show_taxon_thumbnails" => 1,
359
    "cdm_dataportal_show_synonym_thumbnails" => 0,
360
    "cdm_dataportal_show_thumbnail_captions" => 1,
361
    "cdm_dataportal_media_maxextend" => 120,
362
    "cdm_dataportal_media_cols" => 3,
363
    "cdm_dataportal_media_maxRows" => 1,
364
);
365

    
366
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
367
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
368
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
369
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
370
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
371
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
372
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
373
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
374
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
375
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
376
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
377
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
378

    
379
/**
380
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
381
 * the snonymy.
382
 *
383
 * @var string
384
 */
385
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
386

    
387
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
388
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
389
    array(
390
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
391
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
392
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
393
    )
394
  )
395
);
396

    
397
/**
398
 * The drupal variable for the configuration of the information aggregation along
399
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
400
 *    - direct: the uuids of the taxon relationship types to take into account in invers
401
 *      direction.
402
 *    - invers: the uuids of the taxon relationship types to take into account in direct
403
 *      direction.
404
 *
405
 * @var String
406
 */
407
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
408
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
409
    array(
410
        'direct'=>array(),
411
        'invers'=>array()
412
     )
413
   ));
414
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
415
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
416
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
417

    
418
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
419
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
420
      array(
421
      'filter_rules' => array(
422
        'statusOrderPreference' => 0,
423
        'subAreaPreference' => 0,
424
      ),
425
      'hiddenAreaMarkerType' => array()
426
     )
427
));
428

    
429
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
430
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
431
  "level_0" => array(
432
    'label_suffix' => ':',
433
    'status_glue' => '',
434
    'item_glue' => ' ',
435
    'item_group_prefix' => '',
436
    'item_group_postfix' => ''
437
  ),
438
  "level_1" => array(
439
    'label_suffix' => '',
440
    'status_glue' => '‒ ', // '&#8210; '
441
    'item_glue' => '; ',
442
    'item_group_prefix' => ', ',
443
    'item_group_postfix' => ''
444
  ),
445
  "level_2" => array(
446
    'label_suffix' => '',
447
    'status_glue' => '‒ ', // '&#8210; '
448
    'item_glue' => ', ',
449
    'item_group_prefix' => ' (',
450
    'item_group_postfix' => ')'
451
  )
452
)));
453

    
454
/**
455
 * Constant for the drupal variable key distribution_map_visibility
456
 *
457
 * possible values:
458
 *  - never
459
 *  - automatic
460
 *  - always
461
 */
462
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
463
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
464

    
465
/**
466
 * Constant for the drupal variable key specimen_map_visibility
467
 *
468
 * possible values:
469
 *  - never
470
 *  - automatic
471
 *  - always
472
 */
473
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
474
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
475

    
476
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
477
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
478
    array(
479
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
480
        'includeOccurrences' => 0,
481
        'includeTaxonNameDescriptions' => 0
482
     )
483
  ));
484

    
485
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
486
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
487
  // needs to be merged with user setting by drupal_array_merge_deep()
488
  // 'width' => 512, // optimum size for OSM layers is 512
489
  // 'height' => 512 / 2, // optimum size for OSM layers 256
490
  'aspect_ratio' => 2,
491
  'bbox' => '', // empty to allow automatic zooming to extend
492
  'show_labels' => FALSE,
493
  'caption' => '',
494
  'distribution_opacity' => '0.5',
495
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
496
  'image_map' => array(
497
    'base_layer' => '', // none, formerly this was cyprusdivs
498
    'bg_color' => '1874CD',
499
    'layer_style' => 'ffffff,606060,,',
500
  ),
501
  'openlayers' => array(
502
    'base_layers' =>  array(
503
      // A layer MUST NOT BE SET in the defaults,
504
      // otherwise it can not be overidden by the user settings:
505
      // 'mapproxy_vmap0' => 'mapproxy_vmap0',
506
      // it is sufficient to define the preferred layer,
507
      // since it will automatically be enabled:
508
      'PREFERRED' => 'mapproxy_vmap0'),
509
    'custom_wms_base_layer' => array(
510
      'name' => NULL,
511
      'url' => NULL,
512
      'params' =>  NULL,
513
      'projection' => NULL,
514
      'proj4js_def' => NULL,
515
      'max_extent' => NULL,
516
      'units' => NULL
517
    ),
518
    'show_layer_switcher' => TRUE,
519
    'display_outside_max_extent' => FALSE,
520
    'google_maps_api_key' => NULL,
521
  ),
522
  'legend' => array(
523
    'show' => TRUE,
524
    'opacity' => '0.5',
525
    'font_size' => 10,
526
    'font_style' => FALSE,
527
    'icon_width' => 35,
528
    'icon_height' => 15
529
  )
530
)));
531

    
532
/**
533
 * Merges the named array variable with the array of defaults.
534
 *
535
 * IMPORTANT: The array keys must be strings. When the keys are integers
536
 * the merging will not take place for these entities. Number keyed entities
537
 * are just appended to the result array.
538
 *
539
 * @param string $variable_name
540
 *     The variable name
541
 * @param string | array $default
542
 *     The array containing the default values either as array or serialized as string.
543
 *     Unserialization is cared for if necessary
544
 * @return array
545
 *     The merged array as returned by drupal_array_merge_deep()
546
 *
547
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
548
 * TODO force $default being an array
549
 */
550
function get_array_variable_merged($variable_name, $default){
551

    
552
    // unserialize if nessecary
553
    if(!is_array($default)){
554
      $default = unserialize($default);
555
    }
556
    $variable = variable_get($variable_name, array());
557
    $result = drupal_array_merge_deep($default, $variable);
558
    return $result;
559
}
560

    
561
/**
562
 * @todo document this function.
563
 */
564
function getGallerySettings($gallery_config_form_name) {
565
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
566
}
567

    
568
/**
569
 * Returns the string representation of the default tab.
570
 *
571
 * @param bool $returnTabIndex
572
 *   Defaults to FALSE, if set true this function will return the index number
573
 *   of the default tab. (used to supply default values to form elements).
574
 */
575
function get_default_taxon_tab($returnTabIndex = FALSE) {
576

    
577
  global $user;
578
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
579
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
580
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
581
  // Get the user value if the used has chosen to overwrite the system settings.
582
  $user_tab_on = variable_get($user_tab_active, FALSE);
583
  if ($user_tab_on) {
584
    $user_value = variable_get($user_tab, 0);
585
    $index_value = $user_value;
586
    // Get the system value.
587
  }
588
  else {
589
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
590
    $index_value = $system_value;
591
  }
592

    
593
  // Return the index value or the string representation.
594
  if ($returnTabIndex) {
595
    return $index_value;
596
  }
597
  else {
598
    return ($values[$index_value]);
599
  }
600
}
601

    
602

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

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

    
674
    // ---- DEFAULTS settings
675

    
676
    // only needed as final option, when the settings are not having a default
677
    $default = array(
678
      'DEFAULT' => array(
679
        'as_list' => 'div',
680
        'link_to_reference' => 0,
681
        'link_to_name_used_in_source' => 1,
682
        'sources_as_content' => 0,
683
        'sources_as_content_to_bibliography' => 0,
684
        'sort_elements' => NO_SORT,
685
        'glue' => '',
686
        'element_tag' => NULL
687
      ),
688
      // settings for pseudo feature bibliography
689
      // only hard coded here
690
      'BIBLIOGRAPHY' => array(
691
        'as_list' => 'div',
692
        'link_to_reference' => 0,
693
        'link_to_name_used_in_source' => 1,
694
        'sources_as_content' => 0,
695
        'sources_as_content_to_bibliography' => 0,
696
        'sort_elements' => NO_SORT,
697
        'glue' => '',
698
        'element_tag' => NULL
699
      )
700
    );
701

    
702
    // will be used as preset in the settings
703
    $other_themes_default = array(
704
      'DEFAULT' => array(
705
        'as_list' => 'div',
706
        'link_to_reference' => 0,
707
        'link_to_name_used_in_source' => 1,
708
        'sources_as_content' => 0,
709
        'sources_as_content_to_bibliography' => 0,
710
        'sort_elements' => NO_SORT,
711
        'glue' => '',
712
        'element_tag' => NULL
713
      ),
714
      UUID_CITATION => array(
715
        'as_list' => 'div',
716
        'link_to_reference' => 0,
717
        'link_to_name_used_in_source' => 0,
718
        'sources_as_content' => 1,
719
        'sources_as_content_to_bibliography' => 0,
720
        'sort_elements' => SORT_ASC,
721
        'glue' => '',
722
        'element_tag' => 'div'
723
      ),
724
      UUID_DISTRIBUTION => array(
725
        'as_list' => 'div', // currently ignored
726
        'link_to_reference' => 0,
727
        'link_to_name_used_in_source' => 0,
728
        'sources_as_content' => 0,
729
        'sources_as_content_to_bibliography' => 0,
730
        'sort_elements' => NO_SORT, // will cause ...
731
        'glue' => '',
732
        'element_tag' => 'div',
733
        'special' => array()
734
      ),
735
      UUID_COMMON_NAME => array(
736
        'as_list' => 'div',
737
        'link_to_reference' => 0,
738
        'link_to_name_used_in_source' => 1,
739
        'sources_as_content' => 0,
740
        'sources_as_content_to_bibliography' => 0,
741
        'sort_elements' => NO_SORT,
742
        'glue' => '',
743
        'element_tag' => 'span'
744
      ),
745
    );
746

    
747
    // ---- Special DEFAULTS for existing portals
748
    // TODO:
749
    // this can be removed once the feature block
750
    // settings have been deployed for the first time to these portals
751

    
752
    $cichorieae_default = array(
753
      'DEFAULT' => array(
754
        'as_list' => 'div',
755
        'link_to_reference' => 1,
756
        'link_to_name_used_in_source' => 1,
757
        'sources_as_content' => 1,
758
        'sources_as_content_to_bibliography' => 0,
759
        'sort_elements' => NO_SORT,
760
        'glue' => '',
761
        'element_tag' => 'div'
762
      ),
763
      UUID_CITATION => array(
764
        'as_list' => 'div',
765
        'link_to_reference' => 0,
766
        'link_to_name_used_in_source' => 0,
767
        'sources_as_content' => 1,
768
        'sources_as_content_to_bibliography' => 0,
769
        'sort_elements' => SORT_ASC,
770
        'glue' => '',
771
        'element_tag' => 'div'
772
      ),
773
      UUID_CHROMOSOMES_NUMBERS => array(
774
        'as_list' => 'ul',
775
        'link_to_reference' => 1,
776
        'link_to_name_used_in_source' => 1,
777
        'sources_as_content' => 1,
778
        'sources_as_content_to_bibliography' => 0,
779
        'sort_elements' => NO_SORT,
780
        'glue' => '',
781
        'element_tag' => 'div'
782
      ),
783
      UUID_CHROMOSOMES => array(
784
        'as_list' => 'ul',
785
        'link_to_reference' => 0,
786
        'link_to_name_used_in_source' => 1,
787
        'sources_as_content' => 1,
788
        'sources_as_content_to_bibliography' => 0,
789
        'sort_elements' => NO_SORT,
790
        'glue' => '',
791
        'element_tag' => 'div'
792
      ),
793
      UUID_COMMON_NAME => array(
794
        'as_list' => 'div',
795
        'link_to_reference' => 0,
796
        'link_to_name_used_in_source' => 1,
797
        'sources_as_content' => 0,
798
        'sources_as_content_to_bibliography' => 0,
799
        'sort_elements' => NO_SORT,
800
        'glue' => '',
801
        'element_tag' => 'span'
802
      ),
803
    );
804

    
805
    $palmweb_default = array(
806
      'DEFAULT' => array(
807
        'as_list' => 'ul',
808
        'link_to_reference' => 1,
809
        'link_to_name_used_in_source' => 1,
810
        'sources_as_content' => 1,
811
        'sources_as_content_to_bibliography' => 1,
812
        'sort_elements' => NO_SORT,
813
        'glue' => '',
814
        'element_tag' => NULL
815
      ),
816
      UUID_CITATION => array(
817
        'as_list' => 'ul',
818
        'link_to_reference' => 1,
819
        'link_to_name_used_in_source' => 1,
820
        'sources_as_content' => 0,
821
        'sources_as_content_to_bibliography' => 1,
822
        'sort_elements' => SORT_ASC,
823
        'glue' => '',
824
        'element_tag' => 'div'
825
      ),
826
      UUID_DISTRIBUTION => array(
827
        'as_list' => 'div', // currently ignored
828
        'link_to_reference' => 1,
829
        'link_to_name_used_in_source' => 1,
830
        'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
831
        'sources_as_content_to_bibliography' => 1,
832
        'sort_elements' => NO_SORT, // will cause ...
833
        'glue' => ', ',
834
        'element_tag' => 'span',
835
        'special' => array()
836
      ),
837
    );
838

    
839
    $cyprus_default = $cichorieae_default;
840
    $cyprus_default[UUID_DISTRIBUTION] = array(
841
      'as_list' => 'div', // currently ignored
842
      'link_to_reference' => 0,
843
      'link_to_name_used_in_source' => 0,
844
      'sources_as_content' => 0,
845
      'sources_as_content_to_bibliography' => 0,
846
      'sort_elements' => NO_SORT, // will cause ...
847
      'glue' => ' ',
848
      'element_tag' => 'div',
849
      'special' => array()
850
    );
851

    
852
    $default_theme = variable_get('theme_default', NULL);
853

    
854
    switch ($default_theme) {
855
      case 'garland_cichorieae':
856
        $settings_for_theme = $cichorieae_default;
857
        break;
858
      case 'cyprus':
859
        // cyprus: no longer used in production,
860
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
861
        $settings_for_theme = $cyprus_default;
862
        break;
863
      case 'flore_afrique_centrale':
864
      case 'flora_malesiana':
865
      case 'flore_gabon':
866
        $settings_for_theme = $cichorieae_default;
867
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
868
        break;
869
      case 'palmweb_2':
870
        $settings_for_theme = $palmweb_default;
871
        break;
872
      default:
873
        $settings_for_theme = $other_themes_default;
874
    }
875
    // add pseudo feature settings
876
    $settings_for_theme['BIBLIOGRAPHY'] = $default['BIBLIOGRAPHY'];
877

    
878
    // ---- END of DEFAULTS
879

    
880
    $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
881

    
882
    $feature_block_setting = null;
883

    
884
    if (isset($saved_settings[$feature_uuid])) {
885
      $feature_block_setting = $saved_settings[$feature_uuid];
886
    }
887
    else if (isset($settings_for_theme[$feature_uuid])) {
888
      $feature_block_setting = $settings_for_theme[$feature_uuid];
889
    }
890
    else if (isset($settings_for_theme['DEFAULT'])) {
891
      $feature_block_setting = $settings_for_theme['DEFAULT'];
892
    }
893

    
894
    // now merge the default and specific settings
895
    $settings_to_merge = array($default['DEFAULT']);
896
    if(is_array($saved_settings)){
897
      $settings_to_merge[] = $saved_settings['DEFAULT'];
898
    }
899
    if(isset($feature_block_setting)){
900
      $settings_to_merge[] = $feature_block_setting;
901
    }
902
    $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
903

    
904
    return $feature_block_setting;
905
}
906

    
907
/**
908
 * returns the current setting for the original source bibliography
909
 *
910
 * Caches internally
911
 *
912
 * @return array
913
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
914
 *   - 'enabled': 1|0
915
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
916
 */
917
function get_bibliography_settings($clear_cache = false){
918
  static $bibliography_settings = null;
919
  if(!$bibliography_settings || $clear_cache){
920
    $bibliography_settings = get_array_variable_merged(
921
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
922
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
923
    );
924
  }
925
  return $bibliography_settings;
926
}
927

    
928
/**
929
 * @todo Please document this function.
930
 * @see http://drupal.org/node/1354
931
 */
932
function cdm_dataportal_menu_admin(&$items) {
933
  // Display section on admin/config page.
934
  $items['admin/config/cdm_dataportal'] = array(
935
    'title' => 'CDM Dataportal',
936
    'description' => 'Settings for the CDM DataPortal.',
937
    'position' => 'right',
938
    'weight' => 10,
939
    'page callback' => 'system_admin_menu_block_page',
940
    'access arguments' => array('administer cdm_dataportal'),
941
    'file' => 'system.admin.inc',
942
    'file path' => drupal_get_path('module', 'system'),
943
  );
944
  $items['admin/config/cdm_dataportal/settings'] = array(
945
    'title' => 'Settings',
946
    'description' => 'Settings for the CDM DataPortal.',
947
    'weight' => 0,
948
    'page callback' => 'drupal_get_form',
949
    'page arguments' => array('cdm_settings_general'),
950
    'access arguments' => array('administer cdm_dataportal'),
951
    'type' => MENU_NORMAL_ITEM,
952
  );
953
  $items['admin/config/cdm_dataportal/settings/general'] = array(
954
    'title' => 'General',
955
    'description' => 'General',
956
    'weight' => 0,
957
    'page callback' => 'drupal_get_form',
958
    'page arguments' => array('cdm_settings_general'),
959
    'access arguments' => array('administer cdm_dataportal'),
960
    'type' => MENU_DEFAULT_LOCAL_TASK,
961
  );
962

    
963
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
964
    'title' => 'Cache',
965
    'description' => 'Cache',
966
    'access arguments' => array('administer cdm_dataportal'),
967
    'page callback' => 'drupal_get_form',
968
    'page arguments' => array('cdm_settings_cache'),
969
    'weight' => 10,
970
    'type' => MENU_LOCAL_TASK,
971
  );
972

    
973
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
974
    'title' => 'Geo & Map',
975
    'description' => 'Geo & Map',
976
    'access arguments' => array('administer cdm_dataportal'),
977
    'page callback' => 'drupal_get_form',
978
    'page arguments' => array('cdm_settings_geo'),
979
    'weight' => 1,
980
    'type' => MENU_LOCAL_TASK,
981
  );
982

    
983
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
984
    'title' => 'Layout',
985
    'description' => 'Configure and adjust the layout of your DataPortal ',
986
    'access arguments' => array('administer cdm_dataportal'),
987
    'page callback' => 'drupal_get_form',
988
    'page arguments' => array('cdm_settings_layout'),
989
    'weight' => 2,
990
    'type' => MENU_LOCAL_TASK,
991
  );
992

    
993
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
994
    'title' => 'Taxon',
995
    'description' => 'Configure and adjust the layout of your DataPortal ',
996
    'access arguments' => array('administer cdm_dataportal'),
997
    'page callback' => 'drupal_get_form',
998
    'page arguments' => array('cdm_settings_layout_taxon'),
999
    'weight' => 1,
1000
    'type' => MENU_LOCAL_TASK,
1001
  );
1002
  /*
1003
  $items[] = array(
1004
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
1005
  'title' => t('Synonymy'),
1006
  'description' => t('Configure and adjust the layout of your DataPortal '),
1007
  'access' => user_access('administer cdm_dataportal'),
1008
  'callback' => 'drupal_get_form',
1009
  'callback arguments' => array('cdm_settings_layout_synonymy'),
1010
  'weight' => 1,
1011
  'type' => MENU_LOCAL_TASK,
1012
  );
1013

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

    
1035
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1036
    'title' => 'Media',
1037
    'description' => 'Configure and adjust the layout of your DataPortal ',
1038
    'access arguments' => array('administer cdm_dataportal'),
1039
    'page callback' => 'drupal_get_form',
1040
    'page arguments' => array('cdm_settings_layout_media'),
1041
    'weight' => 3,
1042
    'type' => MENU_LOCAL_TASK,
1043
  );
1044

    
1045
}
1046

    
1047
/**
1048
 * @todo document this function.
1049
 */
1050
function cdm_help_general_cache() {
1051
  $form = array();
1052
  $form['cache_help'] = array(
1053
    '#type' => 'fieldset',
1054
    '#title' => t('Help'),
1055
    '#collapsible' => TRUE,
1056
    '#collapsed' => TRUE,
1057
  );
1058
  $form['cache_help']['test'] = array('#value' => t('probando'));
1059
  return drupal_render($form);
1060
  $res = array();
1061
  $res['default'] = drupal_render($help);
1062
  return $res;
1063
}
1064

    
1065
/**
1066
 * Configures the settings form for the CDM-API module.
1067
 *
1068
 * @return array
1069
 *   Drupal settings form.
1070
 */
1071
function cdm_settings_general() {
1072

    
1073
  $form['cdm_webservice'] = array(
1074
    '#type' => 'fieldset',
1075
    '#title' => t('CDM Server'),
1076
    '#collapsible' => FALSE,
1077
    '#collapsed' => FALSE,
1078
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1079
        CDM data base to the web via RESTful web services and thus is the source of the data
1080
        to be displayed by a CDM DataPotal.'),
1081
  );
1082

    
1083
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1084
    '#type' => 'textfield',
1085
    '#title' => t('CDM web service URL') . ':',
1086
    '#description' => t('This is the URL to the CDM-Server exposing your data
1087
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1088
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1089
  );
1090

    
1091
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1092
    '#type' => 'markup',
1093
    '#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')
1094
      . ' visible only for administrators',
1095
  );
1096

    
1097
  $form['cdm_webservice']['freetext_index'] = array(
1098
    '#type' => 'fieldset',
1099
    '#title' => t('Freetext index'),
1100
    '#collapsible' => FALSE,
1101
    '#collapsed' => FALSE,
1102
  );
1103

    
1104
  // Check the cdmserver port number and display a waring if it is not port 80
1105
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1106
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1107
    $form['cdm_webservice']['freetext_index']['message'] = array(
1108
      '#markup' => "<div class=\"description\">"
1109
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1110
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1111
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1112
          array('!port' => $portNumberMatch[1][0])
1113
        )
1114
      . "</div>",
1115
    );
1116
  };
1117

    
1118
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1119
  $trigger_link_options = array(
1120
    'attributes' => array(
1121
      'class' => 'index-trigger'
1122
    ),
1123
  );
1124
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1125
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1126
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1127
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1128
      ))
1129
    . '<div id="index-progress"></div></div>',
1130
  );
1131

    
1132
  $form['cdm_webservice']['freetext_index']['cdm_login'] = array(
1133
    // this must not be stored, it is only used by the _add_js_cdm_ws_progressbar
1134
    '#type' => 'textfield',
1135
    '#title' => t('Login'),
1136
    '#description' => t('Your cdm user credentials in the following form: <code>user:password</code>')
1137
  );
1138
  drupal_add_js('
1139
        jQuery(document).ready(function() {
1140
             jQuery("#edit-cdm-login").change(function (e) {
1141
                var login = jQuery(e.target).val();
1142
                jQuery("#edit-freetext-index .index-trigger").each(function(index){
1143
                   var url = jQuery(this).attr("href");
1144
                   url = url.replace(/:\/\/[^@]+@|:\/\//, "://" + login + "@");
1145
                   jQuery(this).attr("href", url);
1146
                });
1147
            });
1148
        });
1149
      ',
1150
    array(
1151
      'type' => 'inline',
1152
      'scope' => 'footer'
1153
    )
1154
  );
1155
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1156

    
1157
    $form['cdm_webservice']['freetext_index']['cdm_dataportal_taxon_auto_suggest'] = array(
1158
        '#type' => 'checkbox',
1159
        '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
1160
        '#default_value' => variable_get('cdm_dataportal_taxon_auto_suggest', CDM_DATAPORTAL_TAXON_AUTO_SUGGEST),
1161
        '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
1162
        This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
1163
    );
1164

    
1165
  $form['cdm_webservice']['proxy'] = array(
1166
    '#type' => 'fieldset',
1167
    '#title' => t('Proxy'),
1168
    '#collapsible' => TRUE,
1169
    '#collapsed' => TRUE,
1170
  );
1171

    
1172
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1173
    '#type' => 'textfield',
1174
    '#title' => t('Proxy URL') . ':',
1175
    '#description' => t('If this proxy url is set the cdm api tries
1176
    to connect the web service over the given proxy server.
1177
    Otherwise proxy usage is deactivated.'),
1178
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1179
  );
1180

    
1181
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1182
    '#type' => 'textfield',
1183
    '#title' => t('Proxy port') . ':',
1184
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1185
  );
1186

    
1187
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1188
    '#type' => 'textfield',
1189
    '#title' => t('Login') . ':',
1190
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1191
  );
1192

    
1193
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1194
    '#type' => 'textfield',
1195
    '#title' => t('Password') . ':',
1196
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1197
  );
1198

    
1199
  // TODO: settings are still incomplete, compare with
1200
  // trunk/dataportal/inc/config_default.php.inc.
1201
  $form['taxon_tree'] = array(
1202
    '#type' => 'fieldset',
1203
    '#title' => t('Taxon Tree'),
1204
    '#collapsible' => FALSE,
1205
    '#collapsed' => TRUE,
1206
    '#description' => t('<p>When you explore your collection, you can navigate
1207
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1208
      able to navigate through your collection the
1209
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1210
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1211
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1212
      </a></p>'),
1213
  );
1214

    
1215
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1216
    '#type' => 'select',
1217
    '#title' => t('Available classifications') . ':',
1218
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1219
    '#options' => cdm_get_taxontrees_as_options(),
1220
    '#description' => t('Select the default taxa classification for your
1221
      <em>taxon tree</em>, the other classifications will be also available but
1222
      with a manual user change.'),
1223
  );
1224

    
1225
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1226
    '#type' => 'select',
1227
    '#title' => t('Rank of highest displayed taxon') . ':',
1228
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1229
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1230
    '#options' => cdm_rankVocabulary_as_option(),
1231
    '#description' => t('This is the rank of the highest displayed taxon in the
1232
      <em>taxon tree</em>. You can select here which rank should be at the top
1233
      level of the tree structure.'),
1234
  );
1235

    
1236
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1237
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1238
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1239
      '#type' => 'checkboxes',
1240
      '#title' => t('Included Classifications') . ':',
1241
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1242
      '#options' => cdm_get_taxontrees_as_options(),
1243
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1244
  );
1245

    
1246
  $form['distribution'] = array(
1247
      '#type' => 'fieldset',
1248
      '#title' => t('Distributions'),
1249
      '#collapsible' => FALSE,
1250
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1251
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1252
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1253
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1254
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1255
          '<p>
1256
          </p>',
1257
  );
1258

    
1259
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1260
      '#type' => 'fieldset',
1261
      '#title' => 'Distribution filter',
1262
      '#collapsible' => FALSE,
1263
      '#collapsed' => FALSE,
1264
      '#tree' => TRUE,
1265
      '#description' => 'The Distribution filter offers the following options
1266
      <ul>
1267
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1268
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1269
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1270
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1271
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1272
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1273
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1274
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1275
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1276
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1277
      </ul>'
1278
  );
1279

    
1280
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1281
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1282
      '#type' => 'checkboxes',
1283
      '#title' => 'Filter rules',
1284
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1285
      '#options' => array(
1286
          'statusOrderPreference' => 'Status order preference rule',
1287
          'subAreaPreference' => 'Sub area preference rule'
1288
      ),
1289
  );
1290

    
1291
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1292
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1293
      '#type' => 'checkboxes',
1294
      '#title' => 'Hide marked area filter',
1295
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1296
      '#options' => $marker_type_options,
1297
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1298
  );
1299

    
1300
  $form['aggregation'] = array(
1301
      '#type' => 'fieldset',
1302
      '#title' => t('Aggregation of data'),
1303
      '#collapsible' => FALSE,
1304
      '#description' => 'This section covers the different aspects of aggregating information.
1305
          <p>
1306
          </p>',
1307
  );
1308

    
1309
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1310
      '#type' => 'checkboxes',
1311
      '#title' => 'Taxon media filter',
1312
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1313
      '#options' => array(
1314
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1315
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1316
          'includeOccurrences' => 'Media related to specimens and occurrences',
1317
      ),
1318
      '#description' => 'This filter configures which images should be taken into account.',
1319
  );
1320

    
1321
  $form['aggregation']['notice'] = array(
1322
      '#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
1323
          want to make use of the caching capabilities of the dataportal.',
1324
  );
1325

    
1326
  $form['aggregation']['media_aggregation'] = array(
1327
      '#type' => 'fieldset',
1328
      '#title' => t('Media aggregation'),
1329
      '#collapsible' => FALSE,
1330
      '#collapsed' => TRUE,
1331
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1332

    
1333
  );
1334
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1335
      '#type' => 'select',
1336
      '#title' => t('Aggregation of taxon pictures') . ':',
1337
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1338
      '#options' => array(
1339
          0 => "Show only pictures of the current taxon",
1340
          1 => "Include pictures of taxonomic children",
1341
      ),
1342
      '#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."),
1343
  );
1344

    
1345
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1346
      '#type' => 'fieldset',
1347
      '#attributes' => array('class' => array('clearfix')),
1348
      '#title' => t('Aggregation via taxon relationsships'),
1349
      '#collapsible' => TRUE,
1350
      '#collapsed' => TRUE,
1351
      '#tree' => TRUE,
1352
      '#description' => t('Information on taxa will be aggregated along the below chosen
1353
          taxon relation ships. This will affect images and occurrences (specimens).
1354
          Taxon relation ships are directed and point form one taxon to another. The taxon
1355
          relationships to be taken into accunt can therefore configured for the direct direction
1356
          and for the inverse.'),
1357
  );
1358

    
1359
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1360
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1361

    
1362
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1363
      '#type' => 'checkboxes',
1364
      '#title' => t('Direct'),
1365
      '#options' => $taxonRelationshipTypeOptions,
1366
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1367
  );
1368
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1369
      '#type' => 'checkboxes',
1370
      '#title' => t('Invers'),
1371
      '#options' => $taxonRelationshipTypeOptions,
1372
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1373
  );
1374

    
1375
  $form['drupal_integration'] = array(
1376
    '#type' => 'fieldset',
1377
    '#attributes' => array('class'=> array('clearfix')),
1378
    '#title' => t('Drupal integration'),
1379
    '#collapsible' => FALSE,
1380
    '#collapsed' => FALSE,
1381
    '#tree' => FALSE
1382
  );
1383

    
1384
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1385
    '#type' => 'checkbox',
1386
    '#title' => 'Create drupal nodes',
1387
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1388
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1389
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1390
    cdm pages it is required that drupal nodes are created and stored in the database.'
1391
  );
1392

    
1393

    
1394

    
1395
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1396
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1397
    <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>',
1398
  );
1399
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1400
    '#type' => 'submit',
1401
    '#value' => t('Drop all cdm nodes'),
1402
    '#submit' => array('drop_all_cdm_nodes_submit')
1403
  );
1404

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

    
1409
    // ----------------------
1410
  $form['cdm_js_devel_mode'] = array(
1411
      '#type' => 'checkbox',
1412
      '#title' => 'Java-script developer mode',
1413
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1414
      '#description' => 'In production envirionments the java script libraries
1415
      the cdm_dataportal is making use of are compressed and optimized. This
1416
      is good for performance but a caveat if you need to debug java-script. When the
1417
      java-script developer mode is enabled the uncompressed and commented developer
1418
      versions of java-script libraries will be used where possible.
1419
      <br/><strong>Do not use this option in production!</strong>'
1420
  );
1421
  // ----------------------
1422
  $form['cdm_debug_mode'] = array(
1423
      '#type' => 'checkbox',
1424
      '#title' => 'CDM page debug mode',
1425
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1426
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1427
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1428
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1429
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1430
      The log is written by the drupal devel module function <code>dd()</code>.
1431
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1432
  );
1433

    
1434
  // Comment @WA: D7 form api does not support reset buttons,
1435
  // so to mimic the D5 reset button we add one like this.
1436
  $form['actions']['reset'] = array(
1437
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1438
    '#weight' => 1000,
1439
  );
1440

    
1441
  $form['#submit'][] = 'cdm_settings_general_submit';
1442

    
1443
  return system_settings_form($form);
1444
}
1445

    
1446
/**
1447
 * Submit callback; drops all cdm nodes.
1448
 *
1449
 * @ingroup forms
1450
 */
1451
function drop_all_cdm_nodes_submit($form, &$form_state) {
1452
  cdm_delete_all_cdm_nodes();
1453
  drupal_set_message(t('All cdm nodes dropped.'));
1454
}
1455

    
1456

    
1457
/**
1458
 * LAYOUT settings
1459
 * @return
1460
 *   todo
1461
 */
1462
function cdm_settings_layout() {
1463

    
1464
  $form = array();
1465

    
1466
  $form['about'] = array(
1467
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1468
      layout. If you want to configure the specific sites layout visit the
1469
      respective configuration site for taxon, search or media.') . '</p>',
1470
  );
1471

    
1472
  // ---- footnotes --- //
1473
  $form['footnotes'] = array(
1474
    '#type' => 'fieldset',
1475
    '#title' => t('Footnotes'),
1476
    '#collapsible' => FALSE,
1477
    '#collapsed' => FALSE,
1478
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1479
      media or distribution areas may have annotations or footnotes. When the
1480
      footnotes are enabled they will be visible (if they exist).'),
1481
  );
1482

    
1483
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1484
    '#type' => 'checkbox',
1485
    '#title' => t('Do not show footnotes'),
1486
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1487
    '#description' => t('Check this if you do not want to show any footnotes'),
1488
  );
1489

    
1490
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1491
    '#type' => 'checkbox',
1492
    '#title' => t('Do not show annotation footnotes'),
1493
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1494
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1495
  );
1496

    
1497
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1498
  // Additional option for the NULL case.
1499
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1500
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1501
    '#type' => 'checkboxes',
1502
    '#title' => t('Annotation types as footnotes'),
1503
    '#description' => t("Only annotations of the selected type will be displayed
1504
       as footnotes. You may want to turn 'technical annotations' off."),
1505
    '#options' => $annotationTypeOptions,
1506
  );
1507
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1508
  if (!empty($annotationsTypesAsFootnotes)) {
1509
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1510
  }
1511

    
1512
  // ---- original source --- //
1513
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1514
      '#type' => 'fieldset',
1515
      '#tree' => TRUE,
1516
      '#title' => t('Source Citations'),
1517
      '#collapsible' => FALSE,
1518
      '#collapsed' => FALSE,
1519
  );
1520

    
1521
  $bibliography_settings = get_bibliography_settings(true);
1522

    
1523
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1524
      '#type' => 'checkbox',
1525
      '#title' => t('Original Source in bibliography'),
1526
      '#default_value' => $bibliography_settings['enabled'],
1527
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1528
       annotations in each feature block.'),
1529
  );
1530

    
1531
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1532
    '#type' => 'select',
1533
    '#title' => t('The format of the key numerals'),
1534
    '#default_value' => $bibliography_settings['key_format'],
1535
    '#options' => array('latin' => 'Latin',
1536
      'ROMAN' => 'Roman (upper case)',
1537
      'roman' => 'Roman (lower case)',
1538
      'ALPHA'=> 'Alphabet (upper case)',
1539
      'alpha' => 'Alphabet (lower case)')
1540
  );
1541

    
1542
  // --- Advanced Search --- //
1543
  $form['asearch'] = array(
1544
      '#type' => 'fieldset',
1545
      '#title' => t('Advanced search'),
1546
      '#collapsible' => FALSE,
1547
      '#collapsed' => FALSE,
1548
  );
1549
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1550
      '#type' => 'checkbox',
1551
      '#title' => t('Show advanced search link'),
1552
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1553
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1554
  );
1555

    
1556
  // ---- Taxon Name Rendering --- //
1557
  $form['taxon_name'] = array(
1558
      '#type' => 'fieldset',
1559
      '#title' => t('Taxon name display'),
1560
      '#collapsible' => TRUE,
1561
      '#collapsed' => TRUE,
1562
      '#description' => t('The display of taxon names is configured by two parts.
1563
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1564
          The name parts are defined in the <stong>part definitions</strong>'),
1565
  );
1566

    
1567
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1568
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1569
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1570
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1571

    
1572
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1573
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1574
    $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.)';
1575
  } else if($is_custom_part_definition){
1576
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1577
  } else  {
1578
    $which_version_message = '(These are the default part definition.)';
1579
  }
1580

    
1581
  $diff_viewer_markup = '';
1582
  if($is_custom_part_definition){
1583
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1584
  }
1585

    
1586
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1587
    . $which_version_message
1588
    . '</div>'
1589
    . $diff_viewer_markup;
1590

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

    
1680
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1681
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1682
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1683
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1684
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1685

    
1686
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1687
    $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.)';
1688
  } else if($is_custom_render_template){
1689
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1690
  } else {
1691
    $which_version_message = '(These are the default render templates.)';
1692
  }
1693

    
1694
  $diff_viewer_markup = '';
1695
  if($is_custom_render_template){
1696
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1697
  }
1698

    
1699
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1700
    . $which_version_message
1701
    . '</div>'
1702
    . $diff_viewer_markup;
1703

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

    
1744
  // @WA: D7 form api does not support reset buttons,
1745
  // so to mimic the D5 reset button we add one like this.
1746
  $form['actions']['reset'] = array(
1747
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1748
    '#weight' => 1000,
1749
  );
1750

    
1751
  $form['#submit'] = array('submit_json_as_php_array');
1752
  // #json_elements especially defined for submit_json_as_php_array()
1753
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1754
  return system_settings_form($form);
1755
}
1756

    
1757

    
1758
/**
1759
 * @param $form_name
1760
 * @param $form_title
1761
 * @param $collapsed
1762
 * @param string $form_description
1763
 *   The description for the fieldset of the gallery setting.
1764
 * @return mixed
1765
 */
1766
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1767
  $form[$form_name] = array(
1768
    '#type' => 'fieldset',
1769
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1770
    '#collapsible' => TRUE,
1771
    '#collapsed' => $collapsed,
1772
    '#tree' => TRUE,
1773
    '#description' => $form_description,
1774
  );
1775

    
1776
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1777
  $gallery_settings = variable_get($form_name, $default_values);
1778
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1779
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1780
    /*
1781
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1782
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1783
    '#type' => 'textfield',
1784
    '#title' => t('Search Page Size'),
1785
    '#default_value' => $test,
1786
    '#description' => t('Number of Names to display per page in search results.')
1787
    );
1788
    */
1789
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1790
      '#type' => 'checkbox',
1791
      '#title' => t('Show media thumbnails for accepted taxa'),
1792
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1793
    );
1794

    
1795
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1796
      '#type' => 'checkbox',
1797
      '#title' => t('Show media thumbnails for synonyms'),
1798
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1799
      '#description' => '',
1800
    );
1801
  }
1802

    
1803
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1804
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1805
    '#type' => 'checkbox',
1806
    '#title' => t('Show captions under thumbnails'),
1807
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1808
    '#description' => '',
1809
  );
1810

    
1811
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1812
    '#type' => 'textfield',
1813
    '#title' => t('Thumbnail size') . ':',
1814
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1815
    '#description' => t('Select the size of each individual thumbnail.'),
1816
  );
1817

    
1818
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1819
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1820
      '#type' => 'textfield',
1821
      '#title' => t('Number of columns') . ':',
1822
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1823
      '#description' => t('Group the thumbnails in columns: select how many
1824
        columns the gallery should display.'),
1825
    );
1826
  }
1827

    
1828
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1829
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1830
      '#type' => 'textfield',
1831
      '#title' => t('Maximum number of rows') . ':',
1832
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1833
      '#description' => t('You can group the thumbnails in rows, select in how
1834
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1835
        If you want an unlimited number of rows please set to 0.'),
1836
    );
1837
  }
1838

    
1839
  return $form;
1840
}
1841

    
1842
/**
1843
 * @todo document this function.
1844
 */
1845
function cdm_settings_layout_taxon() {
1846
  $collapsed = FALSE;
1847
  $form = array();
1848

    
1849
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1850

    
1851
  // --------- TABBED TAXON ------- //
1852
  $form['taxon_tabs'] = array(
1853
    '#type' => 'fieldset',
1854
    '#title' => t('Taxon tabs'),
1855
    '#collapsible' => TRUE,
1856
    '#collapsed' => TRUE,
1857
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1858
      be splitted in four diferent tabs; General, Synonymy, Images and
1859
      Specimens. If the taxon has no information for any of the tabs/sections
1860
      such tab will be not displayed.'),
1861
  );
1862

    
1863
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1864
    '#type' => 'checkbox',
1865
    '#title' => t('Tabbed taxon page'),
1866
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1867
    '#description' => t('<p>If selected split the taxon page into individual
1868
      tabs for description, images, synonymy and specimens. If not the taxon
1869
      data is rendered as a long single page without tabs.</p>'),
1870
  );
1871

    
1872
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1873
    '#type' => 'checkboxes',
1874
    '#title' => t('Tabs visibility options') . ':',
1875
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1876
    '#options' => get_taxon_options_list(),
1877
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1878
  );
1879

    
1880
  // WEIGHT
1881
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1882
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1883
    '#title'  => 'Tabs order',
1884
    '#type' => 'fieldset',
1885
    '#collapsible' => false,
1886
    '#tree' => true,
1887
    '#description' => 'The weight value defines the order of the tabs or of the respective content block on the 
1888
        taxon page when it is the tabless mode.'
1889
  );
1890
  // Weights range from -delta to +delta, so delta should be at least half
1891
  // of the amount of tabs present.
1892
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1893
  foreach (get_taxon_tabs_list() as $label) {
1894
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1895
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1896
        '#title' => $label,
1897
        '#type'  => 'weight',
1898
        '#default_value' => $taxon_tabs_weights[$key],
1899
        '#delta' => $tab_weight_delta
1900
    );
1901
  }
1902

    
1903
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1904
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1905
    '#title'  => 'Tab label override',
1906
    '#type' => 'fieldset',
1907
    '#collapsible' => false,
1908
    '#tree' => true,
1909
    '#description' => 'Setting a label for a tab will override the default label. 
1910
      Please enter the label text in the default language of the portal.'
1911
  );
1912
  foreach (get_taxon_tabs_list() as $label) {
1913
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1914
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1915
      '#title' => $label,
1916
      '#type'  => 'textfield',
1917
      '#default_value' => $taxon_tabs_labels[$key]
1918
    );
1919
  }
1920

    
1921
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1922
    '#type' => 'select',
1923
    '#title' => t('Default tab to display') . ':',
1924
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1925
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1926
    '#description' => t('<p>Select the default tab to display when visiting a
1927
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1928
      <strong>Note:</strong> After performing a search and clicking in any
1929
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1930
      taxon and not the above selected tab.'),
1931
  );
1932

    
1933
  /* ======  TAXON_PROFILE ====== */
1934
  $form['taxon_profile'] = array(
1935
    '#type' => 'fieldset',
1936
    '#title' => t('Taxon profile (tab)'),
1937
    '#description' => t('<p>This section covers the settings related to the taxon
1938
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1939
    '#collapsible' => TRUE,
1940
    '#collapsed' => TRUE,
1941
  );
1942

    
1943
  // ---- PROFILE PICTURE ----//
1944

    
1945
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1946
    '#type' => 'fieldset',
1947
    '#tree' => TRUE,
1948
    '#title' => t('Taxon profile picture'),
1949
    '#collapsible' => TRUE,
1950
    '#collapsed' => FALSE,
1951
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1952
  );
1953

    
1954
  //FIXME migrate variables:
1955
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1956
  // FIXME
1957
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1958

    
1959
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1960

    
1961
  /*
1962
   * 'show' => 1,
1963
   * 'maxextend' => 184,
1964
   * 'media_uri_query' => ''
1965
   * 'custom_placeholder_image_on' => 1,
1966
   * 'custom_placeholder_image_fid' => ''
1967
   */
1968
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1969
    '#type' => 'checkbox',
1970
    '#title' => t('Enable profile picture'),
1971
    '#description' => t('Show the profile picture.'),
1972
    '#default_value' => $taxon_profile_image_settings['show'],
1973
  );
1974

    
1975
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1976
      '#type' => 'textfield',
1977
      '#tree' => TRUE,
1978
      '#title' => t('Profile picture maximum extend'),
1979
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1980
      '#field_suffix' => 'px',
1981
      '#maxlength' => 4,
1982
      '#size' => 4,
1983
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
1984
  );
1985

    
1986
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1987
      '#type' => 'textfield',
1988
      '#tree' => TRUE,
1989
      '#title' => t('Additional URI query parameter'),
1990
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1991
      '#maxlength' => 1024,
1992
      '#size' => 60,
1993
      '#description' => t('Additional query parameters to be used when requesting for the  
1994
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
1995
            The query parameters will be appended to the uri of the media representation part
1996
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1997
  );
1998

    
1999
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2000
    '#type' => 'checkbox',
2001
    '#title' => t('Show the placeholder image'),
2002
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
2003
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2004
  );
2005

    
2006
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2007
      '#type' => 'checkbox',
2008
      '#title' => t('Use a custom placeholder image'),
2009
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2010
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2011
  );
2012

    
2013
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2014
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2015
        '#type' => 'managed_file',
2016
        '#title' => t('Custom placeholder image file'),
2017
        '#progress_indicator' => 'bar',
2018
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2019
    //       '#name' => 'custom_placeholder_image',
2020
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2021
    );
2022

    
2023
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2024
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2025
      $url = file_create_url($profile_image_file->uri);
2026
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2027
                '#type' => 'item',
2028
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2029
      );
2030
    }
2031
  } else {
2032
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2033
      '#type' => 'hidden',
2034
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2035
    );
2036
  }
2037

    
2038
  $options = cdm_rankVocabulary_as_option();
2039
  array_unshift($options, '-- DISABLED --');
2040
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2041
    '#type' => 'select',
2042
    '#title' => t('Hide profile picture for higher ranks') . ':',
2043
    '#default_value' => variable_get('image_hide_rank', '0'),
2044
    '#options' => $options,
2045
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2046
  );
2047

    
2048
  // -- MEDIA THUMBNAILS -- //
2049
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2050
  $form_title = 'Taxon Profile Images';
2051
  $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>';
2052
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2053

    
2054
  // ---- FEATURE TREE BLOCKS ---- //
2055
  $form['taxon_profile']['feature_blocks'] = array(
2056
    '#type' => 'fieldset',
2057
    '#title' => t('Feature Blocks'),
2058
    '#collapsible' => TRUE,
2059
    '#collapsed' => FALSE,
2060
    '#description' => t("This section covers settings related to the taxon's
2061
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2062
      features such as description, distribution, common names"),
2063
  );
2064
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2065
  $profile_feature_tree = get_profile_feature_tree();
2066
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2067
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2068
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2069
  }
2070
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2071
    '#type' => 'radios',
2072
    '#title' => t('Taxon profile feature tree') . ':',
2073
    '#default_value' => $profile_feature_tree_uuid,
2074
    '#options' =>  $featureTrees['options'],
2075
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2076
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2077
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
2078
      profile page.'
2079
    ),
2080
  );
2081

    
2082
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2083
  $profile_feature_tree = get_profile_feature_tree();
2084

    
2085
  if (isset($profile_feature_tree->root->childNodes)) {
2086

    
2087
    $form_feature_block_layout = array(
2088
      '#type' => 'fieldset',
2089
      '#tree' => true,
2090
      '#title' => t('Taxon profile feature block settings'),
2091
      '#collapsible' => TRUE,
2092
      '#collapsed' => FALSE,
2093
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2094
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
2095
      The subforms have the following settings in common:<br />
2096
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2097
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2098
      <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>
2099
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2100
            <ol>
2101
            <li>If the element is a CDM TextData instance and if the text is not empty the source references will be
2102
                appended in brackets like "text (source references)". If the original source has name in source
2103
                information it will be appended to the citation string,
2104
                like : "(citation-A, as name-in-source-A; citation-B, as name-in-source-B)"</li>
2105
             <li>if the text of the TextData is empty, the original source citations are the only content
2106
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2107
                prepended to the citation string like: "name in source: citation"</li>
2108
            </ol>
2109
            <strong>If disabled:</strong><br />
2110
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2111
             citations are the only content, the resulting feature block content would only consist of footnotes.
2112
             In this case the display of the respective feature block is suppressed.</div>
2113
      </dl>
2114
      <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
2115
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2116
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2117
        . '</em></div>
2118
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2119
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2120
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2121
      <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>
2122
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2123
           cdm_feature_block_element_tag_name()</div>',
2124
    );
2125

    
2126

    
2127
    $feature_list_layout_settings_disabled = FALSE;
2128

    
2129
    // creating helper object to retrieve the default settings
2130
    $featureNode = new stdClass();
2131
    $featureNode->feature = new stdClass();
2132
    $featureNode->feature->uuid="DEFAULT";
2133
    $featureNode->feature->representation_L10n = "Default";
2134
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2135

    
2136
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2137

    
2138
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2139

    
2140
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2141
        $subform_id = $featureNode->feature->uuid;
2142
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2143

    
2144
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2145

    
2146
        $form_feature_block_layout[$subform_id] = array(
2147
          '#type' => 'fieldset',
2148
          '#tree' => TRUE,
2149
          '#title' => $featureNode->feature->representation_L10n,
2150
          '#collapsible' => FALSE,
2151
          '#collapsed' => FALSE,
2152
        );
2153
        if($featureNode->feature->uuid == "DEFAULT"){
2154
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2155
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2156
          references</em> and <em>names in source</em> is only possible in the defaults';
2157
        }
2158

    
2159
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2160
          '#type' => 'select',
2161
          '#title' => 'List type',
2162
          '#default_value' => $feature_block_setting['as_list'],
2163
          '#options' => array(
2164
            'div' => 'not as list',
2165
            'ul' => 'bullet list',
2166
            'ol' => 'numbered list',
2167
            'dl' => 'definition list'
2168
          ),
2169
        );
2170

    
2171
        if($featureNode->feature->uuid == "DEFAULT"){
2172
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2173
            '#type' => 'checkbox',
2174
            '#title' => t('Link to reference'),
2175
            '#default_value' => $feature_block_setting['link_to_reference'],
2176
          );
2177

    
2178
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2179
            '#type' => 'checkbox',
2180
            '#title' => 'Link to name used in source',
2181
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2182
          );
2183
        }
2184

    
2185
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2186
          '#type' => 'checkbox',
2187
          '#title' => 'Sources as content',
2188
          '#default_value' => $feature_block_setting['sources_as_content'],
2189
        );
2190

    
2191
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2192
          '#type' => 'checkbox',
2193
          '#title' => 'Put sources also as content to bibliography',
2194
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2195
        );
2196

    
2197
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2198
          '#type' => 'select',
2199
          '#title' => t('Sort elements'),
2200
          '#default_value' => $feature_block_setting['sort_elements'],
2201
          '#options' => array(
2202
            NO_SORT => 'No sorting',
2203
            SORT_ASC => 'Ascending',
2204
            SORT_DESC => 'Descending',
2205
            SORT_HIERARCHICAL => 'Hierarchical'
2206
          ),
2207
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2208
          <dl>
2209
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2210
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2211
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2212
          <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>
2213
          </dl>',
2214
        );
2215

    
2216
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2217
          '#type' => 'select',
2218
          '#title' => t('Element tag'),
2219
          '#options' => array(
2220
            'span' => 'span',
2221
            'div' => 'div',
2222
            'p' => 'p'
2223
          ),
2224
          '#default_value' => $feature_block_setting['element_tag'],
2225
        );
2226
      }
2227
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2228
    }
2229
  }
2230

    
2231
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2232
  $form['taxon_profile']['structured_description_featuretree'] = array(
2233
    '#type' => 'fieldset',
2234
    '#title' => t('Structured Description Feature Tree'),
2235
    '#collapsible' => TRUE,
2236
    '#collapsed' => FALSE,
2237
  );
2238
  $featureTrees = cdm_get_featureTrees_as_options();
2239
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2240
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2241
    $profile_feature_tree_uuid = NULL;
2242
  }
2243
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2244
    '#type' => 'radios',
2245
    '#title' => t('Natural language representation of structured descriptions') . ':',
2246
    '#default_value' => $profile_feature_tree_uuid,
2247
    '#options' => $featureTrees['options'],
2248
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2249
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2250
    '#description' => t('Taxon descriptions can be stored in a highly structured
2251
      form. The feature tree selected here will be used to generate textual
2252
      representation in natural language.'
2253
    ),
2254
  );
2255

    
2256

    
2257

    
2258
  // ---- DISTRIBUTION LAYOUT ---- //
2259
  $form['taxon_profile']['distribution_layout'] = array(
2260
    '#title' => t('Distribution'),
2261
    '#collapsible' => TRUE,
2262
    '#collapsed' => FALSE,
2263
    '#type' => 'fieldset',
2264
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2265
        Map settings regarding the geometry, layers, etc are found in the '
2266
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2267
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2268
      . l(
2269
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2270
        array('fragment' => 'edit-feature-block-settings')
2271
      )
2272
      . ' More general settings regrading the filtering of Distributions are found at '
2273
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2274
      . '. (These settings here will be merged in future releases into the feature block settings)',
2275

    
2276
  );
2277

    
2278
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2279

    
2280
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2281
    '#type' => 'checkbox',
2282
    '#title' => t('Condensed distribution'),
2283
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2284
    '#description' => 'This option enables the display of a very compact representation
2285
    of the distribution which includes also information on the status.',
2286
  );
2287

    
2288
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2289
    '#type' => 'select',
2290
    '#title' => t('Condensed distribution recipe'),
2291
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2292
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2293
    '#description' => 'Recipe for creating the condensed distribution.',
2294
  );
2295

    
2296
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2297
    '#type' => 'textfield',
2298
    '#title' => t('Condensed distribution info path'),
2299
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2300
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2301
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2302
  );
2303

    
2304

    
2305
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2306
    '#type' => 'radios',
2307
    '#title' => t('Display mode') . ':',
2308
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2309
    '#options' => array(
2310
      'FLAT_ALPHA' => t('Flat list'),
2311
      'TREE' => t('Hierarchically ordered'),
2312
    ),
2313
    '#description' => 'Taxon distribution information is displayed with
2314
    focus on the area of the distribution. The list of areas can either be shown
2315
    as flat list ordered alphabetically or in the hierarchical of the parent
2316
    area and subarea relationship. Fall back areas areas with no Distribution data
2317
    are hidden from the area hierarchy so that their sub areas will move one level up.
2318
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2319
    ' for details on the <em>Marked area filter</em>.',
2320
  );
2321

    
2322
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2323
    '#type' => 'fieldset',
2324
    '#tree' => true,
2325
    '#title' => t('Distribution hierarchy style')
2326
  );
2327

    
2328
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2329
  foreach(array_keys($hierarchy_styles) as $level) {
2330
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2331
      '#type' => 'fieldset',
2332
      '#tree' => true,
2333
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2334
      '#attributes' => array('class' => array('fieldset-float'))
2335
    );
2336
    foreach ($hierarchy_styles[$level] as $key => $value) {
2337
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2338
        '#type' => 'textfield',
2339
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2340
        '#default_value' => $hierarchy_styles[$level][$key],
2341
        '#maxlength' => 4,
2342
        '#size' => 4
2343
      );
2344
    }
2345
  }
2346

    
2347
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2348
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2349
    '#type' => 'checkboxes',
2350
    '#title' => 'Omit area levels',
2351
    '#options' => $level_options,
2352
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2353
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2354
    Areas which belong to the selected area levels will be hidden in the portal.',
2355
  );
2356

    
2357
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2358
    '#type' => 'checkbox',
2359
    '#title' => t('Show TextData elements on top of the map'),
2360
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2361
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2362
      elements on top of the map. Otherwise all <code>TextData</code>
2363
      distribution elements will be listed below the other area elements.
2364
      This option is useful if you need to have descriptive texts for each
2365
      distribution map.'),
2366
  );
2367

    
2368
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2369
      '#type' => 'textarea',
2370
      '#title' => t('Custom status colors'),
2371
      '#element_validate' => array('form_element_validate_json'),
2372
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2373
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2374
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2375
          reference list of the idInVocabulary values of absence and presence terms:
2376
<pre>
2377
Presence Term
2378
p	present
2379
pd	present: doubtfully present
2380
n	native
2381
nq	native: presence questionable
2382
nd	native: doubtfully native
2383
c	cultivated
2384
i	introduced
2385
iq	introduced: presence questionable
2386
id	introduced: doubtfully introduced (perhaps cultivated only)
2387
ip	introduced: uncertain degree of naturalisation
2388
ia	introduced: adventitious (casual)
2389
in	introduced: naturalized
2390
ic	introduced: cultivated
2391
e	endemic for the relevant area
2392
na	naturalised
2393
iv	invasive
2394

    
2395
AbsenceTerm
2396
a	absent
2397
f	reported in error
2398
nf	native: reported in error
2399
if	introduced: reported in error
2400
cf	cultivated: reported in error
2401
ne	native: formerly native
2402
ie	introduced: formerly introduced
2403

    
2404
</pre>'),
2405
  );
2406

    
2407

    
2408
  /* ====== SYNONYMY ====== */
2409
  $form['taxon_synonymy'] = array(
2410
    '#type' => 'fieldset',
2411
    '#title' => t('Taxon synonymy (tab)'),
2412
    '#collapsible' => TRUE,
2413
    '#collapsed' => TRUE,
2414
    '#description' => t('This section covers the settings related to the taxon
2415
      <strong>synonymy</strong> tab.'),
2416
  );
2417

    
2418
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2419
    '#type' => 'checkbox',
2420
    '#title' => t('Show accepted taxon on top of the synonymy'),
2421
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2422
    '#description' => t('If checked, the first homotypic taxon is a repetition
2423
      of the accepted taxon most likely with the full nomenclatural reference
2424
      (depending on the currently chosen theme).'),
2425
  );
2426

    
2427
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2428
    '#type' => 'checkbox',
2429
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2430
      coming from a synonym link.'),
2431
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2432
    '#description' => t('Check this if after doing a search and clicking on a
2433
      synonym you want to see the "accept of" text for the accepted synonym.'),
2434
  );
2435

    
2436
  /* === currently unused ===
2437
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2438
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2439
    '#type' => 'checkboxes',
2440
    '#title' => t('Display name relationships') . ':',
2441
    '#default_value' => variable_get('name_relationships_to_show', 0),
2442
    '#options' => $nameRelationshipTypeOptions,
2443
    '#description' => t('Select the name relationships you want to show for the
2444
      accepted taxa.'),
2445
  );
2446
 */
2447

    
2448
  $form['taxon_synonymy']['taxon_relations'] = array(
2449
    '#type' => 'fieldset',
2450
    '#title' => t('Taxon relationships'),
2451
    '#collapsible' => FALSE,
2452
    '#collapsed' => FALSE
2453
  );
2454

    
2455
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2456
    '#type' => 'checkbox',
2457
    '#title' => t('Show taxon relations ships of accepted taxon'),
2458
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2459
    '#description' => t('If this option is enabled the synonymy will show the
2460
      below selected taxon relationships of accepted taxa.'),
2461
  );
2462

    
2463
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2464
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2465
    '#type' => 'checkboxes',
2466
    '#title' => t('Taxon relationship types') . ':',
2467
    '#description' => t('Only taxon relationships of the selected type will be
2468
      displayed'),
2469
    '#options' => $taxonRelationshipTypeOptions,
2470
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2471
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2472
  );
2473

    
2474
  $form['taxon_synonymy']['name_relations'] = array(
2475
    '#type' => 'fieldset',
2476
    '#title' => t('Name relationships'),
2477
    '#collapsible' => FALSE,
2478
    '#collapsed' => FALSE
2479
  );
2480

    
2481
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2482
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2483
    '#type' => 'checkboxes',
2484
    '#title' => t('Name relationship types') . ':',
2485
    '#description' => t('Only name relationships of the selected type will be
2486
      displayed'),
2487
    '#options' => $taxonRelationshipTypeOptions,
2488
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2489
  );
2490

    
2491
  // ====== SPECIMENS ====== //
2492
  $form['taxon_specimens'] = array(
2493
    '#type' => 'fieldset',
2494
    '#title' => t('Taxon specimens (tab)'),
2495
    '#collapsible' => TRUE,
2496
    '#collapsed' => TRUE,
2497
    '#description' => t('This section covers the settings related to the taxon
2498
      <strong>specimens</strong> tab.'),
2499
  );
2500

    
2501
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2502

    
2503
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2504
    '#type' => 'checkbox',
2505
    '#title' => t('Show specimen derivatives in a compressed table'),
2506
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2507
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2508
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2509
  );
2510

    
2511
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2512
        '#type' => 'textfield',
2513
        '#title' => t('Number of records per page') . ':',
2514
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2515
    );
2516

    
2517
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2518
    '#type' => 'checkbox',
2519
    '#title' => t('Show "Associated with" in specimen table.'),
2520
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2521
  );
2522

    
2523
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2524
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2525
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2526
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2527
  }
2528
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2529
    '#type' => 'radios',
2530
    '#title' => t('Specimen description feature tree') . ':',
2531
    '#default_value' => $profile_feature_tree_uuid,
2532
    '#options' =>  $featureTrees['options'],
2533
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2534
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2535
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2536
    ),
2537
  );
2538

    
2539
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2540
  $form_title = t('Specimen media');
2541
  $form_description = t('Specimens may have media which is displayed at the
2542
     Specimen tab/section as a gallery. It is possible to configure the
2543
     thumbnails gallery here, however for configuring how a single media should
2544
     be displayed please go to !url.</p>',
2545
     array(
2546
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2547
     ));
2548
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2549

    
2550
  // --- MEDIA GALLERY ---- //
2551
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2552
  $form_title = 'Media gallery (tab)';
2553
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2554
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2555
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2556
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2557
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2558
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2559
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2560

    
2561
  // Comment @WA: D7 form api does not support reset buttons,
2562
  // so to mimic the D5 reset button we add one like this.
2563
  $form['actions']['reset'] = array(
2564
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2565
    '#weight' => 1000,
2566
  );
2567
  return system_settings_form($form);
2568
}
2569

    
2570
/**
2571
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2572
 *
2573
 * @param $map_id
2574
 * @param $form
2575
 * @return mixed
2576
 */
2577
function _cdm_map_visibility_setting($map_id)
2578
{
2579
  return array(
2580
    '#type' => 'select',
2581
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2582
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2583
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2584
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2585
        The map also can forced to show up <b>always</b> or <b>never</b>."
2586
  );
2587
}
2588

    
2589
/**
2590
 * @todo document this function.
2591
 */
2592
function cdm_settings_layout_search() {
2593

    
2594
  $form = array();
2595

    
2596
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2597

    
2598
  $form['search_settings'] = array(
2599
    '#type' => 'fieldset',
2600
    '#title' => t('Taxa Search'),
2601
    '#collapsible' => FALSE,
2602
    '#collapsed' => FALSE,
2603
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2604
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2605
         where they can write the text to be searched. You can find Drupal block configuration
2606
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2607
  );
2608

    
2609
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2610
      '#type' => 'checkbox',
2611
      '#title' => t('Ignore the chosen classification in simple search'),
2612
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2613
      '#description' => t('The simple search, which can be executed via the search block,
2614
          will by default search on the classification selected in the classification browser
2615
          selector. Set the tick if you want your portal to search on all classifications.'),
2616
  );
2617

    
2618
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2619
    '#type' => 'checkbox',
2620
    '#title' => t('Run simple search with free-text search backend.'),
2621
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2622
    '#description' => t('The simple search uses by default another search
2623
      backend as the advances search. By checking this option the simple search can be
2624
      configured to also use the free-text search backend.'),
2625
  );
2626

    
2627
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2628
    '#type' => 'textfield',
2629
    '#title' => t('Results per page') . ':',
2630
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2631
    '#description' => t('Number of results to display per page.'),
2632
  );
2633

    
2634
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2635
    '#type' => 'checkbox',
2636
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2637
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2638
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2639
  );
2640

    
2641
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2642
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2643
      '#type' => 'checkboxes',
2644
      '#title' => 'Search mode',
2645
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2646
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2647
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2648
          defaults set here.',
2649
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2650
      '#default_value' => $search_mode_default
2651
      );
2652

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

    
2658
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2659
  );
2660

    
2661
  // --- SEARCH TAXA GALLERY ---- //
2662
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2663
  $collapsed = FALSE;
2664
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2665
  $form_title = 'Taxa Search thumbnails';
2666
  $form_description = 'Search results may show thumbnails. ';
2667
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2668

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

    
2678
/**
2679
 * @todo document this function.
2680
 */
2681
function cdm_settings_layout_media() {
2682

    
2683
  $form = array();
2684

    
2685
  $form['media_settings'] = array(
2686
    '#type' => 'fieldset',
2687
    '#title' => t('Media settings'),
2688
    '#collapsible' => FALSE,
2689
    '#collapsed' => FALSE,
2690
    '#description' => 'This section covers layout settings for media pages.'
2691
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2692
  );
2693

    
2694
  $form['media_settings']['image_gallery_viewer'] = array(
2695
    '#type' => 'select',
2696
    '#title' => t('Image viewer') . ':',
2697
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2698
    '#options' => array(
2699
      'default' => t('Standard image viewer'),
2700
      'fsi' => t('FSI viewer (requires FSI server!)'),
2701
    ),
2702
  );
2703

    
2704
  // --- MEDIA GALLERY ---- //
2705
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2706
  $form_title = 'Standard viewer';
2707
  $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>';
2708
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2709
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2710

    
2711
  // @WA: D7 form api does not support reset buttons,
2712
  // so to mimic the D5 reset button we add one like this.
2713
  $form['actions']['reset'] = array(
2714
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2715
    '#weight' => 1000,
2716
  );
2717
  return system_settings_form($form);
2718
}
2719

    
2720
/**
2721
 * GEOSERVICE and Map settings.
2722
 */
2723
function cdm_settings_geo($form, &$form_state) {
2724

    
2725
  $current_geoserver_settings = get_edit_map_service_settings();
2726
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2727

    
2728

    
2729
  $form = array();
2730

    
2731
  $dummy_distribution_query = NULL;
2732
  if($map_distribution['map_type'] != 1){
2733
    // we need to apply a dummy query since the map service requires for image maps
2734
    // at least as and ad to be defined
2735
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2736
  }
2737

    
2738
  $form['map_preview'] = array(
2739
      '#type' => 'fieldset',
2740
      '#tree' => FALSE,
2741
      '#title' => t('Map preview'),
2742
      '#collapsible' => FALSE,
2743
      '#description' => 'The preview of the map'
2744
       . ($dummy_distribution_query != null ?
2745
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2746
           '.<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.')
2747
  );
2748
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2749
    'move' => "this.cdmOpenlayersMap.printInfo",
2750
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2751
  ), true // resizable
2752
  );
2753

    
2754
  /*
2755
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2756
  );
2757
  */
2758

    
2759
  /*
2760
   * GEO SERVER
2761
   */
2762
  $form['edit_map_server'] = array(
2763
    '#type' => 'fieldset',
2764
    '#tree' => true,
2765
    '#title' => t('EDIT map service'),
2766
    '#collapsible' => TRUE,
2767
    '#collapsed' => TRUE,
2768
    '#description' => t('Configuration and selection of your geo server.
2769
      The Geo Server is responsible for generating the maps.'),
2770
  );
2771

    
2772
  $form['edit_map_server']['base_uri'] = array(
2773
    '#type' => 'select',
2774
    '#title' => t('EDIT map service') . ':',
2775
    '#default_value' => $current_geoserver_settings['base_uri'],
2776
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2777
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2778
  );
2779
  $form['edit_map_server']['version'] = array(
2780
      '#type' => 'select',
2781
      '#title' => t('Version') . ':',
2782
      '#default_value' => $current_geoserver_settings['version'],
2783
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2784
      '#description' => t('The version of the EDIT map services'),
2785
  );
2786

    
2787
  /*
2788
   * MAP SETTINGS
2789
   */
2790

    
2791
  $form[CDM_MAP_DISTRIBUTION] = array(
2792
    '#type' => 'fieldset',
2793
    '#tree' => TRUE,
2794
    '#title' => t('Maps settings'),
2795
    '#collapsible' => TRUE,
2796
    '#collapsed' => TRUE,
2797
    '#description' => t('General configuration for all map types.'),
2798
  );
2799

    
2800
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2801
    '#type' => 'radios',
2802
    '#title' => 'Map types',
2803
    '#options' => array(
2804
      1 => "OpenLayers dynamic map viewer",
2805
      0 => "Plain image",
2806
    ),
2807
    '#default_value' => $map_distribution['map_type'],
2808
    '#description' => 'Two different map types are available :
2809
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2810
      which allows zooming and panning. If enabled you can configure the default layer
2811
      (background of your maps) below.</li>
2812
      <li><em>Plain image</em>: The map will be static non interactive
2813
      image.</li></ul>',
2814
  );
2815
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2816

    
2817
  /*
2818
   * settings for the distribution map are used also for specimens map!!!!
2819
   */
2820

    
2821
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2822
      '#type' => 'textfield',
2823
      '#title' => 'Aspect ratio',
2824
      '#default_value' => $map_distribution['aspect_ratio'],
2825
      '#maxlength' => 4,
2826
      '#size' => 4,
2827
      '#element_validate' => array('element_validate_number'),
2828
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2829
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2830
      width by the height:</br>
2831
      <pre>aspect ratio = w / h</pre>
2832
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2833
      for a square map use <strong>1</strong>.',
2834
  );
2835

    
2836
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2837
    '#type' => 'textfield',
2838
    '#title' => 'Bounding box',
2839
    '#default_value' => $map_distribution['bbox'],
2840
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2841
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2842
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2843
      <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.
2844
      (Maybe you need to change the map base layer to OpeLayers.)
2845
      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
2846
      below the map from where you can copy the bbox string.</p>'),
2847
  );
2848

    
2849
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2850
    '#type' => 'checkbox',
2851
    '#title' => 'Display area labels',
2852
    '#default_value' => $map_distribution['show_labels'],
2853
    '#description' => t('The map will show name labels of the areas'),
2854
  );
2855

    
2856
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2857
    '#type' => 'textfield',
2858
    '#title' => 'Map caption',
2859
    '#default_value' => $map_distribution['caption'],
2860
    '#description' => t('The caption will be shown below the map.'),
2861
  );
2862

    
2863
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2864
    '#type' => 'textfield',
2865
    '#title' => 'Distribution layer opacity',
2866
    '#default_value' => $map_distribution['distribution_opacity'],
2867
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2868
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2869
  );
2870

    
2871
  // --- Plain Image Settings --- //
2872
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2873
    '#type' => 'fieldset',
2874
    '#title' => 'Plain image map settings',
2875
    '#tree' => TRUE,
2876
    '#collapsible' => TRUE,
2877
    '#collapsed' => $open_layers_is_enabled,
2878
    '#description' => 'The settings in this section are still expertimental
2879
      and can only be used with the EDIT map service version 1.1 or above.',
2880
  );
2881
  $edit_mapserver_version = get_edit_map_service_version_number();
2882
  if ($edit_mapserver_version < 1.1) {
2883
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2884
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2885
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2886
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2887
  }
2888

    
2889
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2890
    '#type' => 'textfield',
2891
    '#title' => 'Width',
2892
    '#default_value' => $map_distribution['image_map']['width'],
2893
    '#maxlength' => 4,
2894
    '#size' => 4,
2895
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2896
  );
2897

    
2898
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2899
    '#type' => 'textfield',
2900
    '#title' => 'Background layer',
2901
    '#default_value' => $map_distribution['image_map']['base_layer'],
2902
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2903
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2904
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2905
    )),
2906
  );
2907

    
2908
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2909
    '#type' => 'textfield',
2910
    '#title' => 'Background color',
2911
    '#default_value' => $map_distribution['image_map']['bg_color'],
2912
  );
2913

    
2914
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2915
    '#type' => 'textfield',
2916
    '#title' => 'Background layer style',
2917
     // Only line color by now.
2918
    '#default_value' => $map_distribution['image_map']['layer_style'],
2919
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2920
  );
2921

    
2922
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2923
      '#type' => 'textfield',
2924
      '#title' => 'Projection',
2925
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2926
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2927
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2928
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2929
  );
2930

    
2931

    
2932
  // --- OpenLayers Settings --- //
2933
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2934
    '#type' => 'fieldset',
2935
    '#title' => 'OpenLayers settings',
2936
    '#tree' => TRUE,
2937
    '#collapsible' => TRUE,
2938
    '#collapsed' => !$open_layers_is_enabled,
2939
    '#description' => '',
2940
  );
2941

    
2942

    
2943
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2944
      '#type' => 'checkbox',
2945
      '#title' => 'Display outside max extent',
2946
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2947
      '#description' => t('Allows the map to display parts of the layers which are outside
2948
         the max extent if the aspect ratio of the map and of the baselayer
2949
         are not equal.'),
2950
  );
2951

    
2952

    
2953
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2954
      '#type' => 'checkbox',
2955
      '#title' => 'Show Layer Switcher',
2956
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2957
      '#description' => 'The Layer Switcher control displays a table of contents
2958
      for the map.  This allows the user interface to switch between
2959
      base layers and to show or hide overlays.  By default the switcher is
2960
      shown minimized on the right edge of the map, the user may expand it
2961
      by clicking on the handle.',
2962
  );
2963

    
2964
  if (!$open_layers_is_enabled) {
2965
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2966
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2967
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2968
  }
2969

    
2970
  // The default layer must always be enabled
2971
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2972
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2973

    
2974
  $baselayer_options = array(
2975
    /*
2976
   NOTICE: must correspond to the layers defined in
2977
   js/openlayers_,ap.js#getLayersByName()
2978
   */
2979
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
2980
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
2981
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
2982
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
2983
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2984
    // all others EPSG:900913
2985
    'mapnik' => 'OpenStreetMap',
2986
    'mapquest_open' => "MapQuest",
2987
    'mapquest_sat' => "MapQuest Sattelite",
2988
    'groadmap' => 'Google Roadmap',
2989
    'gsatellite' => 'Google Satellite',
2990
    'ghybrid' => 'Google Hybrid',
2991
    'gterrain' => 'Google Terrain',
2992
//     'veroad' => 'Virtual Earth Roads',
2993
//     'veaer' => 'Virtual Earth Aerial',
2994
//     'vehyb' => 'Virtual Earth Hybrid',
2995
    // 'yahoo' => 'Yahoo Street',
2996
    // 'yahoosat' => 'Yahoo Satellite',
2997
    // 'yahoohyb' => 'Yahoo Hybrid',
2998
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2999
  );
3000

    
3001
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3002
    '#type' => 'checkboxes_preferred',
3003
    '#title' => 'Base Layers',
3004
    '#options' => $baselayer_options,
3005
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3006
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3007
  );
3008

    
3009
  $google_maps_api_key = null;
3010
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3011
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3012
  }
3013
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3014
    '#type' => 'textfield',
3015
    '#title' => 'Google Maps API Key',
3016
    '#default_value' => $google_maps_api_key,
3017
    '#description' => 'In order to use any of the Google map layers you need to provide 
3018
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3019
  );
3020

    
3021
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3022
    $map_distribution['openlayers']['custom_wms_base_layer'],
3023
    'Custom WMS base layer',
3024
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3025
    true // add projection settings
3026
    );
3027

    
3028
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3029
    $map_distribution['openlayers']['wms_overlay_layer'],
3030
    'WMS overlay layer',
3031
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3032
                You can actually combine multiple layers for this overlay. 
3033
                For details please refer to the wms query parameter <code>Layers</code> .'
3034
  );
3035

    
3036
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3037
    '#type' => 'checkbox',
3038
    '#title' => 'Enable overlay layer',
3039
    '#weight' => -100,
3040
    '#default_value' => $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3041
  );
3042

    
3043
  /*
3044
   * Map Legend
3045
   */
3046
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3047
    '#type' => 'fieldset',
3048
    '#title' => 'Map legend',
3049
    '#tree' => TRUE,
3050
    '#collapsible' => TRUE,
3051
    '#collapsed' => TRUE,
3052
    '#description' => 'Configure the maps legend.',
3053
  );
3054

    
3055
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3056
    '#type' => 'checkbox',
3057
    '#title' => 'Display a map legend',
3058
    '#default_value' => $map_distribution['legend']['show'],
3059
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3060
  );
3061

    
3062
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3063
    '#type' => 'textfield',
3064
    '#title' => 'Legend opacity',
3065
    '#default_value' => $map_distribution['legend']['opacity'],
3066
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3067
                         to 0.0 will be not much visible.',
3068
  );
3069

    
3070
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3071
    '#type' => 'textfield',
3072
    '#title' => 'Font size',
3073
    '#default_value' => $map_distribution['legend']['font_size'],
3074
    '#description' => 'Font size in pixels.',
3075
  );
3076

    
3077
  $fontStyles = array(
3078
    0 => "plane",
3079
    1 => "italic",
3080
  );
3081
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3082
    '#type' => 'select',
3083
    '#title' => 'Available font styles',
3084
    '#default_value' => $map_distribution['legend']['font_style'],
3085
    '#options' => $fontStyles,
3086
    '#description' => 'Select a font style for the map legend.',
3087
  );
3088

    
3089
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3090
    '#type' => 'textfield',
3091
    '#title' => 'Icon width',
3092
    '#default_value' => $map_distribution['legend']['icon_width'],
3093
    '#description' => 'Legend icon width in pixels.',
3094
  );
3095
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3096
    '#type' => 'textfield',
3097
    '#title' => 'Icon height',
3098
    '#default_value' => $map_distribution['legend']['icon_height'],
3099
    '#description' => 'Legend icon height in pixels.',
3100
  );
3101

    
3102
  // @WA: D7 form api does not support reset buttons,
3103
  // so to mimic the D5 reset button we add one like this.
3104
  $form['actions']['reset'] = array(
3105
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3106
    '#weight' => 1000,
3107
  );
3108

    
3109
  return system_settings_form($form);
3110
}
3111

    
3112
/**
3113
 * @param $default_settings
3114
 * @param $title
3115
 * @param $description
3116
 * @param bool $add_projection_settings
3117
 * @return array
3118
 */
3119
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3120
{
3121
  $form_elements = array(
3122
    '#type' => 'fieldset',
3123
    '#title' => $title,
3124
    '#tree' => TRUE,
3125
    '#collapsible' => FALSE,
3126
    '#collapsed' => FALSE,
3127
    '#description' => $description,
3128
  );
3129

    
3130
  $form_elements['name'] = array(
3131
    '#type' => 'textfield',
3132
    '#title' => 'Layer name',
3133
    // Only line color by now.
3134
    '#default_value' => $default_settings['name'],
3135
    '#description' => 'A arbitrary name for the layer.',
3136
  );
3137
  $form_elements['url'] = array(
3138
    '#type' => 'textfield',
3139
    '#title' => 'WMS url',
3140
    // Only line color by now.
3141
    '#default_value' => $default_settings['url'],
3142
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3143
  );
3144
  $form_elements['params'] = array(
3145
    '#type' => 'textarea',
3146
    '#title' => 'WMS parameters',
3147
    '#element_validate' => array('form_element_validate_json'),
3148
    // Only line color by now.
3149
    '#default_value' => $default_settings['params'],
3150
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3151
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3152
      . '), entered in valid JSON. For example:
3153
<pre> {
3154
  "Layers": "topp:em_tiny_jan2003",
3155
  "Format": "image/png",
3156
  "BGCOLOR": "0xe0faff"
3157
}
3158
</pre>
3159
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3160
  );
3161

    
3162
  if($add_projection_settings){
3163

    
3164
    $form_elements['projection'] = array(
3165
      '#type' => 'textfield',
3166
      '#title' => 'Projection',
3167
      // Only line color by now.
3168
      '#default_value' => $default_settings['projection'],
3169
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
3170
    );
3171
    $form_elements['proj4js_def'] = array(
3172
      '#type' => 'textfield',
3173
      '#maxlength' => 256,
3174
      '#title' => 'proj4js definition',
3175
      // Only line color by now.
3176
      '#default_value' => $default_settings['proj4js_def'],
3177
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
3178
              The definitions for
3179
              EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
3180
              EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
3181
              are already predefined and must NOT be added here again.  If your dont know the defintion of your desired projection,
3182
              go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
3183
              choose to display the proj4js definition string.
3184
              <h5>Quick Reference on the common proj4js definition parameters:</h5>
3185
              <pre>
3186
  +a         Semimajor radius of the ellipsoid axis
3187
  +alpha     ? Used with Oblique Mercator and possibly a few others
3188
  +axis      Axis orientation (new in 4.8.0)
3189
  +b         Semiminor radius of the ellipsoid axis
3190
  +datum     Datum name (see `proj -ld`)
3191
  +ellps     Ellipsoid name (see `proj -le`)
3192
  +k         Scaling factor (old name)
3193
  +k_0       Scaling factor (new name)
3194
  +lat_0     Latitude of origin
3195
  +lat_1     Latitude of first standard parallel
3196
  +lat_2     Latitude of second standard parallel
3197
  +lat_ts    Latitude of true scale
3198
  +lon_0     Central meridian
3199
  +lonc      ? Longitude used with Oblique Mercator and possibly a few others
3200
  +lon_wrap  Center longitude to use for wrapping (see below)
3201
  +nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
3202
  +no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
3203
  +over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
3204
  +pm        Alternate prime meridian (typically a city name, see below)
3205
  +proj      Projection name (see `proj -l`)
3206
  +south     Denotes southern hemisphere UTM zone
3207
  +to_meter  Multiplier to convert map units to 1.0m
3208
  +towgs84   3 or 7 term datum transform parameters (see below)
3209
  +units     meters, US survey feet, etc.
3210
  +vto_meter vertical conversion to meters.
3211
  +vunits    vertical units.
3212
  +x_0       False easting
3213
  +y_0       False northing
3214
  +zone      UTM zone
3215
              </pre>
3216
            For the full reference please refer to <a href="http://proj4.org/parameters.html">http://proj4.org/parameters.html</a>.'
3217
    );
3218
    $form_elements['max_extent'] = array(
3219
      '#type' => 'textfield',
3220
      '#title' => 'Maximum extent',
3221
      // Only line color by now.
3222
      '#default_value' => $default_settings['max_extent'],
3223
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
3224
    );
3225
    $form_elements['units'] = array(
3226
      '#type' => 'textfield',
3227
      '#title' => 'Units',
3228
      '#default_value' => $default_settings['units'],
3229
      '#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.'
3230
    );
3231

    
3232
  }
3233
  return $form_elements;
3234
}
3235

    
3236

    
3237
/**
3238
 * @todo document this function.
3239
 */
3240
function cdm_settings_cache() {
3241

    
3242
  $form = array();
3243

    
3244
  $form['cache_settings'] = array(
3245
    '#type' => 'fieldset',
3246
    '#title' => t('Cache Settings'),
3247
    '#collapsible' => FALSE,
3248
    '#collapsed' => FALSE,
3249
    '#description' => t('<p>When caching is enabled all single taxon sites are
3250
      stored in an internal drupal cache doing the portal response of taxa pages
3251
      faster. This is possible because the sites are loaded from the cache and
3252
      are not created from scratch.</p>'),
3253
  );
3254

    
3255
  $form['cache_settings']['cdm_webservice_cache'] = array(
3256
    '#type' => 'checkbox',
3257
    '#title' => t('<strong>Enable caching</strong>'),
3258
    '#options' => cdm_help_general_cache(),
3259
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3260
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3261
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3262
       application the changes will be not visible till the cache is erased.
3263
       Therefore developers should deactived this feature when they are working
3264
       on the CDM Dataportal Module.</p>'),
3265
  );
3266

    
3267
  $form['cache_settings']['cdm_run_cache'] = array(
3268
    '#markup' => cdm_view_cache_site(),
3269
  );
3270

    
3271
  // @WA: D7 form api does not support reset buttons,
3272
  // so to mimic the D5 reset button we add one like this.
3273
  $form['actions']['reset'] = array(
3274
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3275
    '#weight' => 1000,
3276
  );
3277
  return system_settings_form($form);
3278
}
3279

    
3280
/**
3281
 * Walk and cache all taxon pages.
3282
 */
3283
function cdm_view_cache_site() {
3284

    
3285
  $out = '';
3286

    
3287
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3288

    
3289
  $request_params = array();
3290
  $request_params['class'] = "Taxon";
3291

    
3292
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3293
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3294
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3295

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

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

    
3305
  // Comment @WA: A form within a form is not valid html and not needed here.
3306
  // Also, it would be recommended just to include this part of the form in the
3307
  // rest of the form array in cdm_settings_cache().
3308
  // $out .= '<form id="cache_site">';
3309
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3310
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3311
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3312
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3313
  // $out .= '</form>';
3314
  $out .= '</div>';
3315
  /*
3316
  foreach($taxonPager->records as $taxon){
3317
    cdm_dataportal_taxon_view($uuid);
3318
  }
3319
  */
3320
  return $out;
3321
}
3322

    
3323

    
3324
function cdm_settings_layout_taxon_submit($form, &$form_state){
3325
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3326
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3327
    if(is_object($file)){
3328
      $file->status = FILE_STATUS_PERMANENT;
3329
      file_save($file);
3330
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3331
    }
3332
  }
3333
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3334
  $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]);
3335
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3336
  if($tab_lables_modified || $tabs_enabled_modified){
3337
    // we first need to set the variable to persist the changes setting
3338
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3339
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3340
    menu_rebuild();
3341
  }
3342
}
3343

    
3344
function cdm_settings_layout_search_submit($form, &$form_state){
3345
  // the visibility of media thumbnails also affects the ui of the search results
3346
  // so reset the according session variable
3347
  //    1. in order to give the user immediate
3348
  //       feedback on potential setting changes
3349
  //    2. let refresh the default if it has changed
3350
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3351
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3352
  }
3353
}
3354

    
3355
/**
3356
 * Form validation handler for cdm_settings_general
3357
 *
3358
 * @param $form
3359
 * @param $form_state
3360
 */
3361
function cdm_settings_general_validate($form, &$form_state) {
3362

    
3363
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3364
    $form_state['values']['cdm_webservice_url'] .= '/';
3365
  }
3366

    
3367
}
3368

    
3369
/**
3370
 * Form submit handler for settings general.
3371
 *
3372
 * tasks performed:
3373
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3374
 *
3375
 * @param $form
3376
 * @param $form_state
3377
 */
3378
function cdm_settings_general_submit($form, &$form_state){
3379
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3380
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3381
  unset($_SESSION['cdm_login']);
3382
}
3383

    
3384
/**
3385
 * Form validation handler for cdm_settings_cache
3386
 */
3387
function cdm_settings_cache_validate($form, &$form_state) {
3388
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3389
    cache_clear_all(NULL, 'cache_cdm_ws');
3390
    // Better clear secref_cache since I can not be sure if the cache has not
3391
    // be used during this response.
3392
    cdm_api_secref_cache_clear();
3393
  }
3394

    
3395
}
3396

    
3397
/**
3398
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3399
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3400
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3401
 *  - version: the version, e.g.: v1.1
3402
 *
3403
 * @return array
3404
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3405
 */
3406
function get_edit_map_service_settings() {
3407

    
3408
  $settings = variable_get('edit_map_server', array(
3409
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3410
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3411
      )
3412
  );
3413

    
3414
  return $settings;
3415
}
3416

    
3417
/**
3418
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3419
 *
3420
 * @return string
3421
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3422
 */
3423
function get_edit_map_service_full_uri() {
3424
  $settings = get_edit_map_service_settings();
3425
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3426
}
3427

    
3428

    
3429
/**
3430
 * Returns the version number of the currently selected edit mapserver as a float
3431
 *
3432
 * @return float
3433
 *   The version number of the currently selected edit mapserver as a float.
3434
 *   Returns 0 on error.
3435
 */
3436
function get_edit_map_service_version_number() {
3437

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

    
3440
  $settings = get_edit_map_service_settings();
3441
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3442
  if (isset($matches[1])) {
3443
    // Convert string to float.
3444
    $version = 1 + $matches[1][0] - 1;
3445
    return $version;
3446
  }
3447
  else {
3448
    // Report error.
3449
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3450
        array(
3451
          '!version' => $settings['version'],
3452
          'warning')
3453
        )
3454
      );
3455
    return 0;
3456
  }
3457
}
3458

    
3459
/**
3460
 * Returns the array of selected items in a options array
3461
 *
3462
 * @param array $options
3463
 *   An options array as generated by a form element like checkoxes, select ...,
3464
 */
3465
function get_selection($options) {
3466
  $selection = array();
3467
  foreach ($options as $key=>$val) {
3468
    if (!empty($val)) {
3469
      $selection[] = $val;
3470
    }
3471
  }
3472
  return $selection;
3473
}
3474

    
3475

    
3476
/**
3477
 * Implements hook_element_info().
3478
 *
3479
 * Allows modules to declare their own Form API element types and specify their default values.
3480
 *
3481
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3482
 */
3483
function cdm_dataportal_element_info() {
3484
  $type['checkboxes_preferred'] = array(
3485
    '#input' => TRUE,
3486
    '#process' => array('checkboxes_preferred_expand'),
3487
    '#after_build' => array('checkboxes_preferred_after_build'),
3488
    '#theme' => array('checkboxes_preferred'),
3489
    // '#theme_wrapper' => array('form_element'),
3490
  );
3491
  return $type;
3492
}
3493

    
3494
/**
3495
 * #process callback function for the custom form element type 'checkbox_preferred'
3496
 *
3497
 *
3498
 */
3499
function checkboxes_preferred_expand($element, &$form_state, $form) {
3500

    
3501
  // First of all create checkboxes for each of the elements
3502
  $element = form_process_checkboxes($element);
3503

    
3504
  // compose the element name
3505
  $parents = array();
3506
  array_deep_copy($element['#parents'], $parents);
3507
  $parents[count($parents) -1 ] .= '_preferred';
3508
  $element_name = $parents[0];
3509
  for ($i=1; $i < count($parents); $i++){
3510
    $element_name .= '[' . $parents[$i] . ']';
3511
  }
3512

    
3513
  $children = element_children($element);
3514

    
3515
  $element['table_start'] = array(
3516
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3517
    '#weight' => -1,
3518
  );
3519

    
3520
  // prepare first part each of the table rows which contains the row label
3521
  $weight = 0;
3522
  foreach ($children as $key) {
3523
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3524
    $element[$key]['#weight'] = $weight;
3525
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3526
    $element[$key]['#suffix'] = '</td>';
3527
    unset($element[$key]['#title']);
3528
    $weight += 2;
3529
  }
3530
  $weight = 0;
3531

    
3532
  // add a radio button to each of the checkboxes, the
3533
  // check boxes have already been created at the beginning
3534
  // of this function
3535
  if (count($element['#options']) > 0) {
3536
    foreach ($element['#options'] as $key => $choice) {
3537
      if (!isset($element[$key . '_preferred'])) {
3538
        $element[$key . '_preferred'] = array(
3539
          '#type' => 'radio',
3540
          '#name' => $element_name,
3541
          '#return_value' => check_plain($key),
3542
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3543
          '#attributes' => $element['#attributes'],
3544
          '#parents' => $element['#parents'],
3545
          // '#spawned' => TRUE,
3546
          '#weight' => $weight + 1,
3547
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3548
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3549
        );
3550
      }
3551
      $weight += 2;
3552
    }
3553
  }
3554

    
3555
  // end the table
3556
  $element['table_end'] = array(
3557
    '#markup' => '</table>',
3558
    '#weight' => $weight++,
3559
  );
3560

    
3561
  return $element;
3562
}
3563

    
3564
/**
3565
 * Theme function for the custom form field 'checkboxes_preferred'.
3566
 */
3567
function theme_checkboxes_preferred($variables) {
3568
  $element = $variables['element'];
3569
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3570
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3571
  $out .= drupal_render_children($element);
3572
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3573
  $out .= '</div>';
3574
  return $out;
3575
}
3576

    
3577
/**
3578
 * Callback for checkboxes preferred for widget which will
3579
 * be called after the form or element is built. The call
3580
 * back is configured in the form element by setting it as
3581
 * #after_build parameter.
3582
 *
3583
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3584
 *
3585
 * @param $element
3586
 *   Nested array of form elements that comprise the form.
3587
 * @param $form_state
3588
 *   A keyed array containing the current state of the form.
3589
 *   This includes the current persistent storage data for the form.
3590
 *   Additional information, like the sanitized $_POST data,
3591
 *   is also accumulated here in $form_state['input']
3592
 *
3593
 * @return the modified form array
3594
 */
3595
function checkboxes_preferred_after_build($element, &$form_state) {
3596

    
3597
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3598

    
3599
  if ($_POST && count($_POST) > 0) {
3600
    // TODO use  $form_state['input'] instead of POST !!!
3601
    // First pass of form processing.
3602
    $parents = array();
3603
    array_deep_copy($element['#parents'], $parents);
3604
    $parents[count($parents) - 1] .= '_preferred';
3605
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3606
    $element['#value']['PREFERRED'] = $preferred_layer;
3607
//     $form_state[$parent_id] = $element['#value'];
3608
//     $form_state['values']['baselayers'] = $element['#value'];
3609
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3610
    $form_state_element_values = $element['#value'];
3611
  }
3612
  else {
3613
    // Second pass of form processing.
3614
    $preferred_layer = $element['#value']['PREFERRED'];
3615
  }
3616

    
3617
  // Also set the chosen value (not sure if this is good Drupal style ....).
3618
  foreach ($children = element_children($element) as $key) {
3619
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3620
      $element[$key]['#value'] = $preferred_layer;
3621
    }
3622
  }
3623
  // The default layer must always be enabled.
3624
  $element[$preferred_layer]['#value'] = $preferred_layer;
3625

    
3626
  return $element;
3627
}
3628

    
3629
function radios_prepare_options_suffix(&$elements){
3630

    
3631
  $childrenKeys = element_children($elements);
3632
  foreach($childrenKeys as $key){
3633
    if(!is_array($elements[$key]['#theme_wrappers'])){
3634
      $elements[$key]['#theme_wrappers'] = array();
3635
    }
3636
    if(isset($elements['#options_suffixes'][$key])){
3637
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3638
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3639
    }
3640
  }
3641
  return $elements;
3642

    
3643
}
3644

    
3645
/**
3646
 * TODO
3647
 * @param unknown $variables
3648
 */
3649
function theme_radio_options_suffix($variables) {
3650
  $element = $variables['element'];
3651
  if(isset($element['#options_suffix'])) {
3652
    $element['#children'] .= $element['#options_suffix'];
3653
  }
3654
  return $element['#children'];
3655
}
3656

    
3657

    
3658
/**
3659
 * Element validate callback for text field and arrays containing json.
3660
 *
3661
 * @param $element
3662
 *   The form element to validate
3663
 * @param $form_state
3664
 *   A keyed array containing the current state of the form.
3665
 * @param $form
3666
 *   Nested array of form elements that comprise the form.
3667
 */
3668
function form_element_validate_json($element, &$form_state, $form) {
3669
   if (!empty($element['#value'])) {
3670
     json_decode($element['#value']);
3671
     if(json_last_error() != JSON_ERROR_NONE){
3672
       form_error($element,
3673
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3674
         . l('JSONLint', 'http://jsonlint.com/')
3675
       );
3676
     }
3677
   }
3678
}
3679

    
3680
/**
3681
 * Form submission handler for textareas and textfields containing JSON.
3682
 *
3683
 * The contained JSON will be converted into an php array
3684
 * or object and will be stored in the variables as such.
3685
 *
3686
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3687
 *
3688
 * @param $form
3689
 *   Nested array of form elements that comprise the form.
3690
 * @param $form_state
3691
 *   A keyed array containing the current state of the form.
3692
 *
3693
 */
3694
function submit_json_as_php_array($form, &$form_state) {
3695
  if (is_array($form['#json_elements'])) {
3696
    foreach ($form['#json_elements'] as $element){
3697
      if (trim($form_state['values'][$element])) {
3698
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3699
      } else {
3700
        $form_state['values'][$element] = NULL;
3701
      }
3702
    }
3703
  }
3704
}
(18-18/18)