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)"
430
   *          2. if the text of the TextData is not empty the original source citations are the only content
431
   *             (e.g. use case CITATION) and are not put into brackets.
432
   *        FALSE:
433
   *          they are put into the bibliography(=references) pseudo feature block. If the original source
434
   *          citations are the only content, the resulting feature block content would only consist of footnotes.
435
   *          In this case the display of the respective feature block is suppressed.
436
   *    - sources_as_content_to_bibliography  (boolean)
437
   *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
438
   *        in the bibliography.
439
   *    - sort_elements
440
   *        whether and how to sort the elements
441
   *        possible values are the constants SORT_ASC, SORT_DESC, NULL
442
   *    - element_tag
443
   *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
444
   *        possible values are span | div
445
   *    - special: array()
446
   *        an array with further settings, this field can be used for special
447
   *        settings for specialized rendering like for distributions
448
   *  }
449
   *
450
   */
451
  function get_feature_block_settings($feature_uuid = 'DEFAULT'){
452
    // the default must conform to the default parameter values of
453
    // compose_cdm_feature_block_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
454
    // theme_cdm_descriptionElementTextData() : asListElement = NULL
455

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

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

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

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

    
547
    $default_theme = variable_get('theme_default', NULL);
548

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

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

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

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

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

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

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

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

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

    
717
}
718

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
895
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
896
      '#type' => 'fieldset',
897
      '#title' => 'Distribution filter',
898
      '#collapsible' => FALSE,
899
      '#collapsed' => FALSE,
900
      '#tree' => TRUE,
901
      '#description' => 'The Distribution filter offers the following options
902
      <ul>
903
      <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>
904
      <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>
905
      <li><strong>Marked area filter:</strong>Skip distributions where the area has a Marker with one of the specified MarkerTypes</li>
906
      </ul>'
907
  );
908

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

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

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

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

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

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

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

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

    
988
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
989
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
990

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

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

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

    
1036
  $form['#submit'][] = 'cdm_settings_general_submit';
1037

    
1038
  return system_settings_form($form);
1039
}
1040

    
1041

    
1042
/**
1043
 * LAYOUT settings
1044
 * @return
1045
 *   todo
1046
 */
1047
function cdm_settings_layout() {
1048

    
1049
  $form = array();
1050

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

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

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

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

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

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

    
1106
  $bibliography_settings = get_bibliography_settings(true);
1107

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

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

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

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

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

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

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

    
1170
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1171

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

    
1260
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1261

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

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

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

    
1314

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

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

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

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

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

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

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

    
1392
  return $form;
1393
}
1394

    
1395
/**
1396
 * @todo document this function.
1397
 */
1398
function cdm_settings_layout_taxon() {
1399
  $collapsed = FALSE;
1400
  $form = array();
1401

    
1402
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1403

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

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

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

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

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

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

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

    
1482
  // ---- PROFILE PICTURE ----//
1483

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

    
1493
  //FIXME migrate variables:
1494
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1495
  // FIXME
1496
  //  eanable file modul in profile and in update
1497

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

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

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

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

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

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

    
1569

    
1570

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

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

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

    
1632
  // ---- LAYOUT PER FEATURE ---- //
1633
  $feature_tree = get_profile_featureTree();
1634
  if (isset($feature_tree->root->childNodes)) {
1635

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

    
1644
    $feature_list_layout_settings_disabled = TRUE;
1645
    foreach ($feature_tree->root->childNodes as $featureNode) {
1646

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

    
1651
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1652
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1653

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

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

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

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

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

    
1694
      }
1695

    
1696
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1697
    }
1698
  }
1699

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

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

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

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

    
1758
AbsenceTerm
1759
a	absent
1760
f	reported in error
1761
nf	native: reported in error
1762
if	introduced: reported in error
1763
cf	cultivated: reported in error
1764
ne	native: formerly native
1765
ie	introduced: formerly introduced
1766

    
1767
</pre>'),
1768
  );
1769

    
1770

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

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

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

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

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

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

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

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

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

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

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

    
1887
/**
1888
 * @todo document this function.
1889
 */
1890
function cdm_settings_layout_search() {
1891

    
1892
  $form = array();
1893

    
1894
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
1895

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

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

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

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

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

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

    
1953
/**
1954
 * @todo document this function.
1955
 */
1956
function cdm_settings_layout_media() {
1957

    
1958
  $form = array();
1959

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

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

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

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

    
1995
/**
1996
 * GEOSERVICE and Map settings.
1997
 */
1998
function cdm_settings_geo($form, &$form_state) {
1999

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

    
2006
  $form = array();
2007

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

    
2031

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

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

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

    
2074

    
2075
  /*
2076
   * MAP SETTINGS
2077
   */
2078

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

    
2088
  /*
2089
   * settings for the distribution map are used also for specimens map!!!!
2090
   */
2091

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

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

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

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

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

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

    
2163

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

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

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

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

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

    
2213

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

    
2224

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

    
2234

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2457
  return system_settings_form($form);
2458
}
2459

    
2460
/**
2461
 * @todo document this function.
2462
 */
2463
function cdm_settings_cache() {
2464

    
2465
  $form = array();
2466

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

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

    
2490
  $form['cache_settings']['cdm_run_cache'] = array(
2491
    '#markup' => cdm_view_cache_site(),
2492
  );
2493

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

    
2503
/**
2504
 * Walk and cache all taxon pages.
2505
 */
2506
function cdm_view_cache_site() {
2507

    
2508
  $out = '';
2509

    
2510
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2511

    
2512
  $request_params = array();
2513
  $request_params['class'] = "Taxon";
2514

    
2515
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2516
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2517
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2518

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

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

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

    
2546

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

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

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

    
2583
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2584
    $form_state['values']['cdm_webservice_url'] .= '/';
2585
  }
2586

    
2587
}
2588

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

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

    
2614
}
2615

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

    
2627
  $settings = variable_get('edit_map_server', array(
2628
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
2629
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
2630
      )
2631
  );
2632

    
2633
  return $settings;
2634
}
2635

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

    
2647

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

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

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

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

    
2694

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

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

    
2720
  // First of all create checkboxes for each of the elements
2721
  $element = form_process_checkboxes($element);
2722

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

    
2732
  $children = element_children($element);
2733

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

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

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

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

    
2780
  return $element;
2781
}
2782

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

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

    
2816
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
2817

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

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

    
2845
  return $element;
2846
}
2847

    
2848
function radios_prepare_options_suffix(&$elements){
2849

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

    
2862
}
2863

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

    
2876

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

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