Project

General

Profile

Download (119 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_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
15
define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
16
define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
17
define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
18
define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
19

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

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

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

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

    
42

    
43

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

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

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

    
98
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
99

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

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

    
118
$taxon_tab_options = get_taxon_tabs_list();
119
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
120

    
121
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
122

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

    
133
}
134

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

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

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

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

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

    
278

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

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

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

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

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

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

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

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

    
400

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

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

    
469
    // only needed as final option, when the settings are not having a default
470
    $default = array(
471
      'DEFAULT' => array(
472
        'as_list' => 'ul',
473
        'link_to_reference' => FALSE,
474
        'link_to_name_used_in_source' => TRUE,
475
        'sources_as_content' => TRUE,
476
        'sources_as_content_to_bibliography' => FALSE,
477
        'sort_elements' => NULL,
478
        'glue' => '',
479
        'element_tag'=> NULL
480
      )
481
    );
482

    
483
    // will be used as preset in the settings
484
    $other_themes_default = array(
485
      'DEFAULT' => array(
486
        'as_list' => 'ul',
487
        'link_to_reference' => FALSE,
488
        'link_to_name_used_in_source' => TRUE,
489
        'sources_as_content' => FALSE,
490
        'sources_as_content_to_bibliography' => FALSE,
491
        'sort_elements' => NULL,
492
        'glue' => '',
493
        'element_tag'=> NULL
494
      ),
495
      UUID_CITATION => array(
496
        'as_list' => 'div',
497
        'link_to_reference' => FALSE,
498
        'link_to_name_used_in_source' => FALSE,
499
        'sources_as_content' => TRUE,
500
        'sources_as_content_to_bibliography' => FALSE,
501
        'sort_elements' => SORT_ASC,
502
        'glue' => '',
503
        'element_tag'=> 'div'
504
      ),
505
      UUID_DISTRIBUTION => array(
506
        'as_list' => 'div', // currently ignored
507
        'link_to_reference' => FALSE,
508
        'link_to_name_used_in_source' => FALSE,
509
        'sources_as_content' => FALSE,
510
        'sources_as_content_to_bibliography' => FALSE,
511
        'sort_elements' => NULL, // will cause ...
512
        'glue' => '',
513
        'element_tag'=> 'div'
514
      ),
515
      UUID_COMMON_NAME => array(
516
        'as_list' => 'div',
517
        'link_to_reference' => FALSE,
518
        'link_to_name_used_in_source' => TRUE,
519
        'sources_as_content' => FALSE,
520
        'sources_as_content_to_bibliography' => FALSE,
521
        'sort_elements' => NULL,
522
        'glue' => '',
523
        'element_tag'=> 'span'
524
      ),
525

    
526
    );
527

    
528
    $cichorieae_default = array(
529
      'DEFAULT' => array(
530
        'as_list' => 'div',
531
        'link_to_reference' => TRUE,
532
        'link_to_name_used_in_source' => TRUE,
533
        'sources_as_content' => TRUE,
534
        'sources_as_content_to_bibliography' => FALSE,
535
        'sort_elements' => NULL,
536
        'glue' => '',
537
        'element_tag'=> 'div'
538
      ),
539
      UUID_CITATION => array(
540
        'as_list' => 'div',
541
        'link_to_reference' => FALSE,
542
        'link_to_name_used_in_source' => FALSE,
543
        'sources_as_content' => TRUE,
544
        'sources_as_content_to_bibliography' => FALSE,
545
        'sort_elements' => SORT_ASC,
546
        'glue' => '',
547
        'element_tag'=> 'div'
548
      ),
549
      UUID_CHROMOSOMES_NUMBERS => array(
550
        'as_list' => 'ul',
551
        'link_to_reference' => TRUE,
552
        'link_to_name_used_in_source' => TRUE,
553
        'sources_as_content' => TRUE,
554
        'sources_as_content_to_bibliography' => FALSE,
555
        'sort_elements' => NULL,
556
        'glue' => '',
557
        'element_tag'=> 'div'
558
      ),
559
      UUID_CHROMOSOMES => array(
560
        'as_list' => 'ul',
561
        'link_to_reference' => FALSE,
562
        'link_to_name_used_in_source' => TRUE,
563
        'sources_as_content' => TRUE,
564
        'sources_as_content_to_bibliography' => FALSE,
565
        'sort_elements' => NULL,
566
        'glue' => '',
567
        'element_tag'=> 'div'
568
      ),
569
      UUID_COMMON_NAME => array(
570
        'as_list' => 'div',
571
        'link_to_reference' => FALSE,
572
        'link_to_name_used_in_source' => TRUE,
573
        'sources_as_content' => FALSE,
574
        'sources_as_content_to_bibliography' => FALSE,
575
        'sort_elements' => NULL,
576
        'glue' => '',
577
        'element_tag'=> 'span'
578
      ),
579
    );
580

    
581
    $palmweb_default = array(
582
      'DEFAULT' => array(
583
        'as_list' => 'ul',
584
        'link_to_reference' => TRUE,
585
        'link_to_name_used_in_source' => TRUE,
586
        'sources_as_content' => TRUE,
587
        'sources_as_content_to_bibliography' => TRUE,
588
        'sort_elements' => NULL,
589
        'glue' => '',
590
        'element_tag'=> NULL
591
      ),
592
      UUID_CITATION => array(
593
        'as_list' => 'ul',
594
        'link_to_reference' => TRUE,
595
        'link_to_name_used_in_source' => TRUE,
596
        'sources_as_content' => FALSE,
597
        'sources_as_content_to_bibliography' => TRUE,
598
        'sort_elements' => SORT_ASC,
599
        'glue' => '',
600
        'element_tag'=> 'div'
601
      ),
602
      UUID_DISTRIBUTION => array(
603
        'as_list' => 'div', // currently ignored
604
        'link_to_reference' => TRUE,
605
        'link_to_name_used_in_source' => TRUE,
606
        'sources_as_content' => TRUE, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
607
        'sources_as_content_to_bibliography' => TRUE,
608
        'sort_elements' => NULL, // will cause ...
609
        'glue' => '',
610
        'element_tag'=> 'div'
611
      ),
612
    );
613

    
614
    $cyprus_default = $cichorieae_default;
615
    $cyprus_default[UUID_DISTRIBUTION ]  =  array(
616
      'as_list' => 'div', // currently ignored
617
      'link_to_reference' => FALSE,
618
      'link_to_name_used_in_source' => FALSE,
619
      'sources_as_content' => FALSE,
620
      'sources_as_content_to_bibliography' => FALSE,
621
      'sort_elements' => NULL, // will cause ...
622
      'glue' => '',
623
      'element_tag'=> 'div'
624
    );
625

    
626
    $default_theme = variable_get('theme_default', NULL);
627

    
628
    switch ($default_theme){
629
      case 'garland_cichorieae':
630
        $settings_for_theme = $cichorieae_default;
631
        break;
632
      case 'cyprus':
633
        // cyprus: no longer used in production,
634
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
635
        $settings_for_theme = $cyprus_default;
636
        break;
637
      case 'flore_afrique_centrale':
638
      case 'flora_malesiana':
639
      case 'flore_gabon':
640
        $settings_for_theme = $cichorieae_default;
641
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
642
        break;
643
      case 'palmweb_2':
644
        $settings_for_theme = $palmweb_default;
645
        break;
646
      default:
647
        $settings_for_theme =  $other_themes_default;
648
    }
649

    
650
    if(isset($settings_for_theme[$feature_uuid])){
651
      return $settings_for_theme[$feature_uuid];
652
    } else if(isset($settings_for_theme['DEFAULT'])){
653
      return $settings_for_theme['DEFAULT']; // the fallback cascade will usually stop here since all settings should have a default
654
    } else {
655
      return $default['DEFAULT'];
656
    }
657
}
658
  /**
659
 * returns the current setting for the original source bibliography
660
 *
661
 * Caches internally
662
 *
663
 * @return array
664
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
665
 *   - 'enabled': 1|0
666
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
667
 */
668
function get_bibliography_settings($clear_cache = false){
669
  static $bibliography_settings = null;
670
  if(!$bibliography_settings || $clear_cache){
671
    $bibliography_settings = get_array_variable_merged(
672
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
673
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
674
    );
675
  }
676
  return $bibliography_settings;
677
}
678

    
679
/**
680
 * @todo Please document this function.
681
 * @see http://drupal.org/node/1354
682
 */
683
function cdm_dataportal_menu_admin(&$items) {
684
  // Display section on admin/config page.
685
  $items['admin/config/cdm_dataportal'] = array(
686
    'title' => 'CDM Dataportal',
687
    'description' => 'Settings for the CDM DataPortal.',
688
    'position' => 'right',
689
    'weight' => 10,
690
    'page callback' => 'system_admin_menu_block_page',
691
    'access arguments' => array('administer cdm_dataportal'),
692
    'file' => 'system.admin.inc',
693
    'file path' => drupal_get_path('module', 'system'),
694
  );
695
  $items['admin/config/cdm_dataportal/settings'] = array(
696
    'title' => 'Settings',
697
    'description' => 'Settings for the CDM DataPortal.',
698
    'weight' => 0,
699
    'page callback' => 'drupal_get_form',
700
    'page arguments' => array('cdm_settings_general'),
701
    'access arguments' => array('administer cdm_dataportal'),
702
    'type' => MENU_NORMAL_ITEM,
703
  );
704
  $items['admin/config/cdm_dataportal/settings/general'] = array(
705
    'title' => 'General',
706
    'description' => 'General',
707
    'weight' => 0,
708
    'page callback' => 'drupal_get_form',
709
    'page arguments' => array('cdm_settings_general'),
710
    'access arguments' => array('administer cdm_dataportal'),
711
    'type' => MENU_DEFAULT_LOCAL_TASK,
712
  );
713

    
714
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
715
    'title' => 'Cache',
716
    'description' => 'Cache',
717
    'access arguments' => array('administer cdm_dataportal'),
718
    'page callback' => 'drupal_get_form',
719
    'page arguments' => array('cdm_settings_cache'),
720
    'weight' => 10,
721
    'type' => MENU_LOCAL_TASK,
722
  );
723

    
724
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
725
    'title' => 'Geo & Map',
726
    'description' => 'Geo & Map',
727
    'access arguments' => array('administer cdm_dataportal'),
728
    'page callback' => 'drupal_get_form',
729
    'page arguments' => array('cdm_settings_geo'),
730
    'weight' => 1,
731
    'type' => MENU_LOCAL_TASK,
732
  );
733

    
734
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
735
    'title' => 'Layout',
736
    'description' => 'Configure and adjust the layout of your DataPortal ',
737
    'access arguments' => array('administer cdm_dataportal'),
738
    'page callback' => 'drupal_get_form',
739
    'page arguments' => array('cdm_settings_layout'),
740
    'weight' => 2,
741
    'type' => MENU_LOCAL_TASK,
742
  );
743

    
744
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
745
    'title' => 'Taxon',
746
    'description' => 'Configure and adjust the layout of your DataPortal ',
747
    'access arguments' => array('administer cdm_dataportal'),
748
    'page callback' => 'drupal_get_form',
749
    'page arguments' => array('cdm_settings_layout_taxon'),
750
    'weight' => 1,
751
    'type' => MENU_LOCAL_TASK,
752
  );
753
  /*
754
  $items[] = array(
755
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
756
  'title' => t('Synonymy'),
757
  'description' => t('Configure and adjust the layout of your DataPortal '),
758
  'access' => user_access('administer cdm_dataportal'),
759
  'callback' => 'drupal_get_form',
760
  'callback arguments' => array('cdm_settings_layout_synonymy'),
761
  'weight' => 1,
762
  'type' => MENU_LOCAL_TASK,
763
  );
764

    
765
  $items[] = array(
766
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
767
  'title' => t('Specimens'),
768
  'description' => t('Configure and adjust the layout of your DataPortal '),
769
  'access' => user_access('administer cdm_dataportal'),
770
  'callback' => 'drupal_get_form',
771
  'callback arguments' => array('cdm_settings_layout_specimens'),
772
  'weight' => 1,
773
  'type' => MENU_LOCAL_TASK,
774
  );
775
  */
776
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
777
    'title' => 'Search',
778
    'description' => 'Configure and adjust the layout of your DataPortal ',
779
    'access arguments' => array('administer cdm_dataportal'),
780
    'page callback' => 'drupal_get_form',
781
    'page arguments' => array('cdm_settings_layout_search'),
782
    'weight' => 2,
783
    'type' => MENU_LOCAL_TASK,
784
  );
785

    
786
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
787
    'title' => 'Media',
788
    'description' => 'Configure and adjust the layout of your DataPortal ',
789
    'access arguments' => array('administer cdm_dataportal'),
790
    'page callback' => 'drupal_get_form',
791
    'page arguments' => array('cdm_settings_layout_media'),
792
    'weight' => 3,
793
    'type' => MENU_LOCAL_TASK,
794
  );
795

    
796
}
797

    
798
/**
799
 * @todo document this function.
800
 */
801
function cdm_help_general_cache() {
802
  $form = array();
803
  $form['cache_help'] = array(
804
    '#type' => 'fieldset',
805
    '#title' => t('Help'),
806
    '#collapsible' => TRUE,
807
    '#collapsed' => TRUE,
808
  );
809
  $form['cache_help']['test'] = array('#value' => t('probando'));
810
  return drupal_render($form);
811
  $res = array();
812
  $res['default'] = drupal_render($help);
813
  return $res;
814
}
815

    
816
/**
817
 * Configures the settings form for the CDM-API module.
818
 *
819
 * @return array
820
 *   Drupal settings form.
821
 */
822
function cdm_settings_general() {
823

    
824
  $form['cdm_webservice'] = array(
825
    '#type' => 'fieldset',
826
    '#title' => t('CDM Server'),
827
    '#collapsible' => FALSE,
828
    '#collapsed' => FALSE,
829
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
830
        CDM data base to the web via RESTful web services and thus is the source of the data
831
        to be displayed by a CDM DataPotal.'),
832
  );
833

    
834
  $form['cdm_webservice']['cdm_webservice_url'] = array(
835
    '#type' => 'textfield',
836
    '#title' => t('CDM web service URL') . ':',
837
    '#description' => t('This is the URL to the CDM-Server exposing your data
838
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
839
    '#default_value' => variable_get('cdm_webservice_url', NULL),
840
  );
841

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

    
849
  $form['cdm_webservice']['freetext_index'] = array(
850
    '#type' => 'fieldset',
851
    '#title' => t('Freetext index'),
852
    '#collapsible' => FALSE,
853
    '#collapsed' => FALSE,
854
  );
855

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

    
868
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
869
  $trigger_link_options = array(
870
    'attributes' => array(
871
      'class' => 'index-trigger',
872
    ),
873
  );
874
  $form['cdm_webservice']['freetext_index']['operations'] = array(
875
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
876
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
877
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
878
      ))
879
    . '<div id="index-progress"></div></div>',
880
  );
881
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
882

    
883
  $form['cdm_webservice']['proxy'] = array(
884
    '#type' => 'fieldset',
885
    '#title' => t('Proxy'),
886
    '#collapsible' => TRUE,
887
    '#collapsed' => TRUE,
888
  );
889

    
890
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
891
    '#type' => 'textfield',
892
    '#title' => t('Proxy URL') . ':',
893
    '#description' => t('If this proxy url is set the cdm api tries
894
    to connect the web service over the given proxy server.
895
    Otherwise proxy usage is deactivated.'),
896
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
897
  );
898

    
899
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
900
    '#type' => 'textfield',
901
    '#title' => t('Proxy port') . ':',
902
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
903
  );
904

    
905
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
906
    '#type' => 'textfield',
907
    '#title' => t('Login') . ':',
908
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
909
  );
910

    
911
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
912
    '#type' => 'textfield',
913
    '#title' => t('Password') . ':',
914
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
915
  );
916

    
917
  // TODO: settings are still incomplete, compare with
918
  // trunk/dataportal/inc/config_default.php.inc.
919
  $form['taxon_tree'] = array(
920
    '#type' => 'fieldset',
921
    '#title' => t('Taxon Tree'),
922
    '#collapsible' => FALSE,
923
    '#collapsed' => TRUE,
924
    '#description' => t('<p>When you explore your collection, you can navigate
925
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
926
      able to navigate through your collection the
927
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
928
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
929
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
930
      </a></p>'),
931
  );
932

    
933
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
934
    '#type' => 'select',
935
    '#title' => t('Available classifications') . ':',
936
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
937
    '#options' => cdm_get_taxontrees_as_options(),
938
    '#description' => t('Select the default taxa classification for your
939
      <em>taxon tree</em>, the other classifications will be also available but
940
      with a manual user change.'),
941
  );
942

    
943
  $form['taxon_tree']['taxontree_ranklimit'] = array(
944
    '#type' => 'select',
945
    '#title' => t('Rank of highest displayed taxon') . ':',
946
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
947
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
948
    '#options' => cdm_rankVocabulary_as_option(),
949
    '#description' => t('This is the rank of the highest displayed taxon in the
950
      <em>taxon tree</em>. You can select here which rank should be at the top
951
      level of the tree structure.'),
952
  );
953

    
954
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
955
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
956
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
957
      '#type' => 'checkboxes',
958
      '#title' => t('Included Classifications') . ':',
959
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
960
      '#options' => cdm_get_taxontrees_as_options(),
961
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
962
  );
963

    
964
  $form['distribution'] = array(
965
      '#type' => 'fieldset',
966
      '#title' => t('Distributions'),
967
      '#collapsible' => FALSE,
968
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
969
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
970
          '<p>
971
          </p>',
972
  );
973

    
974
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
975
      '#type' => 'fieldset',
976
      '#title' => 'Distribution filter',
977
      '#collapsible' => FALSE,
978
      '#collapsed' => FALSE,
979
      '#tree' => TRUE,
980
      '#description' => 'The Distribution filter offers the following options
981
      <ul>
982
      <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>
983
      <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>
984
      <li><strong>Marked area filter:</strong>Skip distributions where the area has a Marker with one of the specified MarkerTypes</li>
985
      </ul>'
986
  );
987

    
988
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
989
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
990
      '#type' => 'checkboxes',
991
      '#title' => 'Filter rules',
992
      '#default_value' => $cdm_distribution_filter['filter_rules'],
993
      '#options' => array(
994
          'statusOrderPreference' => 'Status order preference rule',
995
          'subAreaPreference' => 'Sub area preference rule'
996
      ),
997
  );
998

    
999
  $marker_type_options = cdm_terms_as_options( cdm_ws_fetch_all('term', array('class' => 'MarkerType' )) );
1000
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hideMarkedAreas'] = array(
1001
      '#type' => 'checkboxes',
1002
      '#title' => 'Hide marked area filter',
1003
      '#default_value' => $cdm_distribution_filter['hideMarkedAreas'],
1004
      '#options' => $marker_type_options,
1005
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1006
  );
1007

    
1008
  $form['aggregation'] = array(
1009
      '#type' => 'fieldset',
1010
      '#title' => t('Aggregation of data'),
1011
      '#collapsible' => FALSE,
1012
      '#description' => 'This section covers the different aspects of aggregating information.
1013
          <p>
1014
          </p>',
1015
  );
1016

    
1017
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1018
      '#type' => 'checkboxes',
1019
      '#title' => 'Taxon media filter',
1020
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1021
      '#options' => array(
1022
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1023
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1024
          'includeOccurrences' => 'Media related to specimens and occurrences',
1025
      ),
1026
      '#description' => 'This filter configures which images should be taken into account.',
1027
  );
1028

    
1029
  $form['aggregation']['notice'] = array(
1030
      '#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
1031
          want to make use of the caching capabilities of the dataportal.',
1032
  );
1033

    
1034
  $form['aggregation']['media_aggregation'] = array(
1035
      '#type' => 'fieldset',
1036
      '#title' => t('Media aggregation'),
1037
      '#collapsible' => FALSE,
1038
      '#collapsed' => TRUE,
1039
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1040

    
1041
  );
1042
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1043
      '#type' => 'select',
1044
      '#title' => t('Aggregation of taxon pictures') . ':',
1045
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1046
      '#options' => array(
1047
          0 => "Show only pictures of the current taxon",
1048
          1 => "Include pictures of taxonomic children",
1049
      ),
1050
      '#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."),
1051
  );
1052

    
1053
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1054
      '#type' => 'fieldset',
1055
      '#attributes' => array('class'=>array('clearfix')),
1056
      '#title' => t('Aggregation via taxon relationsships'),
1057
      '#collapsible' => TRUE,
1058
      '#collapsed' => TRUE,
1059
      '#tree' => TRUE,
1060
      '#description' => t('Information on taxa will be aggregated along the below chosen
1061
          taxon relation ships. This will affect images and occurrences (specimens).
1062
          Taxon relation ships are directed and point form one taxon to another. The taxon
1063
          relationships to be taken into accunt can therefore configured for the direct direction
1064
          and for the inverse.'),
1065
  );
1066

    
1067
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1068
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1069

    
1070
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1071
      '#type' => 'checkboxes',
1072
      '#title' => t('Direct'),
1073
      '#options' => $taxonRelationshipTypeOptions,
1074
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1075
  );
1076
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1077
      '#type' => 'checkboxes',
1078
      '#title' => t('Invers'),
1079
      '#options' => $taxonRelationshipTypeOptions,
1080
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1081
  );
1082

    
1083
  // ----------------------
1084
  $form['cdm_js_devel_mode'] = array(
1085
      '#type' => 'checkbox',
1086
      '#title' => 'Java-script developer mode',
1087
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1088
      '#description' => 'In production envirionments the java script libraries
1089
      the cdm_dataportal is making use of are compressed and optimized. This
1090
      is good for performance but a caveat if you need to debug java-script. When the
1091
      java-script developer mode is enabled the uncompressed and commented developer
1092
      versions of java-script libraries will be used where possible.
1093
      <br/><strong>Do not use this option in production!</strong>'
1094
  );
1095
  // ----------------------
1096
  $form['cdm_debug_mode'] = array(
1097
      '#type' => 'checkbox',
1098
      '#title' => 'CDM page debug mode',
1099
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1100
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1101
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1102
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1103
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1104
      The log is written by the drupal devel module function <code>dd()</code>.
1105
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1106
  );
1107

    
1108
  // Comment @WA: D7 form api does not support reset buttons,
1109
  // so to mimic the D5 reset button we add one like this.
1110
  $form['actions']['reset'] = array(
1111
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1112
    '#weight' => 1000,
1113
  );
1114

    
1115
  $form['#submit'][] = 'cdm_settings_general_submit';
1116

    
1117
  return system_settings_form($form);
1118
}
1119

    
1120

    
1121
/**
1122
 * LAYOUT settings
1123
 * @return
1124
 *   todo
1125
 */
1126
function cdm_settings_layout() {
1127

    
1128
  $form = array();
1129

    
1130
  $form['about'] = array(
1131
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1132
      layout. If you want to configure the specific sites layout visit the
1133
      respective configuration site for taxon, search or media.') . '</p>',
1134
  );
1135

    
1136
  // ---- footnotes --- //
1137
  $form['footnotes'] = array(
1138
    '#type' => 'fieldset',
1139
    '#title' => t('Footnotes'),
1140
    '#collapsible' => FALSE,
1141
    '#collapsed' => FALSE,
1142
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1143
      media or distribution areas may have annotations or footnotes. When the
1144
      footnotes are enabled they will be visible (if they exist).'),
1145
  );
1146

    
1147
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1148
    '#type' => 'checkbox',
1149
    '#title' => t('Do not show footnotes'),
1150
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1151
    '#description' => t('Check this if you do not want to show any footnotes'),
1152
  );
1153

    
1154
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1155
    '#type' => 'checkbox',
1156
    '#title' => t('Do not show annotations footnotes'),
1157
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1158
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1159
  );
1160

    
1161
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType', SORT_ASC);
1162
  // Additional option for the NULL case.
1163
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1164
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1165
    '#type' => 'checkboxes',
1166
    '#title' => t('Annotation types as footnotes'),
1167
    '#description' => t("Only annotations of the selected type will be displayed
1168
       as footnotes. You may want to turn 'technical annotations' off."),
1169
    '#options' => $annotationTypeOptions,
1170
  );
1171
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1172
  if (!empty($annotationsTypesAsFootnotes)) {
1173
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1174
  }
1175

    
1176
  // ---- original source --- //
1177
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1178
      '#type' => 'fieldset',
1179
      '#tree' => TRUE,
1180
      '#title' => t('Source Citations'),
1181
      '#collapsible' => FALSE,
1182
      '#collapsed' => FALSE,
1183
  );
1184

    
1185
  $bibliography_settings = get_bibliography_settings(true);
1186

    
1187
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1188
      '#type' => 'checkbox',
1189
      '#title' => t('Original Source in bibliography'),
1190
      '#default_value' => $bibliography_settings['enabled'],
1191
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1192
       annotations in each feature block.'),
1193
  );
1194

    
1195
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1196
    '#type' => 'select',
1197
    '#title' => t('The format of the key numerals'),
1198
    '#default_value' => $bibliography_settings['key_format'],
1199
    '#options' => array('latin' => 'Latin',
1200
      'ROMAN' => 'Roman (upper case)',
1201
      'roman' => 'Roman (lower case)',
1202
      'ALPHA'=> 'Alphabet (upper case)',
1203
      'alpha' => 'Alphabet (lower case)')
1204
  );
1205

    
1206
  // --- Advanced Search --- //
1207
  $form['asearch'] = array(
1208
      '#type' => 'fieldset',
1209
      '#title' => t('Advanced search'),
1210
      '#collapsible' => FALSE,
1211
      '#collapsed' => FALSE,
1212
  );
1213
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1214
      '#type' => 'checkbox',
1215
      '#title' => t('Show advanced search link'),
1216
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1217
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1218
  );
1219

    
1220
  // ---- Taxon Name Rendering --- //
1221
  $form['taxon_name'] = array(
1222
      '#type' => 'fieldset',
1223
      '#title' => t('Taxon name display'),
1224
      '#collapsible' => TRUE,
1225
      '#collapsed' => TRUE,
1226
      '#description' => t('The display of taxon names is configured by two parts.'
1227
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
1228
          . 'The name parts are defined in the <stong>part definitions</strong>'),
1229
  );
1230

    
1231
  drupal_add_js(
1232
      'jQuery(document).ready( function( ) {
1233
         // pretty print json
1234
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
1235
         var obj = JSON.parse(json_text);
1236
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
1237

    
1238
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
1239
         obj = JSON.parse(json_text);
1240
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
1241
       });'
1242
      ,array(
1243
          'type' => 'inline',
1244
          'scope' => 'footer'
1245
      )
1246
  );
1247

    
1248
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1249

    
1250
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1251
      '#type' => 'textarea',
1252
      '#title' => t('Part definitions'),
1253
      '#element_validate' => array('form_element_validate_json'),
1254
      '#default_value' =>  json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions)),
1255
      '#description' => '
1256
          <p>
1257
          (Clearing the text area will reset it to the default)
1258
          </p>
1259
          <p>
1260
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1261
          </p>
1262
          <p>
1263
           A full taxon name plus additional information can consist of the following elements:
1264
          <ul>
1265
             <li>name: the taxon name inclugin rank nbut without author</li>
1266
             <li>authors:  The authors of a reference, also used in taxon names</li>
1267
             <li>reference: the nomenclatural reference,</li>
1268
             <li>microreference:  Volume, page number etc.</li>
1269
             <li>status:  The nomenclatural status of a name</li>
1270
             <li>description: name descriptions like protologues etc ...</li>
1271
          </ul>
1272
          </p>
1273
          <p>
1274
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1275
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1276
           The following parts can be formed and are recognized by the system:
1277
          <ul>
1278
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1279
            <li>authorshipPart: the author (for example: "L.")</li>
1280
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1281
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1282
               be combined when a link to the taxon is rendered.</li>
1283
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1284
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1285
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1286
            <li>statusPart: the nomenclatorical status</li>
1287
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1288
          </ul>
1289
          </p>
1290
          <p>
1291
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1292
           specific parts part definitions:
1293
          <ul>
1294
            <li>BotanicalName</li>
1295
            <li>ZoologicalName</li>
1296
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1297
          </ul>
1298
           An example:
1299
          <pre>
1300
           {
1301
            "ZoologicalName": {
1302
              "namePart": {
1303
                "name": true
1304
              },
1305
              "referencePart": {
1306
                "authors": true
1307
              },
1308
              "microreferencePart": {
1309
                "microreference": true
1310
              },
1311
              "statusPart": {
1312
                "status": true
1313
              },
1314
              "descriptionPart": {
1315
                "description": true
1316
              }
1317
            },
1318
            "BotanicalName": {
1319
              "namePart": {
1320
                "name": true,
1321
                "authors": true
1322
              },
1323
              "referencePart": {
1324
                "reference": true,
1325
                "microreference": true
1326
              },
1327
              "statusPart": {
1328
                "status": true
1329
              },
1330
              "descriptionPart": {
1331
                "description": true
1332
              }
1333
            }
1334
          }
1335
           </pre>',
1336
  );
1337

    
1338
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1339

    
1340
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1341
      '#type' => 'textarea',
1342
      '#title' => t('Name render templates'),
1343
      '#element_validate' => array('form_element_validate_json'),
1344
      '#default_value' =>  json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates)),
1345
      '#description' => '
1346
          <p>
1347
          (Clearing the text area will reset it to the default)
1348
          </p>
1349
          <p>
1350
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1351
          render path. The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1352
          The following render Path keys are curretly recognized:
1353
          <ul>
1354
            <li>list_of_taxa</li>
1355
            <li>acceptedFor</li>
1356
            <li>homonym</li>
1357
            <li>taxon_page_synonymy</li>
1358
            <li>typedesignations</li>
1359
            <li>taxon_page_title</li>
1360
            <li>polytomousKey</li>
1361
            <li>na: name + authorship</li>
1362
            <li>nar:name + authorship + reference</li>
1363
            <li>#DEFAULT</li>
1364
          </ul>
1365
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1366
          array element should be a comma separated list of render paths, without any whitespace!.
1367
          </p>
1368
          <p>
1369
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1370
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1371
          <p>
1372
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1373
          The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
1374
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1375
          links if the paramters $nameLink or $refenceLink are given to the name render function
1376
          (this is hard coded and cannot be configured here).',
1377
  );
1378

    
1379
  // @WA: D7 form api does not support reset buttons,
1380
  // so to mimic the D5 reset button we add one like this.
1381
  $form['actions']['reset'] = array(
1382
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1383
    '#weight' => 1000,
1384
  );
1385

    
1386
  $form['#submit'] = array('submit_json_as_php_array');
1387
  // #json_elements especially defined for submit_json_as_php_array()
1388
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1389
  return system_settings_form($form);
1390
}
1391

    
1392

    
1393
/**
1394
 * @todo Please document this function.
1395
 * @see http://drupal.org/node/1354
1396
 */
1397
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1398
  $form[$form_name] = array(
1399
    '#type' => 'fieldset',
1400
    '#title' => t($form_title),
1401
    '#collapsible' => TRUE,
1402
    '#collapsed' => $collapsed,
1403
    '#tree' => TRUE,
1404
    '#description' => t($form_description),
1405
  );
1406

    
1407
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1408
  $gallery_settings = variable_get($form_name, $default_values);
1409
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1410
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1411
    /*
1412
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1413
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1414
    '#type' => 'textfield',
1415
    '#title' => t('Search Page Size'),
1416
    '#default_value' => $test,
1417
    '#description' => t('Number of Names to display per page in search results.')
1418
    );
1419
    */
1420
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1421
      '#type' => 'checkbox',
1422
      '#title' => t('Show media thumbnails for accepted taxa'),
1423
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1424
    );
1425

    
1426
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1427
      '#type' => 'checkbox',
1428
      '#title' => t('Show media thumbnails for synonyms'),
1429
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1430
      '#description' => '',
1431
    );
1432
  }
1433

    
1434
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1435
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1436
    '#type' => 'checkbox',
1437
    '#title' => t('Show captions under thumbnails'),
1438
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1439
    '#description' => '',
1440
  );
1441

    
1442
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1443
    '#type' => 'textfield',
1444
    '#title' => t('Thumbnail size') . ':',
1445
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1446
    '#description' => t('Select the size of each individual thumbnail.'),
1447
  );
1448

    
1449
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1450
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1451
      '#type' => 'textfield',
1452
      '#title' => t('Number of columns') . ':',
1453
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1454
      '#description' => t('Group the thumbnails in columns: select how many
1455
        columns the gallery should display.'),
1456
    );
1457
  }
1458

    
1459
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1460
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1461
      '#type' => 'textfield',
1462
      '#title' => t('Maximum number of rows') . ':',
1463
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1464
      '#description' => t('You can group the thumbnails in rows, select in how
1465
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1466
        If you want an unlimited number of rows please set to 0.'),
1467
    );
1468
  }
1469

    
1470
  return $form;
1471
}
1472

    
1473
/**
1474
 * @todo document this function.
1475
 */
1476
function cdm_settings_layout_taxon() {
1477
  $collapsed = FALSE;
1478
  $form = array();
1479

    
1480
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1481

    
1482
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1483
      '#type' => 'checkbox',
1484
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1485
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1486
      '#description' => t('<p>If checked the link to search results is rendered at
1487
       the top of the taxon site. Clicking on the link the last search performed
1488
       is rendered again.</p>'),
1489
  );
1490

    
1491
  // --------- TABBED TAXON ------- //
1492
  $form['taxon_tabs'] = array(
1493
    '#type' => 'fieldset',
1494
    '#title' => t('Taxon tabs'),
1495
    '#collapsible' => TRUE,
1496
    '#collapsed' => FALSE,
1497
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1498
      be splitted in four diferent tabs; General, Synonymy, Images and
1499
      Specimens. If the taxon has no information for any of the tabs/sections
1500
      such tab will be not displayed.'),
1501
  );
1502

    
1503
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1504
    '#type' => 'checkbox',
1505
    '#title' => t('Tabbed taxon page'),
1506
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1507
    '#description' => t('<p>If selected split the taxon page into individual
1508
      tabs for description, images, synonymy and specimens. If not the taxon
1509
      data is rendered as a long single page without tabs.</p>'),
1510
  );
1511

    
1512
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1513
    '#type' => 'checkboxes',
1514
    '#title' => t('Tabs visibility options') . ':',
1515
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1516
    '#options' => get_taxon_options_list(),
1517
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1518
  );
1519

    
1520
  // WEIGHT
1521
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1522
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1523
      '#tree' => true
1524
  );
1525
  // Weights range from -delta to +delta, so delta should be at least half
1526
  // of the amount of tabs present.
1527
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1528
  foreach (get_taxon_tabs_list() as $label) {
1529
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1530
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1531
        '#title' => $label,
1532
        '#type'  => 'weight',
1533
        '#default_value' => $taxontabs_weights[$key],
1534
        '#delta' => $tab_weight_delta
1535
    );
1536
  }
1537

    
1538
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1539
    '#type' => 'select',
1540
    '#title' => t('Default tab to display') . ':',
1541
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1542
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1543
    '#description' => t('<p>Select the default tab to display when visiting a
1544
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1545
      <strong>Note:</strong> After performing a search and clicking in any
1546
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1547
      taxon and not the above selected tab.'),
1548
  );
1549

    
1550
  /* ======  TAXON_PROFILE ====== */
1551
  $form['taxon_profile'] = array(
1552
    '#type' => 'fieldset',
1553
    '#title' => t('Taxon profile (tab)'),
1554
    '#description' => t('<p>This section covers the settings related to the taxon
1555
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1556
    '#collapsible' => TRUE,
1557
    '#collapsed' => TRUE,
1558
  );
1559

    
1560
  // ---- PROFILE PICTURE ----//
1561

    
1562
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1563
    '#type' => 'fieldset',
1564
    '#tree' => TRUE,
1565
    '#title' => t('Taxon profile picture'),
1566
    '#collapsible' => TRUE,
1567
    '#collapsed' => FALSE,
1568
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1569
  );
1570

    
1571
  //FIXME migrate variables:
1572
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1573
  // FIXME
1574
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1575

    
1576
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1577
  /*
1578
   * 'show' => 1,
1579
   * 'maxextend' => 184,
1580
   * 'media_uri_query' => ''
1581
   * 'custom_placeholder_image_on' => 1,
1582
   * 'custom_placeholder_image_fid' => ''
1583
   */
1584
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1585
    '#type' => 'checkbox',
1586
    '#title' => t('Enable profil picture'),
1587
    '#description' => t('Show the profil picture.'),
1588
    '#default_value' => $taxon_profile_image_settings['show'],
1589
  );
1590

    
1591
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1592
      '#type' => 'textfield',
1593
      '#tree' => TRUE,
1594
      '#title' => t('Profil picture maximum extend'),
1595
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1596
      '#field_suffix' => 'px',
1597
      '#maxlength' => 4,
1598
      '#size' => 4,
1599
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1600
  );
1601

    
1602
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1603
      '#type' => 'textfield',
1604
      '#tree' => TRUE,
1605
      '#title' => t('Additional URI query parameter'),
1606
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1607
      '#maxlength' => 1024,
1608
      '#size' => 60,
1609
      '#description' => t('Additional query parameters to be used when requesting for the '
1610
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1611
          . 'The query parameters will be appendend to the uri of the media representation part'
1612
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1613
  );
1614

    
1615
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1616
      '#type' => 'checkbox',
1617
      '#title' => t('Use a custom placeholder image'),
1618
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1619
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1620
  );
1621

    
1622
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1623
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1624
        '#type' => 'managed_file',
1625
        '#title' => t('Custom placeholder image file'),
1626
        '#progress_indicator' => 'bar',
1627
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1628
    //       '#name' => 'custom_placeholder_image',
1629
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1630
    );
1631

    
1632
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1633
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1634
      $url = file_create_url($profile_image_file->uri);
1635
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1636
                '#type' => 'item',
1637
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1638
      );
1639
    }
1640
  } else {
1641
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1642
        '#type' => 'hidden',
1643
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1644
    );
1645
  }
1646

    
1647

    
1648

    
1649
  $options = cdm_rankVocabulary_as_option();
1650
  array_unshift($options, '-- DISABLED --');
1651
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1652
    '#type' => 'select',
1653
    '#title' => t('Hide profile picture for higher ranks') . ':',
1654
    '#default_value' => variable_get('image_hide_rank', '0'),
1655
    '#options' => $options,
1656
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1657
  );
1658

    
1659
  // -- MEDIA THUMBNAILS -- //
1660
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1661
  $form_title = 'Taxon Profile Images';
1662
  $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>';
1663
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1664

    
1665
  // ---- FEATURE TREE ---- //
1666
  $form['taxon_profile']['feature_trees'] = array(
1667
    '#type' => 'fieldset',
1668
    '#title' => t('Features'),
1669
    '#collapsible' => TRUE,
1670
    '#collapsed' => FALSE,
1671
    '#description' => t("This section covers settings related to the taxon's
1672
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1673
      features such as description, distribution, common names, etc. that Drupal
1674
      will render at the taxon profile page."),
1675
  );
1676
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1677
  $saved_uuid = variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1678
  if(!isset($featureTrees['options'][$saved_uuid])) {
1679
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1680
  }
1681
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
1682
    '#type' => 'radios',
1683
    '#title' => t('Taxon profile sections') . ':',
1684
    '#default_value' => $saved_uuid,
1685
    '#options' =>  $featureTrees['options'],
1686
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1687
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1688
    '#description' => t('Select the Feature Tree to be displayed at the taxon
1689
      profile. Click "Show Details" to see the Feature Tree elements.'
1690
    ),
1691
  );
1692
  $featureTrees = cdm_get_featureTrees_as_options();
1693
  $saved_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1694
  if(!isset($featureTrees['options'][$saved_uuid])) {
1695
    $saved_uuid = NULL;
1696
  }
1697
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
1698
    '#type' => 'radios',
1699
    '#title' => t('Natural language representation of structured descriptions') . ':',
1700
    '#default_value' => $saved_uuid,
1701
    '#options' => $featureTrees['options'],
1702
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1703
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1704
    '#description' => t('Taxon descriptions can be stored in a highly structured
1705
      form. The feature tree selected here will be used to generate textual
1706
      representation in natural language.'
1707
    ),
1708
  );
1709

    
1710
  // ---- LAYOUT PER FEATURE ---- //
1711
  $feature_tree = get_profile_featureTree();
1712
  if (isset($feature_tree->root->childNodes)) {
1713

    
1714
    $form_feature_list_layout = array(
1715
      '#title' => t('Taxon profile layout'),
1716
      '#collapsible' => TRUE,
1717
      '#collapsed' => FALSE,
1718
      '#type' => 'fieldset',
1719
      '#description' => t('Will be available in a future release.'),
1720
    );
1721

    
1722
    $feature_list_layout_settings_disabled = TRUE;
1723
    foreach ($feature_tree->root->childNodes as $featureNode) {
1724

    
1725
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1726
        // Must not exceed 45 characters !!!
1727
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1728

    
1729
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1730
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1731

    
1732
        $form_feature_list_layout[$subform_id] = array(
1733
          '#tree' => TRUE,
1734
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1735
          '#collapsible' => FALSE,
1736
          '#collapsed' => FALSE,
1737
          '#type' => 'fieldset',
1738
          '#description' => t(''),
1739
        );
1740

    
1741
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1742
          '#type' => 'checkbox',
1743
          '#title' => t('Enable'),
1744
          '#default_value' => $settings['enabled'],
1745
          '#description' => t('Enable user defined layout for this feature'),
1746
        );
1747

    
1748
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1749
          '#type' => 'textfield',
1750
          '#title' => t('Enclosing tag'),
1751
          '#disabled' => !$settings['enabled'],
1752
          '#default_value' => $settings['enclosingTag'],
1753
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1754
        );
1755

    
1756
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1757
          '#type' => 'textfield',
1758
          '#title' => t('Entry enclosing tag'),
1759
          '#disabled' => !$settings['enabled'],
1760
          '#default_value' => $settings['entryEnclosingTag'],
1761
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1762
        );
1763

    
1764
        $form_feature_list_layout[$subform_id]['glue'] = array(
1765
          '#type' => 'textfield',
1766
          '#title' => t('Glue'),
1767
          '#disabled' => !$settings['enabled'],
1768
          '#default_value' => $settings['glue'],
1769
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1770
        );
1771

    
1772
      }
1773

    
1774
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1775
    }
1776
  }
1777

    
1778
  // ---- DISTRIBUTION LAYOUT ---- //
1779
  $form['taxon_profile']['distribution_layout'] = array(
1780
    '#title' => t('Distribution'),
1781
    '#collapsible' => TRUE,
1782
    '#collapsed' => FALSE,
1783
    '#type' => 'fieldset',
1784
    '#description' => t('Select if you want to sort or not the distribution text
1785
      located below the distribution map.'),
1786
  );
1787

    
1788
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1789
    '#type' => 'radios',
1790
    '#title' => t('Sort') . ':',
1791
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1792
    '#options' => array(
1793
      'NO_SORT' => t('Standard (No sort)'),
1794
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1795
    ),
1796
  );
1797

    
1798
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1799
    '#type' => 'checkbox',
1800
    '#title' => t('Show TextData elements on top of the map'),
1801
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1802
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1803
      elements on top of the map. Otherwise all <code>TextData</code>
1804
      distribution elements will be listed below the other area elements.
1805
      This option is useful if you need to have descriptive texts for each
1806
      distribution map.'),
1807
  );
1808

    
1809
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
1810
      '#type' => 'textarea',
1811
      '#title' => t('Custom status colors'),
1812
      '#element_validate' => array('form_element_validate_json'),
1813
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
1814
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
1815
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
1816
          reference list of the idInVocabulary values of absence and presence terms:
1817
<pre>
1818
Presence Term
1819
p	present
1820
pd	present: doubtfully present
1821
n	native
1822
nq	native: presence questionable
1823
nd	native: doubtfully native
1824
c	cultivated
1825
i	introduced
1826
iq	introduced: presence questionable
1827
id	introduced: doubtfully introduced (perhaps cultivated only)
1828
ip	introduced: uncertain degree of naturalisation
1829
ia	introduced: adventitious (casual)
1830
in	introduced: naturalized
1831
ic	introduced: cultivated
1832
e	endemic for the relevant area
1833
na	naturalised
1834
iv	invasive
1835

    
1836
AbsenceTerm
1837
a	absent
1838
f	reported in error
1839
nf	native: reported in error
1840
if	introduced: reported in error
1841
cf	cultivated: reported in error
1842
ne	native: formerly native
1843
ie	introduced: formerly introduced
1844

    
1845
</pre>'),
1846
  );
1847

    
1848

    
1849
  /* ====== SYNONYMY ====== */
1850
  $form['taxon_synonymy'] = array(
1851
    '#type' => 'fieldset',
1852
    '#title' => t('Taxon synonymy (tab)'),
1853
    '#collapsible' => TRUE,
1854
    '#collapsed' => TRUE,
1855
    '#description' => t('This section covers the settings related to the taxon
1856
      <strong>synonymy</strong> tab.'),
1857
  );
1858

    
1859
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1860
    '#type' => 'checkbox',
1861
    '#title' => t('Show accepted taxon on top of the synonymy'),
1862
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1863
    '#description' => t('If checked, the first homotypic taxon is a repetition
1864
      of the accepted taxon most likely with the full nomenclatural reference
1865
      (depending on the currently chosen theme).'),
1866
  );
1867

    
1868
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1869
    '#type' => 'checkbox',
1870
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1871
      coming from a synonym link.'),
1872
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1873
    '#description' => t('Check this if after doing a search and clicking on a
1874
      synonym you want to see the "accept of" text for the accepted synonym.'),
1875
  );
1876

    
1877
  /* === currently unused ===
1878
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1879
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1880
    '#type' => 'checkboxes',
1881
    '#title' => t('Display name relationships') . ':',
1882
    '#default_value' => variable_get('name_relationships_to_show', 0),
1883
    '#options' => $nameRelationshipTypeOptions,
1884
    '#description' => t('Select the name relationships you want to show for the
1885
      accepted taxa.'),
1886
  );
1887
 */
1888

    
1889
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1890
    '#type' => 'checkbox',
1891
    '#title' => t('Show taxon relations ships of accepted taxon'),
1892
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1893
    '#description' => t('If this option is enabled the synonymy will show the
1894
      below selected taxon relationships of accepted taxa.'),
1895
  );
1896

    
1897
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1898
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1899
    '#type' => 'checkboxes',
1900
    '#title' => t('Taxon relationship types') . ':',
1901
    '#description' => t('Only taxon relationships of the selected type will be
1902
      displayed'),
1903
    '#options' => $taxonRelationshipTypeOptions,
1904
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1905
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1906
  );
1907

    
1908
  // ====== SPECIMENS ====== //
1909
  $form['taxon_specimens'] = array(
1910
    '#type' => 'fieldset',
1911
    '#title' => t('Taxon specimens (tab)'),
1912
    '#collapsible' => TRUE,
1913
    '#collapsed' => TRUE,
1914
    '#description' => t('This section covers the settings related to the taxon
1915
      <strong>specimens</strong> tab.'),
1916
  );
1917

    
1918
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
1919
        '#type' => 'checkbox',
1920
        '#title' => t('Show specimen derivates in a compressed table'),
1921
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
1922
        '#description' => t('If checked, the specimen will be listed in a table. Every row represents
1923
        a FieldUnit and it can be expanded to get an overview of the derived specimens.'),
1924
    );
1925

    
1926
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1927
  $saved_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1928
  if(!isset($featureTrees['options'][$saved_uuid])) {
1929
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1930
  }
1931
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1932
      '#type' => 'radios',
1933
      '#title' => t('Specimen description feature tree') . ':',
1934
      '#default_value' => $saved_uuid,
1935
      '#options' =>  $featureTrees['options'],
1936
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1937
      '#options_suffixes' => $featureTrees['treeRepresentations'],
1938
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1939
      ),
1940
  );
1941

    
1942
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1943
  $form_title = t('Specimen media');
1944
  $form_description = t('Specimens may have media which is displayed at the
1945
     Specimen tab/section as a gallery. It is possible to configure the
1946
     thumbnails gallery here, however for configuring how a single media should
1947
     be displayed please go to !url.</p>',
1948
     array(
1949
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1950
     ));
1951
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1952

    
1953
  // --- MEDIA GALLERY ---- //
1954
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1955
  $form_title = 'Media gallery (tab)';
1956
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1957
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1958
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1959
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1960
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1961
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1962
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1963

    
1964
  // Comment @WA: D7 form api does not support reset buttons,
1965
  // so to mimic the D5 reset button we add one like this.
1966
  $form['actions']['reset'] = array(
1967
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1968
    '#weight' => 1000,
1969
  );
1970
  return system_settings_form($form);
1971
}
1972

    
1973
/**
1974
 * @todo document this function.
1975
 */
1976
function cdm_settings_layout_search() {
1977

    
1978
  $form = array();
1979

    
1980
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
1981

    
1982
  $form['search_settings'] = array(
1983
    '#type' => 'fieldset',
1984
    '#title' => t('Taxa Search'),
1985
    '#collapsible' => FALSE,
1986
    '#collapsed' => FALSE,
1987
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1988
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1989
         where they can write the text to be searched. You can find Drupal block configuration
1990
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1991
  );
1992

    
1993
  $form['search_settings']['simple_search_ignore_classification'] = array(
1994
      '#type' => 'checkbox',
1995
      '#title' => t('Ignore the chosen classification in simple search'),
1996
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
1997
      '#description' => t('The simple search, which can be executed via the search block,
1998
          will by default search on all classifications. Remove the tick if you want your
1999
          portal to search on the classification selected in the classification browser
2000
          selector.'),
2001
  );
2002

    
2003
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2004
    '#type' => 'textfield',
2005
    '#title' => t('Results per page') . ':',
2006
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2007
    '#description' => t('Number of results to display per page.'),
2008
  );
2009

    
2010
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2011
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2012
      '#type' => 'checkboxes',
2013
      '#title' => 'Search mode',
2014
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2015
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2016
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2017
          defaults set here.',
2018
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2019
      '#default_value' => $search_mode_default
2020
      );
2021

    
2022
  // --- SEARCH TAXA GALLERY ---- //
2023
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2024
  $collapsed = FALSE;
2025
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2026
  $form_title = 'Taxa Search thumbnails';
2027
  $form_description = 'Search results may show thumbnails. ';
2028
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2029

    
2030
  // Comment @WA: D7 form api does not support reset buttons,
2031
  // so to mimic the D5 reset button we add one like this.
2032
  $form['actions']['reset'] = array(
2033
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2034
    '#weight' => 1000,
2035
  );
2036
  return system_settings_form($form);
2037
}
2038

    
2039
/**
2040
 * @todo document this function.
2041
 */
2042
function cdm_settings_layout_media() {
2043

    
2044
  $form = array();
2045

    
2046
  $form['media_settings'] = array(
2047
    '#type' => 'fieldset',
2048
    '#title' => t('Media settings'),
2049
    '#collapsible' => FALSE,
2050
    '#collapsed' => FALSE,
2051
    '#description' => 'This section covers layout settings for media pages.'
2052
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2053
  );
2054

    
2055
  $form['media_settings']['image_gallery_viewer'] = array(
2056
    '#type' => 'select',
2057
    '#title' => t('Image viewer') . ':',
2058
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2059
    '#options' => array(
2060
      'default' => t('Standard image viewer'),
2061
      'fsi' => t('FSI viewer (requires FSI server!)'),
2062
    ),
2063
  );
2064

    
2065
  // --- MEDIA GALLERY ---- //
2066
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2067
  $form_title = 'Standard viewer';
2068
  $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>';
2069
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2070
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2071

    
2072
  // @WA: D7 form api does not support reset buttons,
2073
  // so to mimic the D5 reset button we add one like this.
2074
  $form['actions']['reset'] = array(
2075
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2076
    '#weight' => 1000,
2077
  );
2078
  return system_settings_form($form);
2079
}
2080

    
2081
/**
2082
 * GEOSERVICE and Map settings.
2083
 */
2084
function cdm_settings_geo($form, &$form_state) {
2085

    
2086
  $current_geoserver_settings = get_edit_map_service_settings();
2087
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2088
  // The default layer must always be enabled
2089
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2090
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2091

    
2092
  $form = array();
2093

    
2094
  $dummy_distribution_query = NULL;
2095
  if($map_distribution['map_type'] != 1){
2096
    // we need to apply a dummy query since the map serice requires for image maps
2097
    // at least as and ad to be defined
2098
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2099
  }
2100
  $form['map_preview'] = array(
2101
      '#type' => 'fieldset',
2102
      '#tree' => FALSE,
2103
      '#title' => t('Map preview'),
2104
      '#collapsible' => FALSE,
2105
      '#description' => 'The preview of the map'
2106
       . ($dummy_distribution_query != null ?
2107
           ' may not be accurate in case if image maps, please check the map display in the taxon pages.':
2108
           '.<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.')
2109
  );
2110
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL,
2111
      array(
2112
          'move' => "this.cdmOpenlayersMap.printInfo",
2113
          '#execute' => "this.cdmOpenlayersMap.printInfo"
2114
      )
2115
  );
2116

    
2117

    
2118
  /*
2119
   * GEO SERVER
2120
   */
2121
  $form['edit_map_server'] = array(
2122
    '#type' => 'fieldset',
2123
    '#tree' => true,
2124
    '#title' => t('EDIT map service'),
2125
    '#collapsible' => TRUE,
2126
    '#collapsed' => TRUE,
2127
    '#description' => t('Configuration and selection of your geo server.
2128
      The Geo Server is responsible for generating the maps.'),
2129
  );
2130

    
2131
  $form['edit_map_server']['base_uri'] = array(
2132
    '#type' => 'select',
2133
    '#title' => t('EDIT map service') . ':',
2134
    '#default_value' => $current_geoserver_settings['base_uri'],
2135
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2136
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2137
  );
2138
  $form['edit_map_server']['version'] = array(
2139
      '#type' => 'select',
2140
      '#title' => t('Version') . ':',
2141
      '#default_value' => $current_geoserver_settings['version'],
2142
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2143
      '#description' => t('The version of the EDIT map services'),
2144
  );
2145

    
2146
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
2147
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
2148
  $form['gmap_api_key'] = array(
2149
      '#type' => 'textfield',
2150
      '#title' => t('Google maps API key') . ':',
2151
      '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
2152
      '#description' => t('If you want to use the Google Maps Layer, a key is
2153
      needed. If you need a key, visit
2154
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
2155
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
2156
      is the default key for the localhost (127.0.0.1).',
2157
      array('!localhostkey' => $localhostkey)),
2158
  );
2159

    
2160

    
2161
  /*
2162
   * MAP SETTINGS
2163
   */
2164

    
2165
  $form[CDM_MAP_DISTRIBUTION] = array(
2166
    '#type' => 'fieldset',
2167
    '#tree' => TRUE,
2168
    '#title' => t('Maps settings'),
2169
    '#collapsible' => TRUE,
2170
    '#collapsed' => TRUE,
2171
    '#description' => t('General configuration for all map types.'),
2172
  );
2173

    
2174
  /*
2175
   * settings for the distribution map are used also for specimens map!!!!
2176
   */
2177

    
2178
  $form[CDM_MAP_DISTRIBUTION]['width'] = array(
2179
    '#type' => 'textfield',
2180
    '#title' => 'Width',
2181
    '#default_value' => $map_distribution['width'],
2182
    '#maxlength' => 4,
2183
    '#size' => 4,
2184
    '#description' => 'Width of the map. To allow OSM baselayers to zoom out to the full extend of the world the map width must be
2185
      a multiple of 256px since the osm tiles from tile.openstreetmap.org have a size of 256px x 256px and frational zoom
2186
      levels are not possible in this case.',
2187
  );
2188
  $form[CDM_MAP_DISTRIBUTION]['height'] = array(
2189
      '#type' => 'textfield',
2190
      '#title' => 'Height',
2191
      '#default_value' => $map_distribution['height'],
2192
      '#maxlength' => 4,
2193
      '#size' => 4,
2194
      '#description' => 'Height of the map. Depending on the chosen base layer you may want to choose the height equal
2195
      to the width or half of the width. Any other aspect ratio is also possible if desired.',
2196
  );
2197

    
2198
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2199
    '#type' => 'textfield',
2200
    '#title' => 'Bounding box',
2201
    '#default_value' => $map_distribution['bbox'],
2202
    '#description' => t('The bounding box (left, bottom, right, top) defines the area to be initially displayed in maps.
2203
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2204
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2205
      <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.
2206
      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
2207
      below the map from where you can copy the bbox string.</p>'),
2208
  );
2209

    
2210
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2211
    '#type' => 'checkbox',
2212
    '#title' => 'Display area labels',
2213
    '#default_value' => $map_distribution['show_labels'],
2214
    '#description' => t('The map will show name labels of the areas'),
2215
  );
2216

    
2217
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2218
    '#type' => 'textfield',
2219
    '#title' => 'Map caption',
2220
    '#default_value' => $map_distribution['caption'],
2221
    '#description' => t('The caption will be shown below the map.'),
2222
  );
2223

    
2224
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2225
    '#type' => 'textfield',
2226
    '#title' => 'Distribution layer opacity',
2227
    '#default_value' => $map_distribution['distribution_opacity'],
2228
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
2229
                           fully visible, while a value near to 0.0 will be not much visible.'),
2230
  );
2231

    
2232
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2233
    '#type' => 'radios',
2234
    '#title' => 'Map types',
2235
    '#options' => array(
2236
      1 => "OpenLayers dynamic map viewer",
2237
      0 => "Plain image",
2238
    ),
2239
    '#default_value' => $map_distribution['map_type'],
2240
    '#description' => 'Two different map types are available :
2241
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2242
      which allows zooming and panning. If enabled you can configure the default layer
2243
      (background of your maps) below.</li>
2244
      <li><em>Plain image</em>: The map will be static non interactive
2245
      image.</li></ul>',
2246
  );
2247
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2248

    
2249

    
2250
  // --- Plain Image Settings --- //
2251
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2252
    '#type' => 'fieldset',
2253
    '#title' => 'Plain image map settings',
2254
    '#tree' => TRUE,
2255
    '#collapsible' => TRUE,
2256
    '#collapsed' => $open_layers_is_enabled,
2257
    '#description' => 'The settings in this section are still expertimental
2258
      and can only be used with the EDIT map service version 1.1 or above.',
2259
  );
2260
  $edit_mapserver_version = get_edit_map_service_version_number();
2261
  if ($edit_mapserver_version < 1.1) {
2262
    $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>'
2263
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2264
  }
2265

    
2266
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2267
    '#type' => 'textfield',
2268
    '#title' => 'Background layer',
2269
    '#default_value' => $map_distribution['image_map']['base_layer'],
2270
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2271
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2272
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2273
    )),
2274
  );
2275

    
2276
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2277
    '#type' => 'textfield',
2278
    '#title' => 'Background color',
2279
    '#default_value' => $map_distribution['image_map']['bg_color'],
2280
  );
2281

    
2282
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2283
    '#type' => 'textfield',
2284
    '#title' => 'Background layer style',
2285
     // Only line color by now.
2286
    '#default_value' => $map_distribution['image_map']['layer_style'],
2287
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2288
  );
2289

    
2290
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2291
      '#type' => 'textfield',
2292
      '#title' => 'Projection',
2293
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2294
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2295
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2296
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2297
  );
2298

    
2299

    
2300
  // --- OpenLayers Settings --- //
2301
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2302
    '#type' => 'fieldset',
2303
    '#title' => 'OpenLayers settings',
2304
    '#tree' => TRUE,
2305
    '#collapsible' => TRUE,
2306
    '#collapsed' => !$open_layers_is_enabled,
2307
    '#description' => '',
2308
  );
2309

    
2310

    
2311
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2312
      '#type' => 'checkbox',
2313
      '#title' => 'Display outside max extent',
2314
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2315
      '#description' => t('Allows the map to display parts of the layers which are outside
2316
         the max extent if the aspect ratio of the map and of the baselayer
2317
         are not equal.'),
2318
  );
2319

    
2320

    
2321
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2322
      '#type' => 'checkbox',
2323
      '#title' => 'Show Layer Switcher',
2324
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2325
      '#description' => 'The Layer Switcher control displays a table of contents
2326
      for the map.  This allows the user interface to switch between
2327
      base layers and to show or hide overlays.  By default the switcher is
2328
      shown minimized on the right edge of the map, the user may expand it
2329
      by clicking on the handle.',
2330
  );
2331

    
2332
  if (!$open_layers_is_enabled) {
2333
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2334
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2335
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2336
  }
2337

    
2338
  $baselayer_options = array(
2339
    /*
2340
   NOTICE: must correspond to the layers defined in
2341
   js/openlayers_,ap.js#getLayersByName()
2342
   */
2343
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
2344
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
2345
    // all others EPSG:900913
2346
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
2347
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2348
    'mapnik' => 'OpenStreetMap',
2349
    'mapquest_open' => "MapQuest",
2350
    'mapquest_sat' => "MapQuest Sattelite",
2351
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2352
    'gmap' => 'Google Streets',
2353
    'gsat' => 'Google Satellite',
2354
    'ghyb' => 'Google Hybrid',
2355
//     'veroad' => 'Virtual Earth Roads',
2356
//     'veaer' => 'Virtual Earth Aerial',
2357
//     'vehyb' => 'Virtual Earth Hybrid',
2358
    // 'yahoo' => 'Yahoo Street',
2359
    // 'yahoosat' => 'Yahoo Satellite',
2360
    // 'yahoohyb' => 'Yahoo Hybrid',
2361
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2362
  );
2363

    
2364
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2365
    '#type' => 'checkboxes_preferred',
2366
    '#title' => 'Base Layers',
2367
    '#options' => $baselayer_options,
2368
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2369
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2370
  );
2371

    
2372
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2373
      '#type' => 'fieldset',
2374
      '#title' => 'Custom WMS base layer',
2375
      '#tree' => TRUE,
2376
      '#collapsible' => FALSE,
2377
      '#collapsed' => FALSE,
2378
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2379
  );
2380

    
2381
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2382
      '#type' => 'textfield',
2383
      '#title' => 'Layer name',
2384
      // Only line color by now.
2385
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2386
      '#description' => 'A arbitrary name for the layer.',
2387
  );
2388
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2389
      '#type' => 'textfield',
2390
      '#title' => 'WMS url',
2391
      // Only line color by now.
2392
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2393
      '#description' => 'Base url for the WMS (e.g.  http://wms.jpl.nasa.gov/wms.cgi)'
2394
  );
2395
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2396
      '#type' => 'textarea',
2397
      '#title' => 'WMS parameters',
2398
      '#element_validate' => array('form_element_validate_json'),
2399
      // Only line color by now.
2400
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2401
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2402
<pre> {
2403
  "Layers": "topp:em_tiny_jan2003",
2404
  "Format": "image/png",
2405
  "BGCOLOR": "0xe0faff"
2406
}
2407
</pre>'
2408
  );
2409
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2410
      '#type' => 'textfield',
2411
      '#title' => 'Projection',
2412
      // Only line color by now.
2413
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2414
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2415
  );
2416
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2417
      '#type' => 'textfield',
2418
      '#maxlength' => 256,
2419
      '#title' => 'proj4js definition',
2420
      // Only line color by now.
2421
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2422
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2423
            The definitions for
2424
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2425
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2426
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2427
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2428
            choose to display the proj4js definition string.
2429
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2430
            <pre>
2431
+a         Semimajor radius of the ellipsoid axis
2432
+alpha     ? Used with Oblique Mercator and possibly a few others
2433
+axis      Axis orientation (new in 4.8.0)
2434
+b         Semiminor radius of the ellipsoid axis
2435
+datum     Datum name (see `proj -ld`)
2436
+ellps     Ellipsoid name (see `proj -le`)
2437
+k         Scaling factor (old name)
2438
+k_0       Scaling factor (new name)
2439
+lat_0     Latitude of origin
2440
+lat_1     Latitude of first standard parallel
2441
+lat_2     Latitude of second standard parallel
2442
+lat_ts    Latitude of true scale
2443
+lon_0     Central meridian
2444
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
2445
+lon_wrap  Center longitude to use for wrapping (see below)
2446
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
2447
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
2448
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
2449
+pm        Alternate prime meridian (typically a city name, see below)
2450
+proj      Projection name (see `proj -l`)
2451
+south     Denotes southern hemisphere UTM zone
2452
+to_meter  Multiplier to convert map units to 1.0m
2453
+towgs84   3 or 7 term datum transform parameters (see below)
2454
+units     meters, US survey feet, etc.
2455
+vto_meter vertical conversion to meters.
2456
+vunits    vertical units.
2457
+x_0       False easting
2458
+y_0       False northing
2459
+zone      UTM zone
2460
            </pre>
2461
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
2462
  );
2463
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
2464
      '#type' => 'textfield',
2465
      '#title' => 'Maximum extent',
2466
      // Only line color by now.
2467
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
2468
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
2469
  );
2470
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
2471
      '#type' => 'textfield',
2472
      '#title' => 'Units',
2473
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
2474
      '#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.'
2475
  );
2476

    
2477
  /*
2478
   * Map Legend
2479
   */
2480
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2481
    '#type' => 'fieldset',
2482
    '#title' => 'Map legend',
2483
    '#tree' => TRUE,
2484
    '#collapsible' => TRUE,
2485
    '#collapsed' => TRUE,
2486
    '#description' => 'Configure the maps legend.',
2487
  );
2488

    
2489
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2490
    '#type' => 'checkbox',
2491
    '#title' => 'Display a map legend',
2492
    '#default_value' => $map_distribution['legend']['show'],
2493
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2494
  );
2495

    
2496
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2497
    '#type' => 'textfield',
2498
    '#title' => 'Legend opacity',
2499
    '#default_value' => $map_distribution['legend']['opacity'],
2500
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2501
                         to 0.0 will be not much visible.',
2502
  );
2503

    
2504
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2505
    '#type' => 'textfield',
2506
    '#title' => 'Font size',
2507
    '#default_value' => $map_distribution['legend']['font_size'],
2508
    '#description' => 'Font size in pixels.',
2509
  );
2510

    
2511
  $fontStyles = array(
2512
    0 => "plane",
2513
    1 => "italic",
2514
  );
2515
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2516
    '#type' => 'select',
2517
    '#title' => 'Available font styles',
2518
    '#default_value' => $map_distribution['legend']['font_style'],
2519
    '#options' => $fontStyles,
2520
    '#description' => 'Select a font style for the map legend.',
2521
  );
2522

    
2523
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2524
    '#type' => 'textfield',
2525
    '#title' => 'Icon width',
2526
    '#default_value' => $map_distribution['legend']['icon_width'],
2527
    '#description' => 'Legend icon width in pixels.',
2528
  );
2529
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2530
    '#type' => 'textfield',
2531
    '#title' => 'Icon height',
2532
    '#default_value' => $map_distribution['legend']['icon_height'],
2533
    '#description' => 'Legend icon height in pixels.',
2534
  );
2535

    
2536
  // @WA: D7 form api does not support reset buttons,
2537
  // so to mimic the D5 reset button we add one like this.
2538
  $form['actions']['reset'] = array(
2539
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2540
    '#weight' => 1000,
2541
  );
2542

    
2543
  return system_settings_form($form);
2544
}
2545

    
2546
/**
2547
 * @todo document this function.
2548
 */
2549
function cdm_settings_cache() {
2550

    
2551
  $form = array();
2552

    
2553
  $form['cache_settings'] = array(
2554
    '#type' => 'fieldset',
2555
    '#title' => t('Cache Settings'),
2556
    '#collapsible' => FALSE,
2557
    '#collapsed' => FALSE,
2558
    '#description' => t('<p>When caching is enabled all single taxon sites are
2559
      stored in an internal drupal cache doing the portal response of taxa pages
2560
      faster. This is possible because the sites are loaded from the cache and
2561
      are not created from scratch.</p>'),
2562
  );
2563

    
2564
  $form['cache_settings']['cdm_webservice_cache'] = array(
2565
    '#type' => 'checkbox',
2566
    '#title' => t('<strong>Enable caching</strong>'),
2567
    '#options' => cdm_help_general_cache(),
2568
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2569
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2570
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2571
       application the changes will be not visible till the cache is erased.
2572
       Therefore developers should deactived this feature when they are working
2573
       on the CDM Dataportal Module.</p>'),
2574
  );
2575

    
2576
  $form['cache_settings']['cdm_run_cache'] = array(
2577
    '#markup' => cdm_view_cache_site(),
2578
  );
2579

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

    
2589
/**
2590
 * Walk and cache all taxon pages.
2591
 */
2592
function cdm_view_cache_site() {
2593

    
2594
  $out = '';
2595

    
2596
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2597

    
2598
  $request_params = array();
2599
  $request_params['class'] = "Taxon";
2600

    
2601
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2602
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2603
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2604

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

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

    
2614
  // Comment @WA: A form within a form is not valid html and not needed here.
2615
  // Also, it would be recommended just to include this part of the form in the
2616
  // rest of the form array in cdm_settings_cache().
2617
  // $out .= '<form id="cache_site">';
2618
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2619
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2620
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2621
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2622
  // $out .= '</form>';
2623
  $out .= '</div>';
2624
  /*
2625
  foreach($taxonPager->records as $taxon){
2626
    cdm_dataportal_taxon_view($uuid);
2627
  }
2628
  */
2629
  return $out;
2630
}
2631

    
2632

    
2633
function cdm_settings_layout_taxon_submit($form, &$form_state){
2634
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2635
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2636
    if(is_object($file)){
2637
      $file->status = FILE_STATUS_PERMANENT;
2638
      file_save($file);
2639
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2640
    }
2641
  }
2642
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2643
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2644
    // we first need to set the variable to persist the changes setting
2645
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
2646
    menu_rebuild();
2647
  }
2648
}
2649

    
2650
function cdm_settings_layout_search_submit($form, &$form_state){
2651
  // the visibility of media thumbnails also affects the ui of the search results
2652
  // so reset the according session variable
2653
  //    1. in order to give the user immediate
2654
  //       feedback on potential setting changes
2655
  //    2. let refresh the default if it has changed
2656
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2657
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
2658
  }
2659
}
2660

    
2661
/**
2662
 * Form validation handler for cdm_settings_general
2663
 *
2664
 * @param $form
2665
 * @param $form_state
2666
 */
2667
function cdm_settings_general_validate($form, &$form_state) {
2668

    
2669
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2670
    $form_state['values']['cdm_webservice_url'] .= '/';
2671
  }
2672

    
2673
}
2674

    
2675
/**
2676
 * Form submit handler for settings general.
2677
 *
2678
 * tasks performed:
2679
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2680
 *
2681
 * @param $form
2682
 * @param $form_state
2683
 */
2684
function cdm_settings_general_submit($form, &$form_state){
2685
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2686
  unset($_SESSION['cdm']['taxonomictree_uuid']);
2687
}
2688

    
2689
/**
2690
 * Form validation handler for cdm_settings_cache
2691
 */
2692
function cdm_settings_cache_validate($form, &$form_state) {
2693
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2694
    cache_clear_all(NULL, 'cache_cdm_ws');
2695
    // Better clear secref_cache since I can not be sure if the cache has not
2696
    // be used during this response.
2697
    cdm_api_secref_cache_clear();
2698
  }
2699

    
2700
}
2701

    
2702
/**
2703
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
2704
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
2705
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
2706
 *  - version: the version, e.g.: v1.1
2707
 *
2708
 * @return array
2709
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
2710
 */
2711
function get_edit_map_service_settings() {
2712

    
2713
  $settings = variable_get('edit_map_server', array(
2714
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
2715
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
2716
      )
2717
  );
2718

    
2719
  return $settings;
2720
}
2721

    
2722
/**
2723
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2724
 *
2725
 * @return string
2726
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2727
 */
2728
function get_edit_map_service_full_uri() {
2729
  $settings = get_edit_map_service_settings();
2730
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
2731
}
2732

    
2733

    
2734
/**
2735
 * Returns the version number of the currently selected edit mapserver as a float
2736
 *
2737
 * @return float
2738
 *   The version number of the currently selected edit mapserver as a float.
2739
 *   Returns 0 on error.
2740
 */
2741
function get_edit_map_service_version_number() {
2742

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

    
2745
  $settings = get_edit_map_service_settings();
2746
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
2747
  if (isset($matches[1])) {
2748
    // Convert string to float.
2749
    $version = 1 + $matches[1][0] - 1;
2750
    return $version;
2751
  }
2752
  else {
2753
    // Report error.
2754
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
2755
        array(
2756
          '!version' => $settings['version'],
2757
          'warning')
2758
        )
2759
      );
2760
    return 0;
2761
  }
2762
}
2763

    
2764
/**
2765
 * Returns the array of selected items in a options array
2766
 *
2767
 * @param array $options
2768
 *   An options array as generated by a form element like checkoxes, select ...,
2769
 */
2770
function get_selection($options) {
2771
  $selection = array();
2772
  foreach ($options as $key=>$val) {
2773
    if (!empty($val)) {
2774
      $selection[] = $val;
2775
    }
2776
  }
2777
  return $selection;
2778
}
2779

    
2780

    
2781
/**
2782
 * Implements hook_element_info().
2783
 *
2784
 * Allows modules to declare their own Form API element types and specify their default values.
2785
 *
2786
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
2787
 */
2788
function cdm_dataportal_element_info() {
2789
  $type['checkboxes_preferred'] = array(
2790
    '#input' => TRUE,
2791
    '#process' => array('checkboxes_preferred_expand'),
2792
    '#after_build' => array('checkboxes_preferred_after_build'),
2793
    '#theme' => array('checkboxes_preferred'),
2794
    // '#theme_wrapper' => array('form_element'),
2795
  );
2796
  return $type;
2797
}
2798

    
2799
/**
2800
 * #process callback function for the custom form element type 'checkbox_preferred'
2801
 *
2802
 *
2803
 */
2804
function checkboxes_preferred_expand($element, &$form_state, $form) {
2805

    
2806
  // First of all create checkboxes for each of the elements
2807
  $element = form_process_checkboxes($element);
2808

    
2809
  // compose the element name
2810
  $parents = array();
2811
  array_deep_copy($element['#parents'], $parents);
2812
  $parents[count($parents) -1 ] .= '_preferred';
2813
  $element_name = $parents[0];
2814
  for ($i=1; $i < count($parents); $i++){
2815
    $element_name .= '[' . $parents[$i] . ']';
2816
  }
2817

    
2818
  $children = element_children($element);
2819

    
2820
  $element['table_start'] = array(
2821
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
2822
    '#weight' => -1,
2823
  );
2824

    
2825
  // prepare first part each of the table rows which contains the row label
2826
  $weight = 0;
2827
  foreach ($children as $key) {
2828
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
2829
    $element[$key]['#weight'] = $weight;
2830
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
2831
    $element[$key]['#suffix'] = '</td>';
2832
    unset($element[$key]['#title']);
2833
    $weight += 2;
2834
  }
2835
  $weight = 0;
2836

    
2837
  // add a radio button to each of the checkboxes, the
2838
  // check boxes have already been created at the beginning
2839
  // of this function
2840
  if (count($element['#options']) > 0) {
2841
    foreach ($element['#options'] as $key => $choice) {
2842
      if (!isset($element[$key . '_preferred'])) {
2843
        $element[$key . '_preferred'] = array(
2844
          '#type' => 'radio',
2845
          '#name' => $element_name,
2846
          '#return_value' => check_plain($key),
2847
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
2848
          '#attributes' => $element['#attributes'],
2849
          '#parents' => $element['#parents'],
2850
          // '#spawned' => TRUE,
2851
          '#weight' => $weight + 1,
2852
          '#prefix' => '<td>',        // add a prefix to start a new table cell
2853
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
2854
        );
2855
      }
2856
      $weight += 2;
2857
    }
2858
  }
2859

    
2860
  // end the table
2861
  $element['table_end'] = array(
2862
    '#markup' => '</table>',
2863
    '#weight' => $weight++,
2864
  );
2865

    
2866
  return $element;
2867
}
2868

    
2869
/**
2870
 * Theme function for the custom form field 'checkboxes_preferred'.
2871
 */
2872
function theme_checkboxes_preferred($variables) {
2873
  $element = $variables['element'];
2874
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
2875
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
2876
  $out .= drupal_render_children($element);
2877
  $out .= '<div class="description">' . $element['#description'] . '</div>';
2878
  $out .= '</div>';
2879
  return $out;
2880
}
2881

    
2882
/**
2883
 * Callback for checkboxes preferred for widget which will
2884
 * be called after the form or element is built. The call
2885
 * back is configured in the form element by setting it as
2886
 * #after_build parameter.
2887
 *
2888
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
2889
 *
2890
 * @param $element
2891
 *   Nested array of form elements that comprise the form.
2892
 * @param $form_state
2893
 *   A keyed array containing the current state of the form.
2894
 *   This includes the current persistent storage data for the form.
2895
 *   Additional information, like the sanitized $_POST data,
2896
 *   is also accumulated here in $form_state['input']
2897
 *
2898
 * @return the modified form array
2899
 */
2900
function checkboxes_preferred_after_build($element, &$form_state) {
2901

    
2902
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
2903

    
2904
  if ($_POST && count($_POST) > 0) {
2905
    // TODO use  $form_state['input'] instead of POST !!!
2906
    // First pass of form processing.
2907
    $parents = array();
2908
    array_deep_copy($element['#parents'], $parents);
2909
    $parents[count($parents) - 1] .= '_preferred';
2910
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
2911
    $element['#value']['PREFERRED'] = $preferred_layer;
2912
//     $form_state[$parent_id] = $element['#value'];
2913
//     $form_state['values']['baselayers'] = $element['#value'];
2914
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
2915
    $form_state_element_values = $element['#value'];
2916
  }
2917
  else {
2918
    // Second pass of form processing.
2919
    $preferred_layer = $element['#value']['PREFERRED'];
2920
  }
2921

    
2922
  // Also set the chosen value (not sure if this is good Drupal style ....).
2923
  foreach ($children = element_children($element) as $key) {
2924
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
2925
      $element[$key]['#value'] = $preferred_layer;
2926
    }
2927
  }
2928
  // The default layer must always be enabled.
2929
  $element[$preferred_layer]['#value'] = $preferred_layer;
2930

    
2931
  return $element;
2932
}
2933

    
2934
function radios_prepare_options_suffix(&$elements){
2935

    
2936
  $childrenKeys = element_children($elements);
2937
  foreach($childrenKeys as $key){
2938
    if(!is_array($elements[$key]['#theme_wrappers'])){
2939
      $elements[$key]['#theme_wrappers'] = array();
2940
    }
2941
    if(isset($elements['#options_suffixes'][$key])){
2942
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
2943
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
2944
    }
2945
  }
2946
  return $elements;
2947

    
2948
}
2949

    
2950
/**
2951
 * TODO
2952
 * @param unknown $variables
2953
 */
2954
function theme_radio_options_suffix($variables) {
2955
  $element = $variables['element'];
2956
  if(isset($element['#options_suffix'])) {
2957
    $element['#children'] .= $element['#options_suffix'];
2958
  }
2959
  return $element['#children'];
2960
}
2961

    
2962

    
2963
/**
2964
 * Element validate callback for text field and arrays containing json.
2965
 *
2966
 * @param $element
2967
 *   The form element to validate
2968
 * @param $form_state
2969
 *   A keyed array containing the current state of the form.
2970
 * @param $form
2971
 *   Nested array of form elements that comprise the form.
2972
 */
2973
function form_element_validate_json($element, &$form_state, $form) {
2974
   if (!empty($element['#value'])) {
2975
     json_decode($element['#value']);
2976
     if(json_last_error() != JSON_ERROR_NONE){
2977
       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/'));
2978
     }
2979
   }
2980
}
2981

    
2982
/**
2983
 * Form submission handler for textareas and textfields containing JSON.
2984
 *
2985
 * The contained JSON will be converted into an php array
2986
 * or object and will be stored in the variables as such.
2987
 *
2988
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2989
 *
2990
 * @param $form
2991
 *   Nested array of form elements that comprise the form.
2992
 * @param $form_state
2993
 *   A keyed array containing the current state of the form.
2994
 *
2995
 */
2996
function submit_json_as_php_array($form, &$form_state) {
2997
  if (is_array($form['#json_elements'])) {
2998
    foreach ($form['#json_elements'] as $element){
2999
      if (trim($form_state['values'][$element])) {
3000
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3001
      } else {
3002
        $form_state['values'][$element] = NULL;
3003
      }
3004
    }
3005
  }
3006
}
(14-14/14)