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

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

    
101

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

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

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

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

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

    
142

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

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

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

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

    
171
}
172

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

    
264
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
265
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
266
  array (
267
    'taxon_page_title,polytomousKey'=> array(
268
        'namePart' => array('#uri' => TRUE),
269
      ),
270
    'not_in_current_classification' => array(
271
     'nameAuthorPart' => TRUE,
272
     'referencePart' => TRUE,
273
     'statusPart' => TRUE,
274
     'secReferencePart' => TRUE,
275
    ),
276
    'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy'=> array(
277
      'nameAuthorPart' => array('#uri' => TRUE),
278
      'referencePart' => TRUE,
279
      'descriptionPart' => TRUE,
280
      'statusPart' => TRUE,
281
    ),
282
    'related_taxon.other_taxon_relationship.taxon_relationships.taxon_page_synonymy'=> array(
283
      'nameAuthorPart' => array('#uri' => TRUE),
284
      'referencePart' => TRUE,
285
      'descriptionPart' => TRUE,
286
      'statusPart' => TRUE,
287
      'secReferencePart' => TRUE,
288
    ),
289
    'related_taxon.misapplied_name_for.taxon_relationships.taxon_page_synonymy' => array(
290
      'nameAuthorPart' => array('#uri' => TRUE),
291
      'referencePart' => TRUE,
292
      'descriptionPart' => 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
    ),
297
    'homonym'=> array(
298
        'nameAuthorPart' => array('#uri' => TRUE),
299
        'referenceYearPart' => TRUE,
300
        'statusPart' => TRUE,
301
    ),
302
    'acceptedFor,typedesignations,list_of_taxa' => array(
303
        'nameAuthorPart' => array('#uri' => TRUE),
304
        'referencePart' => TRUE,
305
      ),
306
    '#DEFAULT' => array(
307
        'nameAuthorPart' => array('#uri' => TRUE),
308
        'referencePart' => TRUE,
309
     )
310
  )
311
));
312
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
313
  array (
314
    'taxon_page_title,polytomousKey'=> array(
315
      'namePart' => array('#uri' => TRUE),
316
    ),
317
    'taxon_page_synonymy,related_taxon'=> array(
318
      'nameAuthorPart' => array('#uri' => TRUE),
319
      'referencePart' => TRUE,
320
      'statusPart' => TRUE,
321
      'descriptionPart' => TRUE,
322
    ),
323
    'homonym'=> array(
324
      'nameAuthorPart' => array('#uri' => TRUE),
325
      'referenceYearPart' => TRUE,
326
    ),
327
    'acceptedFor,typedesignations,list_of_taxa' => array(
328
      'nameAuthorPart' => array('#uri' => TRUE),
329
      'referencePart' => TRUE,
330
    ),
331
    '#DEFAULT' => array(
332
      'nameAuthorPart' => array('#uri' => TRUE),
333
      'referencePart' => TRUE,
334
    )
335
  )
336
));
337

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

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

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

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

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

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

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

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

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

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

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

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

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

    
484
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
485
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
486
  // needs to be merged with user setting by drupal_array_merge_deep()
487
  // 'width' => 512, // optimum size for OSM layers is 512
488
  // 'height' => 512 / 2, // optimum size for OSM layers 256
489
  'aspect_ratio' => 2,
490
  'bbox' => '', // empty to allow automatic zooming to extend
491
  'maxZoom' => 15, // corresponds to the default in cdm_openlayers_map.defaults
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
      'untiled' => FALSE
518
    ),
519
    'wms_overlay_layer' => array(
520
      'name' => NULL,
521
      'url' => NULL,
522
      'params' =>  NULL,
523
      'untiled' => FALSE
524
    ),
525
    'show_layer_switcher' => TRUE,
526
    'display_outside_max_extent' => FALSE,
527
    'google_maps_api_key' => NULL,
528
  ),
529
  'legend' => array(
530
    'show' => TRUE,
531
    'opacity' => '0.5',
532
    'font_size' => 10,
533
    'font_style' => FALSE,
534
    'icon_width' => 35,
535
    'icon_height' => 15
536
  )
537
)));
538

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

    
559
    // unserialize if nessecary
560
    if(!is_array($default)){
561
      $default = unserialize($default);
562
    }
563
    $variable = variable_get($variable_name, array());
564
    $result = drupal_array_merge_deep($default, $variable);
565
    return $result;
566
}
567

    
568
/**
569
 * @todo document this function.
570
 */
571
function getGallerySettings($gallery_config_form_name) {
572
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
573
}
574

    
575
/**
576
 * Returns the string representation of the default tab.
577
 *
578
 * @param bool $returnTabIndex
579
 *   Defaults to FALSE, if set true this function will return the index number
580
 *   of the default tab. (used to supply default values to form elements).
581
 */
582
function get_default_taxon_tab($returnTabIndex = FALSE) {
583

    
584
  global $user;
585
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
586
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
587
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
588
  // Get the user value if the used has chosen to overwrite the system settings.
589
  $user_tab_on = variable_get($user_tab_active, FALSE);
590
  if ($user_tab_on) {
591
    $user_value = variable_get($user_tab, 0);
592
    $index_value = $user_value;
593
    // Get the system value.
594
  }
595
  else {
596
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
597
    $index_value = $system_value;
598
  }
599

    
600
  // Return the index value or the string representation.
601
  if ($returnTabIndex) {
602
    return $index_value;
603
  }
604
  else {
605
    return ($values[$index_value]);
606
  }
607
}
608

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

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

    
680
  // ---- DEFAULTS settings
681

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

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

    
753
  // ---- Special DEFAULTS for existing portals
754
  // TODO:
755
  // this can be removed once the feature block
756
  // settings have been deployed for the first time to these portals
757

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

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

    
845
  $cyprus_default = $cichorieae_default;
846
  $cyprus_default[UUID_DISTRIBUTION] = array(
847
    'as_list' => 'div', // currently ignored
848
    'link_to_reference' => 0,
849
    'link_to_name_used_in_source' => 0,
850
    'sources_as_content' => 0,
851
    'sources_as_content_to_bibliography' => 0,
852
    'sort_elements' => NO_SORT, // will cause ...
853
    'glue' => ' ',
854
    'element_tag' => 'div',
855
    'special' => array()
856
  );
857

    
858
  $default_theme = variable_get('theme_default', NULL);
859

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

    
884
  // ---- END of DEFAULTS
885

    
886
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
887

    
888
  $feature_block_setting = null;
889

    
890
  if (isset($saved_settings[$feature_uuid])) {
891
    $feature_block_setting = $saved_settings[$feature_uuid];
892
  }
893
  else if (isset($settings_for_theme[$feature_uuid])) {
894
    $feature_block_setting = $settings_for_theme[$feature_uuid];
895
  }
896
  else if (isset($settings_for_theme['DEFAULT'])) {
897
    $feature_block_setting = $settings_for_theme['DEFAULT'];
898
  }
899

    
900
  // now merge the default and specific settings
901
  $settings_to_merge = array($default['DEFAULT']);
902
  if(is_array($saved_settings)){
903
    $settings_to_merge[] = $saved_settings['DEFAULT'];
904
  }
905
  if(isset($feature_block_setting)){
906
    $settings_to_merge[] = $feature_block_setting;
907
  }
908
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
909

    
910
  return $feature_block_setting;
911
}
912

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

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

    
969
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
970
    'title' => 'Cache',
971
    'description' => 'Cache',
972
    'access arguments' => array('administer cdm_dataportal'),
973
    'page callback' => 'drupal_get_form',
974
    'page arguments' => array('cdm_settings_cache'),
975
    'weight' => 10,
976
    'type' => MENU_LOCAL_TASK,
977
  );
978

    
979
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
980
    'title' => 'Geo & Map',
981
    'description' => 'Geo & Map',
982
    'access arguments' => array('administer cdm_dataportal'),
983
    'page callback' => 'drupal_get_form',
984
    'page arguments' => array('cdm_settings_geo'),
985
    'weight' => 1,
986
    'type' => MENU_LOCAL_TASK,
987
  );
988

    
989
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
990
    'title' => 'Layout',
991
    'description' => 'Configure and adjust the layout of your DataPortal ',
992
    'access arguments' => array('administer cdm_dataportal'),
993
    'page callback' => 'drupal_get_form',
994
    'page arguments' => array('cdm_settings_layout'),
995
    'weight' => 2,
996
    'type' => MENU_LOCAL_TASK,
997
  );
998

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

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

    
1041
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1042
    'title' => 'Media',
1043
    'description' => 'Configure and adjust the layout of your DataPortal ',
1044
    'access arguments' => array('administer cdm_dataportal'),
1045
    'page callback' => 'drupal_get_form',
1046
    'page arguments' => array('cdm_settings_layout_media'),
1047
    'weight' => 3,
1048
    'type' => MENU_LOCAL_TASK,
1049
  );
1050

    
1051
}
1052

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

    
1071
/**
1072
 * Configures the settings form for the CDM-API module.
1073
 *
1074
 * @return array
1075
 *   Drupal settings form.
1076
 */
1077
function cdm_settings_general() {
1078

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

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

    
1097
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1098
    '#type' => 'markup',
1099
    '#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')
1100
      . ' visible only for administrators',
1101
  );
1102

    
1103
  $form['cdm_webservice']['freetext_index'] = array(
1104
    '#type' => 'fieldset',
1105
    '#title' => t('Freetext index'),
1106
    '#collapsible' => FALSE,
1107
    '#collapsed' => FALSE,
1108
  );
1109

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

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

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

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

    
1171
  $form['cdm_webservice']['proxy'] = array(
1172
    '#type' => 'fieldset',
1173
    '#title' => t('Proxy'),
1174
    '#collapsible' => TRUE,
1175
    '#collapsed' => TRUE,
1176
  );
1177

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

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

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

    
1199
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1200
    '#type' => 'textfield',
1201
    '#title' => t('Password') . ':',
1202
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1203
  );
1204

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

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

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

    
1242
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1243
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1244
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1245
      '#type' => 'checkboxes',
1246
      '#title' => t('Included Classifications') . ':',
1247
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1248
      '#options' => cdm_get_taxontrees_as_options(),
1249
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1250
  );
1251

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

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

    
1286
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1287
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1288
      '#type' => 'checkboxes',
1289
      '#title' => 'Filter rules',
1290
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1291
      '#options' => array(
1292
          'statusOrderPreference' => 'Status order preference rule',
1293
          'subAreaPreference' => 'Sub area preference rule'
1294
      ),
1295
  );
1296

    
1297
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1298
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1299
      '#type' => 'checkboxes',
1300
      '#title' => 'Hide marked area filter',
1301
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1302
      '#options' => $marker_type_options,
1303
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1304
  );
1305

    
1306
  $form['aggregation'] = array(
1307
      '#type' => 'fieldset',
1308
      '#title' => t('Aggregation of data'),
1309
      '#collapsible' => FALSE,
1310
      '#description' => 'This section covers the different aspects of aggregating information.
1311
          <p>
1312
          </p>',
1313
  );
1314

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

    
1327
  $form['aggregation']['notice'] = array(
1328
      '#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
1329
          want to make use of the caching capabilities of the dataportal.',
1330
  );
1331

    
1332
  $form['aggregation']['media_aggregation'] = array(
1333
      '#type' => 'fieldset',
1334
      '#title' => t('Media aggregation'),
1335
      '#collapsible' => FALSE,
1336
      '#collapsed' => TRUE,
1337
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1338

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

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

    
1365
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1366
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1367

    
1368
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1369
      '#type' => 'checkboxes',
1370
      '#title' => t('Direct'),
1371
      '#options' => $taxonRelationshipTypeOptions,
1372
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1373
  );
1374
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1375
      '#type' => 'checkboxes',
1376
      '#title' => t('Invers'),
1377
      '#options' => $taxonRelationshipTypeOptions,
1378
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1379
  );
1380

    
1381
  $form['drupal_integration'] = array(
1382
    '#type' => 'fieldset',
1383
    '#attributes' => array('class'=> array('clearfix')),
1384
    '#title' => t('Drupal integration'),
1385
    '#collapsible' => FALSE,
1386
    '#collapsed' => FALSE,
1387
    '#tree' => FALSE
1388
  );
1389

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

    
1399

    
1400

    
1401
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1402
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1403
    <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>',
1404
  );
1405
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1406
    '#type' => 'submit',
1407
    '#value' => t('Drop all cdm nodes'),
1408
    '#submit' => array('drop_all_cdm_nodes_submit')
1409
  );
1410

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

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

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

    
1447
  $form['#submit'][] = 'cdm_settings_general_submit';
1448

    
1449
  return system_settings_form($form);
1450
}
1451

    
1452
/**
1453
 * Submit callback; drops all cdm nodes.
1454
 *
1455
 * @ingroup forms
1456
 */
1457
function drop_all_cdm_nodes_submit($form, &$form_state) {
1458
  cdm_delete_all_cdm_nodes();
1459
  drupal_set_message(t('All cdm nodes dropped.'));
1460
}
1461

    
1462

    
1463
/**
1464
 * LAYOUT settings
1465
 * @return
1466
 *   todo
1467
 */
1468
function cdm_settings_layout() {
1469

    
1470
  $form = array();
1471

    
1472
  $form['about'] = array(
1473
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1474
      layout. If you want to configure the specific sites layout visit the
1475
      respective configuration site for taxon, search or media.') . '</p>',
1476
  );
1477

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

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

    
1496
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1497
    '#type' => 'checkbox',
1498
    '#title' => t('Do not show annotation footnotes'),
1499
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1500
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1501
  );
1502

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

    
1518
  // ---- original source --- //
1519
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1520
      '#type' => 'fieldset',
1521
      '#tree' => TRUE,
1522
      '#title' => t('Source Citations'),
1523
      '#collapsible' => FALSE,
1524
      '#collapsed' => FALSE,
1525
  );
1526

    
1527
  $bibliography_settings = get_bibliography_settings(true);
1528

    
1529
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1530
      '#type' => 'checkbox',
1531
      '#title' => t('Original Source in bibliography'),
1532
      '#default_value' => $bibliography_settings['enabled'],
1533
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1534
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1535
       into the bibliography also depends on the settings in the ' .
1536
        l("Taxon profile feature block settings", "settings/layout/taxon") .
1537
        '. For more information please refer to the description on the settings "<em>Sources as content</em>" & "<em>Sources as content to bibliography</em>" in that settings page.'),
1538
  );
1539

    
1540
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1541
    '#type' => 'select',
1542
    '#title' => t('The format of the key numerals'),
1543
    '#default_value' => $bibliography_settings['key_format'],
1544
    '#options' => array('latin' => 'Latin',
1545
      'ROMAN' => 'Roman (upper case)',
1546
      'roman' => 'Roman (lower case)',
1547
      'ALPHA'=> 'Alphabet (upper case)',
1548
      'alpha' => 'Alphabet (lower case)')
1549
  );
1550

    
1551
  // --- Advanced Search --- //
1552
  $form['asearch'] = array(
1553
      '#type' => 'fieldset',
1554
      '#title' => t('Advanced search'),
1555
      '#collapsible' => FALSE,
1556
      '#collapsed' => FALSE,
1557
  );
1558
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1559
      '#type' => 'checkbox',
1560
      '#title' => t('Show advanced search link'),
1561
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1562
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1563
  );
1564

    
1565
  // ---- Taxon Name Rendering --- //
1566
  $form['taxon_name'] = array(
1567
      '#type' => 'fieldset',
1568
      '#title' => t('Taxon name display'),
1569
      '#collapsible' => TRUE,
1570
      '#collapsed' => TRUE,
1571
      '#description' => t('The display of taxon names is configured by two parts.
1572
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1573
          The name parts are defined in the <stong>part definitions</strong>'),
1574
  );
1575

    
1576
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1577
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1578
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1579
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1580

    
1581
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1582
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1583
    $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.)';
1584
  } else if($is_custom_part_definition){
1585
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1586
  } else  {
1587
    $which_version_message = '(These are the default part definition.)';
1588
  }
1589

    
1590
  $diff_viewer_markup = '';
1591
  if($is_custom_part_definition){
1592
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1593
  }
1594

    
1595
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1596
    . $which_version_message
1597
    . '</div>'
1598
    . $diff_viewer_markup;
1599

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

    
1689
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1690
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1691
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1692
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1693
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1694

    
1695
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1696
    $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.)';
1697
  } else if($is_custom_render_template){
1698
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1699
  } else {
1700
    $which_version_message = '(These are the default render templates.)';
1701
  }
1702

    
1703
  $diff_viewer_markup = '';
1704
  if($is_custom_render_template){
1705
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1706
  }
1707

    
1708
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1709
    . $which_version_message
1710
    . '</div>'
1711
    . $diff_viewer_markup;
1712

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

    
1753
  // @WA: D7 form api does not support reset buttons,
1754
  // so to mimic the D5 reset button we add one like this.
1755
  $form['actions']['reset'] = array(
1756
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1757
    '#weight' => 1000,
1758
  );
1759

    
1760
  $form['#submit'] = array('submit_json_as_php_array');
1761
  // #json_elements especially defined for submit_json_as_php_array()
1762
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1763
  return system_settings_form($form);
1764
}
1765

    
1766

    
1767
/**
1768
 * @param $form_name
1769
 * @param $form_title
1770
 * @param $collapsed
1771
 * @param string $form_description
1772
 *   The description for the fieldset of the gallery setting.
1773
 * @return mixed
1774
 */
1775
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1776
  $form[$form_name] = array(
1777
    '#type' => 'fieldset',
1778
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1779
    '#collapsible' => TRUE,
1780
    '#collapsed' => $collapsed,
1781
    '#tree' => TRUE,
1782
    '#description' => $form_description,
1783
  );
1784

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

    
1804
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1805
      '#type' => 'checkbox',
1806
      '#title' => t('Show media thumbnails for synonyms'),
1807
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1808
      '#description' => '',
1809
    );
1810
  }
1811

    
1812
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1813
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1814
    '#type' => 'checkbox',
1815
    '#title' => t('Show captions under thumbnails'),
1816
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1817
    '#description' => '',
1818
  );
1819

    
1820
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1821
    '#type' => 'textfield',
1822
    '#title' => t('Thumbnail size') . ':',
1823
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1824
    '#description' => t('Select the size of each individual thumbnail.'),
1825
  );
1826

    
1827
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1828
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1829
      '#type' => 'textfield',
1830
      '#title' => t('Number of columns') . ':',
1831
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1832
      '#description' => t('Group the thumbnails in columns: select how many
1833
        columns the gallery should display.'),
1834
    );
1835
  }
1836

    
1837
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1838
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1839
      '#type' => 'textfield',
1840
      '#title' => t('Maximum number of rows') . ':',
1841
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1842
      '#description' => t('You can group the thumbnails in rows, select in how
1843
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1844
        If you want an unlimited number of rows please set to 0.'),
1845
    );
1846
  }
1847

    
1848
  return $form;
1849
}
1850

    
1851
/**
1852
 * @todo document this function.
1853
 */
1854
function cdm_settings_layout_taxon() {
1855
  $collapsed = FALSE;
1856
  $form = array();
1857

    
1858
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1859

    
1860
  // --------- TABBED TAXON ------- //
1861
  $form['taxon_tabs'] = array(
1862
    '#type' => 'fieldset',
1863
    '#title' => t('Taxon tabs'),
1864
    '#collapsible' => TRUE,
1865
    '#collapsed' => TRUE,
1866
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1867
      be splitted in four diferent tabs; General, Synonymy, Images and
1868
      Specimens. If the taxon has no information for any of the tabs/sections
1869
      such tab will be not displayed.'),
1870
  );
1871

    
1872
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1873
    '#type' => 'checkbox',
1874
    '#title' => t('Tabbed taxon page'),
1875
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1876
    '#description' => t('<p>If selected split the taxon page into individual
1877
      tabs for description, images, synonymy and specimens. If not the taxon
1878
      data is rendered as a long single page without tabs.</p>'),
1879
  );
1880

    
1881
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1882
    '#type' => 'checkboxes',
1883
    '#title' => t('Tabs visibility options') . ':',
1884
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1885
    '#options' => get_taxon_options_list(),
1886
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1887
  );
1888

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

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

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

    
1942
  /* ======  TAXON_PROFILE ====== */
1943
  $form['taxon_profile'] = array(
1944
    '#type' => 'fieldset',
1945
    '#title' => t('Taxon profile (tab)'),
1946
    '#description' => t('<p>This section covers the settings related to the taxon
1947
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1948
    '#collapsible' => TRUE,
1949
    '#collapsed' => TRUE,
1950
  );
1951

    
1952
  // ---- PROFILE PICTURE ----//
1953

    
1954
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1955
    '#type' => 'fieldset',
1956
    '#tree' => TRUE,
1957
    '#title' => t('Taxon profile picture'),
1958
    '#collapsible' => TRUE,
1959
    '#collapsed' => FALSE,
1960
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1961
  );
1962

    
1963
  //FIXME migrate variables:
1964
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1965
  // FIXME
1966
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1967

    
1968
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1969

    
1970
  /*
1971
   * 'show' => 1,
1972
   * 'maxextend' => 184,
1973
   * 'media_uri_query' => ''
1974
   * 'custom_placeholder_image_on' => 1,
1975
   * 'custom_placeholder_image_fid' => ''
1976
   */
1977
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1978
    '#type' => 'checkbox',
1979
    '#title' => t('Enable profile picture'),
1980
    '#description' => t('Show the profile picture.'),
1981
    '#default_value' => $taxon_profile_image_settings['show'],
1982
  );
1983

    
1984
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1985
      '#type' => 'textfield',
1986
      '#tree' => TRUE,
1987
      '#title' => t('Profile picture maximum extend'),
1988
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1989
      '#field_suffix' => 'px',
1990
      '#maxlength' => 4,
1991
      '#size' => 4,
1992
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
1993
  );
1994

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

    
2008
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2009
    '#type' => 'checkbox',
2010
    '#title' => t('Show the placeholder image'),
2011
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
2012
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2013
  );
2014

    
2015
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2016
      '#type' => 'checkbox',
2017
      '#title' => t('Use a custom placeholder image'),
2018
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2019
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2020
  );
2021

    
2022
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2023
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2024
        '#type' => 'managed_file',
2025
        '#title' => t('Custom placeholder image file'),
2026
        '#progress_indicator' => 'bar',
2027
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2028
    //       '#name' => 'custom_placeholder_image',
2029
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2030
    );
2031

    
2032
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2033
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2034
      $url = file_create_url($profile_image_file->uri);
2035
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2036
                '#type' => 'item',
2037
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2038
      );
2039
    }
2040
  } else {
2041
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2042
      '#type' => 'hidden',
2043
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2044
    );
2045
  }
2046

    
2047
  $options = cdm_rankVocabulary_as_option();
2048
  array_unshift($options, '-- DISABLED --');
2049
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2050
    '#type' => 'select',
2051
    '#title' => t('Hide profile picture for higher ranks') . ':',
2052
    '#default_value' => variable_get('image_hide_rank', '0'),
2053
    '#options' => $options,
2054
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2055
  );
2056

    
2057
  // -- MEDIA THUMBNAILS -- //
2058
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2059
  $form_title = 'Taxon Profile Images';
2060
  $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>';
2061
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2062

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

    
2091
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2092
  $profile_feature_tree = get_profile_feature_tree();
2093

    
2094
  if (isset($profile_feature_tree->root->childNodes)) {
2095

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

    
2135

    
2136
    $feature_list_layout_settings_disabled = FALSE;
2137

    
2138
    // creating helper object to retrieve the default settings
2139
    $featureNode = new stdClass();
2140
    $featureNode->feature = new stdClass();
2141
    $featureNode->feature->uuid="DEFAULT";
2142
    $featureNode->feature->representation_L10n = "Default";
2143
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2144

    
2145
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2146

    
2147
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2148

    
2149
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2150
        $subform_id = $featureNode->feature->uuid;
2151
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2152

    
2153
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2154

    
2155
        $form_feature_block_layout[$subform_id] = array(
2156
          '#type' => 'fieldset',
2157
          '#tree' => TRUE,
2158
          '#title' => $featureNode->feature->representation_L10n,
2159
          '#collapsible' => FALSE,
2160
          '#collapsed' => FALSE,
2161
        );
2162
        if($featureNode->feature->uuid == "DEFAULT"){
2163
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2164
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2165
          references</em> and <em>names in source</em> is only possible in the defaults';
2166
        }
2167

    
2168
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2169
          '#type' => 'select',
2170
          '#title' => 'List type',
2171
          '#default_value' => $feature_block_setting['as_list'],
2172
          '#options' => array(
2173
            'div' => 'not as list',
2174
            'ul' => 'bullet list',
2175
            'ol' => 'numbered list',
2176
            'dl' => 'definition list'
2177
          ),
2178
        );
2179

    
2180
        if($featureNode->feature->uuid == "DEFAULT"){
2181
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2182
            '#type' => 'checkbox',
2183
            '#title' => t('Link to reference'),
2184
            '#default_value' => $feature_block_setting['link_to_reference'],
2185
          );
2186

    
2187
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2188
            '#type' => 'checkbox',
2189
            '#title' => 'Link to name used in source',
2190
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2191
          );
2192
        }
2193

    
2194
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2195
          '#type' => 'checkbox',
2196
          '#title' => 'Sources as content',
2197
          '#default_value' => $feature_block_setting['sources_as_content'],
2198
        );
2199

    
2200
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2201
          '#type' => 'checkbox',
2202
          '#title' => 'Put sources also as content to bibliography',
2203
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2204
        );
2205

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

    
2225
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2226
          '#type' => 'select',
2227
          '#title' => t('Element tag'),
2228
          '#options' => array(
2229
            'span' => 'span',
2230
            'div' => 'div',
2231
            'p' => 'p'
2232
          ),
2233
          '#default_value' => $feature_block_setting['element_tag'],
2234
        );
2235
      }
2236
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2237
    }
2238
  }
2239

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

    
2265

    
2266

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

    
2285
  );
2286

    
2287
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2288

    
2289
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2290
    '#type' => 'checkbox',
2291
    '#title' => t('Condensed distribution'),
2292
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2293
    '#description' => 'This option enables the display of a very compact representation
2294
    of the distribution which includes also information on the status.',
2295
  );
2296

    
2297
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2298
    '#type' => 'select',
2299
    '#title' => t('Condensed distribution recipe'),
2300
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2301
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2302
    '#description' => 'Recipe for creating the condensed distribution.',
2303
  );
2304

    
2305
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2306
    '#type' => 'textfield',
2307
    '#title' => t('Condensed distribution info path'),
2308
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2309
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2310
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2311
  );
2312

    
2313

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

    
2331
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2332
    '#type' => 'fieldset',
2333
    '#tree' => true,
2334
    '#title' => t('Distribution hierarchy style')
2335
  );
2336

    
2337
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2338
  foreach(array_keys($hierarchy_styles) as $level) {
2339
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2340
      '#type' => 'fieldset',
2341
      '#tree' => true,
2342
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2343
      '#attributes' => array('class' => array('fieldset-float'))
2344
    );
2345
    foreach ($hierarchy_styles[$level] as $key => $value) {
2346
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2347
        '#type' => 'textfield',
2348
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2349
        '#default_value' => $hierarchy_styles[$level][$key],
2350
        '#maxlength' => 4,
2351
        '#size' => 4
2352
      );
2353
    }
2354
  }
2355

    
2356
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2357
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2358
    '#type' => 'checkboxes',
2359
    '#title' => 'Omit area levels',
2360
    '#options' => $level_options,
2361
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2362
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2363
    Areas which belong to the selected area levels will be hidden in the portal.',
2364
  );
2365

    
2366
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2367
    '#type' => 'checkbox',
2368
    '#title' => t('Show TextData elements on top of the map'),
2369
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2370
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2371
      elements on top of the map. Otherwise all <code>TextData</code>
2372
      distribution elements will be listed below the other area elements.
2373
      This option is useful if you need to have descriptive texts for each
2374
      distribution map.'),
2375
  );
2376

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

    
2404
AbsenceTerm
2405
a	absent
2406
f	reported in error
2407
nf	native: reported in error
2408
if	introduced: reported in error
2409
cf	cultivated: reported in error
2410
ne	native: formerly native
2411
ie	introduced: formerly introduced
2412

    
2413
</pre>'),
2414
  );
2415

    
2416

    
2417
  /* ====== SYNONYMY ====== */
2418
  $form['taxon_synonymy'] = array(
2419
    '#type' => 'fieldset',
2420
    '#title' => t('Taxon synonymy (tab)'),
2421
    '#collapsible' => TRUE,
2422
    '#collapsed' => TRUE,
2423
    '#description' => t('This section covers the settings related to the taxon
2424
      <strong>synonymy</strong> tab.'),
2425
  );
2426

    
2427
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2428
    '#type' => 'checkbox',
2429
    '#title' => t('Show accepted taxon on top of the synonymy'),
2430
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2431
    '#description' => t('If checked, the first homotypic taxon is a repetition
2432
      of the accepted taxon most likely with the full nomenclatural reference
2433
      (depending on the currently chosen theme).'),
2434
  );
2435

    
2436
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2437
    '#type' => 'checkbox',
2438
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2439
      coming from a synonym link.'),
2440
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2441
    '#description' => t('Check this if after doing a search and clicking on a
2442
      synonym you want to see the "accept of" text for the accepted synonym.'),
2443
  );
2444

    
2445
  /* === currently unused ===
2446
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2447
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2448
    '#type' => 'checkboxes',
2449
    '#title' => t('Display name relationships') . ':',
2450
    '#default_value' => variable_get('name_relationships_to_show', 0),
2451
    '#options' => $nameRelationshipTypeOptions,
2452
    '#description' => t('Select the name relationships you want to show for the
2453
      accepted taxa.'),
2454
  );
2455
 */
2456

    
2457
  $form['taxon_synonymy']['taxon_relations'] = array(
2458
    '#type' => 'fieldset',
2459
    '#title' => t('Taxon relationships'),
2460
    '#collapsible' => FALSE,
2461
    '#collapsed' => FALSE
2462
  );
2463

    
2464
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2465
    '#type' => 'checkbox',
2466
    '#title' => t('Show taxon relations ships of accepted taxon'),
2467
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2468
    '#description' => t('If this option is enabled the synonymy will show the
2469
      below selected taxon relationships of accepted taxa.'),
2470
  );
2471

    
2472
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2473
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2474
    '#type' => 'checkboxes',
2475
    '#title' => t('Taxon relationship types') . ':',
2476
    '#description' => t('Only taxon relationships of the selected type will be
2477
      displayed'),
2478
    '#options' => $taxonRelationshipTypeOptions,
2479
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2480
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2481
  );
2482

    
2483
  $form['taxon_synonymy']['name_relations'] = array(
2484
    '#type' => 'fieldset',
2485
    '#title' => t('Name relationships'),
2486
    '#collapsible' => FALSE,
2487
    '#collapsed' => FALSE
2488
  );
2489

    
2490
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2491
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2492
    '#type' => 'checkboxes',
2493
    '#title' => t('Name relationship types') . ':',
2494
    '#description' => t('Only name relationships of the selected type will be
2495
      displayed'),
2496
    '#options' => $taxonRelationshipTypeOptions,
2497
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2498
  );
2499

    
2500
  // ====== SPECIMENS ====== //
2501
  $form['taxon_specimens'] = array(
2502
    '#type' => 'fieldset',
2503
    '#title' => t('Taxon specimens (tab)'),
2504
    '#collapsible' => TRUE,
2505
    '#collapsed' => TRUE,
2506
    '#description' => t('This section covers the settings related to the taxon
2507
      <strong>specimens</strong> tab.'),
2508
  );
2509

    
2510
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2511

    
2512
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2513
    '#type' => 'checkbox',
2514
    '#title' => t('Show specimen derivatives in a compressed table'),
2515
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2516
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2517
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2518
  );
2519

    
2520
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2521
        '#type' => 'textfield',
2522
        '#title' => t('Number of records per page') . ':',
2523
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2524
    );
2525

    
2526
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2527
    '#type' => 'checkbox',
2528
    '#title' => t('Show "Associated with" in specimen table.'),
2529
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2530
  );
2531

    
2532
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2533
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2534
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2535
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2536
  }
2537
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2538
    '#type' => 'radios',
2539
    '#title' => t('Specimen description feature tree') . ':',
2540
    '#default_value' => $profile_feature_tree_uuid,
2541
    '#options' =>  $featureTrees['options'],
2542
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2543
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2544
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2545
    ),
2546
  );
2547

    
2548
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2549
  $form_title = t('Specimen media');
2550
  $form_description = t('Specimens may have media which is displayed at the
2551
     Specimen tab/section as a gallery. It is possible to configure the
2552
     thumbnails gallery here, however for configuring how a single media should
2553
     be displayed please go to !url.</p>',
2554
     array(
2555
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2556
     ));
2557
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2558

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

    
2570
  // Comment @WA: D7 form api does not support reset buttons,
2571
  // so to mimic the D5 reset button we add one like this.
2572
  $form['actions']['reset'] = array(
2573
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2574
    '#weight' => 1000,
2575
  );
2576
  return system_settings_form($form);
2577
}
2578

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

    
2598
/**
2599
 * @todo document this function.
2600
 */
2601
function cdm_settings_layout_search() {
2602

    
2603
  $form = array();
2604

    
2605
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2606

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

    
2618
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2619
      '#type' => 'checkbox',
2620
      '#title' => t('Ignore the chosen classification in simple search'),
2621
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2622
      '#description' => t('The simple search, which can be executed via the search block,
2623
          will by default search on the classification selected in the classification browser
2624
          selector. Set the tick if you want your portal to search on all classifications.'),
2625
  );
2626

    
2627
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2628
    '#type' => 'checkbox',
2629
    '#title' => t('Run simple search with free-text search backend.'),
2630
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2631
    '#description' => t('The simple search uses by default another search
2632
      backend as the advances search. By checking this option the simple search can be
2633
      configured to also use the free-text search backend.'),
2634
  );
2635

    
2636
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2637
    '#type' => 'textfield',
2638
    '#title' => t('Results per page') . ':',
2639
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2640
    '#description' => t('Number of results to display per page.'),
2641
  );
2642

    
2643
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2644
    '#type' => 'checkbox',
2645
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2646
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2647
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2648
  );
2649

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

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

    
2667
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2668
  );
2669

    
2670
  // --- SEARCH TAXA GALLERY ---- //
2671
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2672
  $collapsed = FALSE;
2673
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2674
  $form_title = 'Taxa Search thumbnails';
2675
  $form_description = 'Search results may show thumbnails. ';
2676
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2677

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

    
2687
/**
2688
 * @todo document this function.
2689
 */
2690
function cdm_settings_layout_media() {
2691

    
2692
  $form = array();
2693

    
2694
  $form['media_settings'] = array(
2695
    '#type' => 'fieldset',
2696
    '#title' => t('Media settings'),
2697
    '#collapsible' => FALSE,
2698
    '#collapsed' => FALSE,
2699
    '#description' => 'This section covers layout settings for media pages.'
2700
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2701
  );
2702

    
2703
  $form['media_settings']['image_gallery_viewer'] = array(
2704
    '#type' => 'select',
2705
    '#title' => t('Image viewer') . ':',
2706
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2707
    '#options' => array(
2708
      'default' => t('Standard image viewer'),
2709
      'fsi' => t('FSI viewer (requires FSI server!)'),
2710
    ),
2711
  );
2712

    
2713
  // --- MEDIA GALLERY ---- //
2714
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2715
  $form_title = 'Standard viewer';
2716
  $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>';
2717
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2718
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2719

    
2720
  // @WA: D7 form api does not support reset buttons,
2721
  // so to mimic the D5 reset button we add one like this.
2722
  $form['actions']['reset'] = array(
2723
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2724
    '#weight' => 1000,
2725
  );
2726
  return system_settings_form($form);
2727
}
2728

    
2729
/**
2730
 * GEOSERVICE and Map settings.
2731
 */
2732
function cdm_settings_geo($form, &$form_state) {
2733

    
2734
  $current_geoserver_settings = get_edit_map_service_settings();
2735
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2736

    
2737

    
2738
  $form = array();
2739

    
2740
  $dummy_distribution_query = NULL;
2741
  if($map_distribution['map_type'] != 1){
2742
    // we need to apply a dummy query since the map service requires for image maps
2743
    // at least as and ad to be defined
2744
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2745
  }
2746

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

    
2763
  /*
2764
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2765
  );
2766
  */
2767

    
2768
  /*
2769
   * GEO SERVER
2770
   */
2771
  $form['edit_map_server'] = array(
2772
    '#type' => 'fieldset',
2773
    '#tree' => true,
2774
    '#title' => t('EDIT map service'),
2775
    '#collapsible' => TRUE,
2776
    '#collapsed' => TRUE,
2777
    '#description' => t('Configuration and selection of your geo server.
2778
      The Geo Server is responsible for generating the maps.'),
2779
  );
2780

    
2781
  $form['edit_map_server']['base_uri'] = array(
2782
    '#type' => 'select',
2783
    '#title' => t('EDIT map service') . ':',
2784
    '#default_value' => $current_geoserver_settings['base_uri'],
2785
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2786
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2787
  );
2788
  $form['edit_map_server']['version'] = array(
2789
      '#type' => 'select',
2790
      '#title' => t('Version') . ':',
2791
      '#default_value' => $current_geoserver_settings['version'],
2792
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2793
      '#description' => t('The version of the EDIT map services'),
2794
  );
2795

    
2796
  /*
2797
   * MAP SETTINGS
2798
   */
2799

    
2800
  $form[CDM_MAP_DISTRIBUTION] = array(
2801
    '#type' => 'fieldset',
2802
    '#tree' => TRUE,
2803
    '#title' => t('Maps settings'),
2804
    '#collapsible' => TRUE,
2805
    '#collapsed' => TRUE,
2806
    '#description' => t('General configuration for all map types.'),
2807
  );
2808

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

    
2826
  /*
2827
   * settings for the distribution map are used also for specimens map!!!!
2828
   */
2829

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

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

    
2858
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
2859
    '#type' => 'select',
2860
    '#title' => 'Max zoom level',
2861
    '#default_value' => $map_distribution['maxZoom'],
2862
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
2863
  );
2864

    
2865
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2866
    '#type' => 'checkbox',
2867
    '#title' => 'Display area labels',
2868
    '#default_value' => $map_distribution['show_labels'],
2869
    '#description' => t('The map will show name labels of the areas'),
2870
  );
2871

    
2872
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2873
    '#type' => 'textfield',
2874
    '#title' => 'Map caption',
2875
    '#default_value' => $map_distribution['caption'],
2876
    '#description' => t('The caption will be shown below the map.'),
2877
  );
2878

    
2879
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2880
    '#type' => 'textfield',
2881
    '#title' => 'Distribution layer opacity',
2882
    '#default_value' => $map_distribution['distribution_opacity'],
2883
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2884
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2885
  );
2886

    
2887
  // --- Plain Image Settings --- //
2888
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2889
    '#type' => 'fieldset',
2890
    '#title' => 'Plain image map settings',
2891
    '#tree' => TRUE,
2892
    '#collapsible' => TRUE,
2893
    '#collapsed' => $open_layers_is_enabled,
2894
    '#description' => 'The settings in this section are still expertimental
2895
      and can only be used with the EDIT map service version 1.1 or above.',
2896
  );
2897
  $edit_mapserver_version = get_edit_map_service_version_number();
2898
  if ($edit_mapserver_version < 1.1) {
2899
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2900
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2901
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2902
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2903
  }
2904

    
2905
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2906
    '#type' => 'textfield',
2907
    '#title' => 'Width',
2908
    '#default_value' => $map_distribution['image_map']['width'],
2909
    '#maxlength' => 4,
2910
    '#size' => 4,
2911
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2912
  );
2913

    
2914
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2915
    '#type' => 'textfield',
2916
    '#title' => 'Background layer',
2917
    '#default_value' => $map_distribution['image_map']['base_layer'],
2918
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2919
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2920
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2921
    )),
2922
  );
2923

    
2924
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2925
    '#type' => 'textfield',
2926
    '#title' => 'Background color',
2927
    '#default_value' => $map_distribution['image_map']['bg_color'],
2928
  );
2929

    
2930
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2931
    '#type' => 'textfield',
2932
    '#title' => 'Background layer style',
2933
     // Only line color by now.
2934
    '#default_value' => $map_distribution['image_map']['layer_style'],
2935
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2936
  );
2937

    
2938
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2939
      '#type' => 'textfield',
2940
      '#title' => 'Projection',
2941
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2942
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2943
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2944
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2945
  );
2946

    
2947

    
2948
  // --- OpenLayers Settings --- //
2949
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2950
    '#type' => 'fieldset',
2951
    '#title' => 'OpenLayers settings',
2952
    '#tree' => TRUE,
2953
    '#collapsible' => TRUE,
2954
    '#collapsed' => !$open_layers_is_enabled,
2955
    '#description' => '',
2956
  );
2957

    
2958

    
2959
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2960
      '#type' => 'checkbox',
2961
      '#title' => 'Display outside max extent',
2962
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2963
      '#description' => t('Allows the map to display parts of the layers which are outside
2964
         the max extent if the aspect ratio of the map and of the baselayer
2965
         are not equal.'),
2966
  );
2967

    
2968

    
2969
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2970
      '#type' => 'checkbox',
2971
      '#title' => 'Show Layer Switcher',
2972
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2973
      '#description' => 'The Layer Switcher control displays a table of contents
2974
      for the map.  This allows the user interface to switch between
2975
      base layers and to show or hide overlays.  By default the switcher is
2976
      shown minimized on the right edge of the map, the user may expand it
2977
      by clicking on the handle.',
2978
  );
2979

    
2980
  if (!$open_layers_is_enabled) {
2981
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2982
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2983
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2984
  }
2985

    
2986
  // The default layer must always be enabled
2987
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2988
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2989

    
2990
  $baselayer_options = array(
2991
    /*
2992
   NOTICE: must correspond to the layers defined in
2993
   js/openlayers_,ap.js#getLayersByName()
2994
   */
2995
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
2996
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
2997
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
2998
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
2999
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3000
    // all others EPSG:900913
3001
    'mapnik' => 'OpenStreetMap (mapnik)',
3002
    'stamen_terrain' => 'Stamen Terrain',
3003
    'open_topomap' => 'OpenTopoMap',
3004
    // map quest is no longer free. it is required to sign up for a test plan.
3005
    // 'mapquest_open' => "MapQuest",
3006
    // 'mapquest_sat' => "MapQuest Sattelite",
3007
    'groadmap' => 'Google Roadmap',
3008
    'gsatellite' => 'Google Satellite',
3009
    'ghybrid' => 'Google Hybrid',
3010
    'gterrain' => 'Google Terrain',
3011
//     'veroad' => 'Virtual Earth Roads',
3012
//     'veaer' => 'Virtual Earth Aerial',
3013
//     'vehyb' => 'Virtual Earth Hybrid',
3014
    // 'yahoo' => 'Yahoo Street',
3015
    // 'yahoosat' => 'Yahoo Satellite',
3016
    // 'yahoohyb' => 'Yahoo Hybrid',
3017
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3018
  );
3019

    
3020
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3021
    '#type' => 'checkboxes_preferred',
3022
    '#title' => 'Base Layers',
3023
    '#options' => $baselayer_options,
3024
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3025
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3026
  );
3027

    
3028
  $google_maps_api_key = null;
3029
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3030
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3031
  }
3032
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3033
    '#type' => 'textfield',
3034
    '#title' => 'Google Maps API Key',
3035
    '#default_value' => $google_maps_api_key,
3036
    '#description' => 'In order to use any of the Google map layers you need to provide 
3037
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3038
  );
3039

    
3040
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3041
    $map_distribution['openlayers']['custom_wms_base_layer'],
3042
    'Custom WMS base layer',
3043
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3044
    true // add projection settings
3045
    );
3046

    
3047
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3048
    $map_distribution['openlayers']['wms_overlay_layer'],
3049
    'WMS overlay layer',
3050
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3051
                You can actually combine multiple layers for this overlay. 
3052
                For details please refer to the wms query parameter <code>Layers</code> .'
3053
  );
3054

    
3055
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3056
    '#type' => 'checkbox',
3057
    '#title' => 'Enable overlay layer',
3058
    '#weight' => -100,
3059
    '#default_value' => $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3060
  );
3061

    
3062
  /*
3063
   * Map Legend
3064
   */
3065
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3066
    '#type' => 'fieldset',
3067
    '#title' => 'Map legend',
3068
    '#tree' => TRUE,
3069
    '#collapsible' => TRUE,
3070
    '#collapsed' => TRUE,
3071
    '#description' => 'Configure the maps legend.',
3072
  );
3073

    
3074
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3075
    '#type' => 'checkbox',
3076
    '#title' => 'Display a map legend',
3077
    '#default_value' => $map_distribution['legend']['show'],
3078
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3079
  );
3080

    
3081
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3082
    '#type' => 'textfield',
3083
    '#title' => 'Legend opacity',
3084
    '#default_value' => $map_distribution['legend']['opacity'],
3085
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3086
                         to 0.0 will be not much visible.',
3087
  );
3088

    
3089
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3090
    '#type' => 'textfield',
3091
    '#title' => 'Font size',
3092
    '#default_value' => $map_distribution['legend']['font_size'],
3093
    '#description' => 'Font size in pixels.',
3094
  );
3095

    
3096
  $fontStyles = array(
3097
    0 => "plane",
3098
    1 => "italic",
3099
  );
3100
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3101
    '#type' => 'select',
3102
    '#title' => 'Available font styles',
3103
    '#default_value' => $map_distribution['legend']['font_style'],
3104
    '#options' => $fontStyles,
3105
    '#description' => 'Select a font style for the map legend.',
3106
  );
3107

    
3108
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3109
    '#type' => 'textfield',
3110
    '#title' => 'Icon width',
3111
    '#default_value' => $map_distribution['legend']['icon_width'],
3112
    '#description' => 'Legend icon width in pixels.',
3113
  );
3114
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3115
    '#type' => 'textfield',
3116
    '#title' => 'Icon height',
3117
    '#default_value' => $map_distribution['legend']['icon_height'],
3118
    '#description' => 'Legend icon height in pixels.',
3119
  );
3120

    
3121
  // @WA: D7 form api does not support reset buttons,
3122
  // so to mimic the D5 reset button we add one like this.
3123
  $form['actions']['reset'] = array(
3124
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3125
    '#weight' => 1000,
3126
  );
3127

    
3128
  return system_settings_form($form);
3129
}
3130

    
3131
/**
3132
 * @param $default_settings
3133
 * @param $title
3134
 * @param $description
3135
 * @param bool $add_projection_settings
3136
 * @return array
3137
 */
3138
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3139
{
3140
  $form_elements = array(
3141
    '#type' => 'fieldset',
3142
    '#title' => $title,
3143
    '#tree' => TRUE,
3144
    '#collapsible' => FALSE,
3145
    '#collapsed' => FALSE,
3146
    '#description' => $description,
3147
  );
3148

    
3149
  $form_elements['name'] = array(
3150
    '#type' => 'textfield',
3151
    '#title' => 'Layer name',
3152
    '#default_value' => $default_settings['name'],
3153
    '#description' => 'A arbitrary name for the layer.',
3154
  );
3155
  $form_elements['url'] = array(
3156
    '#type' => 'textfield',
3157
    '#title' => 'WMS url',
3158
    '#default_value' => $default_settings['url'],
3159
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3160
  );
3161
  $form_elements['untiled'] = array(
3162
    '#type' => 'checkbox',
3163
    '#title' => 'Untiled',
3164
    '#default_value' => $default_settings['untiled'],
3165
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3166
  );
3167
  $form_elements['params'] = array(
3168
    '#type' => 'textarea',
3169
    '#title' => 'WMS parameters',
3170
    '#element_validate' => array('form_element_validate_json'),
3171
    '#default_value' => $default_settings['params'],
3172
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3173
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3174
      . '), entered in valid JSON. For example:
3175
<pre> {
3176
  "Layers": "topp:em_tiny_jan2003",
3177
  "Format": "image/png",
3178
  "BGCOLOR": "0xe0faff"
3179
}
3180
</pre>
3181
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3182
  );
3183

    
3184
  if($add_projection_settings){
3185

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

    
3251
  }
3252
  return $form_elements;
3253
}
3254

    
3255

    
3256
/**
3257
 * @todo document this function.
3258
 */
3259
function cdm_settings_cache() {
3260

    
3261
  $form = array();
3262

    
3263
  $form['cache_settings'] = array(
3264
    '#type' => 'fieldset',
3265
    '#title' => t('Cache Settings'),
3266
    '#collapsible' => FALSE,
3267
    '#collapsed' => FALSE,
3268
    '#description' => t('<p>When caching is enabled all single taxon sites are
3269
      stored in an internal drupal cache doing the portal response of taxa pages
3270
      faster. This is possible because the sites are loaded from the cache and
3271
      are not created from scratch.</p>'),
3272
  );
3273

    
3274
  $form['cache_settings']['cdm_webservice_cache'] = array(
3275
    '#type' => 'checkbox',
3276
    '#title' => t('<strong>Enable caching</strong>'),
3277
    '#options' => cdm_help_general_cache(),
3278
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3279
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3280
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3281
       application the changes will be not visible till the cache is erased.
3282
       Therefore developers should deactived this feature when they are working
3283
       on the CDM Dataportal Module.</p>'),
3284
  );
3285

    
3286
  $form['cache_settings']['cdm_run_cache'] = array(
3287
    '#markup' => cdm_view_cache_site(),
3288
  );
3289

    
3290
  // @WA: D7 form api does not support reset buttons,
3291
  // so to mimic the D5 reset button we add one like this.
3292
  $form['actions']['reset'] = array(
3293
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3294
    '#weight' => 1000,
3295
  );
3296
  return system_settings_form($form);
3297
}
3298

    
3299
/**
3300
 * Walk and cache all taxon pages.
3301
 */
3302
function cdm_view_cache_site() {
3303

    
3304
  $out = '';
3305

    
3306
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3307

    
3308
  $request_params = array();
3309
  $request_params['class'] = "Taxon";
3310

    
3311
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3312
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3313
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3314

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

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

    
3324
  // Comment @WA: A form within a form is not valid html and not needed here.
3325
  // Also, it would be recommended just to include this part of the form in the
3326
  // rest of the form array in cdm_settings_cache().
3327
  // $out .= '<form id="cache_site">';
3328
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3329
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3330
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3331
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3332
  // $out .= '</form>';
3333
  $out .= '</div>';
3334
  /*
3335
  foreach($taxonPager->records as $taxon){
3336
    cdm_dataportal_taxon_view($uuid);
3337
  }
3338
  */
3339
  return $out;
3340
}
3341

    
3342

    
3343
function cdm_settings_layout_taxon_submit($form, &$form_state){
3344
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3345
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3346
    if(is_object($file)){
3347
      $file->status = FILE_STATUS_PERMANENT;
3348
      file_save($file);
3349
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3350
    }
3351
  }
3352
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3353
  $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]);
3354
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3355
  if($tab_lables_modified || $tabs_enabled_modified){
3356
    // we first need to set the variable to persist the changes setting
3357
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3358
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3359
    menu_rebuild();
3360
  }
3361
}
3362

    
3363
function cdm_settings_layout_search_submit($form, &$form_state){
3364
  // the visibility of media thumbnails also affects the ui of the search results
3365
  // so reset the according session variable
3366
  //    1. in order to give the user immediate
3367
  //       feedback on potential setting changes
3368
  //    2. let refresh the default if it has changed
3369
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3370
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3371
  }
3372
}
3373

    
3374
/**
3375
 * Form validation handler for cdm_settings_general
3376
 *
3377
 * @param $form
3378
 * @param $form_state
3379
 */
3380
function cdm_settings_general_validate($form, &$form_state) {
3381

    
3382
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3383
    $form_state['values']['cdm_webservice_url'] .= '/';
3384
  }
3385

    
3386
}
3387

    
3388
/**
3389
 * Form submit handler for settings general.
3390
 *
3391
 * tasks performed:
3392
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3393
 *
3394
 * @param $form
3395
 * @param $form_state
3396
 */
3397
function cdm_settings_general_submit($form, &$form_state){
3398
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3399
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3400
  unset($_SESSION['cdm_login']);
3401
}
3402

    
3403
/**
3404
 * Form validation handler for cdm_settings_cache
3405
 */
3406
function cdm_settings_cache_validate($form, &$form_state) {
3407
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3408
    cache_clear_all(NULL, 'cache_cdm_ws');
3409
    // Better clear secref_cache since I can not be sure if the cache has not
3410
    // be used during this response.
3411
    cdm_api_secref_cache_clear();
3412
  }
3413

    
3414
}
3415

    
3416
/**
3417
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3418
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3419
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3420
 *  - version: the version, e.g.: v1.1
3421
 *
3422
 * @return array
3423
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3424
 */
3425
function get_edit_map_service_settings() {
3426

    
3427
  $settings = variable_get('edit_map_server', array(
3428
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3429
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3430
      )
3431
  );
3432

    
3433
  return $settings;
3434
}
3435

    
3436
/**
3437
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3438
 *
3439
 * @return string
3440
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3441
 */
3442
function get_edit_map_service_full_uri() {
3443
  $settings = get_edit_map_service_settings();
3444
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3445
}
3446

    
3447

    
3448
/**
3449
 * Returns the version number of the currently selected edit mapserver as a float
3450
 *
3451
 * @return float
3452
 *   The version number of the currently selected edit mapserver as a float.
3453
 *   Returns 0 on error.
3454
 */
3455
function get_edit_map_service_version_number() {
3456

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

    
3459
  $settings = get_edit_map_service_settings();
3460
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3461
  if (isset($matches[1])) {
3462
    // Convert string to float.
3463
    $version = 1 + $matches[1][0] - 1;
3464
    return $version;
3465
  }
3466
  else {
3467
    // Report error.
3468
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3469
        array(
3470
          '!version' => $settings['version'],
3471
          'warning')
3472
        )
3473
      );
3474
    return 0;
3475
  }
3476
}
3477

    
3478
/**
3479
 * Returns the array of selected items in a options array
3480
 *
3481
 * @param array $options
3482
 *   An options array as generated by a form element like checkoxes, select ...,
3483
 */
3484
function get_selection($options) {
3485
  $selection = array();
3486
  foreach ($options as $key=>$val) {
3487
    if (!empty($val)) {
3488
      $selection[] = $val;
3489
    }
3490
  }
3491
  return $selection;
3492
}
3493

    
3494

    
3495
/**
3496
 * Implements hook_element_info().
3497
 *
3498
 * Allows modules to declare their own Form API element types and specify their default values.
3499
 *
3500
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3501
 */
3502
function cdm_dataportal_element_info() {
3503
  $type['checkboxes_preferred'] = array(
3504
    '#input' => TRUE,
3505
    '#process' => array('checkboxes_preferred_expand'),
3506
    '#after_build' => array('checkboxes_preferred_after_build'),
3507
    '#theme' => array('checkboxes_preferred'),
3508
    // '#theme_wrapper' => array('form_element'),
3509
  );
3510
  return $type;
3511
}
3512

    
3513
/**
3514
 * #process callback function for the custom form element type 'checkbox_preferred'
3515
 *
3516
 *
3517
 */
3518
function checkboxes_preferred_expand($element, &$form_state, $form) {
3519

    
3520
  // First of all create checkboxes for each of the elements
3521
  $element = form_process_checkboxes($element);
3522

    
3523
  // compose the element name
3524
  $parents = array();
3525
  array_deep_copy($element['#parents'], $parents);
3526
  $parents[count($parents) -1 ] .= '_preferred';
3527
  $element_name = $parents[0];
3528
  for ($i=1; $i < count($parents); $i++){
3529
    $element_name .= '[' . $parents[$i] . ']';
3530
  }
3531

    
3532
  $children = element_children($element);
3533

    
3534
  $element['table_start'] = array(
3535
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3536
    '#weight' => -1,
3537
  );
3538

    
3539
  // prepare first part each of the table rows which contains the row label
3540
  $weight = 0;
3541
  foreach ($children as $key) {
3542
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3543
    $element[$key]['#weight'] = $weight;
3544
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3545
    $element[$key]['#suffix'] = '</td>';
3546
    unset($element[$key]['#title']);
3547
    $weight += 2;
3548
  }
3549
  $weight = 0;
3550

    
3551
  // add a radio button to each of the checkboxes, the
3552
  // check boxes have already been created at the beginning
3553
  // of this function
3554
  if (count($element['#options']) > 0) {
3555
    foreach ($element['#options'] as $key => $choice) {
3556
      if (!isset($element[$key . '_preferred'])) {
3557
        $element[$key . '_preferred'] = array(
3558
          '#type' => 'radio',
3559
          '#name' => $element_name,
3560
          '#return_value' => check_plain($key),
3561
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3562
          '#attributes' => $element['#attributes'],
3563
          '#parents' => $element['#parents'],
3564
          // '#spawned' => TRUE,
3565
          '#weight' => $weight + 1,
3566
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3567
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3568
        );
3569
      }
3570
      $weight += 2;
3571
    }
3572
  }
3573

    
3574
  // end the table
3575
  $element['table_end'] = array(
3576
    '#markup' => '</table>',
3577
    '#weight' => $weight++,
3578
  );
3579

    
3580
  return $element;
3581
}
3582

    
3583
/**
3584
 * Theme function for the custom form field 'checkboxes_preferred'.
3585
 */
3586
function theme_checkboxes_preferred($variables) {
3587
  $element = $variables['element'];
3588
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3589
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3590
  $out .= drupal_render_children($element);
3591
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3592
  $out .= '</div>';
3593
  return $out;
3594
}
3595

    
3596
/**
3597
 * Callback for checkboxes preferred for widget which will
3598
 * be called after the form or element is built. The call
3599
 * back is configured in the form element by setting it as
3600
 * #after_build parameter.
3601
 *
3602
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3603
 *
3604
 * @param $element
3605
 *   Nested array of form elements that comprise the form.
3606
 * @param $form_state
3607
 *   A keyed array containing the current state of the form.
3608
 *   This includes the current persistent storage data for the form.
3609
 *   Additional information, like the sanitized $_POST data,
3610
 *   is also accumulated here in $form_state['input']
3611
 *
3612
 * @return the modified form array
3613
 */
3614
function checkboxes_preferred_after_build($element, &$form_state) {
3615

    
3616
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3617

    
3618
  if ($_POST && count($_POST) > 0) {
3619
    // TODO use  $form_state['input'] instead of POST !!!
3620
    // First pass of form processing.
3621
    $parents = array();
3622
    array_deep_copy($element['#parents'], $parents);
3623
    $parents[count($parents) - 1] .= '_preferred';
3624
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3625
    $element['#value']['PREFERRED'] = $preferred_layer;
3626
//     $form_state[$parent_id] = $element['#value'];
3627
//     $form_state['values']['baselayers'] = $element['#value'];
3628
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3629
    $form_state_element_values = $element['#value'];
3630
  }
3631
  else {
3632
    // Second pass of form processing.
3633
    $preferred_layer = $element['#value']['PREFERRED'];
3634
  }
3635

    
3636
  // Also set the chosen value (not sure if this is good Drupal style ....).
3637
  foreach ($children = element_children($element) as $key) {
3638
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3639
      $element[$key]['#value'] = $preferred_layer;
3640
    }
3641
  }
3642
  // The default layer must always be enabled.
3643
  $element[$preferred_layer]['#value'] = $preferred_layer;
3644

    
3645
  return $element;
3646
}
3647

    
3648
function radios_prepare_options_suffix(&$elements){
3649

    
3650
  $childrenKeys = element_children($elements);
3651
  foreach($childrenKeys as $key){
3652
    if(!is_array($elements[$key]['#theme_wrappers'])){
3653
      $elements[$key]['#theme_wrappers'] = array();
3654
    }
3655
    if(isset($elements['#options_suffixes'][$key])){
3656
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3657
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3658
    }
3659
  }
3660
  return $elements;
3661

    
3662
}
3663

    
3664
/**
3665
 * TODO
3666
 * @param unknown $variables
3667
 */
3668
function theme_radio_options_suffix($variables) {
3669
  $element = $variables['element'];
3670
  if(isset($element['#options_suffix'])) {
3671
    $element['#children'] .= $element['#options_suffix'];
3672
  }
3673
  return $element['#children'];
3674
}
3675

    
3676

    
3677
/**
3678
 * Element validate callback for text field and arrays containing json.
3679
 *
3680
 * @param $element
3681
 *   The form element to validate
3682
 * @param $form_state
3683
 *   A keyed array containing the current state of the form.
3684
 * @param $form
3685
 *   Nested array of form elements that comprise the form.
3686
 */
3687
function form_element_validate_json($element, &$form_state, $form) {
3688
   if (!empty($element['#value'])) {
3689
     json_decode($element['#value']);
3690
     if(json_last_error() != JSON_ERROR_NONE){
3691
       form_error($element,
3692
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3693
         . l('JSONLint', 'http://jsonlint.com/')
3694
       );
3695
     }
3696
   }
3697
}
3698

    
3699
/**
3700
 * Form submission handler for textareas and textfields containing JSON.
3701
 *
3702
 * The contained JSON will be converted into an php array
3703
 * or object and will be stored in the variables as such.
3704
 *
3705
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3706
 *
3707
 * @param $form
3708
 *   Nested array of form elements that comprise the form.
3709
 * @param $form_state
3710
 *   A keyed array containing the current state of the form.
3711
 *
3712
 */
3713
function submit_json_as_php_array($form, &$form_state) {
3714
  if (is_array($form['#json_elements'])) {
3715
    foreach ($form['#json_elements'] as $element){
3716
      if (trim($form_state['values'][$element])) {
3717
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3718
      } else {
3719
        $form_state['values'][$element] = NULL;
3720
      }
3721
    }
3722
  }
3723
}
(18-18/18)