Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / settings.php @ f695daf4

History | View | Annotate | Download (137 KB)

1
<?php
2
/**
3
 * @file
4
 * CDM Dataportal settings.
5
 */
6

    
7

    
8
  // TODO Genus UUID.
9

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

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

    
17
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
18

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

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

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

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

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

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

    
52

    
53

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

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

    
100

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

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

    
109

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

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

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

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

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

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

    
156
}
157

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

    
249
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
250
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
251
  array (
252
    'taxon_page_title,polytomousKey'=> array(
253
        'namePart' => array('#uri' => TRUE),
254
      ),
255
    'not_in_current_classification' => array(
256
     'nameAuthorPart' => TRUE,
257
     'referencePart' => TRUE,
258
     'statusPart' => TRUE,
259
     'secReferencePart' => TRUE,
260
    ),
261
    'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy'=> array(
262
      'nameAuthorPart' => array('#uri' => TRUE),
263
      'referencePart' => TRUE,
264
      'statusPart' => TRUE,
265
      'descriptionPart' => TRUE,
266
    ),
267
    'related_taxon'=> array(
268
      'nameAuthorPart' => array('#uri' => TRUE),
269
      'referencePart' => TRUE,
270
      'statusPart' => TRUE,
271
      'secReferencePart' => TRUE,
272
      'descriptionPart' => TRUE,
273
    ),
274
    'homonym'=> array(
275
        'nameAuthorPart' => array('#uri' => TRUE),
276
        'referenceYearPart' => TRUE,
277
    ),
278
    'acceptedFor,typedesignations,list_of_taxa' => array(
279
        'nameAuthorPart' => array('#uri' => TRUE),
280
        'referencePart' => TRUE,
281
      ),
282
    '#DEFAULT' => array(
283
        'nameAuthorPart' => array('#uri' => TRUE),
284
        'referencePart' => TRUE,
285
     )
286
  )
287
));
288
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
289
  array (
290
    'taxon_page_title,polytomousKey'=> array(
291
      'namePart' => array('#uri' => TRUE),
292
    ),
293
    'taxon_page_synonymy,related_taxon'=> array(
294
      'nameAuthorPart' => array('#uri' => TRUE),
295
      'referencePart' => TRUE,
296
      'statusPart' => TRUE,
297
      'descriptionPart' => TRUE,
298
    ),
299
    'homonym'=> array(
300
      'nameAuthorPart' => array('#uri' => TRUE),
301
      'referenceYearPart' => TRUE,
302
    ),
303
    'acceptedFor,typedesignations,list_of_taxa' => array(
304
      'nameAuthorPart' => array('#uri' => TRUE),
305
      'referencePart' => TRUE,
306
    ),
307
    '#DEFAULT' => array(
308
      'nameAuthorPart' => array('#uri' => TRUE),
309
      'referencePart' => TRUE,
310
    )
311
  )
312
));
313

    
314
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
315
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
316
    // to unset a default enntry set the value to 0
317
    array(
318
      'doTaxa'=>'doTaxa',
319
      'doSynonyms' => 'doSynonyms',
320
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
321
      'doMisappliedNames' => 'doMisappliedNames'
322
    )
323
  )
324
);
325

    
326
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
327
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
328

    
329
/* Gallery variables. */
330
$gallery_settings = array(
331
    "cdm_dataportal_show_taxon_thumbnails" => 1,
332
    "cdm_dataportal_show_synonym_thumbnails" => 0,
333
    "cdm_dataportal_show_thumbnail_captions" => 1,
334
    "cdm_dataportal_media_maxextend" => 120,
335
    "cdm_dataportal_media_cols" => 3,
336
    "cdm_dataportal_media_maxRows" => 1,
337
);
338

    
339
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
340
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
341
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
342
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
343
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
344
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
345
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
346
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
347
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
348
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
349
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
350
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
351
/**
352
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
353
 * the snonymy.
354
 *
355
 * @var string
356
 */
357
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
358
/**
359
 * The drupal variable for the configuration of the information aggregation along
360
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
361
 *    - direct: the uuids of the taxon relationship types to take into account in invers
362
 *      direction.
363
 *    - invers: the uuids of the taxon relationship types to take into account in direct
364
 *      direction.
365
 *
366
 * @var String
367
 */
368
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
369
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
370
    array(
371
        'direct'=>array(),
372
        'invers'=>array()
373
     )
374
   ));
375
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
376
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
377
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
378

    
379
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
380
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
381
      array(
382
      'filter_rules' => array(
383
        'statusOrderPreference' => 0,
384
        'subAreaPreference' => 0,
385
      ),
386
      'hiddenAreaMarkerType' => array()
387
     )
388
));
389

    
390

    
391
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
392
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
393
    array(
394
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
395
        'includeOccurrences' => 0,
396
        'includeTaxonNameDescriptions' => 0
397
     )
398
  ));
399

    
400
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
401
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
402
  // needs to be merged with user setting by drupal_array_merge_deep()
403
  // 'width' => 512, // optimum size for OSM layers is 512
404
  // 'height' => 512 / 2, // optimum size for OSM layers 256
405
  'aspect_ratio' => 2,
406
  'bbox' => '', // empty to allow automatic zooming to extend
407
  'show_labels' => FALSE,
408
  'caption' => '',
409
  'distribution_opacity' => '0.5',
410
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
411
  'image_map' => array(
412
    'base_layer' => '', // none, formerly this was cyprusdivs
413
    'bg_color' => '1874CD',
414
    'layer_style' => 'ffffff,606060,,',
415
  ),
416
  'openlayers' => array(
417
    'base_layers' =>  array(
418
      // A layer MUST NOT BE SET in the defaults,
419
      // otherwise it can not be overidden by the user settings:
420
      // 'osgeo_vmap0' => 'osgeo_vmap0',
421
      // it is sufficient to define the preferred layer,
422
      // since it will automatically be enabled:
423
      'PREFERRED' => 'osgeo_vmap0'),
424
    'custom_wms_base_layer' => array(
425
      'name' => NULL,
426
      'url' => NULL,
427
      'params' =>  NULL,
428
      'projection' => NULL,
429
      'proj4js_def' => NULL,
430
      'max_extent' => NULL,
431
      'units' => NULL
432
    ),
433
    'show_layer_switcher' => TRUE,
434
    'display_outside_max_extent' => FALSE
435
  ),
436
  'legend' => array(
437
    'show' => TRUE,
438
    'opacity' => '0.5',
439
    'font_size' => 10,
440
    'font_style' => FALSE,
441
    'icon_width' => 35,
442
    'icon_height' => 15
443
  )
444
)));
445

    
446
/**
447
 * Merges the named array variable with the array of defaults.
448
 *
449
 * IMPORTANT: The array keys must be strings. When the keys are integers
450
 * the merging will not take place for these entities. Number keyed entities
451
 * are just appended to the result array.
452
 *
453
 * @param string $variable_name
454
 *     The variable name
455
 * @param string | array $default
456
 *     The array containing the default values either as array or serialized as string.
457
 *     Unserialization is cared for if necessary
458
 * @return array
459
 *     The merged array as returned by drupal_array_merge_deep()
460
 *
461
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
462
 * TODO force $default being an array
463
 */
464
function get_array_variable_merged($variable_name, $default){
465

    
466
    // unserialize if nessecary
467
    if(!is_array($default)){
468
      $default = unserialize($default);
469
    }
470
    $variable = variable_get($variable_name, array());
471
    $result = drupal_array_merge_deep($default, $variable);
472
    return $result;
473
}
474

    
475
/**
476
 * @todo document this function.
477
 */
478
function getGallerySettings($gallery_config_form_name) {
479
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
480
}
481

    
482
/**
483
 * Returns the string representation of the default tab.
484
 *
485
 * @param bool $returnTabIndex
486
 *   Defaults to FALSE, if set true this function will return the index number
487
 *   of the default tab. (used to supply default values to form elements).
488
 */
489
function get_default_taxon_tab($returnTabIndex = FALSE) {
490

    
491
  global $user;
492
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
493
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
494
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
495
  // Get the user value if the used has chosen to overwrite the system settings.
496
  $user_tab_on = variable_get($user_tab_active, FALSE);
497
  if ($user_tab_on) {
498
    $user_value = variable_get($user_tab, 0);
499
    $index_value = $user_value;
500
    // Get the system value.
501
  }
502
  else {
503
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
504
    $index_value = $system_value;
505
  }
506

    
507
  // Return the index value or the string representation.
508
  if ($returnTabIndex) {
509
    return $index_value;
510
  }
511
  else {
512
    return ($values[$index_value]);
513
  }
514
}
515

    
516

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

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

    
588
    // ---- DEFAULTS settings
589

    
590
    // only needed as final option, when the settings are not having a default
591
    $default = array(
592
      'DEFAULT' => array(
593
        'as_list' => 'div',
594
        'link_to_reference' => 0,
595
        'link_to_name_used_in_source' => 1,
596
        'sources_as_content' => 0,
597
        'sources_as_content_to_bibliography' => 0,
598
        'sort_elements' => NO_SORT,
599
        'glue' => '',
600
        'element_tag' => NULL
601
      )
602
    );
603

    
604
    // will be used as preset in the settings
605
    $other_themes_default = array(
606
      'DEFAULT' => array(
607
        'as_list' => 'div',
608
        'link_to_reference' => 0,
609
        'link_to_name_used_in_source' => 1,
610
        'sources_as_content' => 0,
611
        'sources_as_content_to_bibliography' => 0,
612
        'sort_elements' => NO_SORT,
613
        'glue' => '',
614
        'element_tag' => NULL
615
      ),
616
      UUID_CITATION => array(
617
        'as_list' => 'div',
618
        'link_to_reference' => 0,
619
        'link_to_name_used_in_source' => 0,
620
        'sources_as_content' => 1,
621
        'sources_as_content_to_bibliography' => 0,
622
        'sort_elements' => SORT_ASC,
623
        'glue' => '',
624
        'element_tag' => 'div'
625
      ),
626
      UUID_DISTRIBUTION => array(
627
        'as_list' => 'div', // currently ignored
628
        'link_to_reference' => 0,
629
        'link_to_name_used_in_source' => 0,
630
        'sources_as_content' => 0,
631
        'sources_as_content_to_bibliography' => 0,
632
        'sort_elements' => NO_SORT, // will cause ...
633
        'glue' => '',
634
        'element_tag' => 'div',
635
        'special' => array()
636
      ),
637
      UUID_COMMON_NAME => array(
638
        'as_list' => 'div',
639
        'link_to_reference' => 0,
640
        'link_to_name_used_in_source' => 1,
641
        'sources_as_content' => 0,
642
        'sources_as_content_to_bibliography' => 0,
643
        'sort_elements' => NO_SORT,
644
        'glue' => '',
645
        'element_tag' => 'span'
646
      ),
647
    );
648

    
649
    // ---- Special DEFAULTS for existing portals
650
    // TODO:
651
    // this can be removed once the feature block
652
    // settings have been deployed for the first time to these portals
653

    
654
    $cichorieae_default = array(
655
      'DEFAULT' => array(
656
        'as_list' => 'div',
657
        'link_to_reference' => 1,
658
        'link_to_name_used_in_source' => 1,
659
        'sources_as_content' => 1,
660
        'sources_as_content_to_bibliography' => 0,
661
        'sort_elements' => NO_SORT,
662
        'glue' => '',
663
        'element_tag' => 'div'
664
      ),
665
      UUID_CITATION => array(
666
        'as_list' => 'div',
667
        'link_to_reference' => 0,
668
        'link_to_name_used_in_source' => 0,
669
        'sources_as_content' => 1,
670
        'sources_as_content_to_bibliography' => 0,
671
        'sort_elements' => SORT_ASC,
672
        'glue' => '',
673
        'element_tag' => 'div'
674
      ),
675
      UUID_CHROMOSOMES_NUMBERS => array(
676
        'as_list' => 'ul',
677
        'link_to_reference' => 1,
678
        'link_to_name_used_in_source' => 1,
679
        'sources_as_content' => 1,
680
        'sources_as_content_to_bibliography' => 0,
681
        'sort_elements' => NO_SORT,
682
        'glue' => '',
683
        'element_tag' => 'div'
684
      ),
685
      UUID_CHROMOSOMES => array(
686
        'as_list' => 'ul',
687
        'link_to_reference' => 0,
688
        'link_to_name_used_in_source' => 1,
689
        'sources_as_content' => 1,
690
        'sources_as_content_to_bibliography' => 0,
691
        'sort_elements' => NO_SORT,
692
        'glue' => '',
693
        'element_tag' => 'div'
694
      ),
695
      UUID_COMMON_NAME => array(
696
        'as_list' => 'div',
697
        'link_to_reference' => 0,
698
        'link_to_name_used_in_source' => 1,
699
        'sources_as_content' => 0,
700
        'sources_as_content_to_bibliography' => 0,
701
        'sort_elements' => NO_SORT,
702
        'glue' => '',
703
        'element_tag' => 'span'
704
      ),
705
    );
706

    
707
    $palmweb_default = array(
708
      'DEFAULT' => array(
709
        'as_list' => 'ul',
710
        'link_to_reference' => 1,
711
        'link_to_name_used_in_source' => 1,
712
        'sources_as_content' => 1,
713
        'sources_as_content_to_bibliography' => 1,
714
        'sort_elements' => NO_SORT,
715
        'glue' => '',
716
        'element_tag' => NULL
717
      ),
718
      UUID_CITATION => array(
719
        'as_list' => 'ul',
720
        'link_to_reference' => 1,
721
        'link_to_name_used_in_source' => 1,
722
        'sources_as_content' => 0,
723
        'sources_as_content_to_bibliography' => 1,
724
        'sort_elements' => SORT_ASC,
725
        'glue' => '',
726
        'element_tag' => 'div'
727
      ),
728
      UUID_DISTRIBUTION => array(
729
        'as_list' => 'div', // currently ignored
730
        'link_to_reference' => 1,
731
        'link_to_name_used_in_source' => 1,
732
        'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
733
        'sources_as_content_to_bibliography' => 1,
734
        'sort_elements' => NO_SORT, // will cause ...
735
        'glue' => '',
736
        'element_tag' => 'div',
737
        'special' => array()
738
      ),
739
    );
740

    
741
    $cyprus_default = $cichorieae_default;
742
    $cyprus_default[UUID_DISTRIBUTION] = array(
743
      'as_list' => 'div', // currently ignored
744
      'link_to_reference' => 0,
745
      'link_to_name_used_in_source' => 0,
746
      'sources_as_content' => 0,
747
      'sources_as_content_to_bibliography' => 0,
748
      'sort_elements' => NO_SORT, // will cause ...
749
      'glue' => '',
750
      'element_tag' => 'div',
751
      'special' => array()
752
    );
753

    
754
    $default_theme = variable_get('theme_default', NULL);
755

    
756
    switch ($default_theme) {
757
      case 'garland_cichorieae':
758
        $settings_for_theme = $cichorieae_default;
759
        break;
760
      case 'cyprus':
761
        // cyprus: no longer used in production,
762
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
763
        $settings_for_theme = $cyprus_default;
764
        break;
765
      case 'flore_afrique_centrale':
766
      case 'flora_malesiana':
767
      case 'flore_gabon':
768
        $settings_for_theme = $cichorieae_default;
769
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
770
        break;
771
      case 'palmweb_2':
772
        $settings_for_theme = $palmweb_default;
773
        break;
774
      default:
775
        $settings_for_theme = $other_themes_default;
776
    }
777
    // ---- END of DEFAULTS
778

    
779
    $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
780

    
781
    $feature_block_setting = null;
782

    
783
    if (isset($saved_settings[$feature_uuid])) {
784
      $feature_block_setting = $saved_settings[$feature_uuid];
785
    }
786
    else if (isset($settings_for_theme[$feature_uuid])) {
787
      $feature_block_setting = $settings_for_theme[$feature_uuid];
788
    }
789
    else if (isset($settings_for_theme['DEFAULT'])) {
790
      $feature_block_setting = $settings_for_theme['DEFAULT'];
791
    }
792

    
793
    // now merge the default and specific settings
794
    $settings_to_merge = array($default['DEFAULT']);
795
    if(is_array($saved_settings)){
796
      $settings_to_merge[] = $saved_settings['DEFAULT'];
797
    }
798
    if(isset($feature_block_setting)){
799
      $settings_to_merge[] = $feature_block_setting;
800
    }
801
    $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
802

    
803
    return $feature_block_setting;
804
}
805
  /**
806
 * returns the current setting for the original source bibliography
807
 *
808
 * Caches internally
809
 *
810
 * @return array
811
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
812
 *   - 'enabled': 1|0
813
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
814
 */
815
function get_bibliography_settings($clear_cache = false){
816
  static $bibliography_settings = null;
817
  if(!$bibliography_settings || $clear_cache){
818
    $bibliography_settings = get_array_variable_merged(
819
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
820
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
821
    );
822
  }
823
  return $bibliography_settings;
824
}
825

    
826
/**
827
 * @todo Please document this function.
828
 * @see http://drupal.org/node/1354
829
 */
830
function cdm_dataportal_menu_admin(&$items) {
831
  // Display section on admin/config page.
832
  $items['admin/config/cdm_dataportal'] = array(
833
    'title' => 'CDM Dataportal',
834
    'description' => 'Settings for the CDM DataPortal.',
835
    'position' => 'right',
836
    'weight' => 10,
837
    'page callback' => 'system_admin_menu_block_page',
838
    'access arguments' => array('administer cdm_dataportal'),
839
    'file' => 'system.admin.inc',
840
    'file path' => drupal_get_path('module', 'system'),
841
  );
842
  $items['admin/config/cdm_dataportal/settings'] = array(
843
    'title' => 'Settings',
844
    'description' => 'Settings for the CDM DataPortal.',
845
    'weight' => 0,
846
    'page callback' => 'drupal_get_form',
847
    'page arguments' => array('cdm_settings_general'),
848
    'access arguments' => array('administer cdm_dataportal'),
849
    'type' => MENU_NORMAL_ITEM,
850
  );
851
  $items['admin/config/cdm_dataportal/settings/general'] = array(
852
    'title' => 'General',
853
    'description' => 'General',
854
    'weight' => 0,
855
    'page callback' => 'drupal_get_form',
856
    'page arguments' => array('cdm_settings_general'),
857
    'access arguments' => array('administer cdm_dataportal'),
858
    'type' => MENU_DEFAULT_LOCAL_TASK,
859
  );
860

    
861
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
862
    'title' => 'Cache',
863
    'description' => 'Cache',
864
    'access arguments' => array('administer cdm_dataportal'),
865
    'page callback' => 'drupal_get_form',
866
    'page arguments' => array('cdm_settings_cache'),
867
    'weight' => 10,
868
    'type' => MENU_LOCAL_TASK,
869
  );
870

    
871
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
872
    'title' => 'Geo & Map',
873
    'description' => 'Geo & Map',
874
    'access arguments' => array('administer cdm_dataportal'),
875
    'page callback' => 'drupal_get_form',
876
    'page arguments' => array('cdm_settings_geo'),
877
    'weight' => 1,
878
    'type' => MENU_LOCAL_TASK,
879
  );
880

    
881
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
882
    'title' => 'Layout',
883
    'description' => 'Configure and adjust the layout of your DataPortal ',
884
    'access arguments' => array('administer cdm_dataportal'),
885
    'page callback' => 'drupal_get_form',
886
    'page arguments' => array('cdm_settings_layout'),
887
    'weight' => 2,
888
    'type' => MENU_LOCAL_TASK,
889
  );
890

    
891
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
892
    'title' => 'Taxon',
893
    'description' => 'Configure and adjust the layout of your DataPortal ',
894
    'access arguments' => array('administer cdm_dataportal'),
895
    'page callback' => 'drupal_get_form',
896
    'page arguments' => array('cdm_settings_layout_taxon'),
897
    'weight' => 1,
898
    'type' => MENU_LOCAL_TASK,
899
  );
900
  /*
901
  $items[] = array(
902
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
903
  'title' => t('Synonymy'),
904
  'description' => t('Configure and adjust the layout of your DataPortal '),
905
  'access' => user_access('administer cdm_dataportal'),
906
  'callback' => 'drupal_get_form',
907
  'callback arguments' => array('cdm_settings_layout_synonymy'),
908
  'weight' => 1,
909
  'type' => MENU_LOCAL_TASK,
910
  );
911

912
  $items[] = array(
913
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
914
  'title' => t('Specimens'),
915
  'description' => t('Configure and adjust the layout of your DataPortal '),
916
  'access' => user_access('administer cdm_dataportal'),
917
  'callback' => 'drupal_get_form',
918
  'callback arguments' => array('cdm_settings_layout_specimens'),
919
  'weight' => 1,
920
  'type' => MENU_LOCAL_TASK,
921
  );
922
  */
923
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
924
    'title' => 'Search',
925
    'description' => 'Configure and adjust the layout of your DataPortal ',
926
    'access arguments' => array('administer cdm_dataportal'),
927
    'page callback' => 'drupal_get_form',
928
    'page arguments' => array('cdm_settings_layout_search'),
929
    'weight' => 2,
930
    'type' => MENU_LOCAL_TASK,
931
  );
932

    
933
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
934
    'title' => 'Media',
935
    'description' => 'Configure and adjust the layout of your DataPortal ',
936
    'access arguments' => array('administer cdm_dataportal'),
937
    'page callback' => 'drupal_get_form',
938
    'page arguments' => array('cdm_settings_layout_media'),
939
    'weight' => 3,
940
    'type' => MENU_LOCAL_TASK,
941
  );
942

    
943
}
944

    
945
/**
946
 * @todo document this function.
947
 */
948
function cdm_help_general_cache() {
949
  $form = array();
950
  $form['cache_help'] = array(
951
    '#type' => 'fieldset',
952
    '#title' => t('Help'),
953
    '#collapsible' => TRUE,
954
    '#collapsed' => TRUE,
955
  );
956
  $form['cache_help']['test'] = array('#value' => t('probando'));
957
  return drupal_render($form);
958
  $res = array();
959
  $res['default'] = drupal_render($help);
960
  return $res;
961
}
962

    
963
/**
964
 * Configures the settings form for the CDM-API module.
965
 *
966
 * @return array
967
 *   Drupal settings form.
968
 */
969
function cdm_settings_general() {
970

    
971
  $form['cdm_webservice'] = array(
972
    '#type' => 'fieldset',
973
    '#title' => t('CDM Server'),
974
    '#collapsible' => FALSE,
975
    '#collapsed' => FALSE,
976
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
977
        CDM data base to the web via RESTful web services and thus is the source of the data
978
        to be displayed by a CDM DataPotal.'),
979
  );
980

    
981
  $form['cdm_webservice']['cdm_webservice_url'] = array(
982
    '#type' => 'textfield',
983
    '#title' => t('CDM web service URL') . ':',
984
    '#description' => t('This is the URL to the CDM-Server exposing your data
985
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
986
    '#default_value' => variable_get('cdm_webservice_url', NULL),
987
  );
988

    
989
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
990
    '#type' => 'markup',
991
    '#markup' => '<b>Debug CDM Web Service:</b> Debugging web services is possible via the ' . l('CDM web service debug block', 'admin/structure/block/manage/cdm_api/cdm_ws_debug/configure')
992
      . ' visible only for administrators',
993
  );
994

    
995
  $form['cdm_webservice']['freetext_index'] = array(
996
    '#type' => 'fieldset',
997
    '#title' => t('Freetext index'),
998
    '#collapsible' => FALSE,
999
    '#collapsed' => FALSE,
1000
  );
1001

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

    
1014
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1015
  $trigger_link_options = array(
1016
    'attributes' => array(
1017
      'class' => 'index-trigger',
1018
    ),
1019
  );
1020
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1021
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1022
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1023
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1024
      ))
1025
    . '<div id="index-progress"></div></div>',
1026
  );
1027
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1028

    
1029
  $form['cdm_webservice']['proxy'] = array(
1030
    '#type' => 'fieldset',
1031
    '#title' => t('Proxy'),
1032
    '#collapsible' => TRUE,
1033
    '#collapsed' => TRUE,
1034
  );
1035

    
1036
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1037
    '#type' => 'textfield',
1038
    '#title' => t('Proxy URL') . ':',
1039
    '#description' => t('If this proxy url is set the cdm api tries
1040
    to connect the web service over the given proxy server.
1041
    Otherwise proxy usage is deactivated.'),
1042
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1043
  );
1044

    
1045
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1046
    '#type' => 'textfield',
1047
    '#title' => t('Proxy port') . ':',
1048
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1049
  );
1050

    
1051
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1052
    '#type' => 'textfield',
1053
    '#title' => t('Login') . ':',
1054
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1055
  );
1056

    
1057
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1058
    '#type' => 'textfield',
1059
    '#title' => t('Password') . ':',
1060
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1061
  );
1062

    
1063
  // TODO: settings are still incomplete, compare with
1064
  // trunk/dataportal/inc/config_default.php.inc.
1065
  $form['taxon_tree'] = array(
1066
    '#type' => 'fieldset',
1067
    '#title' => t('Taxon Tree'),
1068
    '#collapsible' => FALSE,
1069
    '#collapsed' => TRUE,
1070
    '#description' => t('<p>When you explore your collection, you can navigate
1071
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1072
      able to navigate through your collection the
1073
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1074
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1075
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1076
      </a></p>'),
1077
  );
1078

    
1079
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1080
    '#type' => 'select',
1081
    '#title' => t('Available classifications') . ':',
1082
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1083
    '#options' => cdm_get_taxontrees_as_options(),
1084
    '#description' => t('Select the default taxa classification for your
1085
      <em>taxon tree</em>, the other classifications will be also available but
1086
      with a manual user change.'),
1087
  );
1088

    
1089
  $form['taxon_tree']['taxontree_ranklimit'] = array(
1090
    '#type' => 'select',
1091
    '#title' => t('Rank of highest displayed taxon') . ':',
1092
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1093
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
1094
    '#options' => cdm_rankVocabulary_as_option(),
1095
    '#description' => t('This is the rank of the highest displayed taxon in the
1096
      <em>taxon tree</em>. You can select here which rank should be at the top
1097
      level of the tree structure.'),
1098
  );
1099

    
1100
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1101
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1102
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1103
      '#type' => 'checkboxes',
1104
      '#title' => t('Included Classifications') . ':',
1105
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1106
      '#options' => cdm_get_taxontrees_as_options(),
1107
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1108
  );
1109

    
1110
  $form['distribution'] = array(
1111
      '#type' => 'fieldset',
1112
      '#title' => t('Distributions'),
1113
      '#collapsible' => FALSE,
1114
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1115
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1116
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1117
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1118
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1119
          '<p>
1120
          </p>',
1121
  );
1122

    
1123
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1124
      '#type' => 'fieldset',
1125
      '#title' => 'Distribution filter',
1126
      '#collapsible' => FALSE,
1127
      '#collapsed' => FALSE,
1128
      '#tree' => TRUE,
1129
      '#description' => 'The Distribution filter offers the following options
1130
      <ul>
1131
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1132
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1133
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1134
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1135
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1136
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1137
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1138
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1139
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1140
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1141
      </ul>'
1142
  );
1143

    
1144
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1145
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1146
      '#type' => 'checkboxes',
1147
      '#title' => 'Filter rules',
1148
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1149
      '#options' => array(
1150
          'statusOrderPreference' => 'Status order preference rule',
1151
          'subAreaPreference' => 'Sub area preference rule'
1152
      ),
1153
  );
1154

    
1155
  $marker_type_options = cdm_terms_as_options( cdm_ws_fetch_all('term', array('class' => 'MarkerType' )) );
1156
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1157
      '#type' => 'checkboxes',
1158
      '#title' => 'Hide marked area filter',
1159
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1160
      '#options' => $marker_type_options,
1161
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1162
  );
1163

    
1164
  $form['aggregation'] = array(
1165
      '#type' => 'fieldset',
1166
      '#title' => t('Aggregation of data'),
1167
      '#collapsible' => FALSE,
1168
      '#description' => 'This section covers the different aspects of aggregating information.
1169
          <p>
1170
          </p>',
1171
  );
1172

    
1173
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1174
      '#type' => 'checkboxes',
1175
      '#title' => 'Taxon media filter',
1176
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1177
      '#options' => array(
1178
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1179
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1180
          'includeOccurrences' => 'Media related to specimens and occurrences',
1181
      ),
1182
      '#description' => 'This filter configures which images should be taken into account.',
1183
  );
1184

    
1185
  $form['aggregation']['notice'] = array(
1186
      '#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
1187
          want to make use of the caching capabilities of the dataportal.',
1188
  );
1189

    
1190
  $form['aggregation']['media_aggregation'] = array(
1191
      '#type' => 'fieldset',
1192
      '#title' => t('Media aggregation'),
1193
      '#collapsible' => FALSE,
1194
      '#collapsed' => TRUE,
1195
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1196

    
1197
  );
1198
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1199
      '#type' => 'select',
1200
      '#title' => t('Aggregation of taxon pictures') . ':',
1201
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1202
      '#options' => array(
1203
          0 => "Show only pictures of the current taxon",
1204
          1 => "Include pictures of taxonomic children",
1205
      ),
1206
      '#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."),
1207
  );
1208

    
1209
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1210
      '#type' => 'fieldset',
1211
      '#attributes' => array('class'=>array('clearfix')),
1212
      '#title' => t('Aggregation via taxon relationsships'),
1213
      '#collapsible' => TRUE,
1214
      '#collapsed' => TRUE,
1215
      '#tree' => TRUE,
1216
      '#description' => t('Information on taxa will be aggregated along the below chosen
1217
          taxon relation ships. This will affect images and occurrences (specimens).
1218
          Taxon relation ships are directed and point form one taxon to another. The taxon
1219
          relationships to be taken into accunt can therefore configured for the direct direction
1220
          and for the inverse.'),
1221
  );
1222

    
1223
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1224
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1225

    
1226
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1227
      '#type' => 'checkboxes',
1228
      '#title' => t('Direct'),
1229
      '#options' => $taxonRelationshipTypeOptions,
1230
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1231
  );
1232
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1233
      '#type' => 'checkboxes',
1234
      '#title' => t('Invers'),
1235
      '#options' => $taxonRelationshipTypeOptions,
1236
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1237
  );
1238

    
1239
  // ----------------------
1240
  $form['cdm_js_devel_mode'] = array(
1241
      '#type' => 'checkbox',
1242
      '#title' => 'Java-script developer mode',
1243
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1244
      '#description' => 'In production envirionments the java script libraries
1245
      the cdm_dataportal is making use of are compressed and optimized. This
1246
      is good for performance but a caveat if you need to debug java-script. When the
1247
      java-script developer mode is enabled the uncompressed and commented developer
1248
      versions of java-script libraries will be used where possible.
1249
      <br/><strong>Do not use this option in production!</strong>'
1250
  );
1251
  // ----------------------
1252
  $form['cdm_debug_mode'] = array(
1253
      '#type' => 'checkbox',
1254
      '#title' => 'CDM page debug mode',
1255
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1256
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1257
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1258
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1259
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1260
      The log is written by the drupal devel module function <code>dd()</code>.
1261
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1262
  );
1263

    
1264
  // Comment @WA: D7 form api does not support reset buttons,
1265
  // so to mimic the D5 reset button we add one like this.
1266
  $form['actions']['reset'] = array(
1267
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1268
    '#weight' => 1000,
1269
  );
1270

    
1271
  $form['#submit'][] = 'cdm_settings_general_submit';
1272

    
1273
  return system_settings_form($form);
1274
}
1275

    
1276

    
1277
/**
1278
 * LAYOUT settings
1279
 * @return
1280
 *   todo
1281
 */
1282
function cdm_settings_layout() {
1283

    
1284
  $form = array();
1285

    
1286
  $form['about'] = array(
1287
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1288
      layout. If you want to configure the specific sites layout visit the
1289
      respective configuration site for taxon, search or media.') . '</p>',
1290
  );
1291

    
1292
  // ---- footnotes --- //
1293
  $form['footnotes'] = array(
1294
    '#type' => 'fieldset',
1295
    '#title' => t('Footnotes'),
1296
    '#collapsible' => FALSE,
1297
    '#collapsed' => FALSE,
1298
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1299
      media or distribution areas may have annotations or footnotes. When the
1300
      footnotes are enabled they will be visible (if they exist).'),
1301
  );
1302

    
1303
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1304
    '#type' => 'checkbox',
1305
    '#title' => t('Do not show footnotes'),
1306
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1307
    '#description' => t('Check this if you do not want to show any footnotes'),
1308
  );
1309

    
1310
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1311
    '#type' => 'checkbox',
1312
    '#title' => t('Do not show annotation footnotes'),
1313
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1314
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1315
  );
1316

    
1317
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType', SORT_ASC);
1318
  // Additional option for the NULL case.
1319
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1320
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1321
    '#type' => 'checkboxes',
1322
    '#title' => t('Annotation types as footnotes'),
1323
    '#description' => t("Only annotations of the selected type will be displayed
1324
       as footnotes. You may want to turn 'technical annotations' off."),
1325
    '#options' => $annotationTypeOptions,
1326
  );
1327
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1328
  if (!empty($annotationsTypesAsFootnotes)) {
1329
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1330
  }
1331

    
1332
  // ---- original source --- //
1333
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1334
      '#type' => 'fieldset',
1335
      '#tree' => TRUE,
1336
      '#title' => t('Source Citations'),
1337
      '#collapsible' => FALSE,
1338
      '#collapsed' => FALSE,
1339
  );
1340

    
1341
  $bibliography_settings = get_bibliography_settings(true);
1342

    
1343
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1344
      '#type' => 'checkbox',
1345
      '#title' => t('Original Source in bibliography'),
1346
      '#default_value' => $bibliography_settings['enabled'],
1347
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1348
       annotations in each feature block.'),
1349
  );
1350

    
1351
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1352
    '#type' => 'select',
1353
    '#title' => t('The format of the key numerals'),
1354
    '#default_value' => $bibliography_settings['key_format'],
1355
    '#options' => array('latin' => 'Latin',
1356
      'ROMAN' => 'Roman (upper case)',
1357
      'roman' => 'Roman (lower case)',
1358
      'ALPHA'=> 'Alphabet (upper case)',
1359
      'alpha' => 'Alphabet (lower case)')
1360
  );
1361

    
1362
  // --- Advanced Search --- //
1363
  $form['asearch'] = array(
1364
      '#type' => 'fieldset',
1365
      '#title' => t('Advanced search'),
1366
      '#collapsible' => FALSE,
1367
      '#collapsed' => FALSE,
1368
  );
1369
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1370
      '#type' => 'checkbox',
1371
      '#title' => t('Show advanced search link'),
1372
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1373
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1374
  );
1375

    
1376
  // ---- Taxon Name Rendering --- //
1377
  $form['taxon_name'] = array(
1378
      '#type' => 'fieldset',
1379
      '#title' => t('Taxon name display'),
1380
      '#collapsible' => TRUE,
1381
      '#collapsed' => TRUE,
1382
      '#description' => t('The display of taxon names is configured by two parts.'
1383
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
1384
          . 'The name parts are defined in the <stong>part definitions</strong>'),
1385
  );
1386

    
1387
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1388
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1389
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1390
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1391

    
1392
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1393
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1394
    $which_version_message = '(These are the old default part definition from before EDIT platform release 3.8.0, you may want to reset these by clearing the text area and and submitting the form.)';
1395
  } else if($is_custom_part_definition){
1396
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1397
  } else  {
1398
    $which_version_message = '(These are the default part definition.)';
1399
  }
1400

    
1401
  $diff_viewer_markup = '';
1402
  if($is_custom_part_definition){
1403
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1404
  }
1405

    
1406
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1407
    . $which_version_message
1408
    . '</div>'
1409
    . $diff_viewer_markup;
1410

    
1411
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1412
      '#type' => 'textarea',
1413
      '#title' => t('Part definitions'),
1414
      '#element_validate' => array('form_element_validate_json'),
1415
      '#default_value' =>  $current_part_definition_json,
1416
      '#description' => '
1417
          <p>' . $which_version_message . '</p>
1418
          <p>
1419
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1420
          </p>
1421
          <p>
1422
           A full taxon name plus additional information can consist of the following elements:
1423
          <ul>
1424
             <li>name: the taxon name inclugin rank nbut without author</li>
1425
             <li>authors:  The authors of a reference, also used in taxon names</li>
1426
             <li>reference: the nomenclatural reference,</li>
1427
             <li>microreference:  Volume, page number etc.</li>
1428
             <li>status:  The nomenclatural status of a name</li>
1429
             <li>description: name descriptions like protologues etc ...</li>
1430
          </ul>
1431
          </p>
1432
          <p>
1433
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1434
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1435
           The following parts can be formed and are recognized by the system:
1436
          <ul>
1437
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1438
            <li>authorshipPart: the author (for example: "L.")</li>
1439
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1440
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1441
               be combined when a link to the taxon is rendered.</li>
1442
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1443
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1444
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1445
            <li>statusPart: the nomenclatorical status</li>
1446
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1447
          </ul>
1448
          </p>
1449
          <p>
1450
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1451
           specific parts part definitions:
1452
          <ul>
1453
            <li>BotanicalName</li>
1454
            <li>ZoologicalName</li>
1455
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1456
          </ul>
1457
           An example:
1458
          <pre>
1459
           {
1460
            "ZoologicalName": {
1461
              "namePart": {
1462
                "name": true
1463
              },
1464
              "referencePart": {
1465
                "authors": true
1466
              },
1467
              "microreferencePart": {
1468
                "microreference": true
1469
              },
1470
              "statusPart": {
1471
                "status": true
1472
              },
1473
              "descriptionPart": {
1474
                "description": true
1475
              }
1476
            },
1477
            "BotanicalName": {
1478
              "namePart": {
1479
                "name": true,
1480
                "authors": true
1481
              },
1482
              "referencePart": {
1483
                "reference": true,
1484
                "microreference": true
1485
              },
1486
              "secReferencePart": {
1487
                "secReference": true
1488
              },
1489
              "statusPart": {
1490
                "status": true
1491
              },
1492
              "descriptionPart": {
1493
                "description": true
1494
              }
1495
            }
1496
          }
1497
           </pre>',
1498
  );
1499

    
1500
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1501
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1502
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1503
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1504
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1505

    
1506
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1507
    $which_version_message = '(These are the old default render templates from before EDIT platform release 3.8.0, you may want to reset these by clearing the text area and and submitting the form.)';
1508
  } else if($is_custom_render_template){
1509
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1510
  } else {
1511
    $which_version_message = '(These are the default render templates.)';
1512
  }
1513

    
1514
  $diff_viewer_markup = '';
1515
  if($is_custom_render_template){
1516
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1517
  }
1518

    
1519
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1520
    . $which_version_message
1521
    . '</div>'
1522
    . $diff_viewer_markup;
1523

    
1524
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1525
      '#type' => 'textarea',
1526
      '#title' => t('Name render templates'),
1527
      '#element_validate' => array('form_element_validate_json'),
1528
      '#default_value' =>  $current_render_templates_json,
1529
      '#description' => '
1530
          <p>' . $which_version_message . '</p>
1531
          <p>
1532
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1533
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1534
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1535
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1536
          The following render Path keys are currently recognized:
1537
          <ul>
1538
            <li>list_of_taxa</li>
1539
            <li>acceptedFor</li>
1540
            <li>homonym</li>
1541
            <li>taxon_page_synonymy</li>
1542
            <li>typedesignations</li>
1543
            <li>taxon_page_title</li>
1544
            <li>polytomousKey</li>
1545
            <li>na: name + authorship</li>
1546
            <li>nar:name + authorship + reference</li>
1547
            <li>#DEFAULT</li>
1548
          </ul>
1549
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1550
          array element should be a comma separated list of render paths, without any whitespace!.
1551
          </p>
1552
          <p>
1553
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1554
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1555
          <p>
1556
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1557
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1558
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1559
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1560
          links if the paramters $nameLink or $refenceLink are given to the name render function
1561
          (this is hard coded and cannot be configured here).',
1562
  );
1563

    
1564
  // @WA: D7 form api does not support reset buttons,
1565
  // so to mimic the D5 reset button we add one like this.
1566
  $form['actions']['reset'] = array(
1567
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1568
    '#weight' => 1000,
1569
  );
1570

    
1571
  $form['#submit'] = array('submit_json_as_php_array');
1572
  // #json_elements especially defined for submit_json_as_php_array()
1573
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1574
  return system_settings_form($form);
1575
}
1576

    
1577

    
1578

    
1579
  /**
1580
 * @todo Please document this function.
1581
 * @see http://drupal.org/node/1354
1582
 */
1583
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1584
  $form[$form_name] = array(
1585
    '#type' => 'fieldset',
1586
    '#title' => t($form_title),
1587
    '#collapsible' => TRUE,
1588
    '#collapsed' => $collapsed,
1589
    '#tree' => TRUE,
1590
    '#description' => t($form_description),
1591
  );
1592

    
1593
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1594
  $gallery_settings = variable_get($form_name, $default_values);
1595
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1596
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1597
    /*
1598
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1599
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1600
    '#type' => 'textfield',
1601
    '#title' => t('Search Page Size'),
1602
    '#default_value' => $test,
1603
    '#description' => t('Number of Names to display per page in search results.')
1604
    );
1605
    */
1606
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1607
      '#type' => 'checkbox',
1608
      '#title' => t('Show media thumbnails for accepted taxa'),
1609
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1610
    );
1611

    
1612
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1613
      '#type' => 'checkbox',
1614
      '#title' => t('Show media thumbnails for synonyms'),
1615
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1616
      '#description' => '',
1617
    );
1618
  }
1619

    
1620
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1621
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1622
    '#type' => 'checkbox',
1623
    '#title' => t('Show captions under thumbnails'),
1624
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1625
    '#description' => '',
1626
  );
1627

    
1628
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1629
    '#type' => 'textfield',
1630
    '#title' => t('Thumbnail size') . ':',
1631
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1632
    '#description' => t('Select the size of each individual thumbnail.'),
1633
  );
1634

    
1635
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1636
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1637
      '#type' => 'textfield',
1638
      '#title' => t('Number of columns') . ':',
1639
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1640
      '#description' => t('Group the thumbnails in columns: select how many
1641
        columns the gallery should display.'),
1642
    );
1643
  }
1644

    
1645
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1646
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1647
      '#type' => 'textfield',
1648
      '#title' => t('Maximum number of rows') . ':',
1649
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1650
      '#description' => t('You can group the thumbnails in rows, select in how
1651
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1652
        If you want an unlimited number of rows please set to 0.'),
1653
    );
1654
  }
1655

    
1656
  return $form;
1657
}
1658

    
1659
/**
1660
 * @todo document this function.
1661
 */
1662
function cdm_settings_layout_taxon() {
1663
  $collapsed = FALSE;
1664
  $form = array();
1665

    
1666
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1667

    
1668
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1669
      '#type' => 'checkbox',
1670
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1671
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1672
      '#description' => t('<p>If checked the link to search results is rendered at
1673
       the top of the taxon site. Clicking on the link the last search performed
1674
       is rendered again.</p>'),
1675
  );
1676

    
1677
  // --------- TABBED TAXON ------- //
1678
  $form['taxon_tabs'] = array(
1679
    '#type' => 'fieldset',
1680
    '#title' => t('Taxon tabs'),
1681
    '#collapsible' => TRUE,
1682
    '#collapsed' => FALSE,
1683
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1684
      be splitted in four diferent tabs; General, Synonymy, Images and
1685
      Specimens. If the taxon has no information for any of the tabs/sections
1686
      such tab will be not displayed.'),
1687
  );
1688

    
1689
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1690
    '#type' => 'checkbox',
1691
    '#title' => t('Tabbed taxon page'),
1692
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1693
    '#description' => t('<p>If selected split the taxon page into individual
1694
      tabs for description, images, synonymy and specimens. If not the taxon
1695
      data is rendered as a long single page without tabs.</p>'),
1696
  );
1697

    
1698
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1699
    '#type' => 'checkboxes',
1700
    '#title' => t('Tabs visibility options') . ':',
1701
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1702
    '#options' => get_taxon_options_list(),
1703
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1704
  );
1705

    
1706
  // WEIGHT
1707
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1708
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1709
      '#tree' => true
1710
  );
1711
  // Weights range from -delta to +delta, so delta should be at least half
1712
  // of the amount of tabs present.
1713
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1714
  foreach (get_taxon_tabs_list() as $label) {
1715
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1716
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1717
        '#title' => $label,
1718
        '#type'  => 'weight',
1719
        '#default_value' => $taxontabs_weights[$key],
1720
        '#delta' => $tab_weight_delta
1721
    );
1722
  }
1723

    
1724
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1725
    '#type' => 'select',
1726
    '#title' => t('Default tab to display') . ':',
1727
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1728
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1729
    '#description' => t('<p>Select the default tab to display when visiting a
1730
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1731
      <strong>Note:</strong> After performing a search and clicking in any
1732
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1733
      taxon and not the above selected tab.'),
1734
  );
1735

    
1736
  /* ======  TAXON_PROFILE ====== */
1737
  $form['taxon_profile'] = array(
1738
    '#type' => 'fieldset',
1739
    '#title' => t('Taxon profile (tab)'),
1740
    '#description' => t('<p>This section covers the settings related to the taxon
1741
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1742
    '#collapsible' => TRUE,
1743
    '#collapsed' => FALSE,
1744
  );
1745

    
1746
  // ---- PROFILE PICTURE ----//
1747

    
1748
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1749
    '#type' => 'fieldset',
1750
    '#tree' => TRUE,
1751
    '#title' => t('Taxon profile picture'),
1752
    '#collapsible' => TRUE,
1753
    '#collapsed' => FALSE,
1754
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1755
  );
1756

    
1757
  //FIXME migrate variables:
1758
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1759
  // FIXME
1760
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1761

    
1762
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1763

    
1764
  /*
1765
   * 'show' => 1,
1766
   * 'maxextend' => 184,
1767
   * 'media_uri_query' => ''
1768
   * 'custom_placeholder_image_on' => 1,
1769
   * 'custom_placeholder_image_fid' => ''
1770
   */
1771
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1772
    '#type' => 'checkbox',
1773
    '#title' => t('Enable profil picture'),
1774
    '#description' => t('Show the profil picture.'),
1775
    '#default_value' => $taxon_profile_image_settings['show'],
1776
  );
1777

    
1778
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1779
      '#type' => 'textfield',
1780
      '#tree' => TRUE,
1781
      '#title' => t('Profil picture maximum extend'),
1782
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1783
      '#field_suffix' => 'px',
1784
      '#maxlength' => 4,
1785
      '#size' => 4,
1786
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1787
  );
1788

    
1789
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1790
      '#type' => 'textfield',
1791
      '#tree' => TRUE,
1792
      '#title' => t('Additional URI query parameter'),
1793
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1794
      '#maxlength' => 1024,
1795
      '#size' => 60,
1796
      '#description' => t('Additional query parameters to be used when requesting for the '
1797
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1798
          . 'The query parameters will be appended to the uri of the media representation part'
1799
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1800
  );
1801

    
1802
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1803
    '#type' => 'checkbox',
1804
    '#title' => t('Show the placeholder image'),
1805
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
1806
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1807
  );
1808

    
1809
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1810
      '#type' => 'checkbox',
1811
      '#title' => t('Use a custom placeholder image'),
1812
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1813
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1814
  );
1815

    
1816
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1817
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1818
        '#type' => 'managed_file',
1819
        '#title' => t('Custom placeholder image file'),
1820
        '#progress_indicator' => 'bar',
1821
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1822
    //       '#name' => 'custom_placeholder_image',
1823
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1824
    );
1825

    
1826
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1827
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1828
      $url = file_create_url($profile_image_file->uri);
1829
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1830
                '#type' => 'item',
1831
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1832
      );
1833
    }
1834
  } else {
1835
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1836
      '#type' => 'hidden',
1837
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1838
    );
1839
  }
1840

    
1841
  $options = cdm_rankVocabulary_as_option();
1842
  array_unshift($options, '-- DISABLED --');
1843
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1844
    '#type' => 'select',
1845
    '#title' => t('Hide profile picture for higher ranks') . ':',
1846
    '#default_value' => variable_get('image_hide_rank', '0'),
1847
    '#options' => $options,
1848
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1849
  );
1850

    
1851
  // -- MEDIA THUMBNAILS -- //
1852
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1853
  $form_title = 'Taxon Profile Images';
1854
  $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>';
1855
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1856

    
1857
  // ---- FEATURE TREE BLOCKS ---- //
1858
  $form['taxon_profile']['feature_blocks'] = array(
1859
    '#type' => 'fieldset',
1860
    '#title' => t('Feature Blocks'),
1861
    '#collapsible' => TRUE,
1862
    '#collapsed' => FALSE,
1863
    '#description' => t("This section covers settings related to the taxon's
1864
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1865
      features such as description, distribution, common names"),
1866
  );
1867
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1868
  $profile_feature_tree = get_profile_feature_tree();
1869
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
1870
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
1871
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
1872
  }
1873
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
1874
    '#type' => 'radios',
1875
    '#title' => t('Taxon profile feature tree') . ':',
1876
    '#default_value' => $profile_feature_tree_uuid,
1877
    '#options' =>  $featureTrees['options'],
1878
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1879
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1880
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
1881
      profile page.'
1882
    ),
1883
  );
1884

    
1885
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
1886
  $profile_feature_tree = get_profile_feature_tree();
1887

    
1888
  if (isset($profile_feature_tree->root->childNodes)) {
1889

    
1890
    $form_feature_block_layout = array(
1891
      '#type' => 'fieldset',
1892
      '#tree' => true,
1893
      '#title' => t('Taxon profile feature block settings'),
1894
      '#collapsible' => TRUE,
1895
      '#collapsed' => FALSE,
1896
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
1897
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
1898
      The subforms have the following settings in common:<br />
1899
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
1900
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
1901
      <h6>Link to name used in source:</h6><div>Whether to show name is source information as link which will point to the according name page</div>
1902
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
1903
            <ol>
1904
            <li>If element is of the CDM type TextData and the text is not empty the source references will be
1905
                appended in brackets like "text (source references)". If the original source has name in source
1906
                information it will be appended to the citation string,
1907
                like : "(citation, as name in source; citation, as name in source)"</li>
1908
             <li>if the text of the TextData is empty, the original source citations are the only content
1909
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
1910
                prepended to the citation string like: "name in source: citation"</li>
1911
            </ol>
1912
            <strong>If disabled:</strong><br />
1913
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
1914
             citations are the only content, the resulting feature block content would only consist of footnotes.
1915
             In this case the display of the respective feature block is suppressed.</div>
1916
      </dl>
1917
      <h6>Sources as content to bibliography:</h6><div>Only valid if <em>Sources as content</em> is enabled, will cause the sources to be also shown
1918
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
1919
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
1920
        . '</em></div>
1921
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
1922
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
1923
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
1924
      <h6>Element tag:</h6><div>The tag to be used for creating the elements, only applies if "List type" is set to <em>No list</em>
1925
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
1926
           cdm_feature_block_element_tag_name()</div>',
1927
    );
1928

    
1929

    
1930
    $feature_list_layout_settings_disabled = FALSE;
1931

    
1932
    // creating helper object to retrieve the default settings
1933
    $featureNode = new stdClass();
1934
    $featureNode->feature = new stdClass();
1935
    $featureNode->feature->uuid="DEFAULT";
1936
    $featureNode->feature->representation_L10n = "Default";
1937
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
1938

    
1939
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
1940

    
1941
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1942

    
1943
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
1944
        $subform_id = $featureNode->feature->uuid;
1945
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
1946

    
1947
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1948

    
1949
        $form_feature_block_layout[$subform_id] = array(
1950
          '#type' => 'fieldset',
1951
          '#tree' => TRUE,
1952
          '#title' => $featureNode->feature->representation_L10n,
1953
          '#collapsible' => FALSE,
1954
          '#collapsed' => FALSE,
1955
        );
1956
        if($featureNode->feature->uuid == "DEFAULT"){
1957
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
1958
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
1959
          references</em> and <em>names in source</em> is only possible in the defaults';
1960
        }
1961

    
1962
        $form_feature_block_layout[$subform_id]['as_list'] = array(
1963
          '#type' => 'select',
1964
          '#title' => 'List type',
1965
          '#default_value' => $feature_block_setting['as_list'],
1966
          '#options' => array(
1967
            'div' => 'not as list',
1968
            'ul' => 'bullet list',
1969
            'ol' => 'numbered list',
1970
            'dl' => 'definition list'
1971
          ),
1972
        );
1973

    
1974
        if($featureNode->feature->uuid == "DEFAULT"){
1975
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
1976
            '#type' => 'checkbox',
1977
            '#title' => t('Link to reference'),
1978
            '#default_value' => $feature_block_setting['link_to_reference'],
1979
          );
1980

    
1981
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
1982
            '#type' => 'checkbox',
1983
            '#title' => 'Link to name used in source',
1984
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
1985
          );
1986
        }
1987

    
1988
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
1989
          '#type' => 'checkbox',
1990
          '#title' => 'Sources as content',
1991
          '#default_value' => $feature_block_setting['sources_as_content'],
1992
        );
1993

    
1994
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
1995
          '#type' => 'checkbox',
1996
          '#title' => 'Put sources also as content to bibliography',
1997
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
1998
        );
1999

    
2000
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2001
          '#type' => 'select',
2002
          '#title' => t('Sort elements'),
2003
          '#default_value' => $feature_block_setting['sort_elements'],
2004
          '#options' => array(
2005
            NO_SORT => 'No sorting',
2006
            SORT_ASC => 'Ascending',
2007
            SORT_DESC => 'Descending',
2008
            SORT_HIERARCHICAL => 'Hierarchical'
2009
          ),
2010
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2011
          <dl>
2012
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2013
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2014
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2015
          <dr><dt>Hierarchical</dt><dd>Use the order of items and their hierarchy. This is not possible for all feature and item types.</dd></dr>
2016
          </dl>',
2017
        );
2018

    
2019
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2020
          '#type' => 'select',
2021
          '#title' => t('Element tag'),
2022
          '#options' => array(
2023
            'span' => 'span',
2024
            'div' => 'div'
2025
          ),
2026
          '#default_value' => $feature_block_setting['element_tag'],
2027
        );
2028
      }
2029
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2030
    }
2031
  }
2032

    
2033
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2034
  $form['taxon_profile']['structured_description_featuretree'] = array(
2035
    '#type' => 'fieldset',
2036
    '#title' => t('Structured Description Feature Tree'),
2037
    '#collapsible' => TRUE,
2038
    '#collapsed' => FALSE,
2039
  );
2040
  $featureTrees = cdm_get_featureTrees_as_options();
2041
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2042
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2043
    $profile_feature_tree_uuid = NULL;
2044
  }
2045
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2046
    '#type' => 'radios',
2047
    '#title' => t('Natural language representation of structured descriptions') . ':',
2048
    '#default_value' => $profile_feature_tree_uuid,
2049
    '#options' => $featureTrees['options'],
2050
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2051
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2052
    '#description' => t('Taxon descriptions can be stored in a highly structured
2053
      form. The feature tree selected here will be used to generate textual
2054
      representation in natural language.'
2055
    ),
2056
  );
2057

    
2058

    
2059

    
2060
  // ---- DISTRIBUTION LAYOUT ---- //
2061
  $form['taxon_profile']['distribution_layout'] = array(
2062
    '#title' => t('Distribution'),
2063
    '#collapsible' => TRUE,
2064
    '#collapsed' => FALSE,
2065
    '#type' => 'fieldset',
2066
    '#description' => 'This section covers general settings regarding the textual representation of distributions.
2067
        Map related settings are found in the '
2068
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2069
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2070
      . l(
2071
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2072
        array('fragment' => 'edit-feature-block-settings')
2073
      )
2074
      . ' More general settings regrading the filtering of Distributions are found at '
2075
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2076
      . '. (These settings here will be merged in future releases into the feature block settings)',
2077

    
2078
  );
2079

    
2080
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2081
    '#type' => 'checkbox',
2082
    '#title' => t('Condensed distribution'),
2083
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2084
    '#description' => 'This option enables the display of a very compact representation
2085
    of the distribution which includes also information on the status.',
2086
  );
2087

    
2088
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2089
    '#type' => 'select',
2090
    '#title' => t('Condensed distribution recipe'),
2091
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2092
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2093
    '#description' => 'Recipe for creating the condensed distribution.',
2094
  );
2095

    
2096
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2097
    '#type' => 'textfield',
2098
    '#title' => t('Condensed distribution info path'),
2099
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2100
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2101
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2102
  );
2103

    
2104

    
2105
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2106
    '#type' => 'radios',
2107
    '#title' => t('Display mode') . ':',
2108
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2109
    '#options' => array(
2110
      'FLAT_ALPHA' => t('Flat list'),
2111
      'TREE' => t('Hierarchically ordered'),
2112
    ),
2113
    '#description' => 'Taxon distribution information is displayed with
2114
    focus on the area of the distribution. The list of areas can either be shown
2115
    as flat list ordered alphabetically or in the hierarchical of the parent
2116
    area and subarea relationship. Fall back areas areas with no Distribution data
2117
    are hidden from the area hierarchy so that their sub areas will move one level up.
2118
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2119
    ' for details on the <em>Marked area filter</em>.',
2120
  );
2121

    
2122
  $level_options = cdm_Vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, SORT_ASC);
2123
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2124
    '#type' => 'checkboxes',
2125
    '#title' => 'Omit area levels',
2126
    '#options' => $level_options,
2127
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2128
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2129
    Areas which belong to the selected area levels will be hidden in the portal.',
2130
  );
2131

    
2132
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2133
    '#type' => 'checkbox',
2134
    '#title' => t('Show TextData elements on top of the map'),
2135
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2136
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2137
      elements on top of the map. Otherwise all <code>TextData</code>
2138
      distribution elements will be listed below the other area elements.
2139
      This option is useful if you need to have descriptive texts for each
2140
      distribution map.'),
2141
  );
2142

    
2143
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2144
      '#type' => 'textarea',
2145
      '#title' => t('Custom status colors'),
2146
      '#element_validate' => array('form_element_validate_json'),
2147
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2148
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2149
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2150
          reference list of the idInVocabulary values of absence and presence terms:
2151
<pre>
2152
Presence Term
2153
p        present
2154
pd        present: doubtfully present
2155
n        native
2156
nq        native: presence questionable
2157
nd        native: doubtfully native
2158
c        cultivated
2159
i        introduced
2160
iq        introduced: presence questionable
2161
id        introduced: doubtfully introduced (perhaps cultivated only)
2162
ip        introduced: uncertain degree of naturalisation
2163
ia        introduced: adventitious (casual)
2164
in        introduced: naturalized
2165
ic        introduced: cultivated
2166
e        endemic for the relevant area
2167
na        naturalised
2168
iv        invasive
2169

2170
AbsenceTerm
2171
a        absent
2172
f        reported in error
2173
nf        native: reported in error
2174
if        introduced: reported in error
2175
cf        cultivated: reported in error
2176
ne        native: formerly native
2177
ie        introduced: formerly introduced
2178

2179
</pre>'),
2180
  );
2181

    
2182

    
2183
  /* ====== SYNONYMY ====== */
2184
  $form['taxon_synonymy'] = array(
2185
    '#type' => 'fieldset',
2186
    '#title' => t('Taxon synonymy (tab)'),
2187
    '#collapsible' => TRUE,
2188
    '#collapsed' => TRUE,
2189
    '#description' => t('This section covers the settings related to the taxon
2190
      <strong>synonymy</strong> tab.'),
2191
  );
2192

    
2193
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2194
    '#type' => 'checkbox',
2195
    '#title' => t('Show accepted taxon on top of the synonymy'),
2196
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2197
    '#description' => t('If checked, the first homotypic taxon is a repetition
2198
      of the accepted taxon most likely with the full nomenclatural reference
2199
      (depending on the currently chosen theme).'),
2200
  );
2201

    
2202
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2203
    '#type' => 'checkbox',
2204
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2205
      coming from a synonym link.'),
2206
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2207
    '#description' => t('Check this if after doing a search and clicking on a
2208
      synonym you want to see the "accept of" text for the accepted synonym.'),
2209
  );
2210

    
2211
  /* === currently unused ===
2212
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2213
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2214
    '#type' => 'checkboxes',
2215
    '#title' => t('Display name relationships') . ':',
2216
    '#default_value' => variable_get('name_relationships_to_show', 0),
2217
    '#options' => $nameRelationshipTypeOptions,
2218
    '#description' => t('Select the name relationships you want to show for the
2219
      accepted taxa.'),
2220
  );
2221
 */
2222

    
2223
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2224
    '#type' => 'checkbox',
2225
    '#title' => t('Show taxon relations ships of accepted taxon'),
2226
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2227
    '#description' => t('If this option is enabled the synonymy will show the
2228
      below selected taxon relationships of accepted taxa.'),
2229
  );
2230

    
2231
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2232
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2233
    '#type' => 'checkboxes',
2234
    '#title' => t('Taxon relationship types') . ':',
2235
    '#description' => t('Only taxon relationships of the selected type will be
2236
      displayed'),
2237
    '#options' => $taxonRelationshipTypeOptions,
2238
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2239
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2240
  );
2241

    
2242
  // ====== SPECIMENS ====== //
2243
  $form['taxon_specimens'] = array(
2244
    '#type' => 'fieldset',
2245
    '#title' => t('Taxon specimens (tab)'),
2246
    '#collapsible' => TRUE,
2247
    '#collapsed' => TRUE,
2248
    '#description' => t('This section covers the settings related to the taxon
2249
      <strong>specimens</strong> tab.'),
2250
  );
2251

    
2252
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2253
        '#type' => 'checkbox',
2254
        '#title' => t('Show specimen derivatives in a compressed table'),
2255
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2256
        '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2257
        a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2258
    );
2259
    
2260
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2261
        '#type' => 'checkbox',
2262
        '#title' => t('Show "Associated with" in specimen table.'),
2263
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2264
    );
2265

    
2266
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2267
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2268
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2269
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2270
  }
2271
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2272
      '#type' => 'radios',
2273
      '#title' => t('Specimen description feature tree') . ':',
2274
      '#default_value' => $profile_feature_tree_uuid,
2275
      '#options' =>  $featureTrees['options'],
2276
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2277
      '#options_suffixes' => $featureTrees['treeRepresentations'],
2278
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2279
      ),
2280
  );
2281

    
2282
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2283
  $form_title = t('Specimen media');
2284
  $form_description = t('Specimens may have media which is displayed at the
2285
     Specimen tab/section as a gallery. It is possible to configure the
2286
     thumbnails gallery here, however for configuring how a single media should
2287
     be displayed please go to !url.</p>',
2288
     array(
2289
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2290
     ));
2291
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2292

    
2293
  // --- MEDIA GALLERY ---- //
2294
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2295
  $form_title = 'Media gallery (tab)';
2296
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2297
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2298
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2299
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2300
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2301
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2302
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2303

    
2304
  // Comment @WA: D7 form api does not support reset buttons,
2305
  // so to mimic the D5 reset button we add one like this.
2306
  $form['actions']['reset'] = array(
2307
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2308
    '#weight' => 1000,
2309
  );
2310
  return system_settings_form($form);
2311
}
2312

    
2313
/**
2314
 * @todo document this function.
2315
 */
2316
function cdm_settings_layout_search() {
2317

    
2318
  $form = array();
2319

    
2320
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2321

    
2322
  $form['search_settings'] = array(
2323
    '#type' => 'fieldset',
2324
    '#title' => t('Taxa Search'),
2325
    '#collapsible' => FALSE,
2326
    '#collapsed' => FALSE,
2327
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2328
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2329
         where they can write the text to be searched. You can find Drupal block configuration
2330
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2331
  );
2332

    
2333
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2334
      '#type' => 'checkbox',
2335
      '#title' => t('Ignore the chosen classification in simple search'),
2336
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2337
      '#description' => t('The simple search, which can be executed via the search block,
2338
          will by default search on the classification selected in the classification browser
2339
          selector. Set the tick if you want your portal to search on all classifications.'),
2340
  );
2341

    
2342
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2343
    '#type' => 'checkbox',
2344
    '#title' => t('Run simple search with free-text search backend.'),
2345
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2346
    '#description' => t('The simple search uses by default another search
2347
      backend as the advances search. By checking this option the simple search can be
2348
      configured to also use the free-text search backend.'),
2349
  );
2350

    
2351
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2352
    '#type' => 'textfield',
2353
    '#title' => t('Results per page') . ':',
2354
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2355
    '#description' => t('Number of results to display per page.'),
2356
  );
2357

    
2358
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2359
    '#type' => 'checkbox',
2360
    '#title' => t('Show the <i>Show Image Thumbnails</i> button') . ':',
2361
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2362
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2363
  );
2364

    
2365
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2366
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2367
      '#type' => 'checkboxes',
2368
      '#title' => 'Search mode',
2369
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2370
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2371
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2372
          defaults set here.',
2373
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2374
      '#default_value' => $search_mode_default
2375
      );
2376

    
2377
  // --- SEARCH TAXA GALLERY ---- //
2378
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2379
  $collapsed = FALSE;
2380
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2381
  $form_title = 'Taxa Search thumbnails';
2382
  $form_description = 'Search results may show thumbnails. ';
2383
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2384

    
2385
  // Comment @WA: D7 form api does not support reset buttons,
2386
  // so to mimic the D5 reset button we add one like this.
2387
  $form['actions']['reset'] = array(
2388
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2389
    '#weight' => 1000,
2390
  );
2391
  return system_settings_form($form);
2392
}
2393

    
2394
/**
2395
 * @todo document this function.
2396
 */
2397
function cdm_settings_layout_media() {
2398

    
2399
  $form = array();
2400

    
2401
  $form['media_settings'] = array(
2402
    '#type' => 'fieldset',
2403
    '#title' => t('Media settings'),
2404
    '#collapsible' => FALSE,
2405
    '#collapsed' => FALSE,
2406
    '#description' => 'This section covers layout settings for media pages.'
2407
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2408
  );
2409

    
2410
  $form['media_settings']['image_gallery_viewer'] = array(
2411
    '#type' => 'select',
2412
    '#title' => t('Image viewer') . ':',
2413
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2414
    '#options' => array(
2415
      'default' => t('Standard image viewer'),
2416
      'fsi' => t('FSI viewer (requires FSI server!)'),
2417
    ),
2418
  );
2419

    
2420
  // --- MEDIA GALLERY ---- //
2421
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2422
  $form_title = 'Standard viewer';
2423
  $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>';
2424
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2425
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2426

    
2427
  // @WA: D7 form api does not support reset buttons,
2428
  // so to mimic the D5 reset button we add one like this.
2429
  $form['actions']['reset'] = array(
2430
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2431
    '#weight' => 1000,
2432
  );
2433
  return system_settings_form($form);
2434
}
2435

    
2436
/**
2437
 * GEOSERVICE and Map settings.
2438
 */
2439
function cdm_settings_geo($form, &$form_state) {
2440

    
2441
  $current_geoserver_settings = get_edit_map_service_settings();
2442
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2443

    
2444

    
2445
  $form = array();
2446

    
2447
  $dummy_distribution_query = NULL;
2448
  if($map_distribution['map_type'] != 1){
2449
    // we need to apply a dummy query since the map service requires for image maps
2450
    // at least as and ad to be defined
2451
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2452
  }
2453

    
2454
  $form['map_preview'] = array(
2455
      '#type' => 'fieldset',
2456
      '#tree' => FALSE,
2457
      '#title' => t('Map preview'),
2458
      '#collapsible' => FALSE,
2459
      '#description' => 'The preview of the map'
2460
       . ($dummy_distribution_query != null ?
2461
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2462
           '.<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.')
2463
  );
2464
  $form['map_preview']['openlayers_map'] = compose_map(NULL, $dummy_distribution_query, NULL,
2465
    array(
2466
      'move' => "this.cdmOpenlayersMap.printInfo",
2467
      '#execute' => "this.cdmOpenlayersMap.printInfo"
2468
    ),
2469
    true // resizable
2470
  );
2471

    
2472
  /*
2473
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2474
  );
2475
  */
2476

    
2477
  /*
2478
   * GEO SERVER
2479
   */
2480
  $form['edit_map_server'] = array(
2481
    '#type' => 'fieldset',
2482
    '#tree' => true,
2483
    '#title' => t('EDIT map service'),
2484
    '#collapsible' => TRUE,
2485
    '#collapsed' => TRUE,
2486
    '#description' => t('Configuration and selection of your geo server.
2487
      The Geo Server is responsible for generating the maps.'),
2488
  );
2489

    
2490
  $form['edit_map_server']['base_uri'] = array(
2491
    '#type' => 'select',
2492
    '#title' => t('EDIT map service') . ':',
2493
    '#default_value' => $current_geoserver_settings['base_uri'],
2494
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2495
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2496
  );
2497
  $form['edit_map_server']['version'] = array(
2498
      '#type' => 'select',
2499
      '#title' => t('Version') . ':',
2500
      '#default_value' => $current_geoserver_settings['version'],
2501
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2502
      '#description' => t('The version of the EDIT map services'),
2503
  );
2504

    
2505
  /*
2506
   * MAP SETTINGS
2507
   */
2508

    
2509
  $form[CDM_MAP_DISTRIBUTION] = array(
2510
    '#type' => 'fieldset',
2511
    '#tree' => TRUE,
2512
    '#title' => t('Maps settings'),
2513
    '#collapsible' => TRUE,
2514
    '#collapsed' => TRUE,
2515
    '#description' => t('General configuration for all map types.'),
2516
  );
2517

    
2518
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2519
    '#type' => 'radios',
2520
    '#title' => 'Map types',
2521
    '#options' => array(
2522
      1 => "OpenLayers dynamic map viewer",
2523
      0 => "Plain image",
2524
    ),
2525
    '#default_value' => $map_distribution['map_type'],
2526
    '#description' => 'Two different map types are available :
2527
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2528
      which allows zooming and panning. If enabled you can configure the default layer
2529
      (background of your maps) below.</li>
2530
      <li><em>Plain image</em>: The map will be static non interactive
2531
      image.</li></ul>',
2532
  );
2533
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2534

    
2535
  /*
2536
   * settings for the distribution map are used also for specimens map!!!!
2537
   */
2538

    
2539
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2540
      '#type' => 'textfield',
2541
      '#title' => 'Aspect ratio',
2542
      '#default_value' => $map_distribution['aspect_ratio'],
2543
      '#maxlength' => 4,
2544
      '#size' => 4,
2545
      '#element_validate' => array('element_validate_number'),
2546
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2547
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2548
      width by the height:</br>
2549
      <pre>aspect ratio = w / h</pre>
2550
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2551
      for a square map use <strong>1</strong>.',
2552
  );
2553

    
2554
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2555
    '#type' => 'textfield',
2556
    '#title' => 'Bounding box',
2557
    '#default_value' => $map_distribution['bbox'],
2558
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2559
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2560
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2561
      <strong>TIP:</strong> You can use the map preview above to choose the <span class="map-extent-bbox"><strong>map extent bbox</strong> in <strong class="degree-value"">degree</strong></span> from the map.
2562
      (Maybe you need to change the map base layer to OpeLayers.)
2563
      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
2564
      below the map from where you can copy the bbox string.</p>'),
2565
  );
2566

    
2567
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2568
    '#type' => 'checkbox',
2569
    '#title' => 'Display area labels',
2570
    '#default_value' => $map_distribution['show_labels'],
2571
    '#description' => t('The map will show name labels of the areas'),
2572
  );
2573

    
2574
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2575
    '#type' => 'textfield',
2576
    '#title' => 'Map caption',
2577
    '#default_value' => $map_distribution['caption'],
2578
    '#description' => t('The caption will be shown below the map.'),
2579
  );
2580

    
2581
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2582
    '#type' => 'textfield',
2583
    '#title' => 'Distribution layer opacity',
2584
    '#default_value' => $map_distribution['distribution_opacity'],
2585
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2586
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2587
  );
2588

    
2589
  // --- Plain Image Settings --- //
2590
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2591
    '#type' => 'fieldset',
2592
    '#title' => 'Plain image map settings',
2593
    '#tree' => TRUE,
2594
    '#collapsible' => TRUE,
2595
    '#collapsed' => $open_layers_is_enabled,
2596
    '#description' => 'The settings in this section are still expertimental
2597
      and can only be used with the EDIT map service version 1.1 or above.',
2598
  );
2599
  $edit_mapserver_version = get_edit_map_service_version_number();
2600
  if ($edit_mapserver_version < 1.1) {
2601
    $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>'
2602
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2603
  }
2604

    
2605
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2606
    '#type' => 'textfield',
2607
    '#title' => 'Width',
2608
    '#default_value' => $map_distribution['image_map']['width'],
2609
    '#maxlength' => 4,
2610
    '#size' => 4,
2611
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2612
  );
2613

    
2614
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2615
    '#type' => 'textfield',
2616
    '#title' => 'Background layer',
2617
    '#default_value' => $map_distribution['image_map']['base_layer'],
2618
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2619
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2620
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2621
    )),
2622
  );
2623

    
2624
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2625
    '#type' => 'textfield',
2626
    '#title' => 'Background color',
2627
    '#default_value' => $map_distribution['image_map']['bg_color'],
2628
  );
2629

    
2630
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2631
    '#type' => 'textfield',
2632
    '#title' => 'Background layer style',
2633
     // Only line color by now.
2634
    '#default_value' => $map_distribution['image_map']['layer_style'],
2635
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2636
  );
2637

    
2638
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2639
      '#type' => 'textfield',
2640
      '#title' => 'Projection',
2641
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2642
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2643
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2644
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2645
  );
2646

    
2647

    
2648
  // --- OpenLayers Settings --- //
2649
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2650
    '#type' => 'fieldset',
2651
    '#title' => 'OpenLayers settings',
2652
    '#tree' => TRUE,
2653
    '#collapsible' => TRUE,
2654
    '#collapsed' => !$open_layers_is_enabled,
2655
    '#description' => '',
2656
  );
2657

    
2658

    
2659
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2660
      '#type' => 'checkbox',
2661
      '#title' => 'Display outside max extent',
2662
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2663
      '#description' => t('Allows the map to display parts of the layers which are outside
2664
         the max extent if the aspect ratio of the map and of the baselayer
2665
         are not equal.'),
2666
  );
2667

    
2668

    
2669
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2670
      '#type' => 'checkbox',
2671
      '#title' => 'Show Layer Switcher',
2672
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2673
      '#description' => 'The Layer Switcher control displays a table of contents
2674
      for the map.  This allows the user interface to switch between
2675
      base layers and to show or hide overlays.  By default the switcher is
2676
      shown minimized on the right edge of the map, the user may expand it
2677
      by clicking on the handle.',
2678
  );
2679

    
2680
  if (!$open_layers_is_enabled) {
2681
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2682
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2683
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2684
  }
2685

    
2686
  // The default layer must always be enabled
2687
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2688
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2689

    
2690
  $baselayer_options = array(
2691
    /*
2692
   NOTICE: must correspond to the layers defined in
2693
   js/openlayers_,ap.js#getLayersByName()
2694
   */
2695
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
2696
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
2697
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
2698
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
2699
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2700
    // all others EPSG:900913
2701
    'mapnik' => 'OpenStreetMap',
2702
    'mapquest_open' => "MapQuest",
2703
    'mapquest_sat' => "MapQuest Sattelite",
2704
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2705
//    'gmap' => 'Google Streets',
2706
//    'gsat' => 'Google Satellite',
2707
//    'ghyb' => 'Google Hybrid',
2708
//     'veroad' => 'Virtual Earth Roads',
2709
//     'veaer' => 'Virtual Earth Aerial',
2710
//     'vehyb' => 'Virtual Earth Hybrid',
2711
    // 'yahoo' => 'Yahoo Street',
2712
    // 'yahoosat' => 'Yahoo Satellite',
2713
    // 'yahoohyb' => 'Yahoo Hybrid',
2714
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2715
  );
2716

    
2717
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2718
    '#type' => 'checkboxes_preferred',
2719
    '#title' => 'Base Layers',
2720
    '#options' => $baselayer_options,
2721
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2722
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2723
  );
2724

    
2725
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2726
      '#type' => 'fieldset',
2727
      '#title' => 'Custom WMS base layer',
2728
      '#tree' => TRUE,
2729
      '#collapsible' => FALSE,
2730
      '#collapsed' => FALSE,
2731
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2732
  );
2733

    
2734
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2735
      '#type' => 'textfield',
2736
      '#title' => 'Layer name',
2737
      // Only line color by now.
2738
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2739
      '#description' => 'A arbitrary name for the layer.',
2740
  );
2741
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2742
      '#type' => 'textfield',
2743
      '#title' => 'WMS url',
2744
      // Only line color by now.
2745
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2746
      '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
2747
  );
2748
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2749
      '#type' => 'textarea',
2750
      '#title' => 'WMS parameters',
2751
      '#element_validate' => array('form_element_validate_json'),
2752
      // Only line color by now.
2753
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2754
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2755
<pre> {
2756
  "Layers": "topp:em_tiny_jan2003",
2757
  "Format": "image/png",
2758
  "BGCOLOR": "0xe0faff"
2759
}
2760
</pre>'
2761
  );
2762
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2763
      '#type' => 'textfield',
2764
      '#title' => 'Projection',
2765
      // Only line color by now.
2766
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2767
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2768
  );
2769
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2770
      '#type' => 'textfield',
2771
      '#maxlength' => 256,
2772
      '#title' => 'proj4js definition',
2773
      // Only line color by now.
2774
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2775
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2776
            The definitions for
2777
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2778
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2779
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2780
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2781
            choose to display the proj4js definition string.
2782
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2783
            <pre>
2784
+a         Semimajor radius of the ellipsoid axis
2785
+alpha     ? Used with Oblique Mercator and possibly a few others
2786
+axis      Axis orientation (new in 4.8.0)
2787
+b         Semiminor radius of the ellipsoid axis
2788
+datum     Datum name (see `proj -ld`)
2789
+ellps     Ellipsoid name (see `proj -le`)
2790
+k         Scaling factor (old name)
2791
+k_0       Scaling factor (new name)
2792
+lat_0     Latitude of origin
2793
+lat_1     Latitude of first standard parallel
2794
+lat_2     Latitude of second standard parallel
2795
+lat_ts    Latitude of true scale
2796
+lon_0     Central meridian
2797
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
2798
+lon_wrap  Center longitude to use for wrapping (see below)
2799
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
2800
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
2801
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
2802
+pm        Alternate prime meridian (typically a city name, see below)
2803
+proj      Projection name (see `proj -l`)
2804
+south     Denotes southern hemisphere UTM zone
2805
+to_meter  Multiplier to convert map units to 1.0m
2806
+towgs84   3 or 7 term datum transform parameters (see below)
2807
+units     meters, US survey feet, etc.
2808
+vto_meter vertical conversion to meters.
2809
+vunits    vertical units.
2810
+x_0       False easting
2811
+y_0       False northing
2812
+zone      UTM zone
2813
            </pre>
2814
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
2815
  );
2816
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
2817
      '#type' => 'textfield',
2818
      '#title' => 'Maximum extent',
2819
      // Only line color by now.
2820
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
2821
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
2822
  );
2823
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
2824
      '#type' => 'textfield',
2825
      '#title' => 'Units',
2826
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
2827
      '#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.'
2828
  );
2829

    
2830
  /*
2831
   * Map Legend
2832
   */
2833
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2834
    '#type' => 'fieldset',
2835
    '#title' => 'Map legend',
2836
    '#tree' => TRUE,
2837
    '#collapsible' => TRUE,
2838
    '#collapsed' => TRUE,
2839
    '#description' => 'Configure the maps legend.',
2840
  );
2841

    
2842
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2843
    '#type' => 'checkbox',
2844
    '#title' => 'Display a map legend',
2845
    '#default_value' => $map_distribution['legend']['show'],
2846
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2847
  );
2848

    
2849
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2850
    '#type' => 'textfield',
2851
    '#title' => 'Legend opacity',
2852
    '#default_value' => $map_distribution['legend']['opacity'],
2853
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2854
                         to 0.0 will be not much visible.',
2855
  );
2856

    
2857
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2858
    '#type' => 'textfield',
2859
    '#title' => 'Font size',
2860
    '#default_value' => $map_distribution['legend']['font_size'],
2861
    '#description' => 'Font size in pixels.',
2862
  );
2863

    
2864
  $fontStyles = array(
2865
    0 => "plane",
2866
    1 => "italic",
2867
  );
2868
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2869
    '#type' => 'select',
2870
    '#title' => 'Available font styles',
2871
    '#default_value' => $map_distribution['legend']['font_style'],
2872
    '#options' => $fontStyles,
2873
    '#description' => 'Select a font style for the map legend.',
2874
  );
2875

    
2876
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2877
    '#type' => 'textfield',
2878
    '#title' => 'Icon width',
2879
    '#default_value' => $map_distribution['legend']['icon_width'],
2880
    '#description' => 'Legend icon width in pixels.',
2881
  );
2882
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2883
    '#type' => 'textfield',
2884
    '#title' => 'Icon height',
2885
    '#default_value' => $map_distribution['legend']['icon_height'],
2886
    '#description' => 'Legend icon height in pixels.',
2887
  );
2888

    
2889
  // @WA: D7 form api does not support reset buttons,
2890
  // so to mimic the D5 reset button we add one like this.
2891
  $form['actions']['reset'] = array(
2892
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2893
    '#weight' => 1000,
2894
  );
2895

    
2896
  return system_settings_form($form);
2897
}
2898

    
2899

    
2900
/**
2901
 * @todo document this function.
2902
 */
2903
function cdm_settings_cache() {
2904

    
2905
  $form = array();
2906

    
2907
  $form['cache_settings'] = array(
2908
    '#type' => 'fieldset',
2909
    '#title' => t('Cache Settings'),
2910
    '#collapsible' => FALSE,
2911
    '#collapsed' => FALSE,
2912
    '#description' => t('<p>When caching is enabled all single taxon sites are
2913
      stored in an internal drupal cache doing the portal response of taxa pages
2914
      faster. This is possible because the sites are loaded from the cache and
2915
      are not created from scratch.</p>'),
2916
  );
2917

    
2918
  $form['cache_settings']['cdm_webservice_cache'] = array(
2919
    '#type' => 'checkbox',
2920
    '#title' => t('<strong>Enable caching</strong>'),
2921
    '#options' => cdm_help_general_cache(),
2922
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2923
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2924
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2925
       application the changes will be not visible till the cache is erased.
2926
       Therefore developers should deactived this feature when they are working
2927
       on the CDM Dataportal Module.</p>'),
2928
  );
2929

    
2930
  $form['cache_settings']['cdm_run_cache'] = array(
2931
    '#markup' => cdm_view_cache_site(),
2932
  );
2933

    
2934
  // @WA: D7 form api does not support reset buttons,
2935
  // so to mimic the D5 reset button we add one like this.
2936
  $form['actions']['reset'] = array(
2937
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2938
    '#weight' => 1000,
2939
  );
2940
  return system_settings_form($form);
2941
}
2942

    
2943
/**
2944
 * Walk and cache all taxon pages.
2945
 */
2946
function cdm_view_cache_site() {
2947

    
2948
  $out = '';
2949

    
2950
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2951

    
2952
  $request_params = array();
2953
  $request_params['class'] = "Taxon";
2954

    
2955
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2956
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2957
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2958

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

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

    
2968
  // Comment @WA: A form within a form is not valid html and not needed here.
2969
  // Also, it would be recommended just to include this part of the form in the
2970
  // rest of the form array in cdm_settings_cache().
2971
  // $out .= '<form id="cache_site">';
2972
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2973
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2974
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2975
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2976
  // $out .= '</form>';
2977
  $out .= '</div>';
2978
  /*
2979
  foreach($taxonPager->records as $taxon){
2980
    cdm_dataportal_taxon_view($uuid);
2981
  }
2982
  */
2983
  return $out;
2984
}
2985

    
2986

    
2987
function cdm_settings_layout_taxon_submit($form, &$form_state){
2988
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2989
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2990
    if(is_object($file)){
2991
      $file->status = FILE_STATUS_PERMANENT;
2992
      file_save($file);
2993
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2994
    }
2995
  }
2996
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2997
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2998
    // we first need to set the variable to persist the changes setting
2999
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3000
    menu_rebuild();
3001
  }
3002
}
3003

    
3004
function cdm_settings_layout_search_submit($form, &$form_state){
3005
  // the visibility of media thumbnails also affects the ui of the search results
3006
  // so reset the according session variable
3007
  //    1. in order to give the user immediate
3008
  //       feedback on potential setting changes
3009
  //    2. let refresh the default if it has changed
3010
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3011
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3012
  }
3013
}
3014

    
3015
/**
3016
 * Form validation handler for cdm_settings_general
3017
 *
3018
 * @param $form
3019
 * @param $form_state
3020
 */
3021
function cdm_settings_general_validate($form, &$form_state) {
3022

    
3023
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3024
    $form_state['values']['cdm_webservice_url'] .= '/';
3025
  }
3026

    
3027
}
3028

    
3029
/**
3030
 * Form submit handler for settings general.
3031
 *
3032
 * tasks performed:
3033
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3034
 *
3035
 * @param $form
3036
 * @param $form_state
3037
 */
3038
function cdm_settings_general_submit($form, &$form_state){
3039
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3040
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3041
}
3042

    
3043
/**
3044
 * Form validation handler for cdm_settings_cache
3045
 */
3046
function cdm_settings_cache_validate($form, &$form_state) {
3047
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3048
    cache_clear_all(NULL, 'cache_cdm_ws');
3049
    // Better clear secref_cache since I can not be sure if the cache has not
3050
    // be used during this response.
3051
    cdm_api_secref_cache_clear();
3052
  }
3053

    
3054
}
3055

    
3056
/**
3057
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3058
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3059
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3060
 *  - version: the version, e.g.: v1.1
3061
 *
3062
 * @return array
3063
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3064
 */
3065
function get_edit_map_service_settings() {
3066

    
3067
  $settings = variable_get('edit_map_server', array(
3068
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3069
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3070
      )
3071
  );
3072

    
3073
  return $settings;
3074
}
3075

    
3076
/**
3077
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3078
 *
3079
 * @return string
3080
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3081
 */
3082
function get_edit_map_service_full_uri() {
3083
  $settings = get_edit_map_service_settings();
3084
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3085
}
3086

    
3087

    
3088
/**
3089
 * Returns the version number of the currently selected edit mapserver as a float
3090
 *
3091
 * @return float
3092
 *   The version number of the currently selected edit mapserver as a float.
3093
 *   Returns 0 on error.
3094
 */
3095
function get_edit_map_service_version_number() {
3096

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

    
3099
  $settings = get_edit_map_service_settings();
3100
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3101
  if (isset($matches[1])) {
3102
    // Convert string to float.
3103
    $version = 1 + $matches[1][0] - 1;
3104
    return $version;
3105
  }
3106
  else {
3107
    // Report error.
3108
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3109
        array(
3110
          '!version' => $settings['version'],
3111
          'warning')
3112
        )
3113
      );
3114
    return 0;
3115
  }
3116
}
3117

    
3118
/**
3119
 * Returns the array of selected items in a options array
3120
 *
3121
 * @param array $options
3122
 *   An options array as generated by a form element like checkoxes, select ...,
3123
 */
3124
function get_selection($options) {
3125
  $selection = array();
3126
  foreach ($options as $key=>$val) {
3127
    if (!empty($val)) {
3128
      $selection[] = $val;
3129
    }
3130
  }
3131
  return $selection;
3132
}
3133

    
3134

    
3135
/**
3136
 * Implements hook_element_info().
3137
 *
3138
 * Allows modules to declare their own Form API element types and specify their default values.
3139
 *
3140
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3141
 */
3142
function cdm_dataportal_element_info() {
3143
  $type['checkboxes_preferred'] = array(
3144
    '#input' => TRUE,
3145
    '#process' => array('checkboxes_preferred_expand'),
3146
    '#after_build' => array('checkboxes_preferred_after_build'),
3147
    '#theme' => array('checkboxes_preferred'),
3148
    // '#theme_wrapper' => array('form_element'),
3149
  );
3150
  return $type;
3151
}
3152

    
3153
/**
3154
 * #process callback function for the custom form element type 'checkbox_preferred'
3155
 *
3156
 *
3157
 */
3158
function checkboxes_preferred_expand($element, &$form_state, $form) {
3159

    
3160
  // First of all create checkboxes for each of the elements
3161
  $element = form_process_checkboxes($element);
3162

    
3163
  // compose the element name
3164
  $parents = array();
3165
  array_deep_copy($element['#parents'], $parents);
3166
  $parents[count($parents) -1 ] .= '_preferred';
3167
  $element_name = $parents[0];
3168
  for ($i=1; $i < count($parents); $i++){
3169
    $element_name .= '[' . $parents[$i] . ']';
3170
  }
3171

    
3172
  $children = element_children($element);
3173

    
3174
  $element['table_start'] = array(
3175
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3176
    '#weight' => -1,
3177
  );
3178

    
3179
  // prepare first part each of the table rows which contains the row label
3180
  $weight = 0;
3181
  foreach ($children as $key) {
3182
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3183
    $element[$key]['#weight'] = $weight;
3184
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
3185
    $element[$key]['#suffix'] = '</td>';
3186
    unset($element[$key]['#title']);
3187
    $weight += 2;
3188
  }
3189
  $weight = 0;
3190

    
3191
  // add a radio button to each of the checkboxes, the
3192
  // check boxes have already been created at the beginning
3193
  // of this function
3194
  if (count($element['#options']) > 0) {
3195
    foreach ($element['#options'] as $key => $choice) {
3196
      if (!isset($element[$key . '_preferred'])) {
3197
        $element[$key . '_preferred'] = array(
3198
          '#type' => 'radio',
3199
          '#name' => $element_name,
3200
          '#return_value' => check_plain($key),
3201
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3202
          '#attributes' => $element['#attributes'],
3203
          '#parents' => $element['#parents'],
3204
          // '#spawned' => TRUE,
3205
          '#weight' => $weight + 1,
3206
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3207
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3208
        );
3209
      }
3210
      $weight += 2;
3211
    }
3212
  }
3213

    
3214
  // end the table
3215
  $element['table_end'] = array(
3216
    '#markup' => '</table>',
3217
    '#weight' => $weight++,
3218
  );
3219

    
3220
  return $element;
3221
}
3222

    
3223
/**
3224
 * Theme function for the custom form field 'checkboxes_preferred'.
3225
 */
3226
function theme_checkboxes_preferred($variables) {
3227
  $element = $variables['element'];
3228
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3229
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3230
  $out .= drupal_render_children($element);
3231
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3232
  $out .= '</div>';
3233
  return $out;
3234
}
3235

    
3236
/**
3237
 * Callback for checkboxes preferred for widget which will
3238
 * be called after the form or element is built. The call
3239
 * back is configured in the form element by setting it as
3240
 * #after_build parameter.
3241
 *
3242
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3243
 *
3244
 * @param $element
3245
 *   Nested array of form elements that comprise the form.
3246
 * @param $form_state
3247
 *   A keyed array containing the current state of the form.
3248
 *   This includes the current persistent storage data for the form.
3249
 *   Additional information, like the sanitized $_POST data,
3250
 *   is also accumulated here in $form_state['input']
3251
 *
3252
 * @return the modified form array
3253
 */
3254
function checkboxes_preferred_after_build($element, &$form_state) {
3255

    
3256
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3257

    
3258
  if ($_POST && count($_POST) > 0) {
3259
    // TODO use  $form_state['input'] instead of POST !!!
3260
    // First pass of form processing.
3261
    $parents = array();
3262
    array_deep_copy($element['#parents'], $parents);
3263
    $parents[count($parents) - 1] .= '_preferred';
3264
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3265
    $element['#value']['PREFERRED'] = $preferred_layer;
3266
//