Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / settings.php @ 834fb28c

History | View | Annotate | Download (144 KB)

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_TAXON_AUTO_SUGGEST', 0);
26
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 1);
27
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
28
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
29
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
30
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
31

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

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

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

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

    
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
        'http://edit.br.fgov.be'=>'Secondary (http://edit.br.fgov.be)',
65
      )
66
    )
67
  );
68
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
69
  /**
70
   * @var array of versions eg. "v1.2"
71
   *   An options array
72
   */
73
  define('EDIT_MAPSERVER_VERSION', serialize(
74
      array(
75
//        'v1' => 'v1' ,           // no longer recommended
76
//        'v1.1' => 'v1.1',        // no longer recommended
77
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
78
        'v1.2' => 'v1.2',
79
        'v1.3_dev' => 'v1.3_dev (not recommended)',
80
        'v1.4_dev' => 'v1.4_dev (experimental features)'
81
      )
82
    )
83
  );
84
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
85
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
86

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

    
102

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

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

    
111

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

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

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

    
143
$taxon_tab_options = get_taxon_tabs_list();
144
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
145

    
146
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
147

    
148
/**
149
 * @todo document this function.
150
 */
151
function get_taxon_options_list() {
152
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
153
  foreach ($taxon_tab_options as $key => $value) {
154
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
155
  }
156
  return $taxon_tab_options;
157

    
158
}
159

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

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

    
325
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
326
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
327
    // to unset a default enntry set the value to 0
328
    array(
329
      'doTaxa'=>'doTaxa',
330
      'doSynonyms' => 'doSynonyms',
331
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
332
      'doMisappliedNames' => 'doMisappliedNames'
333
    )
334
  )
335
);
336

    
337
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
338

    
339
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
340
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
341

    
342
/* Gallery variables. */
343
$gallery_settings = array(
344
    "cdm_dataportal_show_taxon_thumbnails" => 1,
345
    "cdm_dataportal_show_synonym_thumbnails" => 0,
346
    "cdm_dataportal_show_thumbnail_captions" => 1,
347
    "cdm_dataportal_media_maxextend" => 120,
348
    "cdm_dataportal_media_cols" => 3,
349
    "cdm_dataportal_media_maxRows" => 1,
350
);
351

    
352
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
353
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
354
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
355
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
356
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
357
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
358
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
359
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
360
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
361
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
362
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
363
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
364

    
365
/**
366
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
367
 * the snonymy.
368
 *
369
 * @var string
370
 */
371
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
372

    
373
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
374
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
375
    array(
376
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
377
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
378
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
379
    )
380
  )
381
);
382

    
383
/**
384
 * The drupal variable for the configuration of the information aggregation along
385
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
386
 *    - direct: the uuids of the taxon relationship types to take into account in invers
387
 *      direction.
388
 *    - invers: the uuids of the taxon relationship types to take into account in direct
389
 *      direction.
390
 *
391
 * @var String
392
 */
393
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
394
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
395
    array(
396
        'direct'=>array(),
397
        'invers'=>array()
398
     )
399
   ));
400
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
401
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
402
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
403

    
404
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
405
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
406
      array(
407
      'filter_rules' => array(
408
        'statusOrderPreference' => 0,
409
        'subAreaPreference' => 0,
410
      ),
411
      'hiddenAreaMarkerType' => array()
412
     )
413
));
414

    
415
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
416
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
417
  "level_0" => array(
418
    'label_suffix' => ':',
419
    'item_glue' => ' ',
420
    'item_group_prefix' => '',
421
    'item_group_postfix' => ''
422
  ),
423
  "level_1" => array(
424
    'label_suffix' => '', // ' &#8210;'
425
    'item_glue' => '; ',
426
    'item_group_prefix' => ', ',
427
    'item_group_postfix' => ''
428
  ),
429
  "level_2" => array(
430
    'label_suffix' => '', // ' &#8210;'
431
    'item_glue' => ', ',
432
    'item_group_prefix' => ' (',
433
    'item_group_postfix' => ')'
434
  )
435
)));
436

    
437
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
438
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
439
    array(
440
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
441
        'includeOccurrences' => 0,
442
        'includeTaxonNameDescriptions' => 0
443
     )
444
  ));
445

    
446
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
447
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
448
  // needs to be merged with user setting by drupal_array_merge_deep()
449
  // 'width' => 512, // optimum size for OSM layers is 512
450
  // 'height' => 512 / 2, // optimum size for OSM layers 256
451
  'aspect_ratio' => 2,
452
  'bbox' => '', // empty to allow automatic zooming to extend
453
  'show_labels' => FALSE,
454
  'caption' => '',
455
  'distribution_opacity' => '0.5',
456
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
457
  'image_map' => array(
458
    'base_layer' => '', // none, formerly this was cyprusdivs
459
    'bg_color' => '1874CD',
460
    'layer_style' => 'ffffff,606060,,',
461
  ),
462
  'openlayers' => array(
463
    'base_layers' =>  array(
464
      // A layer MUST NOT BE SET in the defaults,
465
      // otherwise it can not be overidden by the user settings:
466
      // 'mapproxy_vmap0' => 'mapproxy_vmap0',
467
      // it is sufficient to define the preferred layer,
468
      // since it will automatically be enabled:
469
      'PREFERRED' => 'mapproxy_vmap0'),
470
    'custom_wms_base_layer' => array(
471
      'name' => NULL,
472
      'url' => NULL,
473
      'params' =>  NULL,
474
      'projection' => NULL,
475
      'proj4js_def' => NULL,
476
      'max_extent' => NULL,
477
      'units' => NULL
478
    ),
479
    'show_layer_switcher' => TRUE,
480
    'display_outside_max_extent' => FALSE
481
  ),
482
  'legend' => array(
483
    'show' => TRUE,
484
    'opacity' => '0.5',
485
    'font_size' => 10,
486
    'font_style' => FALSE,
487
    'icon_width' => 35,
488
    'icon_height' => 15
489
  )
490
)));
491

    
492
/**
493
 * Merges the named array variable with the array of defaults.
494
 *
495
 * IMPORTANT: The array keys must be strings. When the keys are integers
496
 * the merging will not take place for these entities. Number keyed entities
497
 * are just appended to the result array.
498
 *
499
 * @param string $variable_name
500
 *     The variable name
501
 * @param string | array $default
502
 *     The array containing the default values either as array or serialized as string.
503
 *     Unserialization is cared for if necessary
504
 * @return array
505
 *     The merged array as returned by drupal_array_merge_deep()
506
 *
507
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
508
 * TODO force $default being an array
509
 */
510
function get_array_variable_merged($variable_name, $default){
511

    
512
    // unserialize if nessecary
513
    if(!is_array($default)){
514
      $default = unserialize($default);
515
    }
516
    $variable = variable_get($variable_name, array());
517
    $result = drupal_array_merge_deep($default, $variable);
518
    return $result;
519
}
520

    
521
/**
522
 * @todo document this function.
523
 */
524
function getGallerySettings($gallery_config_form_name) {
525
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
526
}
527

    
528
/**
529
 * Returns the string representation of the default tab.
530
 *
531
 * @param bool $returnTabIndex
532
 *   Defaults to FALSE, if set true this function will return the index number
533
 *   of the default tab. (used to supply default values to form elements).
534
 */
535
function get_default_taxon_tab($returnTabIndex = FALSE) {
536

    
537
  global $user;
538
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
539
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
540
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
541
  // Get the user value if the used has chosen to overwrite the system settings.
542
  $user_tab_on = variable_get($user_tab_active, FALSE);
543
  if ($user_tab_on) {
544
    $user_value = variable_get($user_tab, 0);
545
    $index_value = $user_value;
546
    // Get the system value.
547
  }
548
  else {
549
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
550
    $index_value = $system_value;
551
  }
552

    
553
  // Return the index value or the string representation.
554
  if ($returnTabIndex) {
555
    return $index_value;
556
  }
557
  else {
558
    return ($values[$index_value]);
559
  }
560
}
561

    
562

    
563
  /**
564
   * Provides the feature block settings for a specific feature which matches the $feature_uuid parameter.
565
   *
566
   * In case specifically configured settings array, like these which are stored in the drupal variables, is missing
567
   * one or more fields these fields are taken from the default. That is the specific settings are always merges
568
   * with the default.
569
   *
570
   * Note: These settings only apply to feature blocks which do not have a special rendering
571
   * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
572
   * 'special' element of the settings
573
   *
574
   * @param $feature_uuid
575
   *   The uuid string representation of the feature to return the settings for
576
   *
577
   * @return array
578
   *  an associative array of settings, with the following fields:
579
   *    - as_list: string
580
   *        this setting will be used in compose_feature_block_wrap_elements() as $enclosing_tag
581
   *        possible values are:
582
   *          div: not as list,
583
   *          ul: as bullet list,
584
   *          ol: as numbered list,
585
   *          dl: as definition list
586
   *        The tag used for the inner element, thus depends on the value of this field. The
587
   *        inner tag name can be retrieved by the function cdm_feature_block_element_tag_name()
588
   *    - link_to_reference: boolean,
589
   *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
590
   *    - link_to_name_used_in_source": boolean
591
   *        whether to show name is source information as link which will point to the according name page
592
   *    - sources_as_content (boolean)
593
   *        TRUE (int: 1):
594
   *          1. If element is of the CDM type TextData and the text is not empty the source references will be
595
   *             appended in brackets like "text (source references)". If the original source has name in source
596
   *             information it will be appended to the citation string,
597
   *             like : "(citation, as name in source; citation, as name in source)"
598
   *          2. if the text of the TextData is empty, the original source citations are the only content
599
   *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
600
   *             prepended to the citation string like: "name in source: citation"
601
   *        FALSE (int: 0):
602
   *          Original sources are put into the bibliography(=references) pseudo feature block. If the original source
603
   *          citations are the only content, the resulting feature block content would only consist of footnotes.
604
   *          In this case the display of the respective feature block is suppressed.
605
   *          TODO if the bibliography is not enabled the sources will be treated as footnotes like annotations,
606
   *               in future however they will in this case be shown in a separate references section for each
607
   *               feature block.
608
   *    - sources_as_content_to_bibliography  (boolean)
609
   *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
610
   *        in the bibliography.
611
   *    - sort_elements
612
   *        whether and how to sort the elements
613
   *        possible values are the constants SORT_ASC, SORT_DESC, NULL,
614
   *        some feature types (Distribution) also support: SORT_HIERARCHICAL (
615
   *        TODO option to exclude levels, put in special?,
616
   *        TODO make use of this setting in compose_feature_block_wrap_elements())
617
   *    - element_tag
618
   *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
619
   *        possible values are span | div. the proper inner tag name can be retrieved by the function
620
   *        cdm_feature_block_element_tag_name()
621
   *    - special: array()
622
   *        an array with further settings, this field can be used for special
623
   *        settings for specialized rendering like for distributions
624
   *  }
625
   *
626
   */
627
  function get_feature_block_settings($feature_uuid = 'DEFAULT') {
628
    // the default must conform to the default parameter values of
629
    // compose_feature_block_wrap_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
630
    // compose_description_element_text_data() : asListElement = NULL
631

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

    
634
    // ---- DEFAULTS settings
635

    
636
    // only needed as final option, when the settings are not having a default
637
    $default = array(
638
      'DEFAULT' => array(
639
        'as_list' => 'div',
640
        'link_to_reference' => 0,
641
        'link_to_name_used_in_source' => 1,
642
        'sources_as_content' => 0,
643
        'sources_as_content_to_bibliography' => 0,
644
        'sort_elements' => NO_SORT,
645
        'glue' => '',
646
        'element_tag' => NULL
647
      )
648
    );
649

    
650
    // will be used as preset in the settings
651
    $other_themes_default = array(
652
      'DEFAULT' => array(
653
        'as_list' => 'div',
654
        'link_to_reference' => 0,
655
        'link_to_name_used_in_source' => 1,
656
        'sources_as_content' => 0,
657
        'sources_as_content_to_bibliography' => 0,
658
        'sort_elements' => NO_SORT,
659
        'glue' => '',
660
        'element_tag' => NULL
661
      ),
662
      UUID_CITATION => array(
663
        'as_list' => 'div',
664
        'link_to_reference' => 0,
665
        'link_to_name_used_in_source' => 0,
666
        'sources_as_content' => 1,
667
        'sources_as_content_to_bibliography' => 0,
668
        'sort_elements' => SORT_ASC,
669
        'glue' => '',
670
        'element_tag' => 'div'
671
      ),
672
      UUID_DISTRIBUTION => array(
673
        'as_list' => 'div', // currently ignored
674
        'link_to_reference' => 0,
675
        'link_to_name_used_in_source' => 0,
676
        'sources_as_content' => 0,
677
        'sources_as_content_to_bibliography' => 0,
678
        'sort_elements' => NO_SORT, // will cause ...
679
        'glue' => '',
680
        'element_tag' => 'div',
681
        'special' => array()
682
      ),
683
      UUID_COMMON_NAME => array(
684
        'as_list' => 'div',
685
        'link_to_reference' => 0,
686
        'link_to_name_used_in_source' => 1,
687
        'sources_as_content' => 0,
688
        'sources_as_content_to_bibliography' => 0,
689
        'sort_elements' => NO_SORT,
690
        'glue' => '',
691
        'element_tag' => 'span'
692
      ),
693
    );
694

    
695
    // ---- Special DEFAULTS for existing portals
696
    // TODO:
697
    // this can be removed once the feature block
698
    // settings have been deployed for the first time to these portals
699

    
700
    $cichorieae_default = array(
701
      'DEFAULT' => array(
702
        'as_list' => 'div',
703
        'link_to_reference' => 1,
704
        'link_to_name_used_in_source' => 1,
705
        'sources_as_content' => 1,
706
        'sources_as_content_to_bibliography' => 0,
707
        'sort_elements' => NO_SORT,
708
        'glue' => '',
709
        'element_tag' => 'div'
710
      ),
711
      UUID_CITATION => array(
712
        'as_list' => 'div',
713
        'link_to_reference' => 0,
714
        'link_to_name_used_in_source' => 0,
715
        'sources_as_content' => 1,
716
        'sources_as_content_to_bibliography' => 0,
717
        'sort_elements' => SORT_ASC,
718
        'glue' => '',
719
        'element_tag' => 'div'
720
      ),
721
      UUID_CHROMOSOMES_NUMBERS => array(
722
        'as_list' => 'ul',
723
        'link_to_reference' => 1,
724
        'link_to_name_used_in_source' => 1,
725
        'sources_as_content' => 1,
726
        'sources_as_content_to_bibliography' => 0,
727
        'sort_elements' => NO_SORT,
728
        'glue' => '',
729
        'element_tag' => 'div'
730
      ),
731
      UUID_CHROMOSOMES => array(
732
        'as_list' => 'ul',
733
        'link_to_reference' => 0,
734
        'link_to_name_used_in_source' => 1,
735
        'sources_as_content' => 1,
736
        'sources_as_content_to_bibliography' => 0,
737
        'sort_elements' => NO_SORT,
738
        'glue' => '',
739
        'element_tag' => 'div'
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
    $palmweb_default = array(
754
      'DEFAULT' => array(
755
        'as_list' => 'ul',
756
        'link_to_reference' => 1,
757
        'link_to_name_used_in_source' => 1,
758
        'sources_as_content' => 1,
759
        'sources_as_content_to_bibliography' => 1,
760
        'sort_elements' => NO_SORT,
761
        'glue' => '',
762
        'element_tag' => NULL
763
      ),
764
      UUID_CITATION => array(
765
        'as_list' => 'ul',
766
        'link_to_reference' => 1,
767
        'link_to_name_used_in_source' => 1,
768
        'sources_as_content' => 0,
769
        'sources_as_content_to_bibliography' => 1,
770
        'sort_elements' => SORT_ASC,
771
        'glue' => '',
772
        'element_tag' => 'div'
773
      ),
774
      UUID_DISTRIBUTION => array(
775
        'as_list' => 'div', // currently ignored
776
        'link_to_reference' => 1,
777
        'link_to_name_used_in_source' => 1,
778
        'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
779
        'sources_as_content_to_bibliography' => 1,
780
        'sort_elements' => NO_SORT, // will cause ...
781
        'glue' => '',
782
        'element_tag' => 'div',
783
        'special' => array()
784
      ),
785
    );
786

    
787
    $cyprus_default = $cichorieae_default;
788
    $cyprus_default[UUID_DISTRIBUTION] = array(
789
      'as_list' => 'div', // currently ignored
790
      'link_to_reference' => 0,
791
      'link_to_name_used_in_source' => 0,
792
      'sources_as_content' => 0,
793
      'sources_as_content_to_bibliography' => 0,
794
      'sort_elements' => NO_SORT, // will cause ...
795
      'glue' => '',
796
      'element_tag' => 'div',
797
      'special' => array()
798
    );
799

    
800
    $default_theme = variable_get('theme_default', NULL);
801

    
802
    switch ($default_theme) {
803
      case 'garland_cichorieae':
804
        $settings_for_theme = $cichorieae_default;
805
        break;
806
      case 'cyprus':
807
        // cyprus: no longer used in production,
808
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
809
        $settings_for_theme = $cyprus_default;
810
        break;
811
      case 'flore_afrique_centrale':
812
      case 'flora_malesiana':
813
      case 'flore_gabon':
814
        $settings_for_theme = $cichorieae_default;
815
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
816
        break;
817
      case 'palmweb_2':
818
        $settings_for_theme = $palmweb_default;
819
        break;
820
      default:
821
        $settings_for_theme = $other_themes_default;
822
    }
823
    // ---- END of DEFAULTS
824

    
825
    $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
826

    
827
    $feature_block_setting = null;
828

    
829
    if (isset($saved_settings[$feature_uuid])) {
830
      $feature_block_setting = $saved_settings[$feature_uuid];
831
    }
832
    else if (isset($settings_for_theme[$feature_uuid])) {
833
      $feature_block_setting = $settings_for_theme[$feature_uuid];
834
    }
835
    else if (isset($settings_for_theme['DEFAULT'])) {
836
      $feature_block_setting = $settings_for_theme['DEFAULT'];
837
    }
838

    
839
    // now merge the default and specific settings
840
    $settings_to_merge = array($default['DEFAULT']);
841
    if(is_array($saved_settings)){
842
      $settings_to_merge[] = $saved_settings['DEFAULT'];
843
    }
844
    if(isset($feature_block_setting)){
845
      $settings_to_merge[] = $feature_block_setting;
846
    }
847
    $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
848

    
849
    return $feature_block_setting;
850
}
851
  /**
852
 * returns the current setting for the original source bibliography
853
 *
854
 * Caches internally
855
 *
856
 * @return array
857
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
858
 *   - 'enabled': 1|0
859
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
860
 */
861
function get_bibliography_settings($clear_cache = false){
862
  static $bibliography_settings = null;
863
  if(!$bibliography_settings || $clear_cache){
864
    $bibliography_settings = get_array_variable_merged(
865
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
866
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
867
    );
868
  }
869
  return $bibliography_settings;
870
}
871

    
872
/**
873
 * @todo Please document this function.
874
 * @see http://drupal.org/node/1354
875
 */
876
function cdm_dataportal_menu_admin(&$items) {
877
  // Display section on admin/config page.
878
  $items['admin/config/cdm_dataportal'] = array(
879
    'title' => 'CDM Dataportal',
880
    'description' => 'Settings for the CDM DataPortal.',
881
    'position' => 'right',
882
    'weight' => 10,
883
    'page callback' => 'system_admin_menu_block_page',
884
    'access arguments' => array('administer cdm_dataportal'),
885
    'file' => 'system.admin.inc',
886
    'file path' => drupal_get_path('module', 'system'),
887
  );
888
  $items['admin/config/cdm_dataportal/settings'] = array(
889
    'title' => 'Settings',
890
    'description' => 'Settings for the CDM DataPortal.',
891
    'weight' => 0,
892
    'page callback' => 'drupal_get_form',
893
    'page arguments' => array('cdm_settings_general'),
894
    'access arguments' => array('administer cdm_dataportal'),
895
    'type' => MENU_NORMAL_ITEM,
896
  );
897
  $items['admin/config/cdm_dataportal/settings/general'] = array(
898
    'title' => 'General',
899
    'description' => 'General',
900
    'weight' => 0,
901
    'page callback' => 'drupal_get_form',
902
    'page arguments' => array('cdm_settings_general'),
903
    'access arguments' => array('administer cdm_dataportal'),
904
    'type' => MENU_DEFAULT_LOCAL_TASK,
905
  );
906

    
907
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
908
    'title' => 'Cache',
909
    'description' => 'Cache',
910
    'access arguments' => array('administer cdm_dataportal'),
911
    'page callback' => 'drupal_get_form',
912
    'page arguments' => array('cdm_settings_cache'),
913
    'weight' => 10,
914
    'type' => MENU_LOCAL_TASK,
915
  );
916

    
917
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
918
    'title' => 'Geo & Map',
919
    'description' => 'Geo & Map',
920
    'access arguments' => array('administer cdm_dataportal'),
921
    'page callback' => 'drupal_get_form',
922
    'page arguments' => array('cdm_settings_geo'),
923
    'weight' => 1,
924
    'type' => MENU_LOCAL_TASK,
925
  );
926

    
927
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
928
    'title' => 'Layout',
929
    'description' => 'Configure and adjust the layout of your DataPortal ',
930
    'access arguments' => array('administer cdm_dataportal'),
931
    'page callback' => 'drupal_get_form',
932
    'page arguments' => array('cdm_settings_layout'),
933
    'weight' => 2,
934
    'type' => MENU_LOCAL_TASK,
935
  );
936

    
937
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
938
    'title' => 'Taxon',
939
    'description' => 'Configure and adjust the layout of your DataPortal ',
940
    'access arguments' => array('administer cdm_dataportal'),
941
    'page callback' => 'drupal_get_form',
942
    'page arguments' => array('cdm_settings_layout_taxon'),
943
    'weight' => 1,
944
    'type' => MENU_LOCAL_TASK,
945
  );
946
  /*
947
  $items[] = array(
948
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
949
  'title' => t('Synonymy'),
950
  'description' => t('Configure and adjust the layout of your DataPortal '),
951
  'access' => user_access('administer cdm_dataportal'),
952
  'callback' => 'drupal_get_form',
953
  'callback arguments' => array('cdm_settings_layout_synonymy'),
954
  'weight' => 1,
955
  'type' => MENU_LOCAL_TASK,
956
  );
957

958
  $items[] = array(
959
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
960
  'title' => t('Specimens'),
961
  'description' => t('Configure and adjust the layout of your DataPortal '),
962
  'access' => user_access('administer cdm_dataportal'),
963
  'callback' => 'drupal_get_form',
964
  'callback arguments' => array('cdm_settings_layout_specimens'),
965
  'weight' => 1,
966
  'type' => MENU_LOCAL_TASK,
967
  );
968
  */
969
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
970
    'title' => 'Search',
971
    'description' => 'Configure and adjust the layout of your DataPortal ',
972
    'access arguments' => array('administer cdm_dataportal'),
973
    'page callback' => 'drupal_get_form',
974
    'page arguments' => array('cdm_settings_layout_search'),
975
    'weight' => 2,
976
    'type' => MENU_LOCAL_TASK,
977
  );
978

    
979
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
980
    'title' => 'Media',
981
    'description' => 'Configure and adjust the layout of your DataPortal ',
982
    'access arguments' => array('administer cdm_dataportal'),
983
    'page callback' => 'drupal_get_form',
984
    'page arguments' => array('cdm_settings_layout_media'),
985
    'weight' => 3,
986
    'type' => MENU_LOCAL_TASK,
987
  );
988

    
989
}
990

    
991
/**
992
 * @todo document this function.
993
 */
994
function cdm_help_general_cache() {
995
  $form = array();
996
  $form['cache_help'] = array(
997
    '#type' => 'fieldset',
998
    '#title' => t('Help'),
999
    '#collapsible' => TRUE,
1000
    '#collapsed' => TRUE,
1001
  );
1002
  $form['cache_help']['test'] = array('#value' => t('probando'));
1003
  return drupal_render($form);
1004
  $res = array();
1005
  $res['default'] = drupal_render($help);
1006
  return $res;
1007
}
1008

    
1009
/**
1010
 * Configures the settings form for the CDM-API module.
1011
 *
1012
 * @return array
1013
 *   Drupal settings form.
1014
 */
1015
function cdm_settings_general() {
1016

    
1017
  $form['cdm_webservice'] = array(
1018
    '#type' => 'fieldset',
1019
    '#title' => t('CDM Server'),
1020
    '#collapsible' => FALSE,
1021
    '#collapsed' => FALSE,
1022
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1023
        CDM data base to the web via RESTful web services and thus is the source of the data
1024
        to be displayed by a CDM DataPotal.'),
1025
  );
1026

    
1027
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1028
    '#type' => 'textfield',
1029
    '#title' => t('CDM web service URL') . ':',
1030
    '#description' => t('This is the URL to the CDM-Server exposing your data
1031
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1032
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1033
  );
1034

    
1035
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1036
    '#type' => 'markup',
1037
    '#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')
1038
      . ' visible only for administrators',
1039
  );
1040

    
1041
  $form['cdm_webservice']['freetext_index'] = array(
1042
    '#type' => 'fieldset',
1043
    '#title' => t('Freetext index'),
1044
    '#collapsible' => FALSE,
1045
    '#collapsed' => FALSE,
1046
  );
1047

    
1048
  // Check the cdmserver port number and display a waring if it is not port 80
1049
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1050
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1051
    $form['cdm_webservice']['freetext_index']['message'] = array(
1052
      '#markup' => "<div class=\"description\">"
1053
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1054
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1055
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1056
          array('!port' => $portNumberMatch[1][0])
1057
        )
1058
      . "</div>",
1059
    );
1060
  };
1061

    
1062
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1063
  $trigger_link_options = array(
1064
    'attributes' => array(
1065
      'class' => 'index-trigger',
1066
    ),
1067
  );
1068
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1069
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1070
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1071
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1072
      ))
1073
    . '<div id="index-progress"></div></div>',
1074
  );
1075
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1076

    
1077
    $form['cdm_webservice']['freetext_index']['cdm_dataportal_taxon_auto_suggest'] = array(
1078
        '#type' => 'checkbox',
1079
        '#title' => t('Enable auto-suggest for taxon search'),
1080
        '#default_value' => variable_get('cdm_dataportal_taxon_auto_suggest', CDM_DATAPORTAL_TAXON_AUTO_SUGGEST),
1081
        '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
1082
        This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
1083
    );
1084

    
1085
  $form['cdm_webservice']['proxy'] = array(
1086
    '#type' => 'fieldset',
1087
    '#title' => t('Proxy'),
1088
    '#collapsible' => TRUE,
1089
    '#collapsed' => TRUE,
1090
  );
1091

    
1092
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1093
    '#type' => 'textfield',
1094
    '#title' => t('Proxy URL') . ':',
1095
    '#description' => t('If this proxy url is set the cdm api tries
1096
    to connect the web service over the given proxy server.
1097
    Otherwise proxy usage is deactivated.'),
1098
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1099
  );
1100

    
1101
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1102
    '#type' => 'textfield',
1103
    '#title' => t('Proxy port') . ':',
1104
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1105
  );
1106

    
1107
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1108
    '#type' => 'textfield',
1109
    '#title' => t('Login') . ':',
1110
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1111
  );
1112

    
1113
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1114
    '#type' => 'textfield',
1115
    '#title' => t('Password') . ':',
1116
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1117
  );
1118

    
1119
  // TODO: settings are still incomplete, compare with
1120
  // trunk/dataportal/inc/config_default.php.inc.
1121
  $form['taxon_tree'] = array(
1122
    '#type' => 'fieldset',
1123
    '#title' => t('Taxon Tree'),
1124
    '#collapsible' => FALSE,
1125
    '#collapsed' => TRUE,
1126
    '#description' => t('<p>When you explore your collection, you can navigate
1127
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1128
      able to navigate through your collection the
1129
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1130
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1131
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1132
      </a></p>'),
1133
  );
1134

    
1135
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1136
    '#type' => 'select',
1137
    '#title' => t('Available classifications') . ':',
1138
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1139
    '#options' => cdm_get_taxontrees_as_options(),
1140
    '#description' => t('Select the default taxa classification for your
1141
      <em>taxon tree</em>, the other classifications will be also available but
1142
      with a manual user change.'),
1143
  );
1144

    
1145
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1146
    '#type' => 'select',
1147
    '#title' => t('Rank of highest displayed taxon') . ':',
1148
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1149
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1150
    '#options' => cdm_rankVocabulary_as_option(),
1151
    '#description' => t('This is the rank of the highest displayed taxon in the
1152
      <em>taxon tree</em>. You can select here which rank should be at the top
1153
      level of the tree structure.'),
1154
  );
1155

    
1156
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1157
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1158
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1159
      '#type' => 'checkboxes',
1160
      '#title' => t('Included Classifications') . ':',
1161
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1162
      '#options' => cdm_get_taxontrees_as_options(),
1163
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1164
  );
1165

    
1166
  $form['distribution'] = array(
1167
      '#type' => 'fieldset',
1168
      '#title' => t('Distributions'),
1169
      '#collapsible' => FALSE,
1170
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1171
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1172
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1173
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1174
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1175
          '<p>
1176
          </p>',
1177
  );
1178

    
1179
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1180
      '#type' => 'fieldset',
1181
      '#title' => 'Distribution filter',
1182
      '#collapsible' => FALSE,
1183
      '#collapsed' => FALSE,
1184
      '#tree' => TRUE,
1185
      '#description' => 'The Distribution filter offers the following options
1186
      <ul>
1187
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1188
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1189
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1190
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1191
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1192
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1193
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1194
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1195
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1196
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1197
      </ul>'
1198
  );
1199

    
1200
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1201
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1202
      '#type' => 'checkboxes',
1203
      '#title' => 'Filter rules',
1204
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1205
      '#options' => array(
1206
          'statusOrderPreference' => 'Status order preference rule',
1207
          'subAreaPreference' => 'Sub area preference rule'
1208
      ),
1209
  );
1210

    
1211
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1212
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1213
      '#type' => 'checkboxes',
1214
      '#title' => 'Hide marked area filter',
1215
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1216
      '#options' => $marker_type_options,
1217
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1218
  );
1219

    
1220
  $form['aggregation'] = array(
1221
      '#type' => 'fieldset',
1222
      '#title' => t('Aggregation of data'),
1223
      '#collapsible' => FALSE,
1224
      '#description' => 'This section covers the different aspects of aggregating information.
1225
          <p>
1226
          </p>',
1227
  );
1228

    
1229
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1230
      '#type' => 'checkboxes',
1231
      '#title' => 'Taxon media filter',
1232
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1233
      '#options' => array(
1234
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1235
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1236
          'includeOccurrences' => 'Media related to specimens and occurrences',
1237
      ),
1238
      '#description' => 'This filter configures which images should be taken into account.',
1239
  );
1240

    
1241
  $form['aggregation']['notice'] = array(
1242
      '#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
1243
          want to make use of the caching capabilities of the dataportal.',
1244
  );
1245

    
1246
  $form['aggregation']['media_aggregation'] = array(
1247
      '#type' => 'fieldset',
1248
      '#title' => t('Media aggregation'),
1249
      '#collapsible' => FALSE,
1250
      '#collapsed' => TRUE,
1251
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1252

    
1253
  );
1254
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1255
      '#type' => 'select',
1256
      '#title' => t('Aggregation of taxon pictures') . ':',
1257
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1258
      '#options' => array(
1259
          0 => "Show only pictures of the current taxon",
1260
          1 => "Include pictures of taxonomic children",
1261
      ),
1262
      '#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."),
1263
  );
1264

    
1265
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1266
      '#type' => 'fieldset',
1267
      '#attributes' => array('class' => array('clearfix')),
1268
      '#title' => t('Aggregation via taxon relationsships'),
1269
      '#collapsible' => TRUE,
1270
      '#collapsed' => TRUE,
1271
      '#tree' => TRUE,
1272
      '#description' => t('Information on taxa will be aggregated along the below chosen
1273
          taxon relation ships. This will affect images and occurrences (specimens).
1274
          Taxon relation ships are directed and point form one taxon to another. The taxon
1275
          relationships to be taken into accunt can therefore configured for the direct direction
1276
          and for the inverse.'),
1277
  );
1278

    
1279
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1280
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1281

    
1282
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1283
      '#type' => 'checkboxes',
1284
      '#title' => t('Direct'),
1285
      '#options' => $taxonRelationshipTypeOptions,
1286
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1287
  );
1288
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1289
      '#type' => 'checkboxes',
1290
      '#title' => t('Invers'),
1291
      '#options' => $taxonRelationshipTypeOptions,
1292
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1293
  );
1294

    
1295
  $form['drupal_integration'] = array(
1296
    '#type' => 'fieldset',
1297
    '#attributes' => array('class'=> array('clearfix')),
1298
    '#title' => t('Drupal integration'),
1299
    '#collapsible' => FALSE,
1300
    '#collapsed' => FALSE,
1301
    '#tree' => FALSE
1302
  );
1303

    
1304
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1305
    '#type' => 'checkbox',
1306
    '#title' => 'Create drupal nodes',
1307
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1308
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1309
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1310
    cdm pages it is required that drupal nodes are created and stored in the database.'
1311
  );
1312

    
1313

    
1314

    
1315
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1316
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1317
    <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>',
1318
  );
1319
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1320
    '#type' => 'submit',
1321
    '#value' => t('Drop all cdm nodes'),
1322
    '#submit' => array('drop_all_cdm_nodes_submit')
1323
  );
1324

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

    
1329
    // ----------------------
1330
  $form['cdm_js_devel_mode'] = array(
1331
      '#type' => 'checkbox',
1332
      '#title' => 'Java-script developer mode',
1333
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1334
      '#description' => 'In production envirionments the java script libraries
1335
      the cdm_dataportal is making use of are compressed and optimized. This
1336
      is good for performance but a caveat if you need to debug java-script. When the
1337
      java-script developer mode is enabled the uncompressed and commented developer
1338
      versions of java-script libraries will be used where possible.
1339
      <br/><strong>Do not use this option in production!</strong>'
1340
  );
1341
  // ----------------------
1342
  $form['cdm_debug_mode'] = array(
1343
      '#type' => 'checkbox',
1344
      '#title' => 'CDM page debug mode',
1345
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1346
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1347
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1348
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1349
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1350
      The log is written by the drupal devel module function <code>dd()</code>.
1351
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1352
  );
1353

    
1354
  // Comment @WA: D7 form api does not support reset buttons,
1355
  // so to mimic the D5 reset button we add one like this.
1356
  $form['actions']['reset'] = array(
1357
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1358
    '#weight' => 1000,
1359
  );
1360

    
1361
  $form['#submit'][] = 'cdm_settings_general_submit';
1362

    
1363
  return system_settings_form($form);
1364
}
1365

    
1366
/**
1367
 * Submit callback; drops all cdm nodes.
1368
 *
1369
 * @ingroup forms
1370
 */
1371
function drop_all_cdm_nodes_submit($form, &$form_state) {
1372
  cdm_delete_all_cdm_nodes();
1373
  drupal_set_message(t('All cdm nodes dropped.'));
1374
}
1375

    
1376

    
1377
/**
1378
 * LAYOUT settings
1379
 * @return
1380
 *   todo
1381
 */
1382
function cdm_settings_layout() {
1383

    
1384
  $form = array();
1385

    
1386
  $form['about'] = array(
1387
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1388
      layout. If you want to configure the specific sites layout visit the
1389
      respective configuration site for taxon, search or media.') . '</p>',
1390
  );
1391

    
1392
  // ---- footnotes --- //
1393
  $form['footnotes'] = array(
1394
    '#type' => 'fieldset',
1395
    '#title' => t('Footnotes'),
1396
    '#collapsible' => FALSE,
1397
    '#collapsed' => FALSE,
1398
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1399
      media or distribution areas may have annotations or footnotes. When the
1400
      footnotes are enabled they will be visible (if they exist).'),
1401
  );
1402

    
1403
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1404
    '#type' => 'checkbox',
1405
    '#title' => t('Do not show footnotes'),
1406
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1407
    '#description' => t('Check this if you do not want to show any footnotes'),
1408
  );
1409

    
1410
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1411
    '#type' => 'checkbox',
1412
    '#title' => t('Do not show annotation footnotes'),
1413
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1414
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1415
  );
1416

    
1417
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1418
  // Additional option for the NULL case.
1419
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1420
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1421
    '#type' => 'checkboxes',
1422
    '#title' => t('Annotation types as footnotes'),
1423
    '#description' => t("Only annotations of the selected type will be displayed
1424
       as footnotes. You may want to turn 'technical annotations' off."),
1425
    '#options' => $annotationTypeOptions,
1426
  );
1427
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1428
  if (!empty($annotationsTypesAsFootnotes)) {
1429
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1430
  }
1431

    
1432
  // ---- original source --- //
1433
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1434
      '#type' => 'fieldset',
1435
      '#tree' => TRUE,
1436
      '#title' => t('Source Citations'),
1437
      '#collapsible' => FALSE,
1438
      '#collapsed' => FALSE,
1439
  );
1440

    
1441
  $bibliography_settings = get_bibliography_settings(true);
1442

    
1443
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1444
      '#type' => 'checkbox',
1445
      '#title' => t('Original Source in bibliography'),
1446
      '#default_value' => $bibliography_settings['enabled'],
1447
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1448
       annotations in each feature block.'),
1449
  );
1450

    
1451
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1452
    '#type' => 'select',
1453
    '#title' => t('The format of the key numerals'),
1454
    '#default_value' => $bibliography_settings['key_format'],
1455
    '#options' => array('latin' => 'Latin',
1456
      'ROMAN' => 'Roman (upper case)',
1457
      'roman' => 'Roman (lower case)',
1458
      'ALPHA'=> 'Alphabet (upper case)',
1459
      'alpha' => 'Alphabet (lower case)')
1460
  );
1461

    
1462
  // --- Advanced Search --- //
1463
  $form['asearch'] = array(
1464
      '#type' => 'fieldset',
1465
      '#title' => t('Advanced search'),
1466
      '#collapsible' => FALSE,
1467
      '#collapsed' => FALSE,
1468
  );
1469
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1470
      '#type' => 'checkbox',
1471
      '#title' => t('Show advanced search link'),
1472
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1473
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1474
  );
1475

    
1476
  // ---- Taxon Name Rendering --- //
1477
  $form['taxon_name'] = array(
1478
      '#type' => 'fieldset',
1479
      '#title' => t('Taxon name display'),
1480
      '#collapsible' => TRUE,
1481
      '#collapsed' => TRUE,
1482
      '#description' => t('The display of taxon names is configured by two parts.
1483
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1484
          The name parts are defined in the <stong>part definitions</strong>'),
1485
  );
1486

    
1487
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1488
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1489
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1490
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1491

    
1492
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1493
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1494
    $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.)';
1495
  } else if($is_custom_part_definition){
1496
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1497
  } else  {
1498
    $which_version_message = '(These are the default part definition.)';
1499
  }
1500

    
1501
  $diff_viewer_markup = '';
1502
  if($is_custom_part_definition){
1503
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1504
  }
1505

    
1506
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1507
    . $which_version_message
1508
    . '</div>'
1509
    . $diff_viewer_markup;
1510

    
1511
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1512
      '#type' => 'textarea',
1513
      '#title' => t('Part definitions'),
1514
      '#element_validate' => array('form_element_validate_json'),
1515
      '#default_value' =>  $current_part_definition_json,
1516
      '#description' => '
1517
          <p>' . $which_version_message . '</p>
1518
          <p>
1519
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1520
          </p>
1521
          <p>
1522
           A full taxon name plus additional information can consist of the following elements:
1523
          <ul>
1524
             <li>name: the taxon name inclugin rank nbut without author</li>
1525
             <li>authors:  The authors of a reference, also used in taxon names</li>
1526
             <li>reference: the nomenclatural reference,</li>
1527
             <li>microreference:  Volume, page number etc.</li>
1528
             <li>status:  The nomenclatural status of a name</li>
1529
             <li>description: name descriptions like protologues etc ...</li>
1530
          </ul>
1531
          </p>
1532
          <p>
1533
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1534
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1535
           The following parts can be formed and are recognized by the system:
1536
          <ul>
1537
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1538
            <li>authorshipPart: the author (for example: "L.")</li>
1539
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1540
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1541
               be combined when a link to the taxon is rendered.</li>
1542
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1543
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1544
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1545
            <li>statusPart: the nomenclatorical status</li>
1546
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1547
          </ul>
1548
          </p>
1549
          <p>
1550
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1551
           specific parts part definitions:
1552
          <ul>
1553
            <li>BotanicalName</li>
1554
            <li>ZoologicalName</li>
1555
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1556
          </ul>
1557
           An example:
1558
          <pre>
1559
           {
1560
            "ZoologicalName": {
1561
              "namePart": {
1562
                "name": true
1563
              },
1564
              "referencePart": {
1565
                "authors": true
1566
              },
1567
              "microreferencePart": {
1568
                "microreference": true
1569
              },
1570
              "statusPart": {
1571
                "status": true
1572
              },
1573
              "descriptionPart": {
1574
                "description": true
1575
              }
1576
            },
1577
            "BotanicalName": {
1578
              "namePart": {
1579
                "name": true,
1580
                "authors": true
1581
              },
1582
              "referencePart": {
1583
                "reference": true,
1584
                "microreference": true
1585
              },
1586
              "secReferencePart": {
1587
                "secReference": true
1588
              },
1589
              "statusPart": {
1590
                "status": true
1591
              },
1592
              "descriptionPart": {
1593
                "description": true
1594
              }
1595
            }
1596
          }
1597
           </pre>',
1598
  );
1599

    
1600
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1601
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1602
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1603
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1604
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1605

    
1606
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1607
    $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.)';
1608
  } else if($is_custom_render_template){
1609
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1610
  } else {
1611
    $which_version_message = '(These are the default render templates.)';
1612
  }
1613

    
1614
  $diff_viewer_markup = '';
1615
  if($is_custom_render_template){
1616
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1617
  }
1618

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

    
1624
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1625
      '#type' => 'textarea',
1626
      '#title' => t('Name render templates'),
1627
      '#element_validate' => array('form_element_validate_json'),
1628
      '#default_value' =>  $current_render_templates_json,
1629
      '#description' => '
1630
          <p>' . $which_version_message . '</p>
1631
          <p>
1632
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1633
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1634
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1635
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1636
          The following render Path keys are currently recognized:
1637
          <ul>
1638
            <li>list_of_taxa</li>
1639
            <li>acceptedFor</li>
1640
            <li>homonym</li>
1641
            <li>taxon_page_synonymy</li>
1642
            <li>typedesignations</li>
1643
            <li>taxon_page_title</li>
1644
            <li>polytomousKey</li>
1645
            <li>na: name + authorship</li>
1646
            <li>nar:name + authorship + reference</li>
1647
            <li>#DEFAULT</li>
1648
          </ul>
1649
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1650
          array element should be a comma separated list of render paths, without any whitespace!.
1651
          </p>
1652
          <p>
1653
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1654
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1655
          <p>
1656
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1657
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1658
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1659
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1660
          links if the paramters $nameLink or $refenceLink are given to the name render function
1661
          (this is hard coded and cannot be configured here).',
1662
  );
1663

    
1664
  // @WA: D7 form api does not support reset buttons,
1665
  // so to mimic the D5 reset button we add one like this.
1666
  $form['actions']['reset'] = array(
1667
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1668
    '#weight' => 1000,
1669
  );
1670

    
1671
  $form['#submit'] = array('submit_json_as_php_array');
1672
  // #json_elements especially defined for submit_json_as_php_array()
1673
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1674
  return system_settings_form($form);
1675
}
1676

    
1677

    
1678

    
1679
  /**
1680
 * @todo Please document this function.
1681
 * @see http://drupal.org/node/1354
1682
 */
1683
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1684
  $form[$form_name] = array(
1685
    '#type' => 'fieldset',
1686
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1687
    '#collapsible' => TRUE,
1688
    '#collapsed' => $collapsed,
1689
    '#tree' => TRUE,
1690
    '#description' => t('@$form-description', array('@$form-description' => $form_description)),
1691
  );
1692

    
1693
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1694
  $gallery_settings = variable_get($form_name, $default_values);
1695
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1696
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1697
    /*
1698
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1699
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1700
    '#type' => 'textfield',
1701
    '#title' => t('Search Page Size'),
1702
    '#default_value' => $test,
1703
    '#description' => t('Number of Names to display per page in search results.')
1704
    );
1705
    */
1706
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1707
      '#type' => 'checkbox',
1708
      '#title' => t('Show media thumbnails for accepted taxa'),
1709
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1710
    );
1711

    
1712
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1713
      '#type' => 'checkbox',
1714
      '#title' => t('Show media thumbnails for synonyms'),
1715
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1716
      '#description' => '',
1717
    );
1718
  }
1719

    
1720
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1721
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1722
    '#type' => 'checkbox',
1723
    '#title' => t('Show captions under thumbnails'),
1724
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1725
    '#description' => '',
1726
  );
1727

    
1728
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1729
    '#type' => 'textfield',
1730
    '#title' => t('Thumbnail size') . ':',
1731
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1732
    '#description' => t('Select the size of each individual thumbnail.'),
1733
  );
1734

    
1735
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1736
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1737
      '#type' => 'textfield',
1738
      '#title' => t('Number of columns') . ':',
1739
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1740
      '#description' => t('Group the thumbnails in columns: select how many
1741
        columns the gallery should display.'),
1742
    );
1743
  }
1744

    
1745
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1746
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1747
      '#type' => 'textfield',
1748
      '#title' => t('Maximum number of rows') . ':',
1749
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1750
      '#description' => t('You can group the thumbnails in rows, select in how
1751
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1752
        If you want an unlimited number of rows please set to 0.'),
1753
    );
1754
  }
1755

    
1756
  return $form;
1757
}
1758

    
1759
/**
1760
 * @todo document this function.
1761
 */
1762
function cdm_settings_layout_taxon() {
1763
  $collapsed = FALSE;
1764
  $form = array();
1765

    
1766
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1767

    
1768
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1769
      '#type' => 'checkbox',
1770
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1771
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1772
      '#description' => t('<p>If checked the link to search results is rendered at
1773
       the top of the taxon site. Clicking on the link the last search performed
1774
       is rendered again.</p>'),
1775
  );
1776

    
1777
  // --------- TABBED TAXON ------- //
1778
  $form['taxon_tabs'] = array(
1779
    '#type' => 'fieldset',
1780
    '#title' => t('Taxon tabs'),
1781
    '#collapsible' => TRUE,
1782
    '#collapsed' => TRUE,
1783
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1784
      be splitted in four diferent tabs; General, Synonymy, Images and
1785
      Specimens. If the taxon has no information for any of the tabs/sections
1786
      such tab will be not displayed.'),
1787
  );
1788

    
1789
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1790
    '#type' => 'checkbox',
1791
    '#title' => t('Tabbed taxon page'),
1792
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1793
    '#description' => t('<p>If selected split the taxon page into individual
1794
      tabs for description, images, synonymy and specimens. If not the taxon
1795
      data is rendered as a long single page without tabs.</p>'),
1796
  );
1797

    
1798
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1799
    '#type' => 'checkboxes',
1800
    '#title' => t('Tabs visibility options') . ':',
1801
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1802
    '#options' => get_taxon_options_list(),
1803
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1804
  );
1805

    
1806
  // WEIGHT
1807
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1808
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1809
      '#tree' => true
1810
  );
1811
  // Weights range from -delta to +delta, so delta should be at least half
1812
  // of the amount of tabs present.
1813
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1814
  foreach (get_taxon_tabs_list() as $label) {
1815
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1816
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1817
        '#title' => $label,
1818
        '#type'  => 'weight',
1819
        '#default_value' => $taxontabs_weights[$key],
1820
        '#delta' => $tab_weight_delta
1821
    );
1822
  }
1823

    
1824
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1825
    '#type' => 'select',
1826
    '#title' => t('Default tab to display') . ':',
1827
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1828
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1829
    '#description' => t('<p>Select the default tab to display when visiting a
1830
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1831
      <strong>Note:</strong> After performing a search and clicking in any
1832
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1833
      taxon and not the above selected tab.'),
1834
  );
1835

    
1836
  /* ======  TAXON_PROFILE ====== */
1837
  $form['taxon_profile'] = array(
1838
    '#type' => 'fieldset',
1839
    '#title' => t('Taxon profile (tab)'),
1840
    '#description' => t('<p>This section covers the settings related to the taxon
1841
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1842
    '#collapsible' => TRUE,
1843
    '#collapsed' => TRUE,
1844
  );
1845

    
1846
  // ---- PROFILE PICTURE ----//
1847

    
1848
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1849
    '#type' => 'fieldset',
1850
    '#tree' => TRUE,
1851
    '#title' => t('Taxon profile picture'),
1852
    '#collapsible' => TRUE,
1853
    '#collapsed' => FALSE,
1854
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1855
  );
1856

    
1857
  //FIXME migrate variables:
1858
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1859
  // FIXME
1860
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1861

    
1862
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1863

    
1864
  /*
1865
   * 'show' => 1,
1866
   * 'maxextend' => 184,
1867
   * 'media_uri_query' => ''
1868
   * 'custom_placeholder_image_on' => 1,
1869
   * 'custom_placeholder_image_fid' => ''
1870
   */
1871
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1872
    '#type' => 'checkbox',
1873
    '#title' => t('Enable profile picture'),
1874
    '#description' => t('Show the profile picture.'),
1875
    '#default_value' => $taxon_profile_image_settings['show'],
1876
  );
1877

    
1878
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1879
      '#type' => 'textfield',
1880
      '#tree' => TRUE,
1881
      '#title' => t('Profile picture maximum extend'),
1882
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1883
      '#field_suffix' => 'px',
1884
      '#maxlength' => 4,
1885
      '#size' => 4,
1886
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
1887
  );
1888

    
1889
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1890
      '#type' => 'textfield',
1891
      '#tree' => TRUE,
1892
      '#title' => t('Additional URI query parameter'),
1893
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1894
      '#maxlength' => 1024,
1895
      '#size' => 60,
1896
      '#description' => t('Additional query parameters to be used when requesting for the  
1897
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
1898
            The query parameters will be appended to the uri of the media representation part
1899
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1900
  );
1901

    
1902
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1903
    '#type' => 'checkbox',
1904
    '#title' => t('Show the placeholder image'),
1905
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
1906
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1907
  );
1908

    
1909
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1910
      '#type' => 'checkbox',
1911
      '#title' => t('Use a custom placeholder image'),
1912
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1913
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1914
  );
1915

    
1916
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1917
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1918
        '#type' => 'managed_file',
1919
        '#title' => t('Custom placeholder image file'),
1920
        '#progress_indicator' => 'bar',
1921
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1922
    //       '#name' => 'custom_placeholder_image',
1923
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1924
    );
1925

    
1926
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1927
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1928
      $url = file_create_url($profile_image_file->uri);
1929
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1930
                '#type' => 'item',
1931
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1932
      );
1933
    }
1934
  } else {
1935
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1936
      '#type' => 'hidden',
1937
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1938
    );
1939
  }
1940

    
1941
  $options = cdm_rankVocabulary_as_option();
1942
  array_unshift($options, '-- DISABLED --');
1943
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1944
    '#type' => 'select',
1945
    '#title' => t('Hide profile picture for higher ranks') . ':',
1946
    '#default_value' => variable_get('image_hide_rank', '0'),
1947
    '#options' => $options,
1948
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1949
  );
1950

    
1951
  // -- MEDIA THUMBNAILS -- //
1952
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1953
  $form_title = 'Taxon Profile Images';
1954
  $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>';
1955
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1956

    
1957
  // ---- FEATURE TREE BLOCKS ---- //
1958
  $form['taxon_profile']['feature_blocks'] = array(
1959
    '#type' => 'fieldset',
1960
    '#title' => t('Feature Blocks'),
1961
    '#collapsible' => TRUE,
1962
    '#collapsed' => FALSE,
1963
    '#description' => t("This section covers settings related to the taxon's
1964
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1965
      features such as description, distribution, common names"),
1966
  );
1967
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1968
  $profile_feature_tree = get_profile_feature_tree();
1969
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
1970
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
1971
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
1972
  }
1973
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
1974
    '#type' => 'radios',
1975
    '#title' => t('Taxon profile feature tree') . ':',
1976
    '#default_value' => $profile_feature_tree_uuid,
1977
    '#options' =>  $featureTrees['options'],
1978
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1979
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1980
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
1981
      profile page.'
1982
    ),
1983
  );
1984

    
1985
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
1986
  $profile_feature_tree = get_profile_feature_tree();
1987

    
1988
  if (isset($profile_feature_tree->root->childNodes)) {
1989

    
1990
    $form_feature_block_layout = array(
1991
      '#type' => 'fieldset',
1992
      '#tree' => true,
1993
      '#title' => t('Taxon profile feature block settings'),
1994
      '#collapsible' => TRUE,
1995
      '#collapsed' => FALSE,
1996
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
1997
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
1998
      The subforms have the following settings in common:<br />
1999
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2000
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2001
      <h6>Link to name used in source:</h6><div>Whether to show name is source information as link which will point to the according name page</div>
2002
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2003
            <ol>
2004
            <li>If element is of the CDM type TextData and the text is not empty the source references will be
2005
                appended in brackets like "text (source references)". If the original source has name in source
2006
                information it will be appended to the citation string,
2007
                like : "(citation, as name in source; citation, as name in source)"</li>
2008
             <li>if the text of the TextData is empty, the original source citations are the only content
2009
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2010
                prepended to the citation string like: "name in source: citation"</li>
2011
            </ol>
2012
            <strong>If disabled:</strong><br />
2013
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2014
             citations are the only content, the resulting feature block content would only consist of footnotes.
2015
             In this case the display of the respective feature block is suppressed.</div>
2016
      </dl>
2017
      <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
2018
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2019
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2020
        . '</em></div>
2021
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2022
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2023
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2024
      <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>
2025
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2026
           cdm_feature_block_element_tag_name()</div>',
2027
    );
2028

    
2029

    
2030
    $feature_list_layout_settings_disabled = FALSE;
2031

    
2032
    // creating helper object to retrieve the default settings
2033
    $featureNode = new stdClass();
2034
    $featureNode->feature = new stdClass();
2035
    $featureNode->feature->uuid="DEFAULT";
2036
    $featureNode->feature->representation_L10n = "Default";
2037
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2038

    
2039
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2040

    
2041
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2042

    
2043
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2044
        $subform_id = $featureNode->feature->uuid;
2045
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2046

    
2047
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2048

    
2049
        $form_feature_block_layout[$subform_id] = array(
2050
          '#type' => 'fieldset',
2051
          '#tree' => TRUE,
2052
          '#title' => $featureNode->feature->representation_L10n,
2053
          '#collapsible' => FALSE,
2054
          '#collapsed' => FALSE,
2055
        );
2056
        if($featureNode->feature->uuid == "DEFAULT"){
2057
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2058
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2059
          references</em> and <em>names in source</em> is only possible in the defaults';
2060
        }
2061

    
2062
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2063
          '#type' => 'select',
2064
          '#title' => 'List type',
2065
          '#default_value' => $feature_block_setting['as_list'],
2066
          '#options' => array(
2067
            'div' => 'not as list',
2068
            'ul' => 'bullet list',
2069
            'ol' => 'numbered list',
2070
            'dl' => 'definition list'
2071
          ),
2072
        );
2073

    
2074
        if($featureNode->feature->uuid == "DEFAULT"){
2075
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2076
            '#type' => 'checkbox',
2077
            '#title' => t('Link to reference'),
2078
            '#default_value' => $feature_block_setting['link_to_reference'],
2079
          );
2080

    
2081
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2082
            '#type' => 'checkbox',
2083
            '#title' => 'Link to name used in source',
2084
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2085
          );
2086
        }
2087

    
2088
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2089
          '#type' => 'checkbox',
2090
          '#title' => 'Sources as content',
2091
          '#default_value' => $feature_block_setting['sources_as_content'],
2092
        );
2093

    
2094
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2095
          '#type' => 'checkbox',
2096
          '#title' => 'Put sources also as content to bibliography',
2097
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2098
        );
2099

    
2100
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2101
          '#type' => 'select',
2102
          '#title' => t('Sort elements'),
2103
          '#default_value' => $feature_block_setting['sort_elements'],
2104
          '#options' => array(
2105
            NO_SORT => 'No sorting',
2106
            SORT_ASC => 'Ascending',
2107
            SORT_DESC => 'Descending',
2108
            SORT_HIERARCHICAL => 'Hierarchical'
2109
          ),
2110
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2111
          <dl>
2112
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2113
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2114
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2115
          <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>
2116
          </dl>',
2117
        );
2118

    
2119
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2120
          '#type' => 'select',
2121
          '#title' => t('Element tag'),
2122
          '#options' => array(
2123
            'span' => 'span',
2124
            'div' => 'div'
2125
          ),
2126
          '#default_value' => $feature_block_setting['element_tag'],
2127
        );
2128
      }
2129
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2130
    }
2131
  }
2132

    
2133
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2134
  $form['taxon_profile']['structured_description_featuretree'] = array(
2135
    '#type' => 'fieldset',
2136
    '#title' => t('Structured Description Feature Tree'),
2137
    '#collapsible' => TRUE,
2138
    '#collapsed' => FALSE,
2139
  );
2140
  $featureTrees = cdm_get_featureTrees_as_options();
2141
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2142
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2143
    $profile_feature_tree_uuid = NULL;
2144
  }
2145
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2146
    '#type' => 'radios',
2147
    '#title' => t('Natural language representation of structured descriptions') . ':',
2148
    '#default_value' => $profile_feature_tree_uuid,
2149
    '#options' => $featureTrees['options'],
2150
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2151
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2152
    '#description' => t('Taxon descriptions can be stored in a highly structured
2153
      form. The feature tree selected here will be used to generate textual
2154
      representation in natural language.'
2155
    ),
2156
  );
2157

    
2158

    
2159

    
2160
  // ---- DISTRIBUTION LAYOUT ---- //
2161
  $form['taxon_profile']['distribution_layout'] = array(
2162
    '#title' => t('Distribution'),
2163
    '#collapsible' => TRUE,
2164
    '#collapsed' => FALSE,
2165
    '#type' => 'fieldset',
2166
    '#description' => 'This section covers general settings regarding the textual representation of distributions.
2167
        Map related settings are found in the '
2168
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2169
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2170
      . l(
2171
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2172
        array('fragment' => 'edit-feature-block-settings')
2173
      )
2174
      . ' More general settings regrading the filtering of Distributions are found at '
2175
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2176
      . '. (These settings here will be merged in future releases into the feature block settings)',
2177

    
2178
  );
2179

    
2180
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2181
    '#type' => 'checkbox',
2182
    '#title' => t('Condensed distribution'),
2183
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2184
    '#description' => 'This option enables the display of a very compact representation
2185
    of the distribution which includes also information on the status.',
2186
  );
2187

    
2188
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2189
    '#type' => 'select',
2190
    '#title' => t('Condensed distribution recipe'),
2191
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2192
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2193
    '#description' => 'Recipe for creating the condensed distribution.',
2194
  );
2195

    
2196
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2197
    '#type' => 'textfield',
2198
    '#title' => t('Condensed distribution info path'),
2199
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2200
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2201
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2202
  );
2203

    
2204

    
2205
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2206
    '#type' => 'radios',
2207
    '#title' => t('Display mode') . ':',
2208
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2209
    '#options' => array(
2210
      'FLAT_ALPHA' => t('Flat list'),
2211
      'TREE' => t('Hierarchically ordered'),
2212
    ),
2213
    '#description' => 'Taxon distribution information is displayed with
2214
    focus on the area of the distribution. The list of areas can either be shown
2215
    as flat list ordered alphabetically or in the hierarchical of the parent
2216
    area and subarea relationship. Fall back areas areas with no Distribution data
2217
    are hidden from the area hierarchy so that their sub areas will move one level up.
2218
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2219
    ' for details on the <em>Marked area filter</em>.',
2220
  );
2221

    
2222
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2223
    '#type' => 'fieldset',
2224
    '#tree' => true,
2225
    '#title' => t('Distribution hierarchy style')
2226
  );
2227

    
2228
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2229
  foreach(array_keys($hierarchy_styles) as $level) {
2230
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2231
      '#type' => 'fieldset',
2232
      '#tree' => true,
2233
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2234
      '#attributes' => array('class' => array('fieldset-float'))
2235
    );
2236
    foreach ($hierarchy_styles[$level] as $key => $value) {
2237
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2238
        '#type' => 'textfield',
2239
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2240
        '#default_value' => $hierarchy_styles[$level][$key],
2241
        '#maxlength' => 4,
2242
        '#size' => 4
2243
      );
2244
    }
2245
  }
2246

    
2247
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, CDM_ORDER_BY_ORDER_INDEX_ASC);
2248
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2249
    '#type' => 'checkboxes',
2250
    '#title' => 'Omit area levels',
2251
    '#options' => $level_options,
2252
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2253
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2254
    Areas which belong to the selected area levels will be hidden in the portal.',
2255
  );
2256

    
2257
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2258
    '#type' => 'checkbox',
2259
    '#title' => t('Show TextData elements on top of the map'),
2260
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2261
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2262
      elements on top of the map. Otherwise all <code>TextData</code>
2263
      distribution elements will be listed below the other area elements.
2264
      This option is useful if you need to have descriptive texts for each
2265
      distribution map.'),
2266
  );
2267

    
2268
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2269
      '#type' => 'textarea',
2270
      '#title' => t('Custom status colors'),
2271
      '#element_validate' => array('form_element_validate_json'),
2272
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2273
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2274
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2275
          reference list of the idInVocabulary values of absence and presence terms:
2276
<pre>
2277
Presence Term
2278
p        present
2279
pd        present: doubtfully present
2280
n        native
2281
nq        native: presence questionable
2282
nd        native: doubtfully native
2283
c        cultivated
2284
i        introduced
2285
iq        introduced: presence questionable
2286
id        introduced: doubtfully introduced (perhaps cultivated only)
2287
ip        introduced: uncertain degree of naturalisation
2288
ia        introduced: adventitious (casual)
2289
in        introduced: naturalized
2290
ic        introduced: cultivated
2291
e        endemic for the relevant area
2292
na        naturalised
2293
iv        invasive
2294

2295
AbsenceTerm
2296
a        absent
2297
f        reported in error
2298
nf        native: reported in error
2299
if        introduced: reported in error
2300
cf        cultivated: reported in error
2301
ne        native: formerly native
2302
ie        introduced: formerly introduced
2303

2304
</pre>'),
2305
  );
2306

    
2307

    
2308
  /* ====== SYNONYMY ====== */
2309
  $form['taxon_synonymy'] = array(
2310
    '#type' => 'fieldset',
2311
    '#title' => t('Taxon synonymy (tab)'),
2312
    '#collapsible' => TRUE,
2313
    '#collapsed' => TRUE,
2314
    '#description' => t('This section covers the settings related to the taxon
2315
      <strong>synonymy</strong> tab.'),
2316
  );
2317

    
2318
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2319
    '#type' => 'checkbox',
2320
    '#title' => t('Show accepted taxon on top of the synonymy'),
2321
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2322
    '#description' => t('If checked, the first homotypic taxon is a repetition
2323
      of the accepted taxon most likely with the full nomenclatural reference
2324
      (depending on the currently chosen theme).'),
2325
  );
2326

    
2327
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2328
    '#type' => 'checkbox',
2329
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2330
      coming from a synonym link.'),
2331
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2332
    '#description' => t('Check this if after doing a search and clicking on a
2333
      synonym you want to see the "accept of" text for the accepted synonym.'),
2334
  );
2335

    
2336
  /* === currently unused ===
2337
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2338
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2339
    '#type' => 'checkboxes',
2340
    '#title' => t('Display name relationships') . ':',
2341
    '#default_value' => variable_get('name_relationships_to_show', 0),
2342
    '#options' => $nameRelationshipTypeOptions,
2343
    '#description' => t('Select the name relationships you want to show for the
2344
      accepted taxa.'),
2345
  );
2346
 */
2347

    
2348
  $form['taxon_synonymy']['taxon_relations'] = array(
2349
    '#type' => 'fieldset',
2350
    '#title' => t('Taxon relationships'),
2351
    '#collapsible' => FALSE,
2352
    '#collapsed' => FALSE
2353
  );
2354

    
2355
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2356
    '#type' => 'checkbox',
2357
    '#title' => t('Show taxon relations ships of accepted taxon'),
2358
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2359
    '#description' => t('If this option is enabled the synonymy will show the
2360
      below selected taxon relationships of accepted taxa.'),
2361
  );
2362

    
2363
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2364
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2365
    '#type' => 'checkboxes',
2366
    '#title' => t('Taxon relationship types') . ':',
2367
    '#description' => t('Only taxon relationships of the selected type will be
2368
      displayed'),
2369
    '#options' => $taxonRelationshipTypeOptions,
2370
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2371
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2372
  );
2373

    
2374
  $form['taxon_synonymy']['name_relations'] = array(
2375
    '#type' => 'fieldset',
2376
    '#title' => t('Name relationships'),
2377
    '#collapsible' => FALSE,
2378
    '#collapsed' => FALSE
2379
  );
2380

    
2381
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2382
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2383
    '#type' => 'checkboxes',
2384
    '#title' => t('Name relationship types') . ':',
2385
    '#description' => t('Only name relationships of the selected type will be
2386
      displayed'),
2387
    '#options' => $taxonRelationshipTypeOptions,
2388
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2389
  );
2390

    
2391
  // ====== SPECIMENS ====== //
2392
  $form['taxon_specimens'] = array(
2393
    '#type' => 'fieldset',
2394
    '#title' => t('Taxon specimens (tab)'),
2395
    '#collapsible' => TRUE,
2396
    '#collapsed' => TRUE,
2397
    '#description' => t('This section covers the settings related to the taxon
2398
      <strong>specimens</strong> tab.'),
2399
  );
2400

    
2401
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2402
        '#type' => 'checkbox',
2403
        '#title' => t('Show specimen derivatives in a compressed table'),
2404
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2405
        '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2406
        a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2407
    );
2408
    
2409
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2410
        '#type' => 'checkbox',
2411
        '#title' => t('Show "Associated with" in specimen table.'),
2412
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2413
    );
2414

    
2415
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2416
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2417
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2418
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2419
  }
2420
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2421
      '#type' => 'radios',
2422
      '#title' => t('Specimen description feature tree') . ':',
2423
      '#default_value' => $profile_feature_tree_uuid,
2424
      '#options' =>  $featureTrees['options'],
2425
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2426
      '#options_suffixes' => $featureTrees['treeRepresentations'],
2427
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2428
      ),
2429
  );
2430

    
2431
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2432
  $form_title = t('Specimen media');
2433
  $form_description = t('Specimens may have media which is displayed at the
2434
     Specimen tab/section as a gallery. It is possible to configure the
2435
     thumbnails gallery here, however for configuring how a single media should
2436
     be displayed please go to !url.</p>',
2437
     array(
2438
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2439
     ));
2440
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2441

    
2442
  // --- MEDIA GALLERY ---- //
2443
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2444
  $form_title = 'Media gallery (tab)';
2445
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2446
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2447
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2448
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2449
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2450
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2451
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2452

    
2453
  // Comment @WA: D7 form api does not support reset buttons,
2454
  // so to mimic the D5 reset button we add one like this.
2455
  $form['actions']['reset'] = array(
2456
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2457
    '#weight' => 1000,
2458
  );
2459
  return system_settings_form($form);
2460
}
2461

    
2462
/**
2463
 * @todo document this function.
2464
 */
2465
function cdm_settings_layout_search() {
2466

    
2467
  $form = array();
2468

    
2469
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2470

    
2471
  $form['search_settings'] = array(
2472
    '#type' => 'fieldset',
2473
    '#title' => t('Taxa Search'),
2474
    '#collapsible' => FALSE,
2475
    '#collapsed' => FALSE,
2476
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2477
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2478
         where they can write the text to be searched. You can find Drupal block configuration
2479
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2480
  );
2481

    
2482
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2483
      '#type' => 'checkbox',
2484
      '#title' => t('Ignore the chosen classification in simple search'),
2485
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2486
      '#description' => t('The simple search, which can be executed via the search block,
2487
          will by default search on the classification selected in the classification browser
2488
          selector. Set the tick if you want your portal to search on all classifications.'),
2489
  );
2490

    
2491
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2492
    '#type' => 'checkbox',
2493
    '#title' => t('Run simple search with free-text search backend.'),
2494
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2495
    '#description' => t('The simple search uses by default another search
2496
      backend as the advances search. By checking this option the simple search can be
2497
      configured to also use the free-text search backend.'),
2498
  );
2499

    
2500
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2501
    '#type' => 'textfield',
2502
    '#title' => t('Results per page') . ':',
2503
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2504
    '#description' => t('Number of results to display per page.'),
2505
  );
2506

    
2507
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2508
    '#type' => 'checkbox',
2509
    '#title' => t('Show the <i>Show Image Thumbnails</i> button') . ':',
2510
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2511
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2512
  );
2513

    
2514
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2515
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2516
      '#type' => 'checkboxes',
2517
      '#title' => 'Search mode',
2518
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2519
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2520
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2521
          defaults set here.',
2522
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2523
      '#default_value' => $search_mode_default
2524
      );
2525

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

    
2531
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2532
  );
2533

    
2534
  // --- SEARCH TAXA GALLERY ---- //
2535
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2536
  $collapsed = FALSE;
2537
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2538
  $form_title = 'Taxa Search thumbnails';
2539
  $form_description = 'Search results may show thumbnails. ';
2540
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2541

    
2542
  // Comment @WA: D7 form api does not support reset buttons,
2543
  // so to mimic the D5 reset button we add one like this.
2544
  $form['actions']['reset'] = array(
2545
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2546
    '#weight' => 1000,
2547
  );
2548
  return system_settings_form($form);
2549
}
2550

    
2551
/**
2552
 * @todo document this function.
2553
 */
2554
function cdm_settings_layout_media() {
2555

    
2556
  $form = array();
2557

    
2558
  $form['media_settings'] = array(
2559
    '#type' => 'fieldset',
2560
    '#title' => t('Media settings'),
2561
    '#collapsible' => FALSE,
2562
    '#collapsed' => FALSE,
2563
    '#description' => 'This section covers layout settings for media pages.'
2564
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2565
  );
2566

    
2567
  $form['media_settings']['image_gallery_viewer'] = array(
2568
    '#type' => 'select',
2569
    '#title' => t('Image viewer') . ':',
2570
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2571
    '#options' => array(
2572
      'default' => t('Standard image viewer'),
2573
      'fsi' => t('FSI viewer (requires FSI server!)'),
2574
    ),
2575
  );
2576

    
2577
  // --- MEDIA GALLERY ---- //
2578
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2579
  $form_title = 'Standard viewer';
2580
  $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>';
2581
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2582
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2583

    
2584
  // @WA: D7 form api does not support reset buttons,
2585
  // so to mimic the D5 reset button we add one like this.
2586
  $form['actions']['reset'] = array(
2587
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2588
    '#weight' => 1000,
2589
  );
2590
  return system_settings_form($form);
2591
}
2592

    
2593
/**
2594
 * GEOSERVICE and Map settings.
2595
 */
2596
function cdm_settings_geo($form, &$form_state) {
2597

    
2598
  $current_geoserver_settings = get_edit_map_service_settings();
2599
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2600

    
2601

    
2602
  $form = array();
2603

    
2604
  $dummy_distribution_query = NULL;
2605
  if($map_distribution['map_type'] != 1){
2606
    // we need to apply a dummy query since the map service requires for image maps
2607
    // at least as and ad to be defined
2608
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2609
  }
2610

    
2611
  $form['map_preview'] = array(
2612
      '#type' => 'fieldset',
2613
      '#tree' => FALSE,
2614
      '#title' => t('Map preview'),
2615
      '#collapsible' => FALSE,
2616
      '#description' => 'The preview of the map'
2617
       . ($dummy_distribution_query != null ?
2618
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2619
           '.<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.')
2620
  );
2621
  $form['map_preview']['openlayers_map'] = compose_map(NULL, $dummy_distribution_query, NULL,
2622
    array(
2623
      'move' => "this.cdmOpenlayersMap.printInfo",
2624
      '#execute' => "this.cdmOpenlayersMap.printInfo"
2625
    ),
2626
    true // resizable
2627
  );
2628

    
2629
  /*
2630
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2631
  );
2632
  */
2633

    
2634
  /*
2635
   * GEO SERVER
2636
   */
2637
  $form['edit_map_server'] = array(
2638
    '#type' => 'fieldset',
2639
    '#tree' => true,
2640
    '#title' => t('EDIT map service'),
2641
    '#collapsible' => TRUE,
2642
    '#collapsed' => TRUE,
2643
    '#description' => t('Configuration and selection of your geo server.
2644
      The Geo Server is responsible for generating the maps.'),
2645
  );
2646

    
2647
  $form['edit_map_server']['base_uri'] = array(
2648
    '#type' => 'select',
2649
    '#title' => t('EDIT map service') . ':',
2650
    '#default_value' => $current_geoserver_settings['base_uri'],
2651
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2652
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2653
  );
2654
  $form['edit_map_server']['version'] = array(
2655
      '#type' => 'select',
2656
      '#title' => t('Version') . ':',
2657
      '#default_value' => $current_geoserver_settings['version'],
2658
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2659
      '#description' => t('The version of the EDIT map services'),
2660
  );
2661

    
2662
  /*
2663
   * MAP SETTINGS
2664
   */
2665

    
2666
  $form[CDM_MAP_DISTRIBUTION] = array(
2667
    '#type' => 'fieldset',
2668
    '#tree' => TRUE,
2669
    '#title' => t('Maps settings'),
2670
    '#collapsible' => TRUE,
2671
    '#collapsed' => TRUE,
2672
    '#description' => t('General configuration for all map types.'),
2673
  );
2674

    
2675
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2676
    '#type' => 'radios',
2677
    '#title' => 'Map types',
2678
    '#options' => array(
2679
      1 => "OpenLayers dynamic map viewer",
2680
      0 => "Plain image",
2681
    ),
2682
    '#default_value' => $map_distribution['map_type'],
2683
    '#description' => 'Two different map types are available :
2684
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2685
      which allows zooming and panning. If enabled you can configure the default layer
2686
      (background of your maps) below.</li>
2687
      <li><em>Plain image</em>: The map will be static non interactive
2688
      image.</li></ul>',
2689
  );
2690
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2691

    
2692
  /*
2693
   * settings for the distribution map are used also for specimens map!!!!
2694
   */
2695

    
2696
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2697
      '#type' => 'textfield',
2698
      '#title' => 'Aspect ratio',
2699
      '#default_value' => $map_distribution['aspect_ratio'],
2700
      '#maxlength' => 4,
2701
      '#size' => 4,
2702
      '#element_validate' => array('element_validate_number'),
2703
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2704
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2705
      width by the height:</br>
2706
      <pre>aspect ratio = w / h</pre>
2707
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2708
      for a square map use <strong>1</strong>.',
2709
  );
2710

    
2711
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2712
    '#type' => 'textfield',
2713
    '#title' => 'Bounding box',
2714
    '#default_value' => $map_distribution['bbox'],
2715
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2716
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2717
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2718
      <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.
2719
      (Maybe you need to change the map base layer to OpeLayers.)
2720
      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
2721
      below the map from where you can copy the bbox string.</p>'),
2722
  );
2723

    
2724
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2725
    '#type' => 'checkbox',
2726
    '#title' => 'Display area labels',
2727
    '#default_value' => $map_distribution['show_labels'],
2728
    '#description' => t('The map will show name labels of the areas'),
2729
  );
2730

    
2731
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2732
    '#type' => 'textfield',
2733
    '#title' => 'Map caption',
2734
    '#default_value' => $map_distribution['caption'],
2735
    '#description' => t('The caption will be shown below the map.'),
2736
  );
2737

    
2738
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2739
    '#type' => 'textfield',
2740
    '#title' => 'Distribution layer opacity',
2741
    '#default_value' => $map_distribution['distribution_opacity'],
2742
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2743
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2744
  );
2745

    
2746
  // --- Plain Image Settings --- //
2747
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2748
    '#type' => 'fieldset',
2749
    '#title' => 'Plain image map settings',
2750
    '#tree' => TRUE,
2751
    '#collapsible' => TRUE,
2752
    '#collapsed' => $open_layers_is_enabled,
2753
    '#description' => 'The settings in this section are still expertimental
2754
      and can only be used with the EDIT map service version 1.1 or above.',
2755
  );
2756
  $edit_mapserver_version = get_edit_map_service_version_number();
2757
  if ($edit_mapserver_version < 1.1) {
2758
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2759
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2760
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2761
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2762
  }
2763

    
2764
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2765
    '#type' => 'textfield',
2766
    '#title' => 'Width',
2767
    '#default_value' => $map_distribution['image_map']['width'],
2768
    '#maxlength' => 4,
2769
    '#size' => 4,
2770
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2771
  );
2772

    
2773
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2774
    '#type' => 'textfield',
2775
    '#title' => 'Background layer',
2776
    '#default_value' => $map_distribution['image_map']['base_layer'],
2777
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2778
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2779
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2780
    )),
2781
  );
2782

    
2783
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2784
    '#type' => 'textfield',
2785
    '#title' => 'Background color',
2786
    '#default_value' => $map_distribution['image_map']['bg_color'],
2787
  );
2788

    
2789
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2790
    '#type' => 'textfield',
2791
    '#title' => 'Background layer style',
2792
     // Only line color by now.
2793
    '#default_value' => $map_distribution['image_map']['layer_style'],
2794
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2795
  );
2796

    
2797
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2798
      '#type' => 'textfield',
2799
      '#title' => 'Projection',
2800
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2801
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2802
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2803
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2804
  );
2805

    
2806

    
2807
  // --- OpenLayers Settings --- //
2808
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2809
    '#type' => 'fieldset',
2810
    '#title' => 'OpenLayers settings',
2811
    '#tree' => TRUE,
2812
    '#collapsible' => TRUE,
2813
    '#collapsed' => !$open_layers_is_enabled,
2814
    '#description' => '',
2815
  );
2816

    
2817

    
2818
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2819
      '#type' => 'checkbox',
2820
      '#title' => 'Display outside max extent',
2821
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2822
      '#description' => t('Allows the map to display parts of the layers which are outside
2823
         the max extent if the aspect ratio of the map and of the baselayer
2824
         are not equal.'),
2825
  );
2826

    
2827

    
2828
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2829
      '#type' => 'checkbox',
2830
      '#title' => 'Show Layer Switcher',
2831
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2832
      '#description' => 'The Layer Switcher control displays a table of contents
2833
      for the map.  This allows the user interface to switch between
2834
      base layers and to show or hide overlays.  By default the switcher is
2835
      shown minimized on the right edge of the map, the user may expand it
2836
      by clicking on the handle.',
2837
  );
2838

    
2839
  if (!$open_layers_is_enabled) {
2840
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2841
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2842
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2843
  }
2844

    
2845
  // The default layer must always be enabled
2846
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2847
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2848

    
2849
  $baselayer_options = array(
2850
    /*
2851
   NOTICE: must correspond to the layers defined in
2852
   js/openlayers_,ap.js#getLayersByName()
2853
   */
2854
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
2855
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
2856
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
2857
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
2858
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2859
    // all others EPSG:900913
2860
    'mapnik' => 'OpenStreetMap',
2861
    'mapquest_open' => "MapQuest",
2862
    'mapquest_sat' => "MapQuest Sattelite",
2863
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2864
//    'gmap' => 'Google Streets',
2865
//    'gsat' => 'Google Satellite',
2866
//    'ghyb' => 'Google Hybrid',
2867
//     'veroad' => 'Virtual Earth Roads',
2868
//     'veaer' => 'Virtual Earth Aerial',
2869
//     'vehyb' => 'Virtual Earth Hybrid',
2870
    // 'yahoo' => 'Yahoo Street',
2871
    // 'yahoosat' => 'Yahoo Satellite',
2872
    // 'yahoohyb' => 'Yahoo Hybrid',
2873
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2874
  );
2875

    
2876
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2877
    '#type' => 'checkboxes_preferred',
2878
    '#title' => 'Base Layers',
2879
    '#options' => $baselayer_options,
2880
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2881
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2882
  );
2883

    
2884
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2885
      '#type' => 'fieldset',
2886
      '#title' => 'Custom WMS base layer',
2887
      '#tree' => TRUE,
2888
      '#collapsible' => FALSE,
2889
      '#collapsed' => FALSE,
2890
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2891
  );
2892

    
2893
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2894
      '#type' => 'textfield',
2895
      '#title' => 'Layer name',
2896
      // Only line color by now.
2897
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2898
      '#description' => 'A arbitrary name for the layer.',
2899
  );
2900
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2901
      '#type' => 'textfield',
2902
      '#title' => 'WMS url',
2903
      // Only line color by now.
2904
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2905
      '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
2906
  );
2907
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2908
      '#type' => 'textarea',
2909
      '#title' => 'WMS parameters',
2910
      '#element_validate' => array('form_element_validate_json'),
2911
      // Only line color by now.
2912
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2913
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2914
<pre> {
2915
  "Layers": "topp:em_tiny_jan2003",
2916
  "Format": "image/png",
2917
  "BGCOLOR": "0xe0faff"
2918
}
2919
</pre>'
2920
  );
2921
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2922
      '#type' => 'textfield',
2923
      '#title' => 'Projection',
2924
      // Only line color by now.
2925
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2926
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2927
  );
2928
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2929
      '#type' => 'textfield',
2930
      '#maxlength' => 256,
2931
      '#title' => 'proj4js definition',
2932
      // Only line color by now.
2933
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2934
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2935
            The definitions for
2936
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2937
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2938
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2939
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2940
            choose to display the proj4js definition string.
2941
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2942
            <pre>
2943
+a         Semimajor radius of the ellipsoid axis
2944
+alpha     ? Used with Oblique Mercator and possibly a few others
2945
+axis      Axis orientation (new in 4.8.0)
2946
+b         Semiminor radius of the ellipsoid axis
2947
+datum     Datum name (see `proj -ld`)
2948
+ellps     Ellipsoid name (see `proj -le`)
2949
+k         Scaling factor (old name)
2950
+k_0       Scaling factor (new name)
2951
+lat_0     Latitude of origin
2952
+lat_1     Latitude of first standard parallel
2953
+lat_2     Latitude of second standard parallel
2954
+lat_ts    Latitude of true scale
2955
+lon_0     Central meridian
2956
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
2957
+lon_wrap  Center longitude to use for wrapping (see below)
2958
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
2959
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
2960
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
2961
+pm        Alternate prime meridian (typically a city name, see below)
2962
+proj      Projection name (see `proj -l`)
2963
+south     Denotes southern hemisphere UTM zone
2964
+to_meter  Multiplier to convert map units to 1.0m
2965
+towgs84   3 or 7 term datum transform parameters (see below)
2966
+units     meters, US survey feet, etc.
2967
+vto_meter vertical conversion to meters.
2968
+vunits    vertical units.
2969
+x_0       False easting
2970
+y_0       False northing
2971
+zone      UTM zone
2972
            </pre>
2973
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
2974
  );
2975
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
2976
      '#type' => 'textfield',
2977
      '#title' => 'Maximum extent',
2978
      // Only line color by now.
2979
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
2980
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
2981
  );
2982
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
2983
      '#type' => 'textfield',
2984
      '#title' => 'Units',
2985
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
2986
      '#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.'
2987
  );
2988

    
2989
  /*
2990
   * Map Legend
2991
   */
2992
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2993
    '#type' => 'fieldset',
2994
    '#title' => 'Map legend',
2995
    '#tree' => TRUE,
2996
    '#collapsible' => TRUE,
2997
    '#collapsed' => TRUE,
2998
    '#description' => 'Configure the maps legend.',
2999
  );
3000

    
3001
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3002
    '#type' => 'checkbox',
3003
    '#title' => 'Display a map legend',
3004
    '#default_value' => $map_distribution['legend']['show'],
3005
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3006
  );
3007

    
3008
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3009
    '#type' => 'textfield',
3010
    '#title' => 'Legend opacity',
3011
    '#default_value' => $map_distribution['legend']['opacity'],
3012
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3013
                         to 0.0 will be not much visible.',
3014
  );
3015

    
3016
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3017
    '#type' => 'textfield',
3018
    '#title' => 'Font size',
3019
    '#default_value' => $map_distribution['legend']['font_size'],
3020
    '#description' => 'Font size in pixels.',
3021
  );
3022

    
3023
  $fontStyles = array(
3024
    0 => "plane",
3025
    1 => "italic",
3026
  );
3027
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3028
    '#type' => 'select',
3029
    '#title' => 'Available font styles',
3030
    '#default_value' => $map_distribution['legend']['font_style'],
3031
    '#options' => $fontStyles,
3032
    '#description' => 'Select a font style for the map legend.',
3033
  );
3034

    
3035
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3036
    '#type' => 'textfield',
3037
    '#title' => 'Icon width',
3038
    '#default_value' => $map_distribution['legend']['icon_width'],
3039
    '#description' => 'Legend icon width in pixels.',
3040
  );
3041
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3042
    '#type' => 'textfield',
3043
    '#title' => 'Icon height',
3044
    '#default_value' => $map_distribution['legend']['icon_height'],
3045
    '#description' => 'Legend icon height in pixels.',
3046
  );
3047

    
3048
  // @WA: D7 form api does not support reset buttons,
3049
  // so to mimic the D5 reset button we add one like this.
3050
  $form['actions']['reset'] = array(
3051
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3052
    '#weight' => 1000,
3053
  );
3054

    
3055
  return system_settings_form($form);
3056
}
3057

    
3058

    
3059
/**
3060
 * @todo document this function.
3061
 */
3062
function cdm_settings_cache() {
3063

    
3064
  $form = array();
3065

    
3066
  $form['cache_settings'] = array(
3067
    '#type' => 'fieldset',
3068
    '#title' => t('Cache Settings'),
3069
    '#collapsible' => FALSE,
3070
    '#collapsed' => FALSE,
3071
    '#description' => t('<p>When caching is enabled all single taxon sites are
3072
      stored in an internal drupal cache doing the portal response of taxa pages
3073
      faster. This is possible because the sites are loaded from the cache and
3074
      are not created from scratch.</p>'),
3075
  );
3076

    
3077
  $form['cache_settings']['cdm_webservice_cache'] = array(
3078
    '#type' => 'checkbox',
3079
    '#title' => t('<strong>Enable caching</strong>'),
3080
    '#options' => cdm_help_general_cache(),
3081
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3082
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3083
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3084
       application the changes will be not visible till the cache is erased.
3085
       Therefore developers should deactived this feature when they are working
3086
       on the CDM Dataportal Module.</p>'),
3087
  );
3088

    
3089
  $form['cache_settings']['cdm_run_cache'] = array(
3090
    '#markup' => cdm_view_cache_site(),
3091
  );
3092

    
3093
  // @WA: D7 form api does not support reset buttons,
3094
  // so to mimic the D5 reset button we add one like this.
3095
  $form['actions']['reset'] = array(
3096
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3097
    '#weight' => 1000,
3098
  );
3099
  return system_settings_form($form);
3100
}
3101

    
3102
/**
3103
 * Walk and cache all taxon pages.
3104
 */
3105
function cdm_view_cache_site() {
3106

    
3107
  $out = '';
3108

    
3109
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3110

    
3111
  $request_params = array();
3112
  $request_params['class'] = "Taxon";
3113

    
3114
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3115
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3116
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3117

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

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

    
3127
  // Comment @WA: A form within a form is not valid html and not needed here.
3128
  // Also, it would be recommended just to include this part of the form in the
3129
  // rest of the form array in cdm_settings_cache().
3130
  // $out .= '<form id="cache_site">';
3131
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3132
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3133
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3134
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3135
  // $out .= '</form>';
3136
  $out .= '</div>';
3137
  /*
3138
  foreach($taxonPager->records as $taxon){
3139
    cdm_dataportal_taxon_view($uuid);
3140
  }
3141
  */
3142
  return $out;
3143
}
3144

    
3145

    
3146
function cdm_settings_layout_taxon_submit($form, &$form_state){
3147
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3148
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3149
    if(is_object($file)){
3150
      $file->status = FILE_STATUS_PERMANENT;
3151
      file_save($file);
3152
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3153
    }
3154
  }
3155
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
3156
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
3157
    // we first need to set the variable to persist the changes setting
3158
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3159
    menu_rebuild();
3160
  }
3161
}
3162

    
3163
function cdm_settings_layout_search_submit($form, &$form_state){
3164
  // the visibility of media thumbnails also affects the ui of the search results
3165
  // so reset the according session variable
3166
  //    1. in order to give the user immediate
3167
  //       feedback on potential setting changes
3168
  //    2. let refresh the default if it has changed
3169
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3170
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3171
  }
3172
}
3173

    
3174
/**
3175
 * Form validation handler for cdm_settings_general
3176
 *
3177
 * @param $form
3178
 * @param $form_state
3179
 */
3180
function cdm_settings_general_validate($form, &$form_state) {
3181

    
3182
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3183
    $form_state['values']['cdm_webservice_url'] .= '/';
3184
  }
3185

    
3186
}
3187

    
3188
/**
3189
 * Form submit handler for settings general.
3190
 *
3191
 * tasks performed:
3192
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3193
 *
3194
 * @param $form
3195
 * @param $form_state
3196
 */
3197
function cdm_settings_general_submit($form, &$form_state){
3198
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3199
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3200
}
3201

    
3202
/**
3203
 * Form validation handler for cdm_settings_cache
3204
 */
3205
function cdm_settings_cache_validate($form, &$form_state) {
3206
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3207
    cache_clear_all(NULL, 'cache_cdm_ws');
3208
    // Better clear secref_cache since I can not be sure if the cache has not
3209
    // be used during this response.
3210
    cdm_api_secref_cache_clear();
3211
  }
3212

    
3213
}
3214

    
3215
/**
3216
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3217
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3218
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3219
 *  - version: the version, e.g.: v1.1
3220
 *
3221
 * @return array
3222
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3223
 */
3224
function get_edit_map_service_settings() {
3225

    
3226
  $settings = variable_get('edit_map_server', array(
3227
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3228
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT