Project

General

Profile

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

    
7
// TODO Genus UUID.
8
define('DEFAULT_TAXONTREE_RANKLIMIT', '1b11c34c-48a8-4efa-98d5-84f7f66ef43a');
9
define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
10
define ('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
11

    
12
define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
13
define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
14
define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
15
define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
16
define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
17
define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
18

    
19
/* annotationTypeKeys */
20
$annotationTypeKeys = array_keys(cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE));
21
if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
22
  $annotationTypeKeys = array_flip($annotationTypeKeys);
23

    
24
  // Technical annotation are off by default.
25
  unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
26
  $annotationTypeKeys = array_flip($annotationTypeKeys);
27
  // Additional value for the NULL case.
28
  $annotationTypeKeys[] = 'NULL_VALUE';
29
}
30
define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
31

    
32
define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
33
define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
34
  'enabled' => 1,
35
  'key_format' => 'ALPHA'
36
)));
37

    
38
/* taxonRelationshipTypes */
39
define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
40

    
41

    
42
/* ---- MAP SETTING CONSTANTS ---- */
43
/**
44
 * @var array of URIs eg. http://edit.africamuseum.be"
45
 *   An options array
46
 */
47
define('EDIT_MAPSERVER_URI', serialize(
48
    array(
49
      'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)',
50
      'http://edit.br.fgov.be'=>'Secondary (http://edit.br.fgov.be)',
51
    )
52
  )
53
);
54
define('EDIT_MAPSERVER_PATH', '/edit_wp5');
55
/**
56
 * @var array of versions eg. "v1.2"
57
 *   An options array
58
 */
59
define('EDIT_MAPSERVER_VERSION', serialize(
60
    array(
61
      'v1' => 'v1' ,
62
      'v1.1' => 'v1.1',
63
      'v1.2_dev' => 'v1.2_dev',
64
      'v1.2' => 'v1.2',
65
      'v1.3_dev' => 'v1.3_dev',
66
      'v1.4_dev' => 'v1.4_dev'
67
    )
68
  )
69
);
70
define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
71
define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
72

    
73
// --- Taxon profile settings --- /
74
define('LAYOUT_SETTING_PREFIX', 'layout_');
75
define('FEATURE_TREE_LAYOUT_DEFAULTS', serialize(
76
  array(
77
    'enabled' => FALSE,
78
    'enclosingTag' => 'ul',
79
    'entryEnclosingTag' => 'li',
80
    'glue' => ' ',
81
  )));
82

    
83
define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
84
define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
85
define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
86
    array(
87
        'show' => 0,
88
        'maxextend' => 184,
89
        'media_uri_query' => '',
90
        'custom_placeholder_image_on' => 0,
91
        'custom_placeholder_image_fid' => ''
92
    )
93
  )
94
);
95

    
96
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
97

    
98
/**
99
 * Returns the array of implemented taxon page tabs.
100
 * The array has fixed integer keys which must not be changed.
101
 */
102
function get_taxon_tabs_list() {
103
  return array(
104
    0 => 'General',
105
    1 => 'Synonymy',
106
    2 => 'Images',
107
    3 => 'Specimens',
108
    4 => 'Keys',
109
  );
110
}
111

    
112
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
113
  array('general' => '-3', 'synonymy' => '-2', 'images' => '0', 'specimens' => '1', 'keys' => '3')
114
));
115

    
116
$taxon_tab_options = get_taxon_tabs_list();
117
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
118

    
119
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
120

    
121
/**
122
 * @todo document this function.
123
 */
124
function get_taxon_options_list() {
125
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
126
  foreach ($taxon_tab_options as $key => $value) {
127
    $taxon_tab_options[$key] = t($key);
128
  }
129
  return $taxon_tab_options;
130

    
131
}
132

    
133
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
134
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
135
  array(
136
      'ZoologicalName' => array(
137
        'namePart' => array('name' => TRUE),
138
        'nameAuthorPart' => array('name' => TRUE),
139
        'referencePart' => array('authors' => TRUE),
140
        'microreferencePart' => array('microreference' => TRUE),
141
        'statusPart' => array('status' => TRUE),
142
        'descriptionPart' => array('description' => TRUE),
143
      ),
144
      'BotanicalName'=> array(
145
        'namePart' => array('name' => TRUE),
146
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
147
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
148
        'referenceYearPart' => array('reference.year' => TRUE),
149
        'statusPart' => array('status' => TRUE),
150
        'descriptionPart' => array('description' => TRUE),
151
      ),
152
     '#DEFAULT' => array(
153
        'namePart' => array(
154
            'name' => TRUE
155
        ),
156
        'nameAuthorPart' => array(
157
            'name' => TRUE,
158
            'authors' => TRUE
159
        ),
160
        'referencePart' => array(
161
            'reference' => TRUE
162
        ),
163
        'microreferencePart' => array(
164
            'microreference' => TRUE,
165
        ),
166
        'statusPart' => array(
167
            'status' => TRUE,
168
        ),
169
        'descriptionPart' => array(
170
            'description' => TRUE,
171
        ),
172
      )
173
    )
174
  )
175
);
176
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
177
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
178
   array (
179
     'taxon_page_title,polytomousKey'=> array(
180
          'namePart' => array('#uri' => TRUE),
181
        ),
182
      'taxon_page_synonymy,related_taxon'=> array(
183
          'nameAuthorPart' => array('#uri' => TRUE),
184
          'referencePart' => TRUE,
185
          'statusPart' => TRUE,
186
          'descriptionPart' => TRUE,
187
        ),
188
       'homonym'=> array(
189
            'nameAuthorPart' => array('#uri' => TRUE),
190
            'referenceYearPart' => TRUE,
191
        ),
192
      'acceptedFor,typedesignations,list_of_taxa' => array(
193
          'nameAuthorPart' => array('#uri' => TRUE),
194
          'referencePart' => TRUE,
195
        ),
196
      '#DEFAULT' => array(
197
          'nameAuthorPart' => array('#uri' => TRUE),
198
          'referencePart' => TRUE,
199
       )
200
    )
201
));
202

    
203
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
204
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
205
    // to unset a default enntry set the value to 0
206
    array(
207
      'doTaxa'=>'doTaxa',
208
      'doSynonyms' => 'doSynonyms',
209
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
210
      'doMisappliedNames' => 'doMisappliedNames'
211
    )
212
  )
213
);
214

    
215
/* Gallery variables. */
216
$gallery_settings = array(
217
    "cdm_dataportal_show_taxon_thumbnails" => 1,
218
    "cdm_dataportal_show_synonym_thumbnails" => 0,
219
    "cdm_dataportal_show_thumbnail_captions" => 1,
220
    "cdm_dataportal_media_maxextend" => 120,
221
    "cdm_dataportal_media_cols" => 3,
222
    "cdm_dataportal_media_maxRows" => 1,
223
);
224

    
225
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
226
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
227
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
228
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
229
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
230
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
231
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
232
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
233
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
234
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
235
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
236
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
237
/**
238
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
239
 * the snonymy.
240
 *
241
 * @var string
242
 */
243
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
244
/**
245
 * The drupal variable for the configuration of the information aggregation along
246
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
247
 *    - direct: the uuids of the taxon relationship types to take into account in invers
248
 *      direction.
249
 *    - invers: the uuids of the taxon relationship types to take into account in direct
250
 *      direction.
251
 *
252
 * @var String
253
 */
254
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
255
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
256
    array(
257
        'direct'=>array(),
258
        'invers'=>array()
259
     )
260
   ));
261
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
262
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
263
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
264

    
265
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
266
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
267
      array(
268
      'filter_rules' => array(
269
        'statusOrderPreference' => 0,
270
        'subAreaPreference' => 0,
271
      ),
272
      'hideMarkedAreas' => array()
273
     )
274
));
275

    
276

    
277
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
278
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
279
    array(
280
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
281
        'includeOccurrences' => 0,
282
        'includeTaxonNameDescriptions' => 0
283
     )
284
  ));
285

    
286
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
287
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
288
  // needs to be merged with user setting by drupal_array_merge_deep()
289
  'width' => 512, // optimum size for OSM layers is 512
290
  'height' => 512 / 2, // optimum size for OSM layers 256
291
  'bbox' => '', // empty to allow automatic zooming to extend
292
  'show_labels' => FALSE,
293
  'caption' => '',
294
  'distribution_opacity' => '0.5',
295
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
296
  'image_map' => array(
297
    'base_layer' => '', // none, formerly this was cyprusdivs
298
    'bg_color' => '1874CD',
299
    'layer_style' => 'ffffff,606060,,',
300
  ),
301
  'openlayers' => array(
302
    'base_layers' =>  array(
303
      // A layer MUST NOT BE SET in the defaults,
304
      // otherwise it can not be overidden by the user settings:
305
      // 'osgeo_vmap0' => 'osgeo_vmap0',
306
      // it is sufficient to define the preferred layer,
307
      // since it will automatically be enabled:
308
      'PREFERRED' => 'osgeo_vmap0'),
309
     'custom_wms_base_layer' => array(
310
            'name' => NULL,
311
            'url' => NULL,
312
            'params' =>  NULL,
313
            'projection' => NULL,
314
            'proj4js_def' => NULL,
315
            'max_extent' => NULL,
316
            'units' => NULL
317
     ),
318
    'show_layer_switcher' => TRUE,
319
    'display_outside_max_extent' => FALSE
320
  ),
321
  'legend' => array(
322
    'show' => TRUE,
323
    'opacity' => '0.5',
324
    'font_size' => 10,
325
    'font_style' => FALSE,
326
    'icon_width' => 35,
327
    'icon_height' => 15
328
  )
329
)));
330

    
331
/**
332
 * Merges the named array variable with the array of defaults.
333
 *
334
 * IMPORTANT: The array keys must be strings. When the keys are integers
335
 * the merging will not take place for these entities. Number keyed entities
336
 * are just appended to the result array.
337
 *
338
 * @param string $variable_name
339
 *     The variable name
340
 * @param string | array $default
341
 *     The array containing the default values either as array or serialized as string.
342
 *     Unserialization is cared for if necessary
343
 * @return array
344
 *     The merged array as returned by drupal_array_merge_deep()
345
 */
346
function get_array_variable_merged($variable_name, $default){
347

    
348
    // unserialize if nessecary
349
    if(!is_array($default)){
350
      $default = unserialize($default);
351
    }
352
    $variable = variable_get($variable_name, array());
353
    $result = drupal_array_merge_deep($default, $variable);
354
    return $result;
355
}
356

    
357
/**
358
 * @todo document this function.
359
 */
360
function getGallerySettings($gallery_config_form_name) {
361
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
362
}
363

    
364
/**
365
 * Returns the string representation of the default tab.
366
 *
367
 * @param bool $returnTabIndex
368
 *   Defaults to FALSE, if set true this function will return the index number
369
 *   of the default tab. (used to supply default values to form elements).
370
 */
371
function get_default_taxon_tab($returnTabIndex = FALSE) {
372

    
373
  global $user;
374
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
375
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
376
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
377
  // Get the user value if the used has chosen to overwrite the system settings.
378
  $user_tab_on = variable_get($user_tab_active, FALSE);
379
  if ($user_tab_on) {
380
    $user_value = variable_get($user_tab, 0);
381
    $index_value = $user_value;
382
    // Get the system value.
383
  }
384
  else {
385
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
386
    $index_value = $system_value;
387
  }
388

    
389
  // Return the index value or the string representation.
390
  if ($returnTabIndex) {
391
    return $index_value;
392
  }
393
  else {
394
    return ($values[$index_value]);
395

    
396
  }
397
}
398

    
399

    
400
  /**
401
   * preliminary mock implementation
402
   *
403
   * Provides the feature block settings for a specific feature it is is provides as $feature_uuid parameter.
404
   *
405
   *
406
   * Note: These settings only apply to feature blocks which do not have a special rendering
407
   * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
408
   * 'special' element of the settings
409
   *
410
   * @param $feature_uuid
411
   *   The uuid string representation of the feature to return the settings for
412
   *
413
   * @return array
414
   *  an associative array of settings, with the following fields:
415
   *    - as_list: string
416
   *        this setting will be used in compose_cdm_feature_block_elements() as $enclosing_tag
417
   *        possible values are:
418
   *          div: not as list,
419
   *          ul: as bullet list,
420
   *          ol: as numbered list,
421
   *          dl: as definition list
422
   *    - link_to_reference: boolean,
423
   *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
424
   *    - link_to_name_used_in_source": boolean
425
   *        whether to show name is source information as link which will point to the according name page
426
   *    - sources_as_content (boolean)
427
   *        TRUE:
428
   *          1. If element is of the CDM type TextData and the text is not empty the source references will be
429
   *             appended in brackets like "text (source references)". If the original source has name in source
430
   *             information it will be appended to the citation string,
431
   *             like : "(citation, as name in source; citation, as name in source)"
432
   *          2. if the text of the TextData is empty, the original source citations are the only content
433
   *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
434
   *             prepended to the citation string like: "name in source: citation"
435
   *        FALSE:
436
   *          they are put into the bibliography(=references) pseudo feature block. If the original source
437
   *          citations are the only content, the resulting feature block content would only consist of footnotes.
438
   *          In this case the display of the respective feature block is suppressed.
439
   *    - sources_as_content_to_bibliography  (boolean)
440
   *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
441
   *        in the bibliography.
442
   *    - sort_elements
443
   *        whether and how to sort the elements
444
   *        possible values are the constants SORT_ASC, SORT_DESC, NULL
445
   *    - element_tag
446
   *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
447
   *        possible values are span | div
448
   *    - special: array()
449
   *        an array with further settings, this field can be used for special
450
   *        settings for specialized rendering like for distributions
451
   *  }
452
   *
453
   */
454
  function get_feature_block_settings($feature_uuid = 'DEFAULT'){
455
    // the default must conform to the default parameter values of
456
    // compose_cdm_feature_block_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
457
    // theme_cdm_descriptionElementTextData() : asListElement = NULL
458

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

    
461
    $default = array(
462
      'DEFAULT' => array(
463
        'as_list' => 'ul',
464
        'link_to_reference' => FALSE,
465
        'link_to_name_used_in_source' => TRUE,
466
        'sources_as_content' => TRUE,
467
        'sources_as_content_to_bibliography' => FALSE,
468
        'sort_elements' => FALSE,
469
        'glue' => '',
470
        'element_tag'=> NULL
471
      ),
472
      UUID_CITATION => array(
473
        'as_list' => 'div',
474
        'link_to_reference' => FALSE,
475
        'link_to_name_used_in_source' => FALSE,
476
        'sources_as_content' => TRUE,
477
        'sources_as_content_to_bibliography' => FALSE,
478
        'sort_elements' => FALSE,
479
        'glue' => '',
480
        'element_tag'=> 'div'
481
      )
482
    );
483

    
484
    $cichorieae_default = array(
485
      'DEFAULT' => array(
486
        'as_list' => 'div',
487
        'link_to_reference' => TRUE,
488
        'link_to_name_used_in_source' => TRUE,
489
        'sources_as_content' => TRUE,
490
        'sources_as_content_to_bibliography' => FALSE,
491
        'sort_elements' => FALSE,
492
        'glue' => '',
493
        'element_tag'=> 'div'
494
      ),
495
      UUID_CITATION => array(
496
        'as_list' => 'div',
497
        'link_to_reference' => FALSE,
498
        'link_to_name_used_in_source' => FALSE,
499
        'sources_as_content' => TRUE,
500
        'sources_as_content_to_bibliography' => FALSE,
501
        'sort_elements' => FALSE,
502
        'glue' => '',
503
        'element_tag'=> 'div'
504
      ),
505
      UUID_CHROMOSOMES_NUMBERS => array(
506
        'as_list' => 'ul',
507
        'link_to_reference' => TRUE,
508
        'link_to_name_used_in_source' => TRUE,
509
        'sources_as_content' => TRUE,
510
        'sources_as_content_to_bibliography' => FALSE,
511
        'sort_elements' => FALSE,
512
        'glue' => '',
513
        'element_tag'=> 'div'
514
      ),
515
      UUID_CHROMOSOMES => array(
516
        'as_list' => 'ul',
517
        'link_to_reference' => FALSE,
518
        'link_to_name_used_in_source' => TRUE,
519
        'sources_as_content' => TRUE,
520
        'sources_as_content_to_bibliography' => FALSE,
521
        'sort_elements' => FALSE,
522
        'glue' => '',
523
        'element_tag'=> 'div'
524
      ),
525
    );
526

    
527
    $palmweb_default = array(
528
      'DEFAULT' => array(
529
        'as_list' => 'ul',
530
        'link_to_reference' => TRUE,
531
        'link_to_name_used_in_source' => TRUE,
532
        'sources_as_content' => TRUE,
533
        'sources_as_content_to_bibliography' => TRUE,
534
        'sort_elements' => FALSE,
535
        'glue' => '',
536
        'element_tag'=> NULL
537
      ),
538
      UUID_CITATION => array(
539
        'as_list' => 'ul',
540
        'link_to_reference' => TRUE,
541
        'link_to_name_used_in_source' => TRUE,
542
        'sources_as_content' => FALSE,
543
        'sources_as_content_to_bibliography' => TRUE,
544
        'sort_elements' => FALSE,
545
        'glue' => '',
546
        'element_tag'=> 'div'
547
      )
548
    );
549

    
550
    $default_theme = variable_get('theme_default', NULL);
551

    
552
    switch ($default_theme){
553
      case 'garland_cichorieae':
554
      case 'cyprus':
555
        // cyprus: no longer used in production,
556
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
557
        $settings_for_theme = $cichorieae_default;
558
        break;
559
      case 'flore_afrique_centrale':
560
      case 'flora_malesiana':
561
      case 'flore_gabon':
562
        $settings_for_theme = $cichorieae_default;
563
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
564
        break;
565
      case 'palmweb_2':
566
        $settings_for_theme = $palmweb_default;
567
        break;
568
      default:
569
        $settings_for_theme =  $default;
570
    }
571

    
572
    if(isset($settings_for_theme[$feature_uuid])){
573
      return $settings_for_theme[$feature_uuid];
574
    } else if(isset($settings_for_theme['DEFAULT'])){
575
      return $settings_for_theme['DEFAULT'];
576
    } else if(isset($settings_for_theme[$feature_uuid])){
577
      return $default[$feature_uuid];
578
    } else {
579
      return $default['DEFAULT'];
580
    }
581
  }
582
  /**
583
 * returns the current setting for the original source bibliography
584
 *
585
 * Caches internally
586
 *
587
 * @return array
588
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
589
 *   - 'enabled': 1|0
590
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
591
 */
592
function get_bibliography_settings($clear_cache = false){
593
  static $bibliography_settings = null;
594
  if(!$bibliography_settings || $clear_cache){
595
    $bibliography_settings = get_array_variable_merged(
596
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
597
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
598
    );
599
  }
600
  return $bibliography_settings;
601
}
602

    
603
/**
604
 * @todo Please document this function.
605
 * @see http://drupal.org/node/1354
606
 */
607
function cdm_dataportal_menu_admin(&$items) {
608
  // Display section on admin/config page.
609
  $items['admin/config/cdm_dataportal'] = array(
610
    'title' => 'CDM Dataportal',
611
    'description' => 'Settings for the CDM DataPortal.',
612
    'position' => 'right',
613
    'weight' => 10,
614
    'page callback' => 'system_admin_menu_block_page',
615
    'access arguments' => array('administer cdm_dataportal'),
616
    'file' => 'system.admin.inc',
617
    'file path' => drupal_get_path('module', 'system'),
618
  );
619
  $items['admin/config/cdm_dataportal/settings'] = array(
620
    'title' => 'Settings',
621
    'description' => 'Settings for the CDM DataPortal.',
622
    'weight' => 0,
623
    'page callback' => 'drupal_get_form',
624
    'page arguments' => array('cdm_settings_general'),
625
    'access arguments' => array('administer cdm_dataportal'),
626
    'type' => MENU_NORMAL_ITEM,
627
  );
628
  $items['admin/config/cdm_dataportal/settings/general'] = array(
629
    'title' => 'General',
630
    'description' => 'General',
631
    'weight' => 0,
632
    'page callback' => 'drupal_get_form',
633
    'page arguments' => array('cdm_settings_general'),
634
    'access arguments' => array('administer cdm_dataportal'),
635
    'type' => MENU_DEFAULT_LOCAL_TASK,
636
  );
637

    
638
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
639
    'title' => 'Cache',
640
    'description' => 'Cache',
641
    'access arguments' => array('administer cdm_dataportal'),
642
    'page callback' => 'drupal_get_form',
643
    'page arguments' => array('cdm_settings_cache'),
644
    'weight' => 10,
645
    'type' => MENU_LOCAL_TASK,
646
  );
647

    
648
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
649
    'title' => 'Geo & Map',
650
    'description' => 'Geo & Map',
651
    'access arguments' => array('administer cdm_dataportal'),
652
    'page callback' => 'drupal_get_form',
653
    'page arguments' => array('cdm_settings_geo'),
654
    'weight' => 1,
655
    'type' => MENU_LOCAL_TASK,
656
  );
657

    
658
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
659
    'title' => 'Layout',
660
    'description' => 'Configure and adjust the layout of your DataPortal ',
661
    'access arguments' => array('administer cdm_dataportal'),
662
    'page callback' => 'drupal_get_form',
663
    'page arguments' => array('cdm_settings_layout'),
664
    'weight' => 2,
665
    'type' => MENU_LOCAL_TASK,
666
  );
667

    
668
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
669
    'title' => 'Taxon',
670
    'description' => 'Configure and adjust the layout of your DataPortal ',
671
    'access arguments' => array('administer cdm_dataportal'),
672
    'page callback' => 'drupal_get_form',
673
    'page arguments' => array('cdm_settings_layout_taxon'),
674
    'weight' => 1,
675
    'type' => MENU_LOCAL_TASK,
676
  );
677
  /*
678
  $items[] = array(
679
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
680
  'title' => t('Synonymy'),
681
  'description' => t('Configure and adjust the layout of your DataPortal '),
682
  'access' => user_access('administer cdm_dataportal'),
683
  'callback' => 'drupal_get_form',
684
  'callback arguments' => array('cdm_settings_layout_synonymy'),
685
  'weight' => 1,
686
  'type' => MENU_LOCAL_TASK,
687
  );
688

    
689
  $items[] = array(
690
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
691
  'title' => t('Specimens'),
692
  'description' => t('Configure and adjust the layout of your DataPortal '),
693
  'access' => user_access('administer cdm_dataportal'),
694
  'callback' => 'drupal_get_form',
695
  'callback arguments' => array('cdm_settings_layout_specimens'),
696
  'weight' => 1,
697
  'type' => MENU_LOCAL_TASK,
698
  );
699
  */
700
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
701
    'title' => 'Search',
702
    'description' => 'Configure and adjust the layout of your DataPortal ',
703
    'access arguments' => array('administer cdm_dataportal'),
704
    'page callback' => 'drupal_get_form',
705
    'page arguments' => array('cdm_settings_layout_search'),
706
    'weight' => 2,
707
    'type' => MENU_LOCAL_TASK,
708
  );
709

    
710
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
711
    'title' => 'Media',
712
    'description' => 'Configure and adjust the layout of your DataPortal ',
713
    'access arguments' => array('administer cdm_dataportal'),
714
    'page callback' => 'drupal_get_form',
715
    'page arguments' => array('cdm_settings_layout_media'),
716
    'weight' => 3,
717
    'type' => MENU_LOCAL_TASK,
718
  );
719

    
720
}
721

    
722
/**
723
 * @todo document this function.
724
 */
725
function cdm_help_general_cache() {
726
  $form = array();
727
  $form['cache_help'] = array(
728
    '#type' => 'fieldset',
729
    '#title' => t('Help'),
730
    '#collapsible' => TRUE,
731
    '#collapsed' => TRUE,
732
  );
733
  $form['cache_help']['test'] = array('#value' => t('probando'));
734
  return drupal_render($form);
735
  $res = array();
736
  $res['default'] = drupal_render($help);
737
  return $res;
738
}
739

    
740
/**
741
 * Configures the settings form for the CDM-API module.
742
 *
743
 * @return array
744
 *   Drupal settings form.
745
 */
746
function cdm_settings_general() {
747

    
748
  $form['cdm_webservice'] = array(
749
    '#type' => 'fieldset',
750
    '#title' => t('CDM Server'),
751
    '#collapsible' => FALSE,
752
    '#collapsed' => FALSE,
753
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
754
        CDM data base to the web via RESTful web services and thus is the source of the data
755
        to be displayed by a CDM DataPotal.'),
756
  );
757

    
758
  $form['cdm_webservice']['cdm_webservice_url'] = array(
759
    '#type' => 'textfield',
760
    '#title' => t('CDM web service URL') . ':',
761
    '#description' => t('This is the URL to the CDM-Server exposing your data
762
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
763
    '#default_value' => variable_get('cdm_webservice_url', NULL),
764
  );
765

    
766
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
767
    '#type' => 'markup',
768
    '#markup' => '<b>Debug CDM Web Service:</b> The web service debug box has completely been replaced '
769
      . 'by  the ' . l('CDM web service debug block', 'admin/structure/block/manage/cdm_api/cdm_ws_debug/configure')
770
      . '. It is usually only visible for administrative roles like <i>administrator</i> and <i>CDM admin</i>'
771
  );
772

    
773
  $form['cdm_webservice']['freetext_index'] = array(
774
    '#type' => 'fieldset',
775
    '#title' => t('Freetext index'),
776
    '#collapsible' => FALSE,
777
    '#collapsed' => FALSE,
778
  );
779

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

    
792
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
793
  $trigger_link_options = array(
794
    'attributes' => array(
795
      'class' => 'index-trigger',
796
    ),
797
  );
798
  $form['cdm_webservice']['freetext_index']['operations'] = array(
799
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
800
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
801
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
802
      ))
803
    . '<div id="index-progress"></div></div>',
804
  );
805
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
806

    
807
  $form['cdm_webservice']['proxy'] = array(
808
    '#type' => 'fieldset',
809
    '#title' => t('Proxy'),
810
    '#collapsible' => TRUE,
811
    '#collapsed' => TRUE,
812
  );
813

    
814
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
815
    '#type' => 'textfield',
816
    '#title' => t('Proxy URL') . ':',
817
    '#description' => t('If this proxy url is set the cdm api tries
818
    to connect the web service over the given proxy server.
819
    Otherwise proxy usage is deactivated.'),
820
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
821
  );
822

    
823
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
824
    '#type' => 'textfield',
825
    '#title' => t('Proxy port') . ':',
826
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
827
  );
828

    
829
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
830
    '#type' => 'textfield',
831
    '#title' => t('Login') . ':',
832
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
833
  );
834

    
835
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
836
    '#type' => 'textfield',
837
    '#title' => t('Password') . ':',
838
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
839
  );
840

    
841
  // TODO: settings are still incomplete, compare with
842
  // trunk/dataportal/inc/config_default.php.inc.
843
  $form['taxon_tree'] = array(
844
    '#type' => 'fieldset',
845
    '#title' => t('Taxon Tree'),
846
    '#collapsible' => FALSE,
847
    '#collapsed' => TRUE,
848
    '#description' => t('<p>When you explore your collection, you can navigate
849
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
850
      able to navigate through your collection the
851
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
852
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
853
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
854
      </a></p>'),
855
  );
856

    
857
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
858
    '#type' => 'select',
859
    '#title' => t('Available classifications') . ':',
860
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
861
    '#options' => cdm_get_taxontrees_as_options(),
862
    '#description' => t('Select the default taxa classification for your
863
      <em>taxon tree</em>, the other classifications will be also available but
864
      with a manual user change.'),
865
  );
866

    
867
  $form['taxon_tree']['taxontree_ranklimit'] = array(
868
    '#type' => 'select',
869
    '#title' => t('Rank of highest displayed taxon') . ':',
870
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
871
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
872
    '#options' => cdm_rankVocabulary_as_option(),
873
    '#description' => t('This is the rank of the highest displayed taxon in the
874
      <em>taxon tree</em>. You can select here which rank should be at the top
875
      level of the tree structure.'),
876
  );
877

    
878
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
879
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
880
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
881
      '#type' => 'checkboxes',
882
      '#title' => t('Included Classifications') . ':',
883
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
884
      '#options' => cdm_get_taxontrees_as_options(),
885
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
886
  );
887

    
888
  $form['distribution'] = array(
889
      '#type' => 'fieldset',
890
      '#title' => t('Distributions'),
891
      '#collapsible' => FALSE,
892
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
893
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
894
          '<p>
895
          </p>',
896
  );
897

    
898
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
899
      '#type' => 'fieldset',
900
      '#title' => 'Distribution filter',
901
      '#collapsible' => FALSE,
902
      '#collapsed' => FALSE,
903
      '#tree' => TRUE,
904
      '#description' => 'The Distribution filter offers the following options
905
      <ul>
906
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
907
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
908
      <li><strong>Marked area filter:</strong>Skip distributions where the area has a Marker with one of the specified MarkerTypes</li>
909
      </ul>'
910
  );
911

    
912
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
913
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
914
      '#type' => 'checkboxes',
915
      '#title' => 'Filter rules',
916
      '#default_value' => $cdm_distribution_filter['filter_rules'],
917
      '#options' => array(
918
          'statusOrderPreference' => 'Status order preference rule',
919
          'subAreaPreference' => 'Sub area preference rule'
920
      ),
921
  );
922

    
923
  $marker_type_options = cdm_terms_as_options( cdm_ws_fetch_all('term', array('class' => 'MarkerType' )) );
924
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hideMarkedAreas'] = array(
925
      '#type' => 'checkboxes',
926
      '#title' => 'Hide marked area filter',
927
      '#default_value' => $cdm_distribution_filter['hideMarkedAreas'],
928
      '#options' => $marker_type_options,
929
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
930
  );
931

    
932
  $form['aggregation'] = array(
933
      '#type' => 'fieldset',
934
      '#title' => t('Aggregation of data'),
935
      '#collapsible' => FALSE,
936
      '#description' => 'This section covers the different aspects of aggregating information.
937
          <p>
938
          </p>',
939
  );
940

    
941
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
942
      '#type' => 'checkboxes',
943
      '#title' => 'Taxon media filter',
944
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
945
      '#options' => array(
946
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
947
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
948
          'includeOccurrences' => 'Media related to specimens and occurrences',
949
      ),
950
      '#description' => 'This filter configures which images should be taken into account.',
951
  );
952

    
953
  $form['aggregation']['notice'] = array(
954
      '#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
955
          want to make use of the caching capabilities of the dataportal.',
956
  );
957

    
958
  $form['aggregation']['media_aggregation'] = array(
959
      '#type' => 'fieldset',
960
      '#title' => t('Media aggregation'),
961
      '#collapsible' => FALSE,
962
      '#collapsed' => TRUE,
963
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
964

    
965
  );
966
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
967
      '#type' => 'select',
968
      '#title' => t('Aggregation of taxon pictures') . ':',
969
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
970
      '#options' => array(
971
          0 => "Show only pictures of the current taxon",
972
          1 => "Include pictures of taxonomic children",
973
      ),
974
      '#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."),
975
  );
976

    
977
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
978
      '#type' => 'fieldset',
979
      '#attributes' => array('class'=>array('clearfix')),
980
      '#title' => t('Aggregation via taxon relationsships'),
981
      '#collapsible' => TRUE,
982
      '#collapsed' => TRUE,
983
      '#tree' => TRUE,
984
      '#description' => t('Information on taxa will be aggregated along the below chosen
985
          taxon relation ships. This will affect images and occurrences (specimens).
986
          Taxon relation ships are directed and point form one taxon to another. The taxon
987
          relationships to be taken into accunt can therefore configured for the direct direction
988
          and for the inverse.'),
989
  );
990

    
991
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
992
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
993

    
994
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
995
      '#type' => 'checkboxes',
996
      '#title' => t('Direct'),
997
      '#options' => $taxonRelationshipTypeOptions,
998
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
999
  );
1000
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1001
      '#type' => 'checkboxes',
1002
      '#title' => t('Invers'),
1003
      '#options' => $taxonRelationshipTypeOptions,
1004
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1005
  );
1006

    
1007
  // ----------------------
1008
  $form['cdm_js_devel_mode'] = array(
1009
      '#type' => 'checkbox',
1010
      '#title' => 'Java-script developer mode',
1011
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1012
      '#description' => 'In production envirionments the java script libraries
1013
      the cdm_dataportal is making use of are compressed and optimized. This
1014
      is good for performance but a caveat if you need to debug java-script. When the
1015
      java-script developer mode is enabled the uncompressed and commented developer
1016
      versions of java-script libraries will be used where possible.
1017
      <br/><strong>Do not use this option in production!</strong>'
1018
  );
1019
  // ----------------------
1020
  $form['cdm_debug_mode'] = array(
1021
      '#type' => 'checkbox',
1022
      '#title' => 'CDM page debug mode',
1023
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1024
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1025
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1026
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1027
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1028
      The log is written by the drupal devel module function <code>dd()</code>.
1029
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1030
  );
1031

    
1032
  // Comment @WA: D7 form api does not support reset buttons,
1033
  // so to mimic the D5 reset button we add one like this.
1034
  $form['actions']['reset'] = array(
1035
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1036
    '#weight' => 1000,
1037
  );
1038

    
1039
  $form['#submit'][] = 'cdm_settings_general_submit';
1040

    
1041
  return system_settings_form($form);
1042
}
1043

    
1044

    
1045
/**
1046
 * LAYOUT settings
1047
 * @return
1048
 *   todo
1049
 */
1050
function cdm_settings_layout() {
1051

    
1052
  $form = array();
1053

    
1054
  $form['about'] = array(
1055
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1056
      layout. If you want to configure the specific sites layout visit the
1057
      respective configuration site for taxon, search or media.') . '</p>',
1058
  );
1059

    
1060
  // ---- footnotes --- //
1061
  $form['footnotes'] = array(
1062
    '#type' => 'fieldset',
1063
    '#title' => t('Footnotes'),
1064
    '#collapsible' => FALSE,
1065
    '#collapsed' => FALSE,
1066
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1067
      media or distribution areas may have annotations or footnotes. When the
1068
      footnotes are enabled they will be visible (if they exist).'),
1069
  );
1070

    
1071
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1072
    '#type' => 'checkbox',
1073
    '#title' => t('Do not show footnotes'),
1074
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1075
    '#description' => t('Check this if you do not want to show any footnotes'),
1076
  );
1077

    
1078
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1079
    '#type' => 'checkbox',
1080
    '#title' => t('Do not show annotations footnotes'),
1081
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1082
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1083
  );
1084

    
1085
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType', SORT_ASC);
1086
  // Additional option for the NULL case.
1087
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1088
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1089
    '#type' => 'checkboxes',
1090
    '#title' => t('Annotation types as footnotes'),
1091
    '#description' => t("Only annotations of the selected type will be displayed
1092
       as footnotes. You may want to turn 'technical annotations' off."),
1093
    '#options' => $annotationTypeOptions,
1094
  );
1095
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1096
  if (!empty($annotationsTypesAsFootnotes)) {
1097
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1098
  }
1099

    
1100
  // ---- original source --- //
1101
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1102
      '#type' => 'fieldset',
1103
      '#tree' => TRUE,
1104
      '#title' => t('Source Citations'),
1105
      '#collapsible' => FALSE,
1106
      '#collapsed' => FALSE,
1107
  );
1108

    
1109
  $bibliography_settings = get_bibliography_settings(true);
1110

    
1111
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1112
      '#type' => 'checkbox',
1113
      '#title' => t('Original Source in bibliography'),
1114
      '#default_value' => $bibliography_settings['enabled'],
1115
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1116
       annotations in each feature block.'),
1117
  );
1118

    
1119
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1120
    '#type' => 'select',
1121
    '#title' => t('The format of the key numerals'),
1122
    '#default_value' => $bibliography_settings['key_format'],
1123
    '#options' => array('latin' => 'Latin',
1124
      'ROMAN' => 'Roman (upper case)',
1125
      'roman' => 'Roman (lower case)',
1126
      'ALPHA'=> 'Alphabet (upper case)',
1127
      'alpha' => 'Alphabet (lower case)')
1128
  );
1129

    
1130
  // --- Advanced Search --- //
1131
  $form['asearch'] = array(
1132
    '#type' => 'fieldset',
1133
    '#title' => t('Advanced search'),
1134
    '#collapsible' => FALSE,
1135
    '#collapsed' => FALSE,
1136
  );
1137

    
1138
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1139
    '#type' => 'checkbox',
1140
    '#title' => t('Show advanced search link'),
1141
    '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1142
    '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1143
  );
1144

    
1145
  // ---- Taxon Name Rendering --- //
1146
  $form['taxon_name'] = array(
1147
      '#type' => 'fieldset',
1148
      '#title' => t('Taxon name display'),
1149
      '#collapsible' => TRUE,
1150
      '#collapsed' => TRUE,
1151
      '#description' => t('The display of taxon names is configured by two parts.'
1152
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
1153
          . 'The name parts are defined in the <stong>part definitions</strong>'),
1154
  );
1155

    
1156
  drupal_add_js(
1157
      'jQuery(document).ready( function( ) {
1158
         // pretty print json
1159
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
1160
         var obj = JSON.parse(json_text);
1161
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
1162

    
1163
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
1164
         obj = JSON.parse(json_text);
1165
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
1166
       });'
1167
      ,array(
1168
          'type' => 'inline',
1169
          'scope' => 'footer'
1170
      )
1171
  );
1172

    
1173
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1174

    
1175
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1176
      '#type' => 'textarea',
1177
      '#title' => t('Part definitions'),
1178
      '#element_validate' => array('form_element_validate_json'),
1179
      '#default_value' =>  json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions)),
1180
      '#description' => '
1181
          <p>
1182
          (Clearing the text area will reset it to the default)
1183
          </p>
1184
          <p>
1185
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1186
          </p>
1187
          <p>
1188
           A full taxon name plus additional information can consist of the following elements:
1189
          <ul>
1190
             <li>name: the taxon name inclugin rank nbut without author</li>
1191
             <li>authors:  The authors of a reference, also used in taxon names</li>
1192
             <li>reference: the nomenclatural reference,</li>
1193
             <li>microreference:  Volume, page number etc.</li>
1194
             <li>status:  The nomenclatural status of a name</li>
1195
             <li>description: name descriptions like protologues etc ...</li>
1196
          </ul>
1197
          </p>
1198
          <p>
1199
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1200
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1201
           The following parts can be formed and are recognized by the system:
1202
          <ul>
1203
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1204
            <li>authorshipPart: the author (for example: "L.")</li>
1205
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1206
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1207
               be combined when a link to the taxon is rendered.</li>
1208
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1209
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1210
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1211
            <li>statusPart: the nomenclatorical status</li>
1212
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1213
          </ul>
1214
          </p>
1215
          <p>
1216
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1217
           specific parts part definitions:
1218
          <ul>
1219
            <li>BotanicalName</li>
1220
            <li>ZoologicalName</li>
1221
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1222
          </ul>
1223
           An example:
1224
          <pre>
1225
           {
1226
            "ZoologicalName": {
1227
              "namePart": {
1228
                "name": true
1229
              },
1230
              "referencePart": {
1231
                "authors": true
1232
              },
1233
              "microreferencePart": {
1234
                "microreference": true
1235
              },
1236
              "statusPart": {
1237
                "status": true
1238
              },
1239
              "descriptionPart": {
1240
                "description": true
1241
              }
1242
            },
1243
            "BotanicalName": {
1244
              "namePart": {
1245
                "name": true,
1246
                "authors": true
1247
              },
1248
              "referencePart": {
1249
                "reference": true,
1250
                "microreference": true
1251
              },
1252
              "statusPart": {
1253
                "status": true
1254
              },
1255
              "descriptionPart": {
1256
                "description": true
1257
              }
1258
            }
1259
          }
1260
           </pre>',
1261
  );
1262

    
1263
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1264

    
1265
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1266
      '#type' => 'textarea',
1267
      '#title' => t('Name render templates'),
1268
      '#element_validate' => array('form_element_validate_json'),
1269
      '#default_value' =>  json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates)),
1270
      '#description' => '
1271
          <p>
1272
          (Clearing the text area will reset it to the default)
1273
          </p>
1274
          <p>
1275
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1276
          render path. The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1277
          The following render Path keys are curretly recognized:
1278
          <ul>
1279
            <li>list_of_taxa</li>
1280
            <li>acceptedFor</li>
1281
            <li>homonym</li>
1282
            <li>taxon_page_synonymy</li>
1283
            <li>typedesignations</li>
1284
            <li>taxon_page_title</li>
1285
            <li>polytomousKey</li>
1286
            <li>na: name + authorship</li>
1287
            <li>nar:name + authorship + reference</li>
1288
            <li>#DEFAULT</li>
1289
          </ul>
1290
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1291
          array element should be a comma separated list of render paths, without any whitespace!.
1292
          </p>
1293
          <p>
1294
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1295
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1296
          <p>
1297
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1298
          The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
1299
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1300
          links if the paramters $nameLink or $refenceLink are given to the name render function
1301
          (this is hard coded and cannot be configured here).',
1302
  );
1303

    
1304
  // @WA: D7 form api does not support reset buttons,
1305
  // so to mimic the D5 reset button we add one like this.
1306
  $form['actions']['reset'] = array(
1307
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1308
    '#weight' => 1000,
1309
  );
1310

    
1311
  $form['#submit'] = array('submit_json_as_php_array');
1312
  // #json_elements especially defined for submit_json_as_php_array()
1313
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1314
  return system_settings_form($form);
1315
}
1316

    
1317

    
1318
/**
1319
 * @todo Please document this function.
1320
 * @see http://drupal.org/node/1354
1321
 */
1322
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1323
  $form[$form_name] = array(
1324
    '#type' => 'fieldset',
1325
    '#title' => t($form_title),
1326
    '#collapsible' => TRUE,
1327
    '#collapsed' => $collapsed,
1328
    '#tree' => TRUE,
1329
    '#description' => t($form_description),
1330
  );
1331

    
1332
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1333
  $gallery_settings = variable_get($form_name, $default_values);
1334
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1335
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1336
    /*
1337
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1338
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1339
    '#type' => 'textfield',
1340
    '#title' => t('Search Page Size'),
1341
    '#default_value' => $test,
1342
    '#description' => t('Number of Names to display per page in search results.')
1343
    );
1344
    */
1345
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1346
      '#type' => 'checkbox',
1347
      '#title' => t('Show media thumbnails for accepted taxa'),
1348
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1349
    );
1350

    
1351
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1352
      '#type' => 'checkbox',
1353
      '#title' => t('Show media thumbnails for synonyms'),
1354
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1355
      '#description' => '',
1356
    );
1357
  }
1358

    
1359
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1360
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1361
    '#type' => 'checkbox',
1362
    '#title' => t('Show captions under thumbnails'),
1363
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1364
    '#description' => '',
1365
  );
1366

    
1367
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1368
    '#type' => 'textfield',
1369
    '#title' => t('Thumbnail size') . ':',
1370
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1371
    '#description' => t('Select the size of each individual thumbnail.'),
1372
  );
1373

    
1374
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1375
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1376
      '#type' => 'textfield',
1377
      '#title' => t('Number of columns') . ':',
1378
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1379
      '#description' => t('Group the thumbnails in columns: select how many
1380
        columns the gallery should display.'),
1381
    );
1382
  }
1383

    
1384
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1385
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1386
      '#type' => 'textfield',
1387
      '#title' => t('Maximum number of rows') . ':',
1388
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1389
      '#description' => t('You can group the thumbnails in rows, select in how
1390
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1391
        If you want an unlimited number of rows please set to 0.'),
1392
    );
1393
  }
1394

    
1395
  return $form;
1396
}
1397

    
1398
/**
1399
 * @todo document this function.
1400
 */
1401
function cdm_settings_layout_taxon() {
1402
  $collapsed = FALSE;
1403
  $form = array();
1404

    
1405
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1406

    
1407
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1408
      '#type' => 'checkbox',
1409
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1410
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1411
      '#description' => t('<p>If checked the link to search results is rendered at
1412
       the top of the taxon site. Clicking on the link the last search performed
1413
       is rendered again.</p>'),
1414
  );
1415

    
1416
  // --------- TABBED TAXON ------- //
1417
  $form['taxon_tabs'] = array(
1418
    '#type' => 'fieldset',
1419
    '#title' => t('Taxon tabs'),
1420
    '#collapsible' => TRUE,
1421
    '#collapsed' => FALSE,
1422
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1423
      be splitted in four diferent tabs; General, Synonymy, Images and
1424
      Specimens. If the taxon has no information for any of the tabs/sections
1425
      such tab will be not displayed.'),
1426
  );
1427

    
1428
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1429
    '#type' => 'checkbox',
1430
    '#title' => t('Tabbed taxon page'),
1431
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1432
    '#description' => t('<p>If selected split the taxon page into individual
1433
      tabs for description, images, synonymy and specimens. If not the taxon
1434
      data is rendered as a long single page without tabs.</p>'),
1435
  );
1436

    
1437
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1438
    '#type' => 'checkboxes',
1439
    '#title' => t('Tabs visibility options') . ':',
1440
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1441
    '#options' => get_taxon_options_list(),
1442
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1443
  );
1444

    
1445
  // WEIGHT
1446
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1447
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1448
      '#tree' => true
1449
  );
1450
  // Weights range from -delta to +delta, so delta should be at least half
1451
  // of the amount of tabs present.
1452
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1453
  foreach (get_taxon_tabs_list() as $label) {
1454
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1455
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1456
        '#title' => $label,
1457
        '#type'  => 'weight',
1458
        '#default_value' => $taxontabs_weights[$key],
1459
        '#delta' => $tab_weight_delta
1460
    );
1461
  }
1462

    
1463
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1464
    '#type' => 'select',
1465
    '#title' => t('Default tab to display') . ':',
1466
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1467
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1468
    '#description' => t('<p>Select the default tab to display when visiting a
1469
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1470
      <strong>Note:</strong> After performing a search and clicking in any
1471
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1472
      taxon and not the above selected tab.'),
1473
  );
1474

    
1475
  /* ======  TAXON_PROFILE ====== */
1476
  $form['taxon_profile'] = array(
1477
    '#type' => 'fieldset',
1478
    '#title' => t('Taxon profile (tab)'),
1479
    '#description' => t('<p>This section covers the settings related to the taxon
1480
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1481
    '#collapsible' => TRUE,
1482
    '#collapsed' => TRUE,
1483
  );
1484

    
1485
  // ---- PROFILE PICTURE ----//
1486

    
1487
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1488
    '#type' => 'fieldset',
1489
    '#tree' => TRUE,
1490
    '#title' => t('Taxon profile picture'),
1491
    '#collapsible' => TRUE,
1492
    '#collapsed' => FALSE,
1493
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1494
  );
1495

    
1496
  //FIXME migrate variables:
1497
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1498
  // FIXME
1499
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1500

    
1501
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1502
  /*
1503
   * 'show' => 1,
1504
   * 'maxextend' => 184,
1505
   * 'media_uri_query' => ''
1506
   * 'custom_placeholder_image_on' => 1,
1507
   * 'custom_placeholder_image_fid' => ''
1508
   */
1509
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1510
    '#type' => 'checkbox',
1511
    '#title' => t('Enable profil picture'),
1512
    '#description' => t('Show the profil picture.'),
1513
    '#default_value' => $taxon_profile_image_settings['show'],
1514
  );
1515

    
1516
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1517
      '#type' => 'textfield',
1518
      '#tree' => TRUE,
1519
      '#title' => t('Profil picture maximum extend'),
1520
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1521
      '#field_suffix' => 'px',
1522
      '#maxlength' => 4,
1523
      '#size' => 4,
1524
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1525
  );
1526

    
1527
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1528
      '#type' => 'textfield',
1529
      '#tree' => TRUE,
1530
      '#title' => t('Additional URI query parameter'),
1531
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1532
      '#maxlength' => 1024,
1533
      '#size' => 60,
1534
      '#description' => t('Additional query parameters to be used when requesting for the '
1535
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1536
          . 'The query parameters will be appendend to the uri of the media representation part'
1537
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1538
  );
1539

    
1540
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1541
      '#type' => 'checkbox',
1542
      '#title' => t('Use a custom placeholder image'),
1543
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1544
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1545
  );
1546

    
1547
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1548
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1549
        '#type' => 'managed_file',
1550
        '#title' => t('Custom placeholder image file'),
1551
        '#progress_indicator' => 'bar',
1552
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1553
    //       '#name' => 'custom_placeholder_image',
1554
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1555
    );
1556

    
1557
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1558
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1559
      $url = file_create_url($profile_image_file->uri);
1560
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1561
                '#type' => 'item',
1562
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1563
      );
1564
    }
1565
  } else {
1566
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1567
        '#type' => 'hidden',
1568
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1569
    );
1570
  }
1571

    
1572

    
1573

    
1574
  $options = cdm_rankVocabulary_as_option();
1575
  array_unshift($options, '-- DISABLED --');
1576
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1577
    '#type' => 'select',
1578
    '#title' => t('Hide profile picture for higher ranks') . ':',
1579
    '#default_value' => variable_get('image_hide_rank', '0'),
1580
    '#options' => $options,
1581
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1582
  );
1583

    
1584
  // -- MEDIA THUMBNAILS -- //
1585
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1586
  $form_title = 'Taxon Profile Images';
1587
  $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>';
1588
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1589

    
1590
  // ---- FEATURE TREE ---- //
1591
  $form['taxon_profile']['feature_trees'] = array(
1592
    '#type' => 'fieldset',
1593
    '#title' => t('Features'),
1594
    '#collapsible' => TRUE,
1595
    '#collapsed' => FALSE,
1596
    '#description' => t("This section covers settings related to the taxon's
1597
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1598
      features such as description, distribution, common names, etc. that Drupal
1599
      will render at the taxon profile page."),
1600
  );
1601
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1602
  $saved_uuid = variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1603
  if(!isset($featureTrees['options'][$saved_uuid])) {
1604
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1605
  }
1606
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
1607
    '#type' => 'radios',
1608
    '#title' => t('Taxon profile sections') . ':',
1609
    '#default_value' => $saved_uuid,
1610
    '#options' =>  $featureTrees['options'],
1611
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1612
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1613
    '#description' => t('Select the Feature Tree to be displayed at the taxon
1614
      profile. Click "Show Details" to see the Feature Tree elements.'
1615
    ),
1616
  );
1617
  $featureTrees = cdm_get_featureTrees_as_options();
1618
  $saved_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1619
  if(!isset($featureTrees['options'][$saved_uuid])) {
1620
    $saved_uuid = NULL;
1621
  }
1622
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
1623
    '#type' => 'radios',
1624
    '#title' => t('Natural language representation of structured descriptions') . ':',
1625
    '#default_value' => $saved_uuid,
1626
    '#options' => $featureTrees['options'],
1627
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1628
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1629
    '#description' => t('Taxon descriptions can be stored in a highly structured
1630
      form. The feature tree selected here will be used to generate textual
1631
      representation in natural language.'
1632
    ),
1633
  );
1634

    
1635
  // ---- LAYOUT PER FEATURE ---- //
1636
  $feature_tree = get_profile_featureTree();
1637
  if (isset($feature_tree->root->childNodes)) {
1638

    
1639
    $form_feature_list_layout = array(
1640
      '#title' => t('Taxon profile layout'),
1641
      '#collapsible' => TRUE,
1642
      '#collapsed' => FALSE,
1643
      '#type' => 'fieldset',
1644
      '#description' => t('Will be available in a future release.'),
1645
    );
1646

    
1647
    $feature_list_layout_settings_disabled = TRUE;
1648
    foreach ($feature_tree->root->childNodes as $featureNode) {
1649

    
1650
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1651
        // Must not exceed 45 characters !!!
1652
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1653

    
1654
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1655
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1656

    
1657
        $form_feature_list_layout[$subform_id] = array(
1658
          '#tree' => TRUE,
1659
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1660
          '#collapsible' => FALSE,
1661
          '#collapsed' => FALSE,
1662
          '#type' => 'fieldset',
1663
          '#description' => t(''),
1664
        );
1665

    
1666
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1667
          '#type' => 'checkbox',
1668
          '#title' => t('Enable'),
1669
          '#default_value' => $settings['enabled'],
1670
          '#description' => t('Enable user defined layout for this feature'),
1671
        );
1672

    
1673
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1674
          '#type' => 'textfield',
1675
          '#title' => t('Enclosing tag'),
1676
          '#disabled' => !$settings['enabled'],
1677
          '#default_value' => $settings['enclosingTag'],
1678
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1679
        );
1680

    
1681
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1682
          '#type' => 'textfield',
1683
          '#title' => t('Entry enclosing tag'),
1684
          '#disabled' => !$settings['enabled'],
1685
          '#default_value' => $settings['entryEnclosingTag'],
1686
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1687
        );
1688

    
1689
        $form_feature_list_layout[$subform_id]['glue'] = array(
1690
          '#type' => 'textfield',
1691
          '#title' => t('Glue'),
1692
          '#disabled' => !$settings['enabled'],
1693
          '#default_value' => $settings['glue'],
1694
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1695
        );
1696

    
1697
      }
1698

    
1699
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1700
    }
1701
  }
1702

    
1703
  // ---- DISTRIBUTION LAYOUT ---- //
1704
  $form['taxon_profile']['distribution_layout'] = array(
1705
    '#title' => t('Distribution'),
1706
    '#collapsible' => TRUE,
1707
    '#collapsed' => FALSE,
1708
    '#type' => 'fieldset',
1709
    '#description' => t('Select if you want to sort or not the distribution text
1710
      located below the distribution map.'),
1711
  );
1712

    
1713
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1714
    '#type' => 'radios',
1715
    '#title' => t('Sort') . ':',
1716
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1717
    '#options' => array(
1718
      'NO_SORT' => t('Standard (No sort)'),
1719
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1720
    ),
1721
  );
1722

    
1723
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1724
    '#type' => 'checkbox',
1725
    '#title' => t('Show TextData elements on top of the map'),
1726
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1727
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1728
      elements on top of the map. Otherwise all <code>TextData</code>
1729
      distribution elements will be listed below the other area elements.
1730
      This option is useful if you need to have descriptive texts for each
1731
      distribution map.'),
1732
  );
1733

    
1734
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
1735
      '#type' => 'textarea',
1736
      '#title' => t('Custom status colors'),
1737
      '#element_validate' => array('form_element_validate_json'),
1738
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
1739
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
1740
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
1741
          reference list of the idInVocabulary values of absence and presence terms:
1742
<pre>
1743
Presence Term
1744
p	present
1745
pd	present: doubtfully present
1746
n	native
1747
nq	native: presence questionable
1748
nd	native: doubtfully native
1749
c	cultivated
1750
i	introduced
1751
iq	introduced: presence questionable
1752
id	introduced: doubtfully introduced (perhaps cultivated only)
1753
ip	introduced: uncertain degree of naturalisation
1754
ia	introduced: adventitious (casual)
1755
in	introduced: naturalized
1756
ic	introduced: cultivated
1757
e	endemic for the relevant area
1758
na	naturalised
1759
iv	invasive
1760

    
1761
AbsenceTerm
1762
a	absent
1763
f	reported in error
1764
nf	native: reported in error
1765
if	introduced: reported in error
1766
cf	cultivated: reported in error
1767
ne	native: formerly native
1768
ie	introduced: formerly introduced
1769

    
1770
</pre>'),
1771
  );
1772

    
1773

    
1774
  /* ====== SYNONYMY ====== */
1775
  $form['taxon_synonymy'] = array(
1776
    '#type' => 'fieldset',
1777
    '#title' => t('Taxon synonymy (tab)'),
1778
    '#collapsible' => TRUE,
1779
    '#collapsed' => TRUE,
1780
    '#description' => t('This section covers the settings related to the taxon
1781
      <strong>synonymy</strong> tab.'),
1782
  );
1783

    
1784
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1785
    '#type' => 'checkbox',
1786
    '#title' => t('Show accepted taxon on top of the synonymy'),
1787
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1788
    '#description' => t('If checked, the first homotypic taxon is a repetition
1789
      of the accepted taxon most likely with the full nomenclatural reference
1790
      (depending on the currently chosen theme).'),
1791
  );
1792

    
1793
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1794
    '#type' => 'checkbox',
1795
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1796
      coming from a synonym link.'),
1797
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1798
    '#description' => t('Check this if after doing a search and clicking on a
1799
      synonym you want to see the "accept of" text for the accepted synonym.'),
1800
  );
1801

    
1802
  /* === currently unused ===
1803
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1804
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1805
    '#type' => 'checkboxes',
1806
    '#title' => t('Display name relationships') . ':',
1807
    '#default_value' => variable_get('name_relationships_to_show', 0),
1808
    '#options' => $nameRelationshipTypeOptions,
1809
    '#description' => t('Select the name relationships you want to show for the
1810
      accepted taxa.'),
1811
  );
1812
 */
1813

    
1814
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1815
    '#type' => 'checkbox',
1816
    '#title' => t('Show taxon relations ships of accepted taxon'),
1817
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1818
    '#description' => t('If this option is enabled the synonymy will show the
1819
      below selected taxon relationships of accepted taxa.'),
1820
  );
1821

    
1822
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1823
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1824
    '#type' => 'checkboxes',
1825
    '#title' => t('Taxon relationship types') . ':',
1826
    '#description' => t('Only taxon relationships of the selected type will be
1827
      displayed'),
1828
    '#options' => $taxonRelationshipTypeOptions,
1829
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1830
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1831
  );
1832

    
1833
  // ====== SPECIMENS ====== //
1834
  $form['taxon_specimens'] = array(
1835
    '#type' => 'fieldset',
1836
    '#title' => t('Taxon specimens (tab)'),
1837
    '#collapsible' => TRUE,
1838
    '#collapsed' => TRUE,
1839
    '#description' => t('This section covers the settings related to the taxon
1840
      <strong>specimens</strong> tab.'),
1841
  );
1842

    
1843
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1844
  $saved_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1845
  if(!isset($featureTrees['options'][$saved_uuid])) {
1846
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1847
  }
1848
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1849
      '#type' => 'radios',
1850
      '#title' => t('Specimen description feature tree') . ':',
1851
      '#default_value' => $saved_uuid,
1852
      '#options' =>  $featureTrees['options'],
1853
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1854
      '#options_suffixes' => $featureTrees['treeRepresentations'],
1855
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1856
      ),
1857
  );
1858

    
1859
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1860
  $form_title = t('Specimen media');
1861
  $form_description = t('Specimens may have media which is displayed at the
1862
     Specimen tab/section as a gallery. It is possible to configure the
1863
     thumbnails gallery here, however for configuring how a single media should
1864
     be displayed please go to !url.</p>',
1865
     array(
1866
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1867
     ));
1868
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1869

    
1870
  // --- MEDIA GALLERY ---- //
1871
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1872
  $form_title = 'Media gallery (tab)';
1873
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1874
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1875
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1876
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1877
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1878
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1879
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1880

    
1881
  // Comment @WA: D7 form api does not support reset buttons,
1882
  // so to mimic the D5 reset button we add one like this.
1883
  $form['actions']['reset'] = array(
1884
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1885
    '#weight' => 1000,
1886
  );
1887
  return system_settings_form($form);
1888
}
1889

    
1890
/**
1891
 * @todo document this function.
1892
 */
1893
function cdm_settings_layout_search() {
1894

    
1895
  $form = array();
1896

    
1897
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
1898

    
1899
  $form['search_settings'] = array(
1900
    '#type' => 'fieldset',
1901
    '#title' => t('Taxa Search'),
1902
    '#collapsible' => FALSE,
1903
    '#collapsed' => FALSE,
1904
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1905
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1906
         where they can write the text to be searched. You can find Drupal block configuration
1907
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1908
  );
1909

    
1910
  $form['search_settings']['simple_search_ignore_classification'] = array(
1911
      '#type' => 'checkbox',
1912
      '#title' => t('Ignore the chosen classification in simple search'),
1913
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
1914
      '#description' => t('The simple search, which can be executed via the search block,
1915
          will by default search on all classifications. Remove the tick if you want your
1916
          portal to search on the classification selected in the classification browser
1917
          selector.'),
1918
  );
1919

    
1920
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1921
    '#type' => 'textfield',
1922
    '#title' => t('Results per page') . ':',
1923
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1924
    '#description' => t('Number of results to display per page.'),
1925
  );
1926

    
1927
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
1928
  $form['search_settings']['cdm_search_taxa_mode'] = array(
1929
      '#type' => 'checkboxes',
1930
      '#title' => 'Search mode',
1931
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
1932
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
1933
          for the advance search form and the behaviour of the simple search form which always will behave according to the
1934
          defaults set here.',
1935
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
1936
      '#default_value' => $search_mode_default
1937
      );
1938

    
1939
  // --- SEARCH TAXA GALLERY ---- //
1940
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1941
  $collapsed = FALSE;
1942
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1943
  $form_title = 'Taxa Search thumbnails';
1944
  $form_description = 'Search results may show thumbnails. ';
1945
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1946

    
1947
  // Comment @WA: D7 form api does not support reset buttons,
1948
  // so to mimic the D5 reset button we add one like this.
1949
  $form['actions']['reset'] = array(
1950
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1951
    '#weight' => 1000,
1952
  );
1953
  return system_settings_form($form);
1954
}
1955

    
1956
/**
1957
 * @todo document this function.
1958
 */
1959
function cdm_settings_layout_media() {
1960

    
1961
  $form = array();
1962

    
1963
  $form['media_settings'] = array(
1964
    '#type' => 'fieldset',
1965
    '#title' => t('Media settings'),
1966
    '#collapsible' => FALSE,
1967
    '#collapsed' => FALSE,
1968
    '#description' => 'This section covers layout settings for media pages.'
1969
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
1970
  );
1971

    
1972
  $form['media_settings']['image_gallery_viewer'] = array(
1973
    '#type' => 'select',
1974
    '#title' => t('Image viewer') . ':',
1975
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1976
    '#options' => array(
1977
      'default' => t('Standard image viewer'),
1978
      'fsi' => t('FSI viewer (requires FSI server!)'),
1979
    ),
1980
  );
1981

    
1982
  // --- MEDIA GALLERY ---- //
1983
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1984
  $form_title = 'Standard viewer';
1985
  $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>';
1986
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1987
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1988

    
1989
  // @WA: D7 form api does not support reset buttons,
1990
  // so to mimic the D5 reset button we add one like this.
1991
  $form['actions']['reset'] = array(
1992
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1993
    '#weight' => 1000,
1994
  );
1995
  return system_settings_form($form);
1996
}
1997

    
1998
/**
1999
 * GEOSERVICE and Map settings.
2000
 */
2001
function cdm_settings_geo($form, &$form_state) {
2002

    
2003
  $current_geoserver_settings = get_edit_map_service_settings();
2004
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2005
  // The default layer must always be enabled
2006
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2007
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2008

    
2009
  $form = array();
2010

    
2011
  $dummy_distribution_query = NULL;
2012
  if($map_distribution['map_type'] != 1){
2013
    // we need to apply a dummy query since the map serice requires for image maps
2014
    // at least as and ad to be defined
2015
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2016
  }
2017
  $form['map_preview'] = array(
2018
      '#type' => 'fieldset',
2019
      '#tree' => FALSE,
2020
      '#title' => t('Map preview'),
2021
      '#collapsible' => FALSE,
2022
      '#description' => 'The preview of the map'
2023
       . ($dummy_distribution_query != null ?
2024
           ' may not be accurate in case if image maps, please check the map display in the taxon pages.':
2025
           '.<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.')
2026
  );
2027
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL,
2028
      array(
2029
          'move' => "this.cdmOpenlayersMap.printInfo",
2030
          '#execute' => "this.cdmOpenlayersMap.printInfo"
2031
      )
2032
  );
2033

    
2034

    
2035
  /*
2036
   * GEO SERVER
2037
   */
2038
  $form['edit_map_server'] = array(
2039
    '#type' => 'fieldset',
2040
    '#tree' => true,
2041
    '#title' => t('EDIT map service'),
2042
    '#collapsible' => TRUE,
2043
    '#collapsed' => TRUE,
2044
    '#description' => t('Configuration and selection of your geo server.
2045
      The Geo Server is responsible for generating the maps.'),
2046
  );
2047

    
2048
  $form['edit_map_server']['base_uri'] = array(
2049
    '#type' => 'select',
2050
    '#title' => t('EDIT map service') . ':',
2051
    '#default_value' => $current_geoserver_settings['base_uri'],
2052
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2053
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2054
  );
2055
  $form['edit_map_server']['version'] = array(
2056
      '#type' => 'select',
2057
      '#title' => t('Version') . ':',
2058
      '#default_value' => $current_geoserver_settings['version'],
2059
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2060
      '#description' => t('The version of the EDIT map services'),
2061
  );
2062

    
2063
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
2064
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
2065
  $form['gmap_api_key'] = array(
2066
      '#type' => 'textfield',
2067
      '#title' => t('Google maps API key') . ':',
2068
      '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
2069
      '#description' => t('If you want to use the Google Maps Layer, a key is
2070
      needed. If you need a key, visit
2071
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
2072
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
2073
      is the default key for the localhost (127.0.0.1).',
2074
      array('!localhostkey' => $localhostkey)),
2075
  );
2076

    
2077

    
2078
  /*
2079
   * MAP SETTINGS
2080
   */
2081

    
2082
  $form[CDM_MAP_DISTRIBUTION] = array(
2083
    '#type' => 'fieldset',
2084
    '#tree' => TRUE,
2085
    '#title' => t('Maps settings'),
2086
    '#collapsible' => TRUE,
2087
    '#collapsed' => TRUE,
2088
    '#description' => t('General configuration for all map types.'),
2089
  );
2090

    
2091
  /*
2092
   * settings for the distribution map are used also for specimens map!!!!
2093
   */
2094

    
2095
  $form[CDM_MAP_DISTRIBUTION]['width'] = array(
2096
    '#type' => 'textfield',
2097
    '#title' => 'Width',
2098
    '#default_value' => $map_distribution['width'],
2099
    '#maxlength' => 4,
2100
    '#size' => 4,
2101
    '#description' => 'Width of the map. To allow OSM baselayers to zoom out to the full extend of the world the map width must be
2102
      a multiple of 256px since the osm tiles from tile.openstreetmap.org have a size of 256px x 256px and frational zoom
2103
      levels are not possible in this case.',
2104
  );
2105
  $form[CDM_MAP_DISTRIBUTION]['height'] = array(
2106
      '#type' => 'textfield',
2107
      '#title' => 'Height',
2108
      '#default_value' => $map_distribution['height'],
2109
      '#maxlength' => 4,
2110
      '#size' => 4,
2111
      '#description' => 'Height of the map. Depending on the chosen base layer you may want to choose the height equal
2112
      to the width or half of the width. Any other aspect ratio is also possible if desired.',
2113
  );
2114

    
2115
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2116
    '#type' => 'textfield',
2117
    '#title' => 'Bounding box',
2118
    '#default_value' => $map_distribution['bbox'],
2119
    '#description' => t('The bounding box (left, bottom, right, top) defines the area to be initially displayed in maps.
2120
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2121
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2122
      <strong>TIP: </strong>You can use the map preview above to choose a bbox from the map. Maybe you need to change the map type to OpeLayers.
2123
      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
2124
      below the map from where you can copy the bbox string.</p>'),
2125
  );
2126

    
2127
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2128
    '#type' => 'checkbox',
2129
    '#title' => 'Display area labels',
2130
    '#default_value' => $map_distribution['show_labels'],
2131
    '#description' => t('The map will show name labels of the areas'),
2132
  );
2133

    
2134
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2135
    '#type' => 'textfield',
2136
    '#title' => 'Map caption',
2137
    '#default_value' => $map_distribution['caption'],
2138
    '#description' => t('The caption will be shown below the map.'),
2139
  );
2140

    
2141
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2142
    '#type' => 'textfield',
2143
    '#title' => 'Distribution layer opacity',
2144
    '#default_value' => $map_distribution['distribution_opacity'],
2145
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
2146
                           fully visible, while a value near to 0.0 will be not much visible.'),
2147
  );
2148

    
2149
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2150
    '#type' => 'radios',
2151
    '#title' => 'Map types',
2152
    '#options' => array(
2153
      1 => "OpenLayers dynamic map viewer",
2154
      0 => "Plain image",
2155
    ),
2156
    '#default_value' => $map_distribution['map_type'],
2157
    '#description' => 'Two different map types are available :
2158
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2159
      which allows zooming and panning. If enabled you can configure the default layer
2160
      (background of your maps) below.</li>
2161
      <li><em>Plain image</em>: The map will be static non interactive
2162
      image.</li></ul>',
2163
  );
2164
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2165

    
2166

    
2167
  // --- Plain Image Settings --- //
2168
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2169
    '#type' => 'fieldset',
2170
    '#title' => 'Plain image map settings',
2171
    '#tree' => TRUE,
2172
    '#collapsible' => TRUE,
2173
    '#collapsed' => $open_layers_is_enabled,
2174
    '#description' => 'The settings in this section are still expertimental
2175
      and can only be used with the EDIT map service version 1.1 or above.',
2176
  );
2177
  $edit_mapserver_version = get_edit_map_service_version_number();
2178
  if ($edit_mapserver_version < 1.1) {
2179
    $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>'
2180
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2181
  }
2182

    
2183
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2184
    '#type' => 'textfield',
2185
    '#title' => 'Background layer',
2186
    '#default_value' => $map_distribution['image_map']['base_layer'],
2187
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2188
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2189
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2190
    )),
2191
  );
2192

    
2193
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2194
    '#type' => 'textfield',
2195
    '#title' => 'Background color',
2196
    '#default_value' => $map_distribution['image_map']['bg_color'],
2197
  );
2198

    
2199
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2200
    '#type' => 'textfield',
2201
    '#title' => 'Background layer style',
2202
     // Only line color by now.
2203
    '#default_value' => $map_distribution['image_map']['layer_style'],
2204
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2205
  );
2206

    
2207
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2208
      '#type' => 'textfield',
2209
      '#title' => 'Projection',
2210
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2211
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2212
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2213
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2214
  );
2215

    
2216

    
2217
  // --- OpenLayers Settings --- //
2218
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2219
    '#type' => 'fieldset',
2220
    '#title' => 'OpenLayers settings',
2221
    '#tree' => TRUE,
2222
    '#collapsible' => TRUE,
2223
    '#collapsed' => !$open_layers_is_enabled,
2224
    '#description' => '',
2225
  );
2226

    
2227

    
2228
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2229
      '#type' => 'checkbox',
2230
      '#title' => 'Display outside max extent',
2231
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2232
      '#description' => t('Allows the map to display parts of the layers which are outside
2233
         the max extent if the aspect ratio of the map and of the baselayer
2234
         are not equal.'),
2235
  );
2236

    
2237

    
2238
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2239
      '#type' => 'checkbox',
2240
      '#title' => 'Show Layer Switcher',
2241
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2242
      '#description' => 'The Layer Switcher control displays a table of contents
2243
      for the map.  This allows the user interface to switch between
2244
      base layers and to show or hide overlays.  By default the switcher is
2245
      shown minimized on the right edge of the map, the user may expand it
2246
      by clicking on the handle.',
2247
  );
2248

    
2249
  if (!$open_layers_is_enabled) {
2250
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2251
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2252
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2253
  }
2254

    
2255
  $baselayer_options = array(
2256
    /*
2257
   NOTICE: must correspond to the layers defined in
2258
   js/openlayers_,ap.js#getLayersByName()
2259
   */
2260
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
2261
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
2262
    // all others EPSG:900913
2263
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
2264
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2265
    'mapnik' => 'OpenStreetMap',
2266
    'mapquest_open' => "MapQuest",
2267
    'mapquest_sat' => "MapQuest Sattelite",
2268
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2269
    'gmap' => 'Google Streets',
2270
    'gsat' => 'Google Satellite',
2271
    'ghyb' => 'Google Hybrid',
2272
//     'veroad' => 'Virtual Earth Roads',
2273
//     'veaer' => 'Virtual Earth Aerial',
2274
//     'vehyb' => 'Virtual Earth Hybrid',
2275
    // 'yahoo' => 'Yahoo Street',
2276
    // 'yahoosat' => 'Yahoo Satellite',
2277
    // 'yahoohyb' => 'Yahoo Hybrid',
2278
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2279
  );
2280

    
2281
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2282
    '#type' => 'checkboxes_preferred',
2283
    '#title' => 'Base Layers',
2284
    '#options' => $baselayer_options,
2285
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2286
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2287
  );
2288

    
2289
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2290
      '#type' => 'fieldset',
2291
      '#title' => 'Custom WMS base layer',
2292
      '#tree' => TRUE,
2293
      '#collapsible' => FALSE,
2294
      '#collapsed' => FALSE,
2295
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2296
  );
2297

    
2298
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2299
      '#type' => 'textfield',
2300
      '#title' => 'Layer name',
2301
      // Only line color by now.
2302
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2303
      '#description' => 'A arbitrary name for the layer.',
2304
  );
2305
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2306
      '#type' => 'textfield',
2307
      '#title' => 'WMS url',
2308
      // Only line color by now.
2309
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2310
      '#description' => 'Base url for the WMS (e.g.  http://wms.jpl.nasa.gov/wms.cgi)'
2311
  );
2312
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2313
      '#type' => 'textarea',
2314
      '#title' => 'WMS parameters',
2315
      '#element_validate' => array('form_element_validate_json'),
2316
      // Only line color by now.
2317
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2318
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2319
<pre> {
2320
  "Layers": "topp:em_tiny_jan2003",
2321
  "Format": "image/png",
2322
  "BGCOLOR": "0xe0faff"
2323
}
2324
</pre>'
2325
  );
2326
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2327
      '#type' => 'textfield',
2328
      '#title' => 'Projection',
2329
      // Only line color by now.
2330
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2331
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2332
  );
2333
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2334
      '#type' => 'textfield',
2335
      '#maxlength' => 256,
2336
      '#title' => 'proj4js definition',
2337
      // Only line color by now.
2338
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2339
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2340
            The definitions for
2341
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2342
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2343
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2344
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2345
            choose to display the proj4js definition string.
2346
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2347
            <pre>
2348
+a         Semimajor radius of the ellipsoid axis
2349
+alpha     ? Used with Oblique Mercator and possibly a few others
2350
+axis      Axis orientation (new in 4.8.0)
2351
+b         Semiminor radius of the ellipsoid axis
2352
+datum     Datum name (see `proj -ld`)
2353
+ellps     Ellipsoid name (see `proj -le`)
2354
+k         Scaling factor (old name)
2355
+k_0       Scaling factor (new name)
2356
+lat_0     Latitude of origin
2357
+lat_1     Latitude of first standard parallel
2358
+lat_2     Latitude of second standard parallel
2359
+lat_ts    Latitude of true scale
2360
+lon_0     Central meridian
2361
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
2362
+lon_wrap  Center longitude to use for wrapping (see below)
2363
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
2364
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
2365
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
2366
+pm        Alternate prime meridian (typically a city name, see below)
2367
+proj      Projection name (see `proj -l`)
2368
+south     Denotes southern hemisphere UTM zone
2369
+to_meter  Multiplier to convert map units to 1.0m
2370
+towgs84   3 or 7 term datum transform parameters (see below)
2371
+units     meters, US survey feet, etc.
2372
+vto_meter vertical conversion to meters.
2373
+vunits    vertical units.
2374
+x_0       False easting
2375
+y_0       False northing
2376
+zone      UTM zone
2377
            </pre>
2378
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
2379
  );
2380
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
2381
      '#type' => 'textfield',
2382
      '#title' => 'Maximum extent',
2383
      // Only line color by now.
2384
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
2385
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
2386
  );
2387
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
2388
      '#type' => 'textfield',
2389
      '#title' => 'Units',
2390
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
2391
      '#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.'
2392
  );
2393

    
2394
  /*
2395
   * Map Legend
2396
   */
2397
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2398
    '#type' => 'fieldset',
2399
    '#title' => 'Map legend',
2400
    '#tree' => TRUE,
2401
    '#collapsible' => TRUE,
2402
    '#collapsed' => TRUE,
2403
    '#description' => 'Configure the maps legend.',
2404
  );
2405

    
2406
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2407
    '#type' => 'checkbox',
2408
    '#title' => 'Display a map legend',
2409
    '#default_value' => $map_distribution['legend']['show'],
2410
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2411
  );
2412

    
2413
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2414
    '#type' => 'textfield',
2415
    '#title' => 'Legend opacity',
2416
    '#default_value' => $map_distribution['legend']['opacity'],
2417
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2418
                         to 0.0 will be not much visible.',
2419
  );
2420

    
2421
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2422
    '#type' => 'textfield',
2423
    '#title' => 'Font size',
2424
    '#default_value' => $map_distribution['legend']['font_size'],
2425
    '#description' => 'Font size in pixels.',
2426
  );
2427

    
2428
  $fontStyles = array(
2429
    0 => "plane",
2430
    1 => "italic",
2431
  );
2432
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2433
    '#type' => 'select',
2434
    '#title' => 'Available font styles',
2435
    '#default_value' => $map_distribution['legend']['font_style'],
2436
    '#options' => $fontStyles,
2437
    '#description' => 'Select a font style for the map legend.',
2438
  );
2439

    
2440
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2441
    '#type' => 'textfield',
2442
    '#title' => 'Icon width',
2443
    '#default_value' => $map_distribution['legend']['icon_width'],
2444
    '#description' => 'Legend icon width in pixels.',
2445
  );
2446
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2447
    '#type' => 'textfield',
2448
    '#title' => 'Icon height',
2449
    '#default_value' => $map_distribution['legend']['icon_height'],
2450
    '#description' => 'Legend icon height in pixels.',
2451
  );
2452

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

    
2460
  return system_settings_form($form);
2461
}
2462

    
2463
/**
2464
 * @todo document this function.
2465
 */
2466
function cdm_settings_cache() {
2467

    
2468
  $form = array();
2469

    
2470
  $form['cache_settings'] = array(
2471
    '#type' => 'fieldset',
2472
    '#title' => t('Cache Settings'),
2473
    '#collapsible' => FALSE,
2474
    '#collapsed' => FALSE,
2475
    '#description' => t('<p>When caching is enabled all single taxon sites are
2476
      stored in an internal drupal cache doing the portal response of taxa pages
2477
      faster. This is possible because the sites are loaded from the cache and
2478
      are not created from scratch.</p>'),
2479
  );
2480

    
2481
  $form['cache_settings']['cdm_webservice_cache'] = array(
2482
    '#type' => 'checkbox',
2483
    '#title' => t('<strong>Enable caching</strong>'),
2484
    '#options' => cdm_help_general_cache(),
2485
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2486
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2487
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2488
       application the changes will be not visible till the cache is erased.
2489
       Therefore developers should deactived this feature when they are working
2490
       on the CDM Dataportal Module.</p>'),
2491
  );
2492

    
2493
  $form['cache_settings']['cdm_run_cache'] = array(
2494
    '#markup' => cdm_view_cache_site(),
2495
  );
2496

    
2497
  // @WA: D7 form api does not support reset buttons,
2498
  // so to mimic the D5 reset button we add one like this.
2499
  $form['actions']['reset'] = array(
2500
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2501
    '#weight' => 1000,
2502
  );
2503
  return system_settings_form($form);
2504
}
2505

    
2506
/**
2507
 * Walk and cache all taxon pages.
2508
 */
2509
function cdm_view_cache_site() {
2510

    
2511
  $out = '';
2512

    
2513
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2514

    
2515
  $request_params = array();
2516
  $request_params['class'] = "Taxon";
2517

    
2518
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2519
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2520
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2521

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

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

    
2531
  // Comment @WA: A form within a form is not valid html and not needed here.
2532
  // Also, it would be recommended just to include this part of the form in the
2533
  // rest of the form array in cdm_settings_cache().
2534
  // $out .= '<form id="cache_site">';
2535
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2536
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2537
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2538
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2539
  // $out .= '</form>';
2540
  $out .= '</div>';
2541
  /*
2542
  foreach($taxonPager->records as $taxon){
2543
    cdm_dataportal_taxon_view($uuid);
2544
  }
2545
  */
2546
  return $out;
2547
}
2548

    
2549

    
2550
function cdm_settings_layout_taxon_submit($form, &$form_state){
2551
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2552
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2553
    if(is_object($file)){
2554
      $file->status = FILE_STATUS_PERMANENT;
2555
      file_save($file);
2556
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2557
    }
2558
  }
2559
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2560
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2561
    // we first need to set the variable to persist the changes setting
2562
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
2563
    menu_rebuild();
2564
  }
2565
}
2566

    
2567
function cdm_settings_layout_search_submit($form, &$form_state){
2568
  // the visibility of media thumbnails also affects the ui of the search results
2569
  // so reset the according session variable
2570
  //    1. in order to give the user immediate
2571
  //       feedback on potential setting changes
2572
  //    2. let refresh the default if it has changed
2573
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2574
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
2575
  }
2576
}
2577

    
2578
/**
2579
 * Form validation handler for cdm_settings_general
2580
 *
2581
 * @param $form
2582
 * @param $form_state
2583
 */
2584
function cdm_settings_general_validate($form, &$form_state) {
2585

    
2586
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2587
    $form_state['values']['cdm_webservice_url'] .= '/';
2588
  }
2589

    
2590
}
2591

    
2592
/**
2593
 * Form submit handler for settings general.
2594
 *
2595
 * tasks performed:
2596
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2597
 *
2598
 * @param $form
2599
 * @param $form_state
2600
 */
2601
function cdm_settings_general_submit($form, &$form_state){
2602
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2603
  unset($_SESSION['cdm']['taxonomictree_uuid']);
2604
}
2605

    
2606
/**
2607
 * Form validation handler for cdm_settings_cache
2608
 */
2609
function cdm_settings_cache_validate($form, &$form_state) {
2610
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2611
    cache_clear_all(NULL, 'cache_cdm_ws');
2612
    // Better clear secref_cache since I can not be sure if the cache has not
2613
    // be used during this response.
2614
    cdm_api_secref_cache_clear();
2615
  }
2616

    
2617
}
2618

    
2619
/**
2620
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
2621
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
2622
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
2623
 *  - version: the version, e.g.: v1.1
2624
 *
2625
 * @return array
2626
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
2627
 */
2628
function get_edit_map_service_settings() {
2629

    
2630
  $settings = variable_get('edit_map_server', array(
2631
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
2632
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
2633
      )
2634
  );
2635

    
2636
  return $settings;
2637
}
2638

    
2639
/**
2640
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2641
 *
2642
 * @return string
2643
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2644
 */
2645
function get_edit_map_service_full_uri() {
2646
  $settings = get_edit_map_service_settings();
2647
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
2648
}
2649

    
2650

    
2651
/**
2652
 * Returns the version number of the currently selected edit mapserver as a float
2653
 *
2654
 * @return float
2655
 *   The version number of the currently selected edit mapserver as a float.
2656
 *   Returns 0 on error.
2657
 */
2658
function get_edit_map_service_version_number() {
2659

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

    
2662
  $settings = get_edit_map_service_settings();
2663
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
2664
  if (isset($matches[1])) {
2665
    // Convert string to float.
2666
    $version = 1 + $matches[1][0] - 1;
2667
    return $version;
2668
  }
2669
  else {
2670
    // Report error.
2671
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
2672
        array(
2673
          '!version' => $settings['version'],
2674
          'warning')
2675
        )
2676
      );
2677
    return 0;
2678
  }
2679
}
2680

    
2681
/**
2682
 * Returns the array of selected items in a options array
2683
 *
2684
 * @param array $options
2685
 *   An options array as generated by a form element like checkoxes, select ...,
2686
 */
2687
function get_selection($options) {
2688
  $selection = array();
2689
  foreach ($options as $key=>$val) {
2690
    if (!empty($val)) {
2691
      $selection[] = $val;
2692
    }
2693
  }
2694
  return $selection;
2695
}
2696

    
2697

    
2698
/**
2699
 * Implements hook_element_info().
2700
 *
2701
 * Allows modules to declare their own Form API element types and specify their default values.
2702
 *
2703
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
2704
 */
2705
function cdm_dataportal_element_info() {
2706
  $type['checkboxes_preferred'] = array(
2707
    '#input' => TRUE,
2708
    '#process' => array('checkboxes_preferred_expand'),
2709
    '#after_build' => array('checkboxes_preferred_after_build'),
2710
    '#theme' => array('checkboxes_preferred'),
2711
    // '#theme_wrapper' => array('form_element'),
2712
  );
2713
  return $type;
2714
}
2715

    
2716
/**
2717
 * #process callback function for the custom form element type 'checkbox_preferred'
2718
 *
2719
 *
2720
 */
2721
function checkboxes_preferred_expand($element, &$form_state, $form) {
2722

    
2723
  // First of all create checkboxes for each of the elements
2724
  $element = form_process_checkboxes($element);
2725

    
2726
  // compose the element name
2727
  $parents = array();
2728
  array_deep_copy($element['#parents'], $parents);
2729
  $parents[count($parents) -1 ] .= '_preferred';
2730
  $element_name = $parents[0];
2731
  for ($i=1; $i < count($parents); $i++){
2732
    $element_name .= '[' . $parents[$i] . ']';
2733
  }
2734

    
2735
  $children = element_children($element);
2736

    
2737
  $element['table_start'] = array(
2738
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
2739
    '#weight' => -1,
2740
  );
2741

    
2742
  // prepare first part each of the table rows which contains the row label
2743
  $weight = 0;
2744
  foreach ($children as $key) {
2745
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
2746
    $element[$key]['#weight'] = $weight;
2747
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
2748
    $element[$key]['#suffix'] = '</td>';
2749
    unset($element[$key]['#title']);
2750
    $weight += 2;
2751
  }
2752
  $weight = 0;
2753

    
2754
  // add a radio button to each of the checkboxes, the
2755
  // check boxes have already been created at the beginning
2756
  // of this function
2757
  if (count($element['#options']) > 0) {
2758
    foreach ($element['#options'] as $key => $choice) {
2759
      if (!isset($element[$key . '_preferred'])) {
2760
        $element[$key . '_preferred'] = array(
2761
          '#type' => 'radio',
2762
          '#name' => $element_name,
2763
          '#return_value' => check_plain($key),
2764
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
2765
          '#attributes' => $element['#attributes'],
2766
          '#parents' => $element['#parents'],
2767
          // '#spawned' => TRUE,
2768
          '#weight' => $weight + 1,
2769
          '#prefix' => '<td>',        // add a prefix to start a new table cell
2770
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
2771
        );
2772
      }
2773
      $weight += 2;
2774
    }
2775
  }
2776

    
2777
  // end the table
2778
  $element['table_end'] = array(
2779
    '#markup' => '</table>',
2780
    '#weight' => $weight++,
2781
  );
2782

    
2783
  return $element;
2784
}
2785

    
2786
/**
2787
 * Theme function for the custom form field 'checkboxes_preferred'.
2788
 */
2789
function theme_checkboxes_preferred($variables) {
2790
  $element = $variables['element'];
2791
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
2792
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
2793
  $out .= drupal_render_children($element);
2794
  $out .= '<div class="description">' . $element['#description'] . '</div>';
2795
  $out .= '</div>';
2796
  return $out;
2797
}
2798

    
2799
/**
2800
 * Callback for checkboxes preferred for widget which will
2801
 * be called after the form or element is built. The call
2802
 * back is configured in the form element by setting it as
2803
 * #after_build parameter.
2804
 *
2805
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
2806
 *
2807
 * @param $element
2808
 *   Nested array of form elements that comprise the form.
2809
 * @param $form_state
2810
 *   A keyed array containing the current state of the form.
2811
 *   This includes the current persistent storage data for the form.
2812
 *   Additional information, like the sanitized $_POST data,
2813
 *   is also accumulated here in $form_state['input']
2814
 *
2815
 * @return the modified form array
2816
 */
2817
function checkboxes_preferred_after_build($element, &$form_state) {
2818

    
2819
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
2820

    
2821
  if ($_POST && count($_POST) > 0) {
2822
    // TODO use  $form_state['input'] instead of POST !!!
2823
    // First pass of form processing.
2824
    $parents = array();
2825
    array_deep_copy($element['#parents'], $parents);
2826
    $parents[count($parents) - 1] .= '_preferred';
2827
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
2828
    $element['#value']['PREFERRED'] = $preferred_layer;
2829
//     $form_state[$parent_id] = $element['#value'];
2830
//     $form_state['values']['baselayers'] = $element['#value'];
2831
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
2832
    $form_state_element_values = $element['#value'];
2833
  }
2834
  else {
2835
    // Second pass of form processing.
2836
    $preferred_layer = $element['#value']['PREFERRED'];
2837
  }
2838

    
2839
  // Also set the chosen value (not sure if this is good Drupal style ....).
2840
  foreach ($children = element_children($element) as $key) {
2841
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
2842
      $element[$key]['#value'] = $preferred_layer;
2843
    }
2844
  }
2845
  // The default layer must always be enabled.
2846
  $element[$preferred_layer]['#value'] = $preferred_layer;
2847

    
2848
  return $element;
2849
}
2850

    
2851
function radios_prepare_options_suffix(&$elements){
2852

    
2853
  $childrenKeys = element_children($elements);
2854
  foreach($childrenKeys as $key){
2855
    if(!is_array($elements[$key]['#theme_wrappers'])){
2856
      $elements[$key]['#theme_wrappers'] = array();
2857
    }
2858
    if(isset($elements['#options_suffixes'][$key])){
2859
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
2860
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
2861
    }
2862
  }
2863
  return $elements;
2864

    
2865
}
2866

    
2867
/**
2868
 * TODO
2869
 * @param unknown $variables
2870
 */
2871
function theme_radio_options_suffix($variables) {
2872
  $element = $variables['element'];
2873
  if(isset($element['#options_suffix'])) {
2874
    $element['#children'] .= $element['#options_suffix'];
2875
  }
2876
  return $element['#children'];
2877
}
2878

    
2879

    
2880
/**
2881
 * Element validate callback for text field and arrays containing json.
2882
 *
2883
 * @param $element
2884
 *   The form element to validate
2885
 * @param $form_state
2886
 *   A keyed array containing the current state of the form.
2887
 * @param $form
2888
 *   Nested array of form elements that comprise the form.
2889
 */
2890
function form_element_validate_json($element, &$form_state, $form) {
2891
   if (!empty($element['#value'])) {
2892
     json_decode($element['#value']);
2893
     if(json_last_error() != JSON_ERROR_NONE){
2894
       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/'));
2895
     }
2896
   }
2897
}
2898

    
2899
/**
2900
 * Form submission handler for textareas and textfields containing JSON.
2901
 *
2902
 * The contained JSON will be converted into an php array
2903
 * or object and will be stored in the variables as such.
2904
 *
2905
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2906
 *
2907
 * @param $form
2908
 *   Nested array of form elements that comprise the form.
2909
 * @param $form_state
2910
 *   A keyed array containing the current state of the form.
2911
 *
2912
 */
2913
function submit_json_as_php_array($form, &$form_state) {
2914
  if (is_array($form['#json_elements'])) {
2915
    foreach ($form['#json_elements'] as $element){
2916
      if (trim($form_state['values'][$element])) {
2917
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
2918
      } else {
2919
        $form_state['values'][$element] = NULL;
2920
      }
2921
    }
2922
  }
2923
}
(14-14/14)