Project

General

Profile

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

    
7

    
8
  // TODO Genus UUID.
9

    
10
  define('DEFAULT_TAXONTREE_RANKLIMIT', '1b11c34c-48a8-4efa-98d5-84f7f66ef43a');
11
  define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
12
  define('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
13

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

    
17
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
18

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

    
22
  define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
23
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
24
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 1);
25
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
26
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
27
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
28
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
29

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

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

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

    
49
  /* taxonRelationshipTypes */
50
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
51

    
52

    
53

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

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

    
100

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

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

    
109

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

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

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

    
141
$taxon_tab_options = get_taxon_tabs_list();
142
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
143

    
144
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
145

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

    
156
}
157

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

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

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

    
335
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
336

    
337
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
338
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
339

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

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

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

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

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

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

    
413

    
414
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
415
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
416
    array(
417
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
418
        'includeOccurrences' => 0,
419
        'includeTaxonNameDescriptions' => 0
420
     )
421
  ));
422

    
423
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
424
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
425
  // needs to be merged with user setting by drupal_array_merge_deep()
426
  // 'width' => 512, // optimum size for OSM layers is 512
427
  // 'height' => 512 / 2, // optimum size for OSM layers 256
428
  'aspect_ratio' => 2,
429
  'bbox' => '', // empty to allow automatic zooming to extend
430
  'show_labels' => FALSE,
431
  'caption' => '',
432
  'distribution_opacity' => '0.5',
433
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
434
  'image_map' => array(
435
    'base_layer' => '', // none, formerly this was cyprusdivs
436
    'bg_color' => '1874CD',
437
    'layer_style' => 'ffffff,606060,,',
438
  ),
439
  'openlayers' => array(
440
    'base_layers' =>  array(
441
      // A layer MUST NOT BE SET in the defaults,
442
      // otherwise it can not be overidden by the user settings:
443
      // 'osgeo_vmap0' => 'osgeo_vmap0',
444
      // it is sufficient to define the preferred layer,
445
      // since it will automatically be enabled:
446
      'PREFERRED' => 'osgeo_vmap0'),
447
    'custom_wms_base_layer' => array(
448
      'name' => NULL,
449
      'url' => NULL,
450
      'params' =>  NULL,
451
      'projection' => NULL,
452
      'proj4js_def' => NULL,
453
      'max_extent' => NULL,
454
      'units' => NULL
455
    ),
456
    'show_layer_switcher' => TRUE,
457
    'display_outside_max_extent' => FALSE
458
  ),
459
  'legend' => array(
460
    'show' => TRUE,
461
    'opacity' => '0.5',
462
    'font_size' => 10,
463
    'font_style' => FALSE,
464
    'icon_width' => 35,
465
    'icon_height' => 15
466
  )
467
)));
468

    
469
/**
470
 * Merges the named array variable with the array of defaults.
471
 *
472
 * IMPORTANT: The array keys must be strings. When the keys are integers
473
 * the merging will not take place for these entities. Number keyed entities
474
 * are just appended to the result array.
475
 *
476
 * @param string $variable_name
477
 *     The variable name
478
 * @param string | array $default
479
 *     The array containing the default values either as array or serialized as string.
480
 *     Unserialization is cared for if necessary
481
 * @return array
482
 *     The merged array as returned by drupal_array_merge_deep()
483
 *
484
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
485
 * TODO force $default being an array
486
 */
487
function get_array_variable_merged($variable_name, $default){
488

    
489
    // unserialize if nessecary
490
    if(!is_array($default)){
491
      $default = unserialize($default);
492
    }
493
    $variable = variable_get($variable_name, array());
494
    $result = drupal_array_merge_deep($default, $variable);
495
    return $result;
496
}
497

    
498
/**
499
 * @todo document this function.
500
 */
501
function getGallerySettings($gallery_config_form_name) {
502
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
503
}
504

    
505
/**
506
 * Returns the string representation of the default tab.
507
 *
508
 * @param bool $returnTabIndex
509
 *   Defaults to FALSE, if set true this function will return the index number
510
 *   of the default tab. (used to supply default values to form elements).
511
 */
512
function get_default_taxon_tab($returnTabIndex = FALSE) {
513

    
514
  global $user;
515
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
516
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
517
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
518
  // Get the user value if the used has chosen to overwrite the system settings.
519
  $user_tab_on = variable_get($user_tab_active, FALSE);
520
  if ($user_tab_on) {
521
    $user_value = variable_get($user_tab, 0);
522
    $index_value = $user_value;
523
    // Get the system value.
524
  }
525
  else {
526
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
527
    $index_value = $system_value;
528
  }
529

    
530
  // Return the index value or the string representation.
531
  if ($returnTabIndex) {
532
    return $index_value;
533
  }
534
  else {
535
    return ($values[$index_value]);
536
  }
537
}
538

    
539

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

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

    
611
    // ---- DEFAULTS settings
612

    
613
    // only needed as final option, when the settings are not having a default
614
    $default = array(
615
      'DEFAULT' => array(
616
        'as_list' => 'div',
617
        'link_to_reference' => 0,
618
        'link_to_name_used_in_source' => 1,
619
        'sources_as_content' => 0,
620
        'sources_as_content_to_bibliography' => 0,
621
        'sort_elements' => NO_SORT,
622
        'glue' => '',
623
        'element_tag' => NULL
624
      )
625
    );
626

    
627
    // will be used as preset in the settings
628
    $other_themes_default = array(
629
      'DEFAULT' => array(
630
        'as_list' => 'div',
631
        'link_to_reference' => 0,
632
        'link_to_name_used_in_source' => 1,
633
        'sources_as_content' => 0,
634
        'sources_as_content_to_bibliography' => 0,
635
        'sort_elements' => NO_SORT,
636
        'glue' => '',
637
        'element_tag' => NULL
638
      ),
639
      UUID_CITATION => array(
640
        'as_list' => 'div',
641
        'link_to_reference' => 0,
642
        'link_to_name_used_in_source' => 0,
643
        'sources_as_content' => 1,
644
        'sources_as_content_to_bibliography' => 0,
645
        'sort_elements' => SORT_ASC,
646
        'glue' => '',
647
        'element_tag' => 'div'
648
      ),
649
      UUID_DISTRIBUTION => array(
650
        'as_list' => 'div', // currently ignored
651
        'link_to_reference' => 0,
652
        'link_to_name_used_in_source' => 0,
653
        'sources_as_content' => 0,
654
        'sources_as_content_to_bibliography' => 0,
655
        'sort_elements' => NO_SORT, // will cause ...
656
        'glue' => '',
657
        'element_tag' => 'div',
658
        'special' => array()
659
      ),
660
      UUID_COMMON_NAME => array(
661
        'as_list' => 'div',
662
        'link_to_reference' => 0,
663
        'link_to_name_used_in_source' => 1,
664
        'sources_as_content' => 0,
665
        'sources_as_content_to_bibliography' => 0,
666
        'sort_elements' => NO_SORT,
667
        'glue' => '',
668
        'element_tag' => 'span'
669
      ),
670
    );
671

    
672
    // ---- Special DEFAULTS for existing portals
673
    // TODO:
674
    // this can be removed once the feature block
675
    // settings have been deployed for the first time to these portals
676

    
677
    $cichorieae_default = array(
678
      'DEFAULT' => array(
679
        'as_list' => 'div',
680
        'link_to_reference' => 1,
681
        'link_to_name_used_in_source' => 1,
682
        'sources_as_content' => 1,
683
        'sources_as_content_to_bibliography' => 0,
684
        'sort_elements' => NO_SORT,
685
        'glue' => '',
686
        'element_tag' => 'div'
687
      ),
688
      UUID_CITATION => array(
689
        'as_list' => 'div',
690
        'link_to_reference' => 0,
691
        'link_to_name_used_in_source' => 0,
692
        'sources_as_content' => 1,
693
        'sources_as_content_to_bibliography' => 0,
694
        'sort_elements' => SORT_ASC,
695
        'glue' => '',
696
        'element_tag' => 'div'
697
      ),
698
      UUID_CHROMOSOMES_NUMBERS => array(
699
        'as_list' => 'ul',
700
        'link_to_reference' => 1,
701
        'link_to_name_used_in_source' => 1,
702
        'sources_as_content' => 1,
703
        'sources_as_content_to_bibliography' => 0,
704
        'sort_elements' => NO_SORT,
705
        'glue' => '',
706
        'element_tag' => 'div'
707
      ),
708
      UUID_CHROMOSOMES => array(
709
        'as_list' => 'ul',
710
        'link_to_reference' => 0,
711
        'link_to_name_used_in_source' => 1,
712
        'sources_as_content' => 1,
713
        'sources_as_content_to_bibliography' => 0,
714
        'sort_elements' => NO_SORT,
715
        'glue' => '',
716
        'element_tag' => 'div'
717
      ),
718
      UUID_COMMON_NAME => array(
719
        'as_list' => 'div',
720
        'link_to_reference' => 0,
721
        'link_to_name_used_in_source' => 1,
722
        'sources_as_content' => 0,
723
        'sources_as_content_to_bibliography' => 0,
724
        'sort_elements' => NO_SORT,
725
        'glue' => '',
726
        'element_tag' => 'span'
727
      ),
728
    );
729

    
730
    $palmweb_default = array(
731
      'DEFAULT' => array(
732
        'as_list' => 'ul',
733
        'link_to_reference' => 1,
734
        'link_to_name_used_in_source' => 1,
735
        'sources_as_content' => 1,
736
        'sources_as_content_to_bibliography' => 1,
737
        'sort_elements' => NO_SORT,
738
        'glue' => '',
739
        'element_tag' => NULL
740
      ),
741
      UUID_CITATION => array(
742
        'as_list' => 'ul',
743
        'link_to_reference' => 1,
744
        'link_to_name_used_in_source' => 1,
745
        'sources_as_content' => 0,
746
        'sources_as_content_to_bibliography' => 1,
747
        'sort_elements' => SORT_ASC,
748
        'glue' => '',
749
        'element_tag' => 'div'
750
      ),
751
      UUID_DISTRIBUTION => array(
752
        'as_list' => 'div', // currently ignored
753
        'link_to_reference' => 1,
754
        'link_to_name_used_in_source' => 1,
755
        'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
756
        'sources_as_content_to_bibliography' => 1,
757
        'sort_elements' => NO_SORT, // will cause ...
758
        'glue' => '',
759
        'element_tag' => 'div',
760
        'special' => array()
761
      ),
762
    );
763

    
764
    $cyprus_default = $cichorieae_default;
765
    $cyprus_default[UUID_DISTRIBUTION] = array(
766
      'as_list' => 'div', // currently ignored
767
      'link_to_reference' => 0,
768
      'link_to_name_used_in_source' => 0,
769
      'sources_as_content' => 0,
770
      'sources_as_content_to_bibliography' => 0,
771
      'sort_elements' => NO_SORT, // will cause ...
772
      'glue' => '',
773
      'element_tag' => 'div',
774
      'special' => array()
775
    );
776

    
777
    $default_theme = variable_get('theme_default', NULL);
778

    
779
    switch ($default_theme) {
780
      case 'garland_cichorieae':
781
        $settings_for_theme = $cichorieae_default;
782
        break;
783
      case 'cyprus':
784
        // cyprus: no longer used in production,
785
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
786
        $settings_for_theme = $cyprus_default;
787
        break;
788
      case 'flore_afrique_centrale':
789
      case 'flora_malesiana':
790
      case 'flore_gabon':
791
        $settings_for_theme = $cichorieae_default;
792
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
793
        break;
794
      case 'palmweb_2':
795
        $settings_for_theme = $palmweb_default;
796
        break;
797
      default:
798
        $settings_for_theme = $other_themes_default;
799
    }
800
    // ---- END of DEFAULTS
801

    
802
    $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
803

    
804
    $feature_block_setting = null;
805

    
806
    if (isset($saved_settings[$feature_uuid])) {
807
      $feature_block_setting = $saved_settings[$feature_uuid];
808
    }
809
    else if (isset($settings_for_theme[$feature_uuid])) {
810
      $feature_block_setting = $settings_for_theme[$feature_uuid];
811
    }
812
    else if (isset($settings_for_theme['DEFAULT'])) {
813
      $feature_block_setting = $settings_for_theme['DEFAULT'];
814
    }
815

    
816
    // now merge the default and specific settings
817
    $settings_to_merge = array($default['DEFAULT']);
818
    if(is_array($saved_settings)){
819
      $settings_to_merge[] = $saved_settings['DEFAULT'];
820
    }
821
    if(isset($feature_block_setting)){
822
      $settings_to_merge[] = $feature_block_setting;
823
    }
824
    $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
825

    
826
    return $feature_block_setting;
827
}
828
  /**
829
 * returns the current setting for the original source bibliography
830
 *
831
 * Caches internally
832
 *
833
 * @return array
834
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
835
 *   - 'enabled': 1|0
836
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
837
 */
838
function get_bibliography_settings($clear_cache = false){
839
  static $bibliography_settings = null;
840
  if(!$bibliography_settings || $clear_cache){
841
    $bibliography_settings = get_array_variable_merged(
842
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
843
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
844
    );
845
  }
846
  return $bibliography_settings;
847
}
848

    
849
/**
850
 * @todo Please document this function.
851
 * @see http://drupal.org/node/1354
852
 */
853
function cdm_dataportal_menu_admin(&$items) {
854
  // Display section on admin/config page.
855
  $items['admin/config/cdm_dataportal'] = array(
856
    'title' => 'CDM Dataportal',
857
    'description' => 'Settings for the CDM DataPortal.',
858
    'position' => 'right',
859
    'weight' => 10,
860
    'page callback' => 'system_admin_menu_block_page',
861
    'access arguments' => array('administer cdm_dataportal'),
862
    'file' => 'system.admin.inc',
863
    'file path' => drupal_get_path('module', 'system'),
864
  );
865
  $items['admin/config/cdm_dataportal/settings'] = array(
866
    'title' => 'Settings',
867
    'description' => 'Settings for the CDM DataPortal.',
868
    'weight' => 0,
869
    'page callback' => 'drupal_get_form',
870
    'page arguments' => array('cdm_settings_general'),
871
    'access arguments' => array('administer cdm_dataportal'),
872
    'type' => MENU_NORMAL_ITEM,
873
  );
874
  $items['admin/config/cdm_dataportal/settings/general'] = array(
875
    'title' => 'General',
876
    'description' => 'General',
877
    'weight' => 0,
878
    'page callback' => 'drupal_get_form',
879
    'page arguments' => array('cdm_settings_general'),
880
    'access arguments' => array('administer cdm_dataportal'),
881
    'type' => MENU_DEFAULT_LOCAL_TASK,
882
  );
883

    
884
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
885
    'title' => 'Cache',
886
    'description' => 'Cache',
887
    'access arguments' => array('administer cdm_dataportal'),
888
    'page callback' => 'drupal_get_form',
889
    'page arguments' => array('cdm_settings_cache'),
890
    'weight' => 10,
891
    'type' => MENU_LOCAL_TASK,
892
  );
893

    
894
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
895
    'title' => 'Geo & Map',
896
    'description' => 'Geo & Map',
897
    'access arguments' => array('administer cdm_dataportal'),
898
    'page callback' => 'drupal_get_form',
899
    'page arguments' => array('cdm_settings_geo'),
900
    'weight' => 1,
901
    'type' => MENU_LOCAL_TASK,
902
  );
903

    
904
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
905
    'title' => 'Layout',
906
    'description' => 'Configure and adjust the layout of your DataPortal ',
907
    'access arguments' => array('administer cdm_dataportal'),
908
    'page callback' => 'drupal_get_form',
909
    'page arguments' => array('cdm_settings_layout'),
910
    'weight' => 2,
911
    'type' => MENU_LOCAL_TASK,
912
  );
913

    
914
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
915
    'title' => 'Taxon',
916
    'description' => 'Configure and adjust the layout of your DataPortal ',
917
    'access arguments' => array('administer cdm_dataportal'),
918
    'page callback' => 'drupal_get_form',
919
    'page arguments' => array('cdm_settings_layout_taxon'),
920
    'weight' => 1,
921
    'type' => MENU_LOCAL_TASK,
922
  );
923
  /*
924
  $items[] = array(
925
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
926
  'title' => t('Synonymy'),
927
  'description' => t('Configure and adjust the layout of your DataPortal '),
928
  'access' => user_access('administer cdm_dataportal'),
929
  'callback' => 'drupal_get_form',
930
  'callback arguments' => array('cdm_settings_layout_synonymy'),
931
  'weight' => 1,
932
  'type' => MENU_LOCAL_TASK,
933
  );
934

    
935
  $items[] = array(
936
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
937
  'title' => t('Specimens'),
938
  'description' => t('Configure and adjust the layout of your DataPortal '),
939
  'access' => user_access('administer cdm_dataportal'),
940
  'callback' => 'drupal_get_form',
941
  'callback arguments' => array('cdm_settings_layout_specimens'),
942
  'weight' => 1,
943
  'type' => MENU_LOCAL_TASK,
944
  );
945
  */
946
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
947
    'title' => 'Search',
948
    'description' => 'Configure and adjust the layout of your DataPortal ',
949
    'access arguments' => array('administer cdm_dataportal'),
950
    'page callback' => 'drupal_get_form',
951
    'page arguments' => array('cdm_settings_layout_search'),
952
    'weight' => 2,
953
    'type' => MENU_LOCAL_TASK,
954
  );
955

    
956
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
957
    'title' => 'Media',
958
    'description' => 'Configure and adjust the layout of your DataPortal ',
959
    'access arguments' => array('administer cdm_dataportal'),
960
    'page callback' => 'drupal_get_form',
961
    'page arguments' => array('cdm_settings_layout_media'),
962
    'weight' => 3,
963
    'type' => MENU_LOCAL_TASK,
964
  );
965

    
966
}
967

    
968
/**
969
 * @todo document this function.
970
 */
971
function cdm_help_general_cache() {
972
  $form = array();
973
  $form['cache_help'] = array(
974
    '#type' => 'fieldset',
975
    '#title' => t('Help'),
976
    '#collapsible' => TRUE,
977
    '#collapsed' => TRUE,
978
  );
979
  $form['cache_help']['test'] = array('#value' => t('probando'));
980
  return drupal_render($form);
981
  $res = array();
982
  $res['default'] = drupal_render($help);
983
  return $res;
984
}
985

    
986
/**
987
 * Configures the settings form for the CDM-API module.
988
 *
989
 * @return array
990
 *   Drupal settings form.
991
 */
992
function cdm_settings_general() {
993

    
994
  $form['cdm_webservice'] = array(
995
    '#type' => 'fieldset',
996
    '#title' => t('CDM Server'),
997
    '#collapsible' => FALSE,
998
    '#collapsed' => FALSE,
999
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1000
        CDM data base to the web via RESTful web services and thus is the source of the data
1001
        to be displayed by a CDM DataPotal.'),
1002
  );
1003

    
1004
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1005
    '#type' => 'textfield',
1006
    '#title' => t('CDM web service URL') . ':',
1007
    '#description' => t('This is the URL to the CDM-Server exposing your data
1008
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1009
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1010
  );
1011

    
1012
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1013
    '#type' => 'markup',
1014
    '#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')
1015
      . ' visible only for administrators',
1016
  );
1017

    
1018
  $form['cdm_webservice']['freetext_index'] = array(
1019
    '#type' => 'fieldset',
1020
    '#title' => t('Freetext index'),
1021
    '#collapsible' => FALSE,
1022
    '#collapsed' => FALSE,
1023
  );
1024

    
1025
  // Check the cdmserver port number and display a waring if it is not port 80
1026
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1027
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1028
    $form['cdm_webservice']['freetext_index']['message'] = array(
1029
      '#markup' => "<div class=\"description\">"
1030
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'."
1031
      . " Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server."
1032
      . " You may want to contact the maintainer of the according CDM Server in order to solve this problem.", array('!port' => $portNumberMatch[1][0]))
1033
      . "</div>",
1034
    );
1035
  };
1036

    
1037
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1038
  $trigger_link_options = array(
1039
    'attributes' => array(
1040
      'class' => 'index-trigger',
1041
    ),
1042
  );
1043
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1044
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1045
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1046
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1047
      ))
1048
    . '<div id="index-progress"></div></div>',
1049
  );
1050
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1051

    
1052
  $form['cdm_webservice']['proxy'] = array(
1053
    '#type' => 'fieldset',
1054
    '#title' => t('Proxy'),
1055
    '#collapsible' => TRUE,
1056
    '#collapsed' => TRUE,
1057
  );
1058

    
1059
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1060
    '#type' => 'textfield',
1061
    '#title' => t('Proxy URL') . ':',
1062
    '#description' => t('If this proxy url is set the cdm api tries
1063
    to connect the web service over the given proxy server.
1064
    Otherwise proxy usage is deactivated.'),
1065
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1066
  );
1067

    
1068
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1069
    '#type' => 'textfield',
1070
    '#title' => t('Proxy port') . ':',
1071
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1072
  );
1073

    
1074
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1075
    '#type' => 'textfield',
1076
    '#title' => t('Login') . ':',
1077
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1078
  );
1079

    
1080
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1081
    '#type' => 'textfield',
1082
    '#title' => t('Password') . ':',
1083
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1084
  );
1085

    
1086
  // TODO: settings are still incomplete, compare with
1087
  // trunk/dataportal/inc/config_default.php.inc.
1088
  $form['taxon_tree'] = array(
1089
    '#type' => 'fieldset',
1090
    '#title' => t('Taxon Tree'),
1091
    '#collapsible' => FALSE,
1092
    '#collapsed' => TRUE,
1093
    '#description' => t('<p>When you explore your collection, you can navigate
1094
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1095
      able to navigate through your collection the
1096
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1097
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1098
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1099
      </a></p>'),
1100
  );
1101

    
1102
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1103
    '#type' => 'select',
1104
    '#title' => t('Available classifications') . ':',
1105
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1106
    '#options' => cdm_get_taxontrees_as_options(),
1107
    '#description' => t('Select the default taxa classification for your
1108
      <em>taxon tree</em>, the other classifications will be also available but
1109
      with a manual user change.'),
1110
  );
1111

    
1112
  $form['taxon_tree']['taxontree_ranklimit'] = array(
1113
    '#type' => 'select',
1114
    '#title' => t('Rank of highest displayed taxon') . ':',
1115
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1116
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
1117
    '#options' => cdm_rankVocabulary_as_option(),
1118
    '#description' => t('This is the rank of the highest displayed taxon in the
1119
      <em>taxon tree</em>. You can select here which rank should be at the top
1120
      level of the tree structure.'),
1121
  );
1122

    
1123
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1124
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1125
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1126
      '#type' => 'checkboxes',
1127
      '#title' => t('Included Classifications') . ':',
1128
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1129
      '#options' => cdm_get_taxontrees_as_options(),
1130
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1131
  );
1132

    
1133
  $form['distribution'] = array(
1134
      '#type' => 'fieldset',
1135
      '#title' => t('Distributions'),
1136
      '#collapsible' => FALSE,
1137
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1138
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1139
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1140
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1141
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1142
          '<p>
1143
          </p>',
1144
  );
1145

    
1146
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1147
      '#type' => 'fieldset',
1148
      '#title' => 'Distribution filter',
1149
      '#collapsible' => FALSE,
1150
      '#collapsed' => FALSE,
1151
      '#tree' => TRUE,
1152
      '#description' => 'The Distribution filter offers the following options
1153
      <ul>
1154
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1155
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1156
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1157
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1158
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1159
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1160
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1161
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1162
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1163
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1164
      </ul>'
1165
  );
1166

    
1167
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1168
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1169
      '#type' => 'checkboxes',
1170
      '#title' => 'Filter rules',
1171
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1172
      '#options' => array(
1173
          'statusOrderPreference' => 'Status order preference rule',
1174
          'subAreaPreference' => 'Sub area preference rule'
1175
      ),
1176
  );
1177

    
1178
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1179
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1180
      '#type' => 'checkboxes',
1181
      '#title' => 'Hide marked area filter',
1182
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1183
      '#options' => $marker_type_options,
1184
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1185
  );
1186

    
1187
  $form['aggregation'] = array(
1188
      '#type' => 'fieldset',
1189
      '#title' => t('Aggregation of data'),
1190
      '#collapsible' => FALSE,
1191
      '#description' => 'This section covers the different aspects of aggregating information.
1192
          <p>
1193
          </p>',
1194
  );
1195

    
1196
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1197
      '#type' => 'checkboxes',
1198
      '#title' => 'Taxon media filter',
1199
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1200
      '#options' => array(
1201
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1202
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1203
          'includeOccurrences' => 'Media related to specimens and occurrences',
1204
      ),
1205
      '#description' => 'This filter configures which images should be taken into account.',
1206
  );
1207

    
1208
  $form['aggregation']['notice'] = array(
1209
      '#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
1210
          want to make use of the caching capabilities of the dataportal.',
1211
  );
1212

    
1213
  $form['aggregation']['media_aggregation'] = array(
1214
      '#type' => 'fieldset',
1215
      '#title' => t('Media aggregation'),
1216
      '#collapsible' => FALSE,
1217
      '#collapsed' => TRUE,
1218
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1219

    
1220
  );
1221
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1222
      '#type' => 'select',
1223
      '#title' => t('Aggregation of taxon pictures') . ':',
1224
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1225
      '#options' => array(
1226
          0 => "Show only pictures of the current taxon",
1227
          1 => "Include pictures of taxonomic children",
1228
      ),
1229
      '#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."),
1230
  );
1231

    
1232
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1233
      '#type' => 'fieldset',
1234
      '#attributes' => array('class'=>array('clearfix')),
1235
      '#title' => t('Aggregation via taxon relationsships'),
1236
      '#collapsible' => TRUE,
1237
      '#collapsed' => TRUE,
1238
      '#tree' => TRUE,
1239
      '#description' => t('Information on taxa will be aggregated along the below chosen
1240
          taxon relation ships. This will affect images and occurrences (specimens).
1241
          Taxon relation ships are directed and point form one taxon to another. The taxon
1242
          relationships to be taken into accunt can therefore configured for the direct direction
1243
          and for the inverse.'),
1244
  );
1245

    
1246
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1247
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1248

    
1249
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1250
      '#type' => 'checkboxes',
1251
      '#title' => t('Direct'),
1252
      '#options' => $taxonRelationshipTypeOptions,
1253
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1254
  );
1255
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1256
      '#type' => 'checkboxes',
1257
      '#title' => t('Invers'),
1258
      '#options' => $taxonRelationshipTypeOptions,
1259
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1260
  );
1261

    
1262
  $form['drupal_integration'] = array(
1263
    '#type' => 'fieldset',
1264
    '#attributes' => array('class'=>array('clearfix')),
1265
    '#title' => t('Drupal integration'),
1266
    '#collapsible' => FALSE,
1267
    '#collapsed' => FALSE,
1268
    '#tree' => FALSE
1269
  );
1270

    
1271
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1272
    '#type' => 'checkbox',
1273
    '#title' => 'Create drupal nodes',
1274
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1275
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1276
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1277
    cdm pages it is required that drupal nodes are created and stored in the database.'
1278
  );
1279

    
1280

    
1281

    
1282
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1283
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1284
    <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>',
1285
  );
1286
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1287
    '#type' => 'submit',
1288
    '#value' => t('Drop all cdm nodes'),
1289
    '#submit' => array('drop_all_cdm_nodes_submit')
1290
  );
1291

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

    
1296
    // ----------------------
1297
  $form['cdm_js_devel_mode'] = array(
1298
      '#type' => 'checkbox',
1299
      '#title' => 'Java-script developer mode',
1300
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1301
      '#description' => 'In production envirionments the java script libraries
1302
      the cdm_dataportal is making use of are compressed and optimized. This
1303
      is good for performance but a caveat if you need to debug java-script. When the
1304
      java-script developer mode is enabled the uncompressed and commented developer
1305
      versions of java-script libraries will be used where possible.
1306
      <br/><strong>Do not use this option in production!</strong>'
1307
  );
1308
  // ----------------------
1309
  $form['cdm_debug_mode'] = array(
1310
      '#type' => 'checkbox',
1311
      '#title' => 'CDM page debug mode',
1312
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1313
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1314
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1315
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1316
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1317
      The log is written by the drupal devel module function <code>dd()</code>.
1318
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1319
  );
1320

    
1321
  // Comment @WA: D7 form api does not support reset buttons,
1322
  // so to mimic the D5 reset button we add one like this.
1323
  $form['actions']['reset'] = array(
1324
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1325
    '#weight' => 1000,
1326
  );
1327

    
1328
  $form['#submit'][] = 'cdm_settings_general_submit';
1329

    
1330
  return system_settings_form($form);
1331
}
1332

    
1333
/**
1334
 * Submit callback; drops all cdm nodes.
1335
 *
1336
 * @ingroup forms
1337
 */
1338
function drop_all_cdm_nodes_submit($form, &$form_state) {
1339
  cdm_delete_all_cdm_nodes();
1340
  drupal_set_message(t('All cdm nodes dropped.'));
1341
}
1342

    
1343

    
1344
/**
1345
 * LAYOUT settings
1346
 * @return
1347
 *   todo
1348
 */
1349
function cdm_settings_layout() {
1350

    
1351
  $form = array();
1352

    
1353
  $form['about'] = array(
1354
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1355
      layout. If you want to configure the specific sites layout visit the
1356
      respective configuration site for taxon, search or media.') . '</p>',
1357
  );
1358

    
1359
  // ---- footnotes --- //
1360
  $form['footnotes'] = array(
1361
    '#type' => 'fieldset',
1362
    '#title' => t('Footnotes'),
1363
    '#collapsible' => FALSE,
1364
    '#collapsed' => FALSE,
1365
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1366
      media or distribution areas may have annotations or footnotes. When the
1367
      footnotes are enabled they will be visible (if they exist).'),
1368
  );
1369

    
1370
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1371
    '#type' => 'checkbox',
1372
    '#title' => t('Do not show footnotes'),
1373
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1374
    '#description' => t('Check this if you do not want to show any footnotes'),
1375
  );
1376

    
1377
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1378
    '#type' => 'checkbox',
1379
    '#title' => t('Do not show annotation footnotes'),
1380
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1381
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1382
  );
1383

    
1384
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1385
  // Additional option for the NULL case.
1386
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1387
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1388
    '#type' => 'checkboxes',
1389
    '#title' => t('Annotation types as footnotes'),
1390
    '#description' => t("Only annotations of the selected type will be displayed
1391
       as footnotes. You may want to turn 'technical annotations' off."),
1392
    '#options' => $annotationTypeOptions,
1393
  );
1394
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1395
  if (!empty($annotationsTypesAsFootnotes)) {
1396
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1397
  }
1398

    
1399
  // ---- original source --- //
1400
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1401
      '#type' => 'fieldset',
1402
      '#tree' => TRUE,
1403
      '#title' => t('Source Citations'),
1404
      '#collapsible' => FALSE,
1405
      '#collapsed' => FALSE,
1406
  );
1407

    
1408
  $bibliography_settings = get_bibliography_settings(true);
1409

    
1410
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1411
      '#type' => 'checkbox',
1412
      '#title' => t('Original Source in bibliography'),
1413
      '#default_value' => $bibliography_settings['enabled'],
1414
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1415
       annotations in each feature block.'),
1416
  );
1417

    
1418
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1419
    '#type' => 'select',
1420
    '#title' => t('The format of the key numerals'),
1421
    '#default_value' => $bibliography_settings['key_format'],
1422
    '#options' => array('latin' => 'Latin',
1423
      'ROMAN' => 'Roman (upper case)',
1424
      'roman' => 'Roman (lower case)',
1425
      'ALPHA'=> 'Alphabet (upper case)',
1426
      'alpha' => 'Alphabet (lower case)')
1427
  );
1428

    
1429
  // --- Advanced Search --- //
1430
  $form['asearch'] = array(
1431
      '#type' => 'fieldset',
1432
      '#title' => t('Advanced search'),
1433
      '#collapsible' => FALSE,
1434
      '#collapsed' => FALSE,
1435
  );
1436
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1437
      '#type' => 'checkbox',
1438
      '#title' => t('Show advanced search link'),
1439
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1440
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1441
  );
1442

    
1443
  // ---- Taxon Name Rendering --- //
1444
  $form['taxon_name'] = array(
1445
      '#type' => 'fieldset',
1446
      '#title' => t('Taxon name display'),
1447
      '#collapsible' => TRUE,
1448
      '#collapsed' => TRUE,
1449
      '#description' => t('The display of taxon names is configured by two parts.'
1450
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
1451
          . 'The name parts are defined in the <stong>part definitions</strong>'),
1452
  );
1453

    
1454
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1455
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1456
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1457
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1458

    
1459
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1460
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1461
    $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.)';
1462
  } else if($is_custom_part_definition){
1463
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1464
  } else  {
1465
    $which_version_message = '(These are the default part definition.)';
1466
  }
1467

    
1468
  $diff_viewer_markup = '';
1469
  if($is_custom_part_definition){
1470
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1471
  }
1472

    
1473
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1474
    . $which_version_message
1475
    . '</div>'
1476
    . $diff_viewer_markup;
1477

    
1478
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1479
      '#type' => 'textarea',
1480
      '#title' => t('Part definitions'),
1481
      '#element_validate' => array('form_element_validate_json'),
1482
      '#default_value' =>  $current_part_definition_json,
1483
      '#description' => '
1484
          <p>' . $which_version_message . '</p>
1485
          <p>
1486
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1487
          </p>
1488
          <p>
1489
           A full taxon name plus additional information can consist of the following elements:
1490
          <ul>
1491
             <li>name: the taxon name inclugin rank nbut without author</li>
1492
             <li>authors:  The authors of a reference, also used in taxon names</li>
1493
             <li>reference: the nomenclatural reference,</li>
1494
             <li>microreference:  Volume, page number etc.</li>
1495
             <li>status:  The nomenclatural status of a name</li>
1496
             <li>description: name descriptions like protologues etc ...</li>
1497
          </ul>
1498
          </p>
1499
          <p>
1500
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1501
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1502
           The following parts can be formed and are recognized by the system:
1503
          <ul>
1504
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1505
            <li>authorshipPart: the author (for example: "L.")</li>
1506
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1507
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1508
               be combined when a link to the taxon is rendered.</li>
1509
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1510
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1511
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1512
            <li>statusPart: the nomenclatorical status</li>
1513
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1514
          </ul>
1515
          </p>
1516
          <p>
1517
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1518
           specific parts part definitions:
1519
          <ul>
1520
            <li>BotanicalName</li>
1521
            <li>ZoologicalName</li>
1522
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1523
          </ul>
1524
           An example:
1525
          <pre>
1526
           {
1527
            "ZoologicalName": {
1528
              "namePart": {
1529
                "name": true
1530
              },
1531
              "referencePart": {
1532
                "authors": true
1533
              },
1534
              "microreferencePart": {
1535
                "microreference": true
1536
              },
1537
              "statusPart": {
1538
                "status": true
1539
              },
1540
              "descriptionPart": {
1541
                "description": true
1542
              }
1543
            },
1544
            "BotanicalName": {
1545
              "namePart": {
1546
                "name": true,
1547
                "authors": true
1548
              },
1549
              "referencePart": {
1550
                "reference": true,
1551
                "microreference": true
1552
              },
1553
              "secReferencePart": {
1554
                "secReference": true
1555
              },
1556
              "statusPart": {
1557
                "status": true
1558
              },
1559
              "descriptionPart": {
1560
                "description": true
1561
              }
1562
            }
1563
          }
1564
           </pre>',
1565
  );
1566

    
1567
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1568
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1569
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1570
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1571
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1572

    
1573
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1574
    $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.)';
1575
  } else if($is_custom_render_template){
1576
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1577
  } else {
1578
    $which_version_message = '(These are the default render templates.)';
1579
  }
1580

    
1581
  $diff_viewer_markup = '';
1582
  if($is_custom_render_template){
1583
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1584
  }
1585

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

    
1591
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1592
      '#type' => 'textarea',
1593
      '#title' => t('Name render templates'),
1594
      '#element_validate' => array('form_element_validate_json'),
1595
      '#default_value' =>  $current_render_templates_json,
1596
      '#description' => '
1597
          <p>' . $which_version_message . '</p>
1598
          <p>
1599
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1600
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1601
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1602
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1603
          The following render Path keys are currently recognized:
1604
          <ul>
1605
            <li>list_of_taxa</li>
1606
            <li>acceptedFor</li>
1607
            <li>homonym</li>
1608
            <li>taxon_page_synonymy</li>
1609
            <li>typedesignations</li>
1610
            <li>taxon_page_title</li>
1611
            <li>polytomousKey</li>
1612
            <li>na: name + authorship</li>
1613
            <li>nar:name + authorship + reference</li>
1614
            <li>#DEFAULT</li>
1615
          </ul>
1616
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1617
          array element should be a comma separated list of render paths, without any whitespace!.
1618
          </p>
1619
          <p>
1620
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1621
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1622
          <p>
1623
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1624
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1625
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1626
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1627
          links if the paramters $nameLink or $refenceLink are given to the name render function
1628
          (this is hard coded and cannot be configured here).',
1629
  );
1630

    
1631
  // @WA: D7 form api does not support reset buttons,
1632
  // so to mimic the D5 reset button we add one like this.
1633
  $form['actions']['reset'] = array(
1634
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1635
    '#weight' => 1000,
1636
  );
1637

    
1638
  $form['#submit'] = array('submit_json_as_php_array');
1639
  // #json_elements especially defined for submit_json_as_php_array()
1640
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1641
  return system_settings_form($form);
1642
}
1643

    
1644

    
1645

    
1646
  /**
1647
 * @todo Please document this function.
1648
 * @see http://drupal.org/node/1354
1649
 */
1650
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1651
  $form[$form_name] = array(
1652
    '#type' => 'fieldset',
1653
    '#title' => t($form_title),
1654
    '#collapsible' => TRUE,
1655
    '#collapsed' => $collapsed,
1656
    '#tree' => TRUE,
1657
    '#description' => t($form_description),
1658
  );
1659

    
1660
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1661
  $gallery_settings = variable_get($form_name, $default_values);
1662
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1663
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1664
    /*
1665
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1666
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1667
    '#type' => 'textfield',
1668
    '#title' => t('Search Page Size'),
1669
    '#default_value' => $test,
1670
    '#description' => t('Number of Names to display per page in search results.')
1671
    );
1672
    */
1673
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1674
      '#type' => 'checkbox',
1675
      '#title' => t('Show media thumbnails for accepted taxa'),
1676
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1677
    );
1678

    
1679
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1680
      '#type' => 'checkbox',
1681
      '#title' => t('Show media thumbnails for synonyms'),
1682
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1683
      '#description' => '',
1684
    );
1685
  }
1686

    
1687
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1688
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1689
    '#type' => 'checkbox',
1690
    '#title' => t('Show captions under thumbnails'),
1691
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1692
    '#description' => '',
1693
  );
1694

    
1695
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1696
    '#type' => 'textfield',
1697
    '#title' => t('Thumbnail size') . ':',
1698
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1699
    '#description' => t('Select the size of each individual thumbnail.'),
1700
  );
1701

    
1702
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1703
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1704
      '#type' => 'textfield',
1705
      '#title' => t('Number of columns') . ':',
1706
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1707
      '#description' => t('Group the thumbnails in columns: select how many
1708
        columns the gallery should display.'),
1709
    );
1710
  }
1711

    
1712
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1713
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1714
      '#type' => 'textfield',
1715
      '#title' => t('Maximum number of rows') . ':',
1716
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1717
      '#description' => t('You can group the thumbnails in rows, select in how
1718
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1719
        If you want an unlimited number of rows please set to 0.'),
1720
    );
1721
  }
1722

    
1723
  return $form;
1724
}
1725

    
1726
/**
1727
 * @todo document this function.
1728
 */
1729
function cdm_settings_layout_taxon() {
1730
  $collapsed = FALSE;
1731
  $form = array();
1732

    
1733
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1734

    
1735
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1736
      '#type' => 'checkbox',
1737
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1738
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1739
      '#description' => t('<p>If checked the link to search results is rendered at
1740
       the top of the taxon site. Clicking on the link the last search performed
1741
       is rendered again.</p>'),
1742
  );
1743

    
1744
  // --------- TABBED TAXON ------- //
1745
  $form['taxon_tabs'] = array(
1746
    '#type' => 'fieldset',
1747
    '#title' => t('Taxon tabs'),
1748
    '#collapsible' => TRUE,
1749
    '#collapsed' => TRUE,
1750
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1751
      be splitted in four diferent tabs; General, Synonymy, Images and
1752
      Specimens. If the taxon has no information for any of the tabs/sections
1753
      such tab will be not displayed.'),
1754
  );
1755

    
1756
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1757
    '#type' => 'checkbox',
1758
    '#title' => t('Tabbed taxon page'),
1759
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1760
    '#description' => t('<p>If selected split the taxon page into individual
1761
      tabs for description, images, synonymy and specimens. If not the taxon
1762
      data is rendered as a long single page without tabs.</p>'),
1763
  );
1764

    
1765
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1766
    '#type' => 'checkboxes',
1767
    '#title' => t('Tabs visibility options') . ':',
1768
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1769
    '#options' => get_taxon_options_list(),
1770
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1771
  );
1772

    
1773
  // WEIGHT
1774
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1775
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1776
      '#tree' => true
1777
  );
1778
  // Weights range from -delta to +delta, so delta should be at least half
1779
  // of the amount of tabs present.
1780
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1781
  foreach (get_taxon_tabs_list() as $label) {
1782
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1783
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1784
        '#title' => $label,
1785
        '#type'  => 'weight',
1786
        '#default_value' => $taxontabs_weights[$key],
1787
        '#delta' => $tab_weight_delta
1788
    );
1789
  }
1790

    
1791
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1792
    '#type' => 'select',
1793
    '#title' => t('Default tab to display') . ':',
1794
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1795
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1796
    '#description' => t('<p>Select the default tab to display when visiting a
1797
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1798
      <strong>Note:</strong> After performing a search and clicking in any
1799
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1800
      taxon and not the above selected tab.'),
1801
  );
1802

    
1803
  /* ======  TAXON_PROFILE ====== */
1804
  $form['taxon_profile'] = array(
1805
    '#type' => 'fieldset',
1806
    '#title' => t('Taxon profile (tab)'),
1807
    '#description' => t('<p>This section covers the settings related to the taxon
1808
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1809
    '#collapsible' => TRUE,
1810
    '#collapsed' => TRUE,
1811
  );
1812

    
1813
  // ---- PROFILE PICTURE ----//
1814

    
1815
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1816
    '#type' => 'fieldset',
1817
    '#tree' => TRUE,
1818
    '#title' => t('Taxon profile picture'),
1819
    '#collapsible' => TRUE,
1820
    '#collapsed' => FALSE,
1821
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1822
  );
1823

    
1824
  //FIXME migrate variables:
1825
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1826
  // FIXME
1827
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1828

    
1829
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1830

    
1831
  /*
1832
   * 'show' => 1,
1833
   * 'maxextend' => 184,
1834
   * 'media_uri_query' => ''
1835
   * 'custom_placeholder_image_on' => 1,
1836
   * 'custom_placeholder_image_fid' => ''
1837
   */
1838
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1839
    '#type' => 'checkbox',
1840
    '#title' => t('Enable profile picture'),
1841
    '#description' => t('Show the profile picture.'),
1842
    '#default_value' => $taxon_profile_image_settings['show'],
1843
  );
1844

    
1845
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1846
      '#type' => 'textfield',
1847
      '#tree' => TRUE,
1848
      '#title' => t('Profile picture maximum extend'),
1849
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1850
      '#field_suffix' => 'px',
1851
      '#maxlength' => 4,
1852
      '#size' => 4,
1853
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1854
  );
1855

    
1856
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1857
      '#type' => 'textfield',
1858
      '#tree' => TRUE,
1859
      '#title' => t('Additional URI query parameter'),
1860
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1861
      '#maxlength' => 1024,
1862
      '#size' => 60,
1863
      '#description' => t('Additional query parameters to be used when requesting for the '
1864
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1865
          . 'The query parameters will be appended to the uri of the media representation part'
1866
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1867
  );
1868

    
1869
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1870
    '#type' => 'checkbox',
1871
    '#title' => t('Show the placeholder image'),
1872
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
1873
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1874
  );
1875

    
1876
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1877
      '#type' => 'checkbox',
1878
      '#title' => t('Use a custom placeholder image'),
1879
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1880
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1881
  );
1882

    
1883
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1884
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1885
        '#type' => 'managed_file',
1886
        '#title' => t('Custom placeholder image file'),
1887
        '#progress_indicator' => 'bar',
1888
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1889
    //       '#name' => 'custom_placeholder_image',
1890
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1891
    );
1892

    
1893
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1894
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1895
      $url = file_create_url($profile_image_file->uri);
1896
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1897
                '#type' => 'item',
1898
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1899
      );
1900
    }
1901
  } else {
1902
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1903
      '#type' => 'hidden',
1904
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1905
    );
1906
  }
1907

    
1908
  $options = cdm_rankVocabulary_as_option();
1909
  array_unshift($options, '-- DISABLED --');
1910
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1911
    '#type' => 'select',
1912
    '#title' => t('Hide profile picture for higher ranks') . ':',
1913
    '#default_value' => variable_get('image_hide_rank', '0'),
1914
    '#options' => $options,
1915
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1916
  );
1917

    
1918
  // -- MEDIA THUMBNAILS -- //
1919
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1920
  $form_title = 'Taxon Profile Images';
1921
  $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>';
1922
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1923

    
1924
  // ---- FEATURE TREE BLOCKS ---- //
1925
  $form['taxon_profile']['feature_blocks'] = array(
1926
    '#type' => 'fieldset',
1927
    '#title' => t('Feature Blocks'),
1928
    '#collapsible' => TRUE,
1929
    '#collapsed' => FALSE,
1930
    '#description' => t("This section covers settings related to the taxon's
1931
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1932
      features such as description, distribution, common names"),
1933
  );
1934
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1935
  $profile_feature_tree = get_profile_feature_tree();
1936
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
1937
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
1938
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
1939
  }
1940
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
1941
    '#type' => 'radios',
1942
    '#title' => t('Taxon profile feature tree') . ':',
1943
    '#default_value' => $profile_feature_tree_uuid,
1944
    '#options' =>  $featureTrees['options'],
1945
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1946
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1947
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
1948
      profile page.'
1949
    ),
1950
  );
1951

    
1952
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
1953
  $profile_feature_tree = get_profile_feature_tree();
1954

    
1955
  if (isset($profile_feature_tree->root->childNodes)) {
1956

    
1957
    $form_feature_block_layout = array(
1958
      '#type' => 'fieldset',
1959
      '#tree' => true,
1960
      '#title' => t('Taxon profile feature block settings'),
1961
      '#collapsible' => TRUE,
1962
      '#collapsed' => FALSE,
1963
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
1964
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
1965
      The subforms have the following settings in common:<br />
1966
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
1967
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
1968
      <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>
1969
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
1970
            <ol>
1971
            <li>If element is of the CDM type TextData and the text is not empty the source references will be
1972
                appended in brackets like "text (source references)". If the original source has name in source
1973
                information it will be appended to the citation string,
1974
                like : "(citation, as name in source; citation, as name in source)"</li>
1975
             <li>if the text of the TextData is empty, the original source citations are the only content
1976
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
1977
                prepended to the citation string like: "name in source: citation"</li>
1978
            </ol>
1979
            <strong>If disabled:</strong><br />
1980
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
1981
             citations are the only content, the resulting feature block content would only consist of footnotes.
1982
             In this case the display of the respective feature block is suppressed.</div>
1983
      </dl>
1984
      <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
1985
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
1986
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
1987
        . '</em></div>
1988
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
1989
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
1990
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
1991
      <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>
1992
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
1993
           cdm_feature_block_element_tag_name()</div>',
1994
    );
1995

    
1996

    
1997
    $feature_list_layout_settings_disabled = FALSE;
1998

    
1999
    // creating helper object to retrieve the default settings
2000
    $featureNode = new stdClass();
2001
    $featureNode->feature = new stdClass();
2002
    $featureNode->feature->uuid="DEFAULT";
2003
    $featureNode->feature->representation_L10n = "Default";
2004
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2005

    
2006
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2007

    
2008
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2009

    
2010
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2011
        $subform_id = $featureNode->feature->uuid;
2012
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2013

    
2014
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2015

    
2016
        $form_feature_block_layout[$subform_id] = array(
2017
          '#type' => 'fieldset',
2018
          '#tree' => TRUE,
2019
          '#title' => $featureNode->feature->representation_L10n,
2020
          '#collapsible' => FALSE,
2021
          '#collapsed' => FALSE,
2022
        );
2023
        if($featureNode->feature->uuid == "DEFAULT"){
2024
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2025
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2026
          references</em> and <em>names in source</em> is only possible in the defaults';
2027
        }
2028

    
2029
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2030
          '#type' => 'select',
2031
          '#title' => 'List type',
2032
          '#default_value' => $feature_block_setting['as_list'],
2033
          '#options' => array(
2034
            'div' => 'not as list',
2035
            'ul' => 'bullet list',
2036
            'ol' => 'numbered list',
2037
            'dl' => 'definition list'
2038
          ),
2039
        );
2040

    
2041
        if($featureNode->feature->uuid == "DEFAULT"){
2042
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2043
            '#type' => 'checkbox',
2044
            '#title' => t('Link to reference'),
2045
            '#default_value' => $feature_block_setting['link_to_reference'],
2046
          );
2047

    
2048
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2049
            '#type' => 'checkbox',
2050
            '#title' => 'Link to name used in source',
2051
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2052
          );
2053
        }
2054

    
2055
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2056
          '#type' => 'checkbox',
2057
          '#title' => 'Sources as content',
2058
          '#default_value' => $feature_block_setting['sources_as_content'],
2059
        );
2060

    
2061
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2062
          '#type' => 'checkbox',
2063
          '#title' => 'Put sources also as content to bibliography',
2064
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2065
        );
2066

    
2067
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2068
          '#type' => 'select',
2069
          '#title' => t('Sort elements'),
2070
          '#default_value' => $feature_block_setting['sort_elements'],
2071
          '#options' => array(
2072
            NO_SORT => 'No sorting',
2073
            SORT_ASC => 'Ascending',
2074
            SORT_DESC => 'Descending',
2075
            SORT_HIERARCHICAL => 'Hierarchical'
2076
          ),
2077
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2078
          <dl>
2079
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2080
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2081
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2082
          <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>
2083
          </dl>',
2084
        );
2085

    
2086
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2087
          '#type' => 'select',
2088
          '#title' => t('Element tag'),
2089
          '#options' => array(
2090
            'span' => 'span',
2091
            'div' => 'div'
2092
          ),
2093
          '#default_value' => $feature_block_setting['element_tag'],
2094
        );
2095
      }
2096
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2097
    }
2098
  }
2099

    
2100
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2101
  $form['taxon_profile']['structured_description_featuretree'] = array(
2102
    '#type' => 'fieldset',
2103
    '#title' => t('Structured Description Feature Tree'),
2104
    '#collapsible' => TRUE,
2105
    '#collapsed' => FALSE,
2106
  );
2107
  $featureTrees = cdm_get_featureTrees_as_options();
2108
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2109
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2110
    $profile_feature_tree_uuid = NULL;
2111
  }
2112
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2113
    '#type' => 'radios',
2114
    '#title' => t('Natural language representation of structured descriptions') . ':',
2115
    '#default_value' => $profile_feature_tree_uuid,
2116
    '#options' => $featureTrees['options'],
2117
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2118
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2119
    '#description' => t('Taxon descriptions can be stored in a highly structured
2120
      form. The feature tree selected here will be used to generate textual
2121
      representation in natural language.'
2122
    ),
2123
  );
2124

    
2125

    
2126

    
2127
  // ---- DISTRIBUTION LAYOUT ---- //
2128
  $form['taxon_profile']['distribution_layout'] = array(
2129
    '#title' => t('Distribution'),
2130
    '#collapsible' => TRUE,
2131
    '#collapsed' => FALSE,
2132
    '#type' => 'fieldset',
2133
    '#description' => 'This section covers general settings regarding the textual representation of distributions.
2134
        Map related settings are found in the '
2135
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2136
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2137
      . l(
2138
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2139
        array('fragment' => 'edit-feature-block-settings')
2140
      )
2141
      . ' More general settings regrading the filtering of Distributions are found at '
2142
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2143
      . '. (These settings here will be merged in future releases into the feature block settings)',
2144

    
2145
  );
2146

    
2147
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2148
    '#type' => 'checkbox',
2149
    '#title' => t('Condensed distribution'),
2150
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2151
    '#description' => 'This option enables the display of a very compact representation
2152
    of the distribution which includes also information on the status.',
2153
  );
2154

    
2155
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2156
    '#type' => 'select',
2157
    '#title' => t('Condensed distribution recipe'),
2158
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2159
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2160
    '#description' => 'Recipe for creating the condensed distribution.',
2161
  );
2162

    
2163
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2164
    '#type' => 'textfield',
2165
    '#title' => t('Condensed distribution info path'),
2166
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2167
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2168
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2169
  );
2170

    
2171

    
2172
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2173
    '#type' => 'radios',
2174
    '#title' => t('Display mode') . ':',
2175
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2176
    '#options' => array(
2177
      'FLAT_ALPHA' => t('Flat list'),
2178
      'TREE' => t('Hierarchically ordered'),
2179
    ),
2180
    '#description' => 'Taxon distribution information is displayed with
2181
    focus on the area of the distribution. The list of areas can either be shown
2182
    as flat list ordered alphabetically or in the hierarchical of the parent
2183
    area and subarea relationship. Fall back areas areas with no Distribution data
2184
    are hidden from the area hierarchy so that their sub areas will move one level up.
2185
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2186
    ' for details on the <em>Marked area filter</em>.',
2187
  );
2188

    
2189
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, SORT_ASC);
2190
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2191
    '#type' => 'checkboxes',
2192
    '#title' => 'Omit area levels',
2193
    '#options' => $level_options,
2194
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2195
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2196
    Areas which belong to the selected area levels will be hidden in the portal.',
2197
  );
2198

    
2199
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2200
    '#type' => 'checkbox',
2201
    '#title' => t('Show TextData elements on top of the map'),
2202
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2203
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2204
      elements on top of the map. Otherwise all <code>TextData</code>
2205
      distribution elements will be listed below the other area elements.
2206
      This option is useful if you need to have descriptive texts for each
2207
      distribution map.'),
2208
  );
2209

    
2210
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2211
      '#type' => 'textarea',
2212
      '#title' => t('Custom status colors'),
2213
      '#element_validate' => array('form_element_validate_json'),
2214
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2215
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2216
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2217
          reference list of the idInVocabulary values of absence and presence terms:
2218
<pre>
2219
Presence Term
2220
p	present
2221
pd	present: doubtfully present
2222
n	native
2223
nq	native: presence questionable
2224
nd	native: doubtfully native
2225
c	cultivated
2226
i	introduced
2227
iq	introduced: presence questionable
2228
id	introduced: doubtfully introduced (perhaps cultivated only)
2229
ip	introduced: uncertain degree of naturalisation
2230
ia	introduced: adventitious (casual)
2231
in	introduced: naturalized
2232
ic	introduced: cultivated
2233
e	endemic for the relevant area
2234
na	naturalised
2235
iv	invasive
2236

    
2237
AbsenceTerm
2238
a	absent
2239
f	reported in error
2240
nf	native: reported in error
2241
if	introduced: reported in error
2242
cf	cultivated: reported in error
2243
ne	native: formerly native
2244
ie	introduced: formerly introduced
2245

    
2246
</pre>'),
2247
  );
2248

    
2249

    
2250
  /* ====== SYNONYMY ====== */
2251
  $form['taxon_synonymy'] = array(
2252
    '#type' => 'fieldset',
2253
    '#title' => t('Taxon synonymy (tab)'),
2254
    '#collapsible' => TRUE,
2255
    '#collapsed' => TRUE,
2256
    '#description' => t('This section covers the settings related to the taxon
2257
      <strong>synonymy</strong> tab.'),
2258
  );
2259

    
2260
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2261
    '#type' => 'checkbox',
2262
    '#title' => t('Show accepted taxon on top of the synonymy'),
2263
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2264
    '#description' => t('If checked, the first homotypic taxon is a repetition
2265
      of the accepted taxon most likely with the full nomenclatural reference
2266
      (depending on the currently chosen theme).'),
2267
  );
2268

    
2269
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2270
    '#type' => 'checkbox',
2271
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2272
      coming from a synonym link.'),
2273
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2274
    '#description' => t('Check this if after doing a search and clicking on a
2275
      synonym you want to see the "accept of" text for the accepted synonym.'),
2276
  );
2277

    
2278
  /* === currently unused ===
2279
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2280
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2281
    '#type' => 'checkboxes',
2282
    '#title' => t('Display name relationships') . ':',
2283
    '#default_value' => variable_get('name_relationships_to_show', 0),
2284
    '#options' => $nameRelationshipTypeOptions,
2285
    '#description' => t('Select the name relationships you want to show for the
2286
      accepted taxa.'),
2287
  );
2288
 */
2289

    
2290
  $form['taxon_synonymy']['taxon_relations'] = array(
2291
    '#type' => 'fieldset',
2292
    '#title' => t('Taxon relationships'),
2293
    '#collapsible' => FALSE,
2294
    '#collapsed' => FALSE
2295
  );
2296

    
2297
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2298
    '#type' => 'checkbox',
2299
    '#title' => t('Show taxon relations ships of accepted taxon'),
2300
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2301
    '#description' => t('If this option is enabled the synonymy will show the
2302
      below selected taxon relationships of accepted taxa.'),
2303
  );
2304

    
2305
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2306
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2307
    '#type' => 'checkboxes',
2308
    '#title' => t('Taxon relationship types') . ':',
2309
    '#description' => t('Only taxon relationships of the selected type will be
2310
      displayed'),
2311
    '#options' => $taxonRelationshipTypeOptions,
2312
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2313
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2314
  );
2315

    
2316
  $form['taxon_synonymy']['name_relations'] = array(
2317
    '#type' => 'fieldset',
2318
    '#title' => t('Name relationships'),
2319
    '#collapsible' => FALSE,
2320
    '#collapsed' => FALSE
2321
  );
2322

    
2323
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2324
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2325
    '#type' => 'checkboxes',
2326
    '#title' => t('Name relationship types') . ':',
2327
    '#description' => t('Only name relationships of the selected type will be
2328
      displayed'),
2329
    '#options' => $taxonRelationshipTypeOptions,
2330
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2331
  );
2332

    
2333
  // ====== SPECIMENS ====== //
2334
  $form['taxon_specimens'] = array(
2335
    '#type' => 'fieldset',
2336
    '#title' => t('Taxon specimens (tab)'),
2337
    '#collapsible' => TRUE,
2338
    '#collapsed' => TRUE,
2339
    '#description' => t('This section covers the settings related to the taxon
2340
      <strong>specimens</strong> tab.'),
2341
  );
2342

    
2343
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2344
        '#type' => 'checkbox',
2345
        '#title' => t('Show specimen derivatives in a compressed table'),
2346
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2347
        '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2348
        a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2349
    );
2350
    
2351
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2352
        '#type' => 'checkbox',
2353
        '#title' => t('Show "Associated with" in specimen table.'),
2354
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2355
    );
2356

    
2357
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2358
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2359
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2360
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2361
  }
2362
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2363
      '#type' => 'radios',
2364
      '#title' => t('Specimen description feature tree') . ':',
2365
      '#default_value' => $profile_feature_tree_uuid,
2366
      '#options' =>  $featureTrees['options'],
2367
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2368
      '#options_suffixes' => $featureTrees['treeRepresentations'],
2369
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2370
      ),
2371
  );
2372

    
2373
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2374
  $form_title = t('Specimen media');
2375
  $form_description = t('Specimens may have media which is displayed at the
2376
     Specimen tab/section as a gallery. It is possible to configure the
2377
     thumbnails gallery here, however for configuring how a single media should
2378
     be displayed please go to !url.</p>',
2379
     array(
2380
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2381
     ));
2382
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2383

    
2384
  // --- MEDIA GALLERY ---- //
2385
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2386
  $form_title = 'Media gallery (tab)';
2387
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2388
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2389
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2390
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2391
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2392
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2393
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2394

    
2395
  // Comment @WA: D7 form api does not support reset buttons,
2396
  // so to mimic the D5 reset button we add one like this.
2397
  $form['actions']['reset'] = array(
2398
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2399
    '#weight' => 1000,
2400
  );
2401
  return system_settings_form($form);
2402
}
2403

    
2404
/**
2405
 * @todo document this function.
2406
 */
2407
function cdm_settings_layout_search() {
2408

    
2409
  $form = array();
2410

    
2411
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2412

    
2413
  $form['search_settings'] = array(
2414
    '#type' => 'fieldset',
2415
    '#title' => t('Taxa Search'),
2416
    '#collapsible' => FALSE,
2417
    '#collapsed' => FALSE,
2418
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2419
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2420
         where they can write the text to be searched. You can find Drupal block configuration
2421
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2422
  );
2423

    
2424
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2425
      '#type' => 'checkbox',
2426
      '#title' => t('Ignore the chosen classification in simple search'),
2427
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2428
      '#description' => t('The simple search, which can be executed via the search block,
2429
          will by default search on the classification selected in the classification browser
2430
          selector. Set the tick if you want your portal to search on all classifications.'),
2431
  );
2432

    
2433
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2434
    '#type' => 'checkbox',
2435
    '#title' => t('Run simple search with free-text search backend.'),
2436
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2437
    '#description' => t('The simple search uses by default another search
2438
      backend as the advances search. By checking this option the simple search can be
2439
      configured to also use the free-text search backend.'),
2440
  );
2441

    
2442
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2443
    '#type' => 'textfield',
2444
    '#title' => t('Results per page') . ':',
2445
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2446
    '#description' => t('Number of results to display per page.'),
2447
  );
2448

    
2449
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2450
    '#type' => 'checkbox',
2451
    '#title' => t('Show the <i>Show Image Thumbnails</i> button') . ':',
2452
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2453
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2454
  );
2455

    
2456
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2457
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2458
      '#type' => 'checkboxes',
2459
      '#title' => 'Search mode',
2460
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2461
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2462
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2463
          defaults set here.',
2464
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2465
      '#default_value' => $search_mode_default
2466
      );
2467

    
2468
  $form['search_settings'][CDM_SEARCH_AREA_FILTER_PRESET] = array(
2469
    '#type' => 'textfield',
2470
    '#title' => t('area_filter_preset') . ':',
2471
    '#default_value' => variable_get(CDM_SEARCH_AREA_FILTER_PRESET, ''), // '05b0dd06-30f8-477d-bf4c-30d9def56320' =>  Caucasia (Ab + Ar + Gg + Rf(CS)) (Cc)
2472

    
2473
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2474
  );
2475

    
2476
  // --- SEARCH TAXA GALLERY ---- //
2477
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2478
  $collapsed = FALSE;
2479
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2480
  $form_title = 'Taxa Search thumbnails';
2481
  $form_description = 'Search results may show thumbnails. ';
2482
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2483

    
2484
  // Comment @WA: D7 form api does not support reset buttons,
2485
  // so to mimic the D5 reset button we add one like this.
2486
  $form['actions']['reset'] = array(
2487
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2488
    '#weight' => 1000,
2489
  );
2490
  return system_settings_form($form);
2491
}
2492

    
2493
/**
2494
 * @todo document this function.
2495
 */
2496
function cdm_settings_layout_media() {
2497

    
2498
  $form = array();
2499

    
2500
  $form['media_settings'] = array(
2501
    '#type' => 'fieldset',
2502
    '#title' => t('Media settings'),
2503
    '#collapsible' => FALSE,
2504
    '#collapsed' => FALSE,
2505
    '#description' => 'This section covers layout settings for media pages.'
2506
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2507
  );
2508

    
2509
  $form['media_settings']['image_gallery_viewer'] = array(
2510
    '#type' => 'select',
2511
    '#title' => t('Image viewer') . ':',
2512
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2513
    '#options' => array(
2514
      'default' => t('Standard image viewer'),
2515
      'fsi' => t('FSI viewer (requires FSI server!)'),
2516
    ),
2517
  );
2518

    
2519
  // --- MEDIA GALLERY ---- //
2520
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2521
  $form_title = 'Standard viewer';
2522
  $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>';
2523
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2524
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2525

    
2526
  // @WA: D7 form api does not support reset buttons,
2527
  // so to mimic the D5 reset button we add one like this.
2528
  $form['actions']['reset'] = array(
2529
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2530
    '#weight' => 1000,
2531
  );
2532
  return system_settings_form($form);
2533
}
2534

    
2535
/**
2536
 * GEOSERVICE and Map settings.
2537
 */
2538
function cdm_settings_geo($form, &$form_state) {
2539

    
2540
  $current_geoserver_settings = get_edit_map_service_settings();
2541
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2542

    
2543

    
2544
  $form = array();
2545

    
2546
  $dummy_distribution_query = NULL;
2547
  if($map_distribution['map_type'] != 1){
2548
    // we need to apply a dummy query since the map service requires for image maps
2549
    // at least as and ad to be defined
2550
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2551
  }
2552

    
2553
  $form['map_preview'] = array(
2554
      '#type' => 'fieldset',
2555
      '#tree' => FALSE,
2556
      '#title' => t('Map preview'),
2557
      '#collapsible' => FALSE,
2558
      '#description' => 'The preview of the map'
2559
       . ($dummy_distribution_query != null ?
2560
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2561
           '.<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.')
2562
  );
2563
  $form['map_preview']['openlayers_map'] = compose_map(NULL, $dummy_distribution_query, NULL,
2564
    array(
2565
      'move' => "this.cdmOpenlayersMap.printInfo",
2566
      '#execute' => "this.cdmOpenlayersMap.printInfo"
2567
    ),
2568
    true // resizable
2569
  );
2570

    
2571
  /*
2572
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2573
  );
2574
  */
2575

    
2576
  /*
2577
   * GEO SERVER
2578
   */
2579
  $form['edit_map_server'] = array(
2580
    '#type' => 'fieldset',
2581
    '#tree' => true,
2582
    '#title' => t('EDIT map service'),
2583
    '#collapsible' => TRUE,
2584
    '#collapsed' => TRUE,
2585
    '#description' => t('Configuration and selection of your geo server.
2586
      The Geo Server is responsible for generating the maps.'),
2587
  );
2588

    
2589
  $form['edit_map_server']['base_uri'] = array(
2590
    '#type' => 'select',
2591
    '#title' => t('EDIT map service') . ':',
2592
    '#default_value' => $current_geoserver_settings['base_uri'],
2593
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2594
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2595
  );
2596
  $form['edit_map_server']['version'] = array(
2597
      '#type' => 'select',
2598
      '#title' => t('Version') . ':',
2599
      '#default_value' => $current_geoserver_settings['version'],
2600
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2601
      '#description' => t('The version of the EDIT map services'),
2602
  );
2603

    
2604
  /*
2605
   * MAP SETTINGS
2606
   */
2607

    
2608
  $form[CDM_MAP_DISTRIBUTION] = array(
2609
    '#type' => 'fieldset',
2610
    '#tree' => TRUE,
2611
    '#title' => t('Maps settings'),
2612
    '#collapsible' => TRUE,
2613
    '#collapsed' => TRUE,
2614
    '#description' => t('General configuration for all map types.'),
2615
  );
2616

    
2617
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2618
    '#type' => 'radios',
2619
    '#title' => 'Map types',
2620
    '#options' => array(
2621
      1 => "OpenLayers dynamic map viewer",
2622
      0 => "Plain image",
2623
    ),
2624
    '#default_value' => $map_distribution['map_type'],
2625
    '#description' => 'Two different map types are available :
2626
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2627
      which allows zooming and panning. If enabled you can configure the default layer
2628
      (background of your maps) below.</li>
2629
      <li><em>Plain image</em>: The map will be static non interactive
2630
      image.</li></ul>',
2631
  );
2632
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2633

    
2634
  /*
2635
   * settings for the distribution map are used also for specimens map!!!!
2636
   */
2637

    
2638
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2639
      '#type' => 'textfield',
2640
      '#title' => 'Aspect ratio',
2641
      '#default_value' => $map_distribution['aspect_ratio'],
2642
      '#maxlength' => 4,
2643
      '#size' => 4,
2644
      '#element_validate' => array('element_validate_number'),
2645
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2646
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2647
      width by the height:</br>
2648
      <pre>aspect ratio = w / h</pre>
2649
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2650
      for a square map use <strong>1</strong>.',
2651
  );
2652

    
2653
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2654
    '#type' => 'textfield',
2655
    '#title' => 'Bounding box',
2656
    '#default_value' => $map_distribution['bbox'],
2657
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2658
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2659
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2660
      <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.
2661
      (Maybe you need to change the map base layer to OpeLayers.)
2662
      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
2663
      below the map from where you can copy the bbox string.</p>'),
2664
  );
2665

    
2666
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2667
    '#type' => 'checkbox',
2668
    '#title' => 'Display area labels',
2669
    '#default_value' => $map_distribution['show_labels'],
2670
    '#description' => t('The map will show name labels of the areas'),
2671
  );
2672

    
2673
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2674
    '#type' => 'textfield',
2675
    '#title' => 'Map caption',
2676
    '#default_value' => $map_distribution['caption'],
2677
    '#description' => t('The caption will be shown below the map.'),
2678
  );
2679

    
2680
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2681
    '#type' => 'textfield',
2682
    '#title' => 'Distribution layer opacity',
2683
    '#default_value' => $map_distribution['distribution_opacity'],
2684
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2685
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2686
  );
2687

    
2688
  // --- Plain Image Settings --- //
2689
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2690
    '#type' => 'fieldset',
2691
    '#title' => 'Plain image map settings',
2692
    '#tree' => TRUE,
2693
    '#collapsible' => TRUE,
2694
    '#collapsed' => $open_layers_is_enabled,
2695
    '#description' => 'The settings in this section are still expertimental
2696
      and can only be used with the EDIT map service version 1.1 or above.',
2697
  );
2698
  $edit_mapserver_version = get_edit_map_service_version_number();
2699
  if ($edit_mapserver_version < 1.1) {
2700
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">' . t("The chosen EDIT map service version ($edit_mapserver_version) is too low, it must be at least 1.1") . '</div>'
2701
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2702
  }
2703

    
2704
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2705
    '#type' => 'textfield',
2706
    '#title' => 'Width',
2707
    '#default_value' => $map_distribution['image_map']['width'],
2708
    '#maxlength' => 4,
2709
    '#size' => 4,
2710
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2711
  );
2712

    
2713
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2714
    '#type' => 'textfield',
2715
    '#title' => 'Background layer',
2716
    '#default_value' => $map_distribution['image_map']['base_layer'],
2717
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2718
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2719
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2720
    )),
2721
  );
2722

    
2723
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2724
    '#type' => 'textfield',
2725
    '#title' => 'Background color',
2726
    '#default_value' => $map_distribution['image_map']['bg_color'],
2727
  );
2728

    
2729
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2730
    '#type' => 'textfield',
2731
    '#title' => 'Background layer style',
2732
     // Only line color by now.
2733
    '#default_value' => $map_distribution['image_map']['layer_style'],
2734
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2735
  );
2736

    
2737
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2738
      '#type' => 'textfield',
2739
      '#title' => 'Projection',
2740
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2741
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2742
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2743
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2744
  );
2745

    
2746

    
2747
  // --- OpenLayers Settings --- //
2748
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2749
    '#type' => 'fieldset',
2750
    '#title' => 'OpenLayers settings',
2751
    '#tree' => TRUE,
2752
    '#collapsible' => TRUE,
2753
    '#collapsed' => !$open_layers_is_enabled,
2754
    '#description' => '',
2755
  );
2756

    
2757

    
2758
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2759
      '#type' => 'checkbox',
2760
      '#title' => 'Display outside max extent',
2761
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2762
      '#description' => t('Allows the map to display parts of the layers which are outside
2763
         the max extent if the aspect ratio of the map and of the baselayer
2764
         are not equal.'),
2765
  );
2766

    
2767

    
2768
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2769
      '#type' => 'checkbox',
2770
      '#title' => 'Show Layer Switcher',
2771
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2772
      '#description' => 'The Layer Switcher control displays a table of contents
2773
      for the map.  This allows the user interface to switch between
2774
      base layers and to show or hide overlays.  By default the switcher is
2775
      shown minimized on the right edge of the map, the user may expand it
2776
      by clicking on the handle.',
2777
  );
2778

    
2779
  if (!$open_layers_is_enabled) {
2780
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2781
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2782
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2783
  }
2784

    
2785
  // The default layer must always be enabled
2786
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2787
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2788

    
2789
  $baselayer_options = array(
2790
    /*
2791
   NOTICE: must correspond to the layers defined in
2792
   js/openlayers_,ap.js#getLayersByName()
2793
   */
2794
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
2795
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
2796
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
2797
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
2798
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2799
    // all others EPSG:900913
2800
    'mapnik' => 'OpenStreetMap',
2801
    'mapquest_open' => "MapQuest",
2802
    'mapquest_sat' => "MapQuest Sattelite",
2803
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2804
//    'gmap' => 'Google Streets',
2805
//    'gsat' => 'Google Satellite',
2806
//    'ghyb' => 'Google Hybrid',
2807
//     'veroad' => 'Virtual Earth Roads',
2808
//     'veaer' => 'Virtual Earth Aerial',
2809
//     'vehyb' => 'Virtual Earth Hybrid',
2810
    // 'yahoo' => 'Yahoo Street',
2811
    // 'yahoosat' => 'Yahoo Satellite',
2812
    // 'yahoohyb' => 'Yahoo Hybrid',
2813
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2814
  );
2815

    
2816
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2817
    '#type' => 'checkboxes_preferred',
2818
    '#title' => 'Base Layers',
2819
    '#options' => $baselayer_options,
2820
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2821
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2822
  );
2823

    
2824
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2825
      '#type' => 'fieldset',
2826
      '#title' => 'Custom WMS base layer',
2827
      '#tree' => TRUE,
2828
      '#collapsible' => FALSE,
2829
      '#collapsed' => FALSE,
2830
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2831
  );
2832

    
2833
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2834
      '#type' => 'textfield',
2835
      '#title' => 'Layer name',
2836
      // Only line color by now.
2837
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2838
      '#description' => 'A arbitrary name for the layer.',
2839
  );
2840
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2841
      '#type' => 'textfield',
2842
      '#title' => 'WMS url',
2843
      // Only line color by now.
2844
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2845
      '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
2846
  );
2847
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2848
      '#type' => 'textarea',
2849
      '#title' => 'WMS parameters',
2850
      '#element_validate' => array('form_element_validate_json'),
2851
      // Only line color by now.
2852
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2853
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2854
<pre> {
2855
  "Layers": "topp:em_tiny_jan2003",
2856
  "Format": "image/png",
2857
  "BGCOLOR": "0xe0faff"
2858
}
2859
</pre>'
2860
  );
2861
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2862
      '#type' => 'textfield',
2863
      '#title' => 'Projection',
2864
      // Only line color by now.
2865
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2866
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2867
  );
2868
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2869
      '#type' => 'textfield',
2870
      '#maxlength' => 256,
2871
      '#title' => 'proj4js definition',
2872
      // Only line color by now.
2873
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2874
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2875
            The definitions for
2876
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2877
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2878
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2879
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2880
            choose to display the proj4js definition string.
2881
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2882
            <pre>
2883
+a         Semimajor radius of the ellipsoid axis
2884
+alpha     ? Used with Oblique Mercator and possibly a few others
2885
+axis      Axis orientation (new in 4.8.0)
2886
+b         Semiminor radius of the ellipsoid axis
2887
+datum     Datum name (see `proj -ld`)
2888
+ellps     Ellipsoid name (see `proj -le`)
2889
+k         Scaling factor (old name)
2890
+k_0       Scaling factor (new name)
2891
+lat_0     Latitude of origin
2892
+lat_1     Latitude of first standard parallel
2893
+lat_2     Latitude of second standard parallel
2894
+lat_ts    Latitude of true scale
2895
+lon_0     Central meridian
2896
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
2897
+lon_wrap  Center longitude to use for wrapping (see below)
2898
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
2899
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
2900
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
2901
+pm        Alternate prime meridian (typically a city name, see below)
2902
+proj      Projection name (see `proj -l`)
2903
+south     Denotes southern hemisphere UTM zone
2904
+to_meter  Multiplier to convert map units to 1.0m
2905
+towgs84   3 or 7 term datum transform parameters (see below)
2906
+units     meters, US survey feet, etc.
2907
+vto_meter vertical conversion to meters.
2908
+vunits    vertical units.
2909
+x_0       False easting
2910
+y_0       False northing
2911
+zone      UTM zone
2912
            </pre>
2913
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
2914
  );
2915
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
2916
      '#type' => 'textfield',
2917
      '#title' => 'Maximum extent',
2918
      // Only line color by now.
2919
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
2920
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
2921
  );
2922
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
2923
      '#type' => 'textfield',
2924
      '#title' => 'Units',
2925
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
2926
      '#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.'
2927
  );
2928

    
2929
  /*
2930
   * Map Legend
2931
   */
2932
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2933
    '#type' => 'fieldset',
2934
    '#title' => 'Map legend',
2935
    '#tree' => TRUE,
2936
    '#collapsible' => TRUE,
2937
    '#collapsed' => TRUE,
2938
    '#description' => 'Configure the maps legend.',
2939
  );
2940

    
2941
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2942
    '#type' => 'checkbox',
2943
    '#title' => 'Display a map legend',
2944
    '#default_value' => $map_distribution['legend']['show'],
2945
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2946
  );
2947

    
2948
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2949
    '#type' => 'textfield',
2950
    '#title' => 'Legend opacity',
2951
    '#default_value' => $map_distribution['legend']['opacity'],
2952
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2953
                         to 0.0 will be not much visible.',
2954
  );
2955

    
2956
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2957
    '#type' => 'textfield',
2958
    '#title' => 'Font size',
2959
    '#default_value' => $map_distribution['legend']['font_size'],
2960
    '#description' => 'Font size in pixels.',
2961
  );
2962

    
2963
  $fontStyles = array(
2964
    0 => "plane",
2965
    1 => "italic",
2966
  );
2967
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2968
    '#type' => 'select',
2969
    '#title' => 'Available font styles',
2970
    '#default_value' => $map_distribution['legend']['font_style'],
2971
    '#options' => $fontStyles,
2972
    '#description' => 'Select a font style for the map legend.',
2973
  );
2974

    
2975
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2976
    '#type' => 'textfield',
2977
    '#title' => 'Icon width',
2978
    '#default_value' => $map_distribution['legend']['icon_width'],
2979
    '#description' => 'Legend icon width in pixels.',
2980
  );
2981
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2982
    '#type' => 'textfield',
2983
    '#title' => 'Icon height',
2984
    '#default_value' => $map_distribution['legend']['icon_height'],
2985
    '#description' => 'Legend icon height in pixels.',
2986
  );
2987

    
2988
  // @WA: D7 form api does not support reset buttons,
2989
  // so to mimic the D5 reset button we add one like this.
2990
  $form['actions']['reset'] = array(
2991
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2992
    '#weight' => 1000,
2993
  );
2994

    
2995
  return system_settings_form($form);
2996
}
2997

    
2998

    
2999
/**
3000
 * @todo document this function.
3001
 */
3002
function cdm_settings_cache() {
3003

    
3004
  $form = array();
3005

    
3006
  $form['cache_settings'] = array(
3007
    '#type' => 'fieldset',
3008
    '#title' => t('Cache Settings'),
3009
    '#collapsible' => FALSE,
3010
    '#collapsed' => FALSE,
3011
    '#description' => t('<p>When caching is enabled all single taxon sites are
3012
      stored in an internal drupal cache doing the portal response of taxa pages
3013
      faster. This is possible because the sites are loaded from the cache and
3014
      are not created from scratch.</p>'),
3015
  );
3016

    
3017
  $form['cache_settings']['cdm_webservice_cache'] = array(
3018
    '#type' => 'checkbox',
3019
    '#title' => t('<strong>Enable caching</strong>'),
3020
    '#options' => cdm_help_general_cache(),
3021
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3022
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3023
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3024
       application the changes will be not visible till the cache is erased.
3025
       Therefore developers should deactived this feature when they are working
3026
       on the CDM Dataportal Module.</p>'),
3027
  );
3028

    
3029
  $form['cache_settings']['cdm_run_cache'] = array(
3030
    '#markup' => cdm_view_cache_site(),
3031
  );
3032

    
3033
  // @WA: D7 form api does not support reset buttons,
3034
  // so to mimic the D5 reset button we add one like this.
3035
  $form['actions']['reset'] = array(
3036
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3037
    '#weight' => 1000,
3038
  );
3039
  return system_settings_form($form);
3040
}
3041

    
3042
/**
3043
 * Walk and cache all taxon pages.
3044
 */
3045
function cdm_view_cache_site() {
3046

    
3047
  $out = '';
3048

    
3049
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3050

    
3051
  $request_params = array();
3052
  $request_params['class'] = "Taxon";
3053

    
3054
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3055
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3056
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3057

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

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

    
3067
  // Comment @WA: A form within a form is not valid html and not needed here.
3068
  // Also, it would be recommended just to include this part of the form in the
3069
  // rest of the form array in cdm_settings_cache().
3070
  // $out .= '<form id="cache_site">';
3071
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3072
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3073
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3074
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3075
  // $out .= '</form>';
3076
  $out .= '</div>';
3077
  /*
3078
  foreach($taxonPager->records as $taxon){
3079
    cdm_dataportal_taxon_view($uuid);
3080
  }
3081
  */
3082
  return $out;
3083
}
3084

    
3085

    
3086
function cdm_settings_layout_taxon_submit($form, &$form_state){
3087
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3088
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3089
    if(is_object($file)){
3090
      $file->status = FILE_STATUS_PERMANENT;
3091
      file_save($file);
3092
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3093
    }
3094
  }
3095
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
3096
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
3097
    // we first need to set the variable to persist the changes setting
3098
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3099
    menu_rebuild();
3100
  }
3101
}
3102

    
3103
function cdm_settings_layout_search_submit($form, &$form_state){
3104
  // the visibility of media thumbnails also affects the ui of the search results
3105
  // so reset the according session variable
3106
  //    1. in order to give the user immediate
3107
  //       feedback on potential setting changes
3108
  //    2. let refresh the default if it has changed
3109
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3110
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3111
  }
3112
}
3113

    
3114
/**
3115
 * Form validation handler for cdm_settings_general
3116
 *
3117
 * @param $form
3118
 * @param $form_state
3119
 */
3120
function cdm_settings_general_validate($form, &$form_state) {
3121

    
3122
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3123
    $form_state['values']['cdm_webservice_url'] .= '/';
3124
  }
3125

    
3126
}
3127

    
3128
/**
3129
 * Form submit handler for settings general.
3130
 *
3131
 * tasks performed:
3132
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3133
 *
3134
 * @param $form
3135
 * @param $form_state
3136
 */
3137
function cdm_settings_general_submit($form, &$form_state){
3138
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3139
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3140
}
3141

    
3142
/**
3143
 * Form validation handler for cdm_settings_cache
3144
 */
3145
function cdm_settings_cache_validate($form, &$form_state) {
3146
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3147
    cache_clear_all(NULL, 'cache_cdm_ws');
3148
    // Better clear secref_cache since I can not be sure if the cache has not
3149
    // be used during this response.
3150
    cdm_api_secref_cache_clear();
3151
  }
3152

    
3153
}
3154

    
3155
/**
3156
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3157
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3158
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3159
 *  - version: the version, e.g.: v1.1
3160
 *
3161
 * @return array
3162
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3163
 */
3164
function get_edit_map_service_settings() {
3165

    
3166
  $settings = variable_get('edit_map_server', array(
3167
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3168
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3169
      )
3170
  );
3171

    
3172
  return $settings;
3173
}
3174

    
3175
/**
3176
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3177
 *
3178
 * @return string
3179
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3180
 */
3181
function get_edit_map_service_full_uri() {
3182
  $settings = get_edit_map_service_settings();
3183
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3184
}
3185

    
3186

    
3187
/**
3188
 * Returns the version number of the currently selected edit mapserver as a float
3189
 *
3190
 * @return float
3191
 *   The version number of the currently selected edit mapserver as a float.
3192
 *   Returns 0 on error.
3193
 */
3194
function get_edit_map_service_version_number() {
3195

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

    
3198
  $settings = get_edit_map_service_settings();
3199
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3200
  if (isset($matches[1])) {
3201
    // Convert string to float.
3202
    $version = 1 + $matches[1][0] - 1;
3203
    return $version;
3204
  }
3205
  else {
3206
    // Report error.
3207
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3208
        array(
3209
          '!version' => $settings['version'],
3210
          'warning')
3211
        )
3212
      );
3213
    return 0;
3214
  }
3215
}
3216

    
3217
/**
3218
 * Returns the array of selected items in a options array
3219
 *
3220
 * @param array $options
3221
 *   An options array as generated by a form element like checkoxes, select ...,
3222
 */
3223
function get_selection($options) {
3224
  $selection = array();
3225
  foreach ($options as $key=>$val) {
3226
    if (!empty($val)) {
3227
      $selection[] = $val;
3228
    }
3229
  }
3230
  return $selection;
3231
}
3232

    
3233

    
3234
/**
3235
 * Implements hook_element_info().
3236
 *
3237
 * Allows modules to declare their own Form API element types and specify their default values.
3238
 *
3239
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3240
 */
3241
function cdm_dataportal_element_info() {
3242
  $type['checkboxes_preferred'] = array(
3243
    '#input' => TRUE,
3244
    '#process' => array('checkboxes_preferred_expand'),
3245
    '#after_build' => array('checkboxes_preferred_after_build'),
3246
    '#theme' => array('checkboxes_preferred'),
3247
    // '#theme_wrapper' => array('form_element'),
3248
  );
3249
  return $type;
3250
}
3251

    
3252
/**
3253
 * #process callback function for the custom form element type 'checkbox_preferred'
3254
 *
3255
 *
3256
 */
3257
function checkboxes_preferred_expand($element, &$form_state, $form) {
3258

    
3259
  // First of all create checkboxes for each of the elements
3260
  $element = form_process_checkboxes($element);
3261

    
3262
  // compose the element name
3263
  $parents = array();
3264
  array_deep_copy($element['#parents'], $parents);
3265
  $parents[count($parents) -1 ] .= '_preferred';
3266
  $element_name = $parents[0];
3267
  for ($i=1; $i < count($parents); $i++){
3268
    $element_name .= '[' . $parents[$i] . ']';
3269
  }
3270

    
3271
  $children = element_children($element);
3272

    
3273
  $element['table_start'] = array(
3274
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3275
    '#weight' => -1,
3276
  );
3277

    
3278
  // prepare first part each of the table rows which contains the row label
3279
  $weight = 0;
3280
  foreach ($children as $key) {
3281
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3282
    $element[$key]['#weight'] = $weight;
3283
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
3284
    $element[$key]['#suffix'] = '</td>';
3285
    unset($element[$key]['#title']);
3286
    $weight += 2;
3287
  }
3288
  $weight = 0;
3289

    
3290
  // add a radio button to each of the checkboxes, the
3291
  // check boxes have already been created at the beginning
3292
  // of this function
3293
  if (count($element['#options']) > 0) {
3294
    foreach ($element['#options'] as $key => $choice) {
3295
      if (!isset($element[$key . '_preferred'])) {
3296
        $element[$key . '_preferred'] = array(
3297
          '#type' => 'radio',
3298
          '#name' => $element_name,
3299
          '#return_value' => check_plain($key),
3300
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3301
          '#attributes' => $element['#attributes'],
3302
          '#parents' => $element['#parents'],
3303
          // '#spawned' => TRUE,
3304
          '#weight' => $weight + 1,
3305
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3306
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3307
        );
3308
      }
3309
      $weight += 2;
3310
    }
3311
  }
3312

    
3313
  // end the table
3314
  $element['table_end'] = array(
3315
    '#markup' => '</table>',
3316
    '#weight' => $weight++,
3317
  );
3318

    
3319
  return $element;
3320
}
3321

    
3322
/**
3323
 * Theme function for the custom form field 'checkboxes_preferred'.
3324
 */
3325
function theme_checkboxes_preferred($variables) {
3326
  $element = $variables['element'];
3327
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3328
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3329
  $out .= drupal_render_children($element);
3330
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3331
  $out .= '</div>';
3332
  return $out;
3333
}
3334

    
3335
/**
3336
 * Callback for checkboxes preferred for widget which will
3337
 * be called after the form or element is built. The call
3338
 * back is configured in the form element by setting it as
3339
 * #after_build parameter.
3340
 *
3341
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3342
 *
3343
 * @param $element
3344
 *   Nested array of form elements that comprise the form.
3345
 * @param $form_state
3346
 *   A keyed array containing the current state of the form.
3347
 *   This includes the current persistent storage data for the form.
3348
 *   Additional information, like the sanitized $_POST data,
3349
 *   is also accumulated here in $form_state['input']
3350
 *
3351
 * @return the modified form array
3352
 */
3353
function checkboxes_preferred_after_build($element, &$form_state) {
3354

    
3355
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3356

    
3357
  if ($_POST && count($_POST) > 0) {
3358
    // TODO use  $form_state['input'] instead of POST !!!
3359
    // First pass of form processing.
3360
    $parents = array();
3361
    array_deep_copy($element['#parents'], $parents);
3362
    $parents[count($parents) - 1] .= '_preferred';
3363
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3364
    $element['#value']['PREFERRED'] = $preferred_layer;
3365
//     $form_state[$parent_id] = $element['#value'];
3366
//     $form_state['values']['baselayers'] = $element['#value'];
3367
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3368
    $form_state_element_values = $element['#value'];
3369
  }
3370
  else {
3371
    // Second pass of form processing.
3372
    $preferred_layer = $element['#value']['PREFERRED'];
3373
  }
3374

    
3375
  // Also set the chosen value (not sure if this is good Drupal style ....).
3376
  foreach ($children = element_children($element) as $key) {
3377
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3378
      $element[$key]['#value'] = $preferred_layer;
3379
    }
3380
  }
3381
  // The default layer must always be enabled.
3382
  $element[$preferred_layer]['#value'] = $preferred_layer;
3383

    
3384
  return $element;
3385
}
3386

    
3387
function radios_prepare_options_suffix(&$elements){
3388

    
3389
  $childrenKeys = element_children($elements);
3390
  foreach($childrenKeys as $key){
3391
    if(!is_array($elements[$key]['#theme_wrappers'])){
3392
      $elements[$key]['#theme_wrappers'] = array();
3393
    }
3394
    if(isset($elements['#options_suffixes'][$key])){
3395
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3396
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3397
    }
3398
  }
3399
  return $elements;
3400

    
3401
}
3402

    
3403
/**
3404
 * TODO
3405
 * @param unknown $variables
3406
 */
3407
function theme_radio_options_suffix($variables) {
3408
  $element = $variables['element'];
3409
  if(isset($element['#options_suffix'])) {
3410
    $element['#children'] .= $element['#options_suffix'];
3411
  }
3412
  return $element['#children'];
3413
}
3414

    
3415

    
3416
/**
3417
 * Element validate callback for text field and arrays containing json.
3418
 *
3419
 * @param $element
3420
 *   The form element to validate
3421
 * @param $form_state
3422
 *   A keyed array containing the current state of the form.
3423
 * @param $form
3424
 *   Nested array of form elements that comprise the form.
3425
 */
3426
function form_element_validate_json($element, &$form_state, $form) {
3427
   if (!empty($element['#value'])) {
3428
     json_decode($element['#value']);
3429
     if(json_last_error() != JSON_ERROR_NONE){
3430
       form_error($element, t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title'])) . l('JSONLint', 'http://jsonlint.com/'));
3431
     }
3432
   }
3433
}
3434

    
3435
/**
3436
 * Form submission handler for textareas and textfields containing JSON.
3437
 *
3438
 * The contained JSON will be converted into an php array
3439
 * or object and will be stored in the variables as such.
3440
 *
3441
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3442
 *
3443
 * @param $form
3444
 *   Nested array of form elements that comprise the form.
3445
 * @param $form_state
3446
 *   A keyed array containing the current state of the form.
3447
 *
3448
 */
3449
function submit_json_as_php_array($form, &$form_state) {
3450
  if (is_array($form['#json_elements'])) {
3451
    foreach ($form['#json_elements'] as $element){
3452
      if (trim($form_state['values'][$element])) {
3453
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3454
      } else {
3455
        $form_state['values'][$element] = NULL;
3456
      }
3457
    }
3458
  }
3459
}
(16-16/16)