Project

General

Profile

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

    
7

    
8
  // TODO Genus UUID.
9

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

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

    
17
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
18

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

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

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

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

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

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

    
52

    
53

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

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

    
100

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

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

    
109

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

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

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

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

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

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

    
156
}
157

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

    
249
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
250
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
251
  array (
252
    'taxon_page_title,polytomousKey'=> array(
253
        'namePart' => array('#uri' => TRUE),
254
      ),
255
    'not_in_current_classification' => array(
256
     'nameAuthorPart' => TRUE,
257
     'referencePart' => TRUE,
258
     'statusPart' => TRUE,
259
     'secReferencePart' => TRUE,
260
    ),
261
    'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy'=> array(
262
      'nameAuthorPart' => array('#uri' => TRUE),
263
      'referencePart' => TRUE,
264
      'statusPart' => TRUE,
265
      'descriptionPart' => TRUE,
266
    ),
267
    'related_taxon'=> 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
/**
353
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
354
 * the snonymy.
355
 *
356
 * @var string
357
 */
358
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
359

    
360
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
361
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
362
    array(
363
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
364
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
365
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
366
    )
367
  )
368
);
369

    
370
/**
371
 * The drupal variable for the configuration of the information aggregation along
372
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
373
 *    - direct: the uuids of the taxon relationship types to take into account in invers
374
 *      direction.
375
 *    - invers: the uuids of the taxon relationship types to take into account in direct
376
 *      direction.
377
 *
378
 * @var String
379
 */
380
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
381
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
382
    array(
383
        'direct'=>array(),
384
        'invers'=>array()
385
     )
386
   ));
387
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
388
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
389
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
390

    
391
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
392
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
393
      array(
394
      'filter_rules' => array(
395
        'statusOrderPreference' => 0,
396
        'subAreaPreference' => 0,
397
      ),
398
      'hiddenAreaMarkerType' => array()
399
     )
400
));
401

    
402

    
403
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
404
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
405
    array(
406
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
407
        'includeOccurrences' => 0,
408
        'includeTaxonNameDescriptions' => 0
409
     )
410
  ));
411

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

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

    
478
    // unserialize if nessecary
479
    if(!is_array($default)){
480
      $default = unserialize($default);
481
    }
482
    $variable = variable_get($variable_name, array());
483
    $result = drupal_array_merge_deep($default, $variable);
484
    return $result;
485
}
486

    
487
/**
488
 * @todo document this function.
489
 */
490
function getGallerySettings($gallery_config_form_name) {
491
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
492
}
493

    
494
/**
495
 * Returns the string representation of the default tab.
496
 *
497
 * @param bool $returnTabIndex
498
 *   Defaults to FALSE, if set true this function will return the index number
499
 *   of the default tab. (used to supply default values to form elements).
500
 */
501
function get_default_taxon_tab($returnTabIndex = FALSE) {
502

    
503
  global $user;
504
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
505
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
506
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
507
  // Get the user value if the used has chosen to overwrite the system settings.
508
  $user_tab_on = variable_get($user_tab_active, FALSE);
509
  if ($user_tab_on) {
510
    $user_value = variable_get($user_tab, 0);
511
    $index_value = $user_value;
512
    // Get the system value.
513
  }
514
  else {
515
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
516
    $index_value = $system_value;
517
  }
518

    
519
  // Return the index value or the string representation.
520
  if ($returnTabIndex) {
521
    return $index_value;
522
  }
523
  else {
524
    return ($values[$index_value]);
525
  }
526
}
527

    
528

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

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

    
600
    // ---- DEFAULTS settings
601

    
602
    // only needed as final option, when the settings are not having a default
603
    $default = array(
604
      'DEFAULT' => array(
605
        'as_list' => 'div',
606
        'link_to_reference' => 0,
607
        'link_to_name_used_in_source' => 1,
608
        'sources_as_content' => 0,
609
        'sources_as_content_to_bibliography' => 0,
610
        'sort_elements' => NO_SORT,
611
        'glue' => '',
612
        'element_tag' => NULL
613
      )
614
    );
615

    
616
    // will be used as preset in the settings
617
    $other_themes_default = array(
618
      'DEFAULT' => array(
619
        'as_list' => 'div',
620
        'link_to_reference' => 0,
621
        'link_to_name_used_in_source' => 1,
622
        'sources_as_content' => 0,
623
        'sources_as_content_to_bibliography' => 0,
624
        'sort_elements' => NO_SORT,
625
        'glue' => '',
626
        'element_tag' => NULL
627
      ),
628
      UUID_CITATION => array(
629
        'as_list' => 'div',
630
        'link_to_reference' => 0,
631
        'link_to_name_used_in_source' => 0,
632
        'sources_as_content' => 1,
633
        'sources_as_content_to_bibliography' => 0,
634
        'sort_elements' => SORT_ASC,
635
        'glue' => '',
636
        'element_tag' => 'div'
637
      ),
638
      UUID_DISTRIBUTION => array(
639
        'as_list' => 'div', // currently ignored
640
        'link_to_reference' => 0,
641
        'link_to_name_used_in_source' => 0,
642
        'sources_as_content' => 0,
643
        'sources_as_content_to_bibliography' => 0,
644
        'sort_elements' => NO_SORT, // will cause ...
645
        'glue' => '',
646
        'element_tag' => 'div',
647
        'special' => array()
648
      ),
649
      UUID_COMMON_NAME => array(
650
        'as_list' => 'div',
651
        'link_to_reference' => 0,
652
        'link_to_name_used_in_source' => 1,
653
        'sources_as_content' => 0,
654
        'sources_as_content_to_bibliography' => 0,
655
        'sort_elements' => NO_SORT,
656
        'glue' => '',
657
        'element_tag' => 'span'
658
      ),
659
    );
660

    
661
    // ---- Special DEFAULTS for existing portals
662
    // TODO:
663
    // this can be removed once the feature block
664
    // settings have been deployed for the first time to these portals
665

    
666
    $cichorieae_default = array(
667
      'DEFAULT' => array(
668
        'as_list' => 'div',
669
        'link_to_reference' => 1,
670
        'link_to_name_used_in_source' => 1,
671
        'sources_as_content' => 1,
672
        'sources_as_content_to_bibliography' => 0,
673
        'sort_elements' => NO_SORT,
674
        'glue' => '',
675
        'element_tag' => 'div'
676
      ),
677
      UUID_CITATION => array(
678
        'as_list' => 'div',
679
        'link_to_reference' => 0,
680
        'link_to_name_used_in_source' => 0,
681
        'sources_as_content' => 1,
682
        'sources_as_content_to_bibliography' => 0,
683
        'sort_elements' => SORT_ASC,
684
        'glue' => '',
685
        'element_tag' => 'div'
686
      ),
687
      UUID_CHROMOSOMES_NUMBERS => array(
688
        'as_list' => 'ul',
689
        'link_to_reference' => 1,
690
        'link_to_name_used_in_source' => 1,
691
        'sources_as_content' => 1,
692
        'sources_as_content_to_bibliography' => 0,
693
        'sort_elements' => NO_SORT,
694
        'glue' => '',
695
        'element_tag' => 'div'
696
      ),
697
      UUID_CHROMOSOMES => array(
698
        'as_list' => 'ul',
699
        'link_to_reference' => 0,
700
        'link_to_name_used_in_source' => 1,
701
        'sources_as_content' => 1,
702
        'sources_as_content_to_bibliography' => 0,
703
        'sort_elements' => NO_SORT,
704
        'glue' => '',
705
        'element_tag' => 'div'
706
      ),
707
      UUID_COMMON_NAME => array(
708
        'as_list' => 'div',
709
        'link_to_reference' => 0,
710
        'link_to_name_used_in_source' => 1,
711
        'sources_as_content' => 0,
712
        'sources_as_content_to_bibliography' => 0,
713
        'sort_elements' => NO_SORT,
714
        'glue' => '',
715
        'element_tag' => 'span'
716
      ),
717
    );
718

    
719
    $palmweb_default = array(
720
      'DEFAULT' => array(
721
        'as_list' => 'ul',
722
        'link_to_reference' => 1,
723
        'link_to_name_used_in_source' => 1,
724
        'sources_as_content' => 1,
725
        'sources_as_content_to_bibliography' => 1,
726
        'sort_elements' => NO_SORT,
727
        'glue' => '',
728
        'element_tag' => NULL
729
      ),
730
      UUID_CITATION => array(
731
        'as_list' => 'ul',
732
        'link_to_reference' => 1,
733
        'link_to_name_used_in_source' => 1,
734
        'sources_as_content' => 0,
735
        'sources_as_content_to_bibliography' => 1,
736
        'sort_elements' => SORT_ASC,
737
        'glue' => '',
738
        'element_tag' => 'div'
739
      ),
740
      UUID_DISTRIBUTION => array(
741
        'as_list' => 'div', // currently ignored
742
        'link_to_reference' => 1,
743
        'link_to_name_used_in_source' => 1,
744
        'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
745
        'sources_as_content_to_bibliography' => 1,
746
        'sort_elements' => NO_SORT, // will cause ...
747
        'glue' => '',
748
        'element_tag' => 'div',
749
        'special' => array()
750
      ),
751
    );
752

    
753
    $cyprus_default = $cichorieae_default;
754
    $cyprus_default[UUID_DISTRIBUTION] = array(
755
      'as_list' => 'div', // currently ignored
756
      'link_to_reference' => 0,
757
      'link_to_name_used_in_source' => 0,
758
      'sources_as_content' => 0,
759
      'sources_as_content_to_bibliography' => 0,
760
      'sort_elements' => NO_SORT, // will cause ...
761
      'glue' => '',
762
      'element_tag' => 'div',
763
      'special' => array()
764
    );
765

    
766
    $default_theme = variable_get('theme_default', NULL);
767

    
768
    switch ($default_theme) {
769
      case 'garland_cichorieae':
770
        $settings_for_theme = $cichorieae_default;
771
        break;
772
      case 'cyprus':
773
        // cyprus: no longer used in production,
774
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
775
        $settings_for_theme = $cyprus_default;
776
        break;
777
      case 'flore_afrique_centrale':
778
      case 'flora_malesiana':
779
      case 'flore_gabon':
780
        $settings_for_theme = $cichorieae_default;
781
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
782
        break;
783
      case 'palmweb_2':
784
        $settings_for_theme = $palmweb_default;
785
        break;
786
      default:
787
        $settings_for_theme = $other_themes_default;
788
    }
789
    // ---- END of DEFAULTS
790

    
791
    $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
792

    
793
    $feature_block_setting = null;
794

    
795
    if (isset($saved_settings[$feature_uuid])) {
796
      $feature_block_setting = $saved_settings[$feature_uuid];
797
    }
798
    else if (isset($settings_for_theme[$feature_uuid])) {
799
      $feature_block_setting = $settings_for_theme[$feature_uuid];
800
    }
801
    else if (isset($settings_for_theme['DEFAULT'])) {
802
      $feature_block_setting = $settings_for_theme['DEFAULT'];
803
    }
804

    
805
    // now merge the default and specific settings
806
    $settings_to_merge = array($default['DEFAULT']);
807
    if(is_array($saved_settings)){
808
      $settings_to_merge[] = $saved_settings['DEFAULT'];
809
    }
810
    if(isset($feature_block_setting)){
811
      $settings_to_merge[] = $feature_block_setting;
812
    }
813
    $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
814

    
815
    return $feature_block_setting;
816
}
817
  /**
818
 * returns the current setting for the original source bibliography
819
 *
820
 * Caches internally
821
 *
822
 * @return array
823
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
824
 *   - 'enabled': 1|0
825
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
826
 */
827
function get_bibliography_settings($clear_cache = false){
828
  static $bibliography_settings = null;
829
  if(!$bibliography_settings || $clear_cache){
830
    $bibliography_settings = get_array_variable_merged(
831
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
832
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
833
    );
834
  }
835
  return $bibliography_settings;
836
}
837

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

    
873
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
874
    'title' => 'Cache',
875
    'description' => 'Cache',
876
    'access arguments' => array('administer cdm_dataportal'),
877
    'page callback' => 'drupal_get_form',
878
    'page arguments' => array('cdm_settings_cache'),
879
    'weight' => 10,
880
    'type' => MENU_LOCAL_TASK,
881
  );
882

    
883
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
884
    'title' => 'Geo & Map',
885
    'description' => 'Geo & Map',
886
    'access arguments' => array('administer cdm_dataportal'),
887
    'page callback' => 'drupal_get_form',
888
    'page arguments' => array('cdm_settings_geo'),
889
    'weight' => 1,
890
    'type' => MENU_LOCAL_TASK,
891
  );
892

    
893
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
894
    'title' => 'Layout',
895
    'description' => 'Configure and adjust the layout of your DataPortal ',
896
    'access arguments' => array('administer cdm_dataportal'),
897
    'page callback' => 'drupal_get_form',
898
    'page arguments' => array('cdm_settings_layout'),
899
    'weight' => 2,
900
    'type' => MENU_LOCAL_TASK,
901
  );
902

    
903
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
904
    'title' => 'Taxon',
905
    'description' => 'Configure and adjust the layout of your DataPortal ',
906
    'access arguments' => array('administer cdm_dataportal'),
907
    'page callback' => 'drupal_get_form',
908
    'page arguments' => array('cdm_settings_layout_taxon'),
909
    'weight' => 1,
910
    'type' => MENU_LOCAL_TASK,
911
  );
912
  /*
913
  $items[] = array(
914
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
915
  'title' => t('Synonymy'),
916
  'description' => t('Configure and adjust the layout of your DataPortal '),
917
  'access' => user_access('administer cdm_dataportal'),
918
  'callback' => 'drupal_get_form',
919
  'callback arguments' => array('cdm_settings_layout_synonymy'),
920
  'weight' => 1,
921
  'type' => MENU_LOCAL_TASK,
922
  );
923

    
924
  $items[] = array(
925
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
926
  'title' => t('Specimens'),
927
  'description' => t('Configure and adjust the layout of your DataPortal '),
928
  'access' => user_access('administer cdm_dataportal'),
929
  'callback' => 'drupal_get_form',
930
  'callback arguments' => array('cdm_settings_layout_specimens'),
931
  'weight' => 1,
932
  'type' => MENU_LOCAL_TASK,
933
  );
934
  */
935
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
936
    'title' => 'Search',
937
    'description' => 'Configure and adjust the layout of your DataPortal ',
938
    'access arguments' => array('administer cdm_dataportal'),
939
    'page callback' => 'drupal_get_form',
940
    'page arguments' => array('cdm_settings_layout_search'),
941
    'weight' => 2,
942
    'type' => MENU_LOCAL_TASK,
943
  );
944

    
945
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
946
    'title' => 'Media',
947
    'description' => 'Configure and adjust the layout of your DataPortal ',
948
    'access arguments' => array('administer cdm_dataportal'),
949
    'page callback' => 'drupal_get_form',
950
    'page arguments' => array('cdm_settings_layout_media'),
951
    'weight' => 3,
952
    'type' => MENU_LOCAL_TASK,
953
  );
954

    
955
}
956

    
957
/**
958
 * @todo document this function.
959
 */
960
function cdm_help_general_cache() {
961
  $form = array();
962
  $form['cache_help'] = array(
963
    '#type' => 'fieldset',
964
    '#title' => t('Help'),
965
    '#collapsible' => TRUE,
966
    '#collapsed' => TRUE,
967
  );
968
  $form['cache_help']['test'] = array('#value' => t('probando'));
969
  return drupal_render($form);
970
  $res = array();
971
  $res['default'] = drupal_render($help);
972
  return $res;
973
}
974

    
975
/**
976
 * Configures the settings form for the CDM-API module.
977
 *
978
 * @return array
979
 *   Drupal settings form.
980
 */
981
function cdm_settings_general() {
982

    
983
  $form['cdm_webservice'] = array(
984
    '#type' => 'fieldset',
985
    '#title' => t('CDM Server'),
986
    '#collapsible' => FALSE,
987
    '#collapsed' => FALSE,
988
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
989
        CDM data base to the web via RESTful web services and thus is the source of the data
990
        to be displayed by a CDM DataPotal.'),
991
  );
992

    
993
  $form['cdm_webservice']['cdm_webservice_url'] = array(
994
    '#type' => 'textfield',
995
    '#title' => t('CDM web service URL') . ':',
996
    '#description' => t('This is the URL to the CDM-Server exposing your data
997
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
998
    '#default_value' => variable_get('cdm_webservice_url', NULL),
999
  );
1000

    
1001
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1002
    '#type' => 'markup',
1003
    '#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')
1004
      . ' visible only for administrators',
1005
  );
1006

    
1007
  $form['cdm_webservice']['freetext_index'] = array(
1008
    '#type' => 'fieldset',
1009
    '#title' => t('Freetext index'),
1010
    '#collapsible' => FALSE,
1011
    '#collapsed' => FALSE,
1012
  );
1013

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

    
1026
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1027
  $trigger_link_options = array(
1028
    'attributes' => array(
1029
      'class' => 'index-trigger',
1030
    ),
1031
  );
1032
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1033
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1034
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1035
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1036
      ))
1037
    . '<div id="index-progress"></div></div>',
1038
  );
1039
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1040

    
1041
  $form['cdm_webservice']['proxy'] = array(
1042
    '#type' => 'fieldset',
1043
    '#title' => t('Proxy'),
1044
    '#collapsible' => TRUE,
1045
    '#collapsed' => TRUE,
1046
  );
1047

    
1048
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1049
    '#type' => 'textfield',
1050
    '#title' => t('Proxy URL') . ':',
1051
    '#description' => t('If this proxy url is set the cdm api tries
1052
    to connect the web service over the given proxy server.
1053
    Otherwise proxy usage is deactivated.'),
1054
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1055
  );
1056

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

    
1063
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1064
    '#type' => 'textfield',
1065
    '#title' => t('Login') . ':',
1066
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1067
  );
1068

    
1069
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1070
    '#type' => 'textfield',
1071
    '#title' => t('Password') . ':',
1072
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1073
  );
1074

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

    
1091
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1092
    '#type' => 'select',
1093
    '#title' => t('Available classifications') . ':',
1094
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1095
    '#options' => cdm_get_taxontrees_as_options(),
1096
    '#description' => t('Select the default taxa classification for your
1097
      <em>taxon tree</em>, the other classifications will be also available but
1098
      with a manual user change.'),
1099
  );
1100

    
1101
  $form['taxon_tree']['taxontree_ranklimit'] = array(
1102
    '#type' => 'select',
1103
    '#title' => t('Rank of highest displayed taxon') . ':',
1104
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1105
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
1106
    '#options' => cdm_rankVocabulary_as_option(),
1107
    '#description' => t('This is the rank of the highest displayed taxon in the
1108
      <em>taxon tree</em>. You can select here which rank should be at the top
1109
      level of the tree structure.'),
1110
  );
1111

    
1112
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1113
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1114
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1115
      '#type' => 'checkboxes',
1116
      '#title' => t('Included Classifications') . ':',
1117
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1118
      '#options' => cdm_get_taxontrees_as_options(),
1119
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1120
  );
1121

    
1122
  $form['distribution'] = array(
1123
      '#type' => 'fieldset',
1124
      '#title' => t('Distributions'),
1125
      '#collapsible' => FALSE,
1126
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1127
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1128
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1129
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1130
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1131
          '<p>
1132
          </p>',
1133
  );
1134

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

    
1156
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1157
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1158
      '#type' => 'checkboxes',
1159
      '#title' => 'Filter rules',
1160
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1161
      '#options' => array(
1162
          'statusOrderPreference' => 'Status order preference rule',
1163
          'subAreaPreference' => 'Sub area preference rule'
1164
      ),
1165
  );
1166

    
1167
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1168
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1169
      '#type' => 'checkboxes',
1170
      '#title' => 'Hide marked area filter',
1171
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1172
      '#options' => $marker_type_options,
1173
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1174
  );
1175

    
1176
  $form['aggregation'] = array(
1177
      '#type' => 'fieldset',
1178
      '#title' => t('Aggregation of data'),
1179
      '#collapsible' => FALSE,
1180
      '#description' => 'This section covers the different aspects of aggregating information.
1181
          <p>
1182
          </p>',
1183
  );
1184

    
1185
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1186
      '#type' => 'checkboxes',
1187
      '#title' => 'Taxon media filter',
1188
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1189
      '#options' => array(
1190
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1191
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1192
          'includeOccurrences' => 'Media related to specimens and occurrences',
1193
      ),
1194
      '#description' => 'This filter configures which images should be taken into account.',
1195
  );
1196

    
1197
  $form['aggregation']['notice'] = array(
1198
      '#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
1199
          want to make use of the caching capabilities of the dataportal.',
1200
  );
1201

    
1202
  $form['aggregation']['media_aggregation'] = array(
1203
      '#type' => 'fieldset',
1204
      '#title' => t('Media aggregation'),
1205
      '#collapsible' => FALSE,
1206
      '#collapsed' => TRUE,
1207
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1208

    
1209
  );
1210
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1211
      '#type' => 'select',
1212
      '#title' => t('Aggregation of taxon pictures') . ':',
1213
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1214
      '#options' => array(
1215
          0 => "Show only pictures of the current taxon",
1216
          1 => "Include pictures of taxonomic children",
1217
      ),
1218
      '#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."),
1219
  );
1220

    
1221
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1222
      '#type' => 'fieldset',
1223
      '#attributes' => array('class'=>array('clearfix')),
1224
      '#title' => t('Aggregation via taxon relationsships'),
1225
      '#collapsible' => TRUE,
1226
      '#collapsed' => TRUE,
1227
      '#tree' => TRUE,
1228
      '#description' => t('Information on taxa will be aggregated along the below chosen
1229
          taxon relation ships. This will affect images and occurrences (specimens).
1230
          Taxon relation ships are directed and point form one taxon to another. The taxon
1231
          relationships to be taken into accunt can therefore configured for the direct direction
1232
          and for the inverse.'),
1233
  );
1234

    
1235
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1236
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1237

    
1238
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1239
      '#type' => 'checkboxes',
1240
      '#title' => t('Direct'),
1241
      '#options' => $taxonRelationshipTypeOptions,
1242
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1243
  );
1244
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1245
      '#type' => 'checkboxes',
1246
      '#title' => t('Invers'),
1247
      '#options' => $taxonRelationshipTypeOptions,
1248
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1249
  );
1250

    
1251
  $form['drupal_integration'] = array(
1252
    '#type' => 'fieldset',
1253
    '#attributes' => array('class'=>array('clearfix')),
1254
    '#title' => t('Drupal integration'),
1255
    '#collapsible' => FALSE,
1256
    '#collapsed' => FALSE,
1257
    '#tree' => FALSE
1258
  );
1259

    
1260
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1261
    '#type' => 'checkbox',
1262
    '#title' => 'Create drupal nodes',
1263
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1264
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1265
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1266
    cdm pages it is required that drupal nodes are created and stored in the database.'
1267
  );
1268

    
1269

    
1270

    
1271
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1272
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1273
    <div class="description">Using this button, you will lose all content associated with the cdm drupal nodes which is stored in the drupal data base.</div>',
1274
  );
1275
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1276
    '#type' => 'submit',
1277
    '#value' => t('Drop all cdm nodes'),
1278
    '#submit' => array('drop_all_cdm_nodes_submit')
1279
  );
1280

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

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

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

    
1317
  $form['#submit'][] = 'cdm_settings_general_submit';
1318

    
1319
  return system_settings_form($form);
1320
}
1321

    
1322
/**
1323
 * Submit callback; drops all cdm nodes.
1324
 *
1325
 * @ingroup forms
1326
 */
1327
function drop_all_cdm_nodes_submit($form, &$form_state) {
1328
  cdm_delete_all_cdm_nodes();
1329
  drupal_set_message(t('All cdm nodes dropped.'));
1330
}
1331

    
1332

    
1333
/**
1334
 * LAYOUT settings
1335
 * @return
1336
 *   todo
1337
 */
1338
function cdm_settings_layout() {
1339

    
1340
  $form = array();
1341

    
1342
  $form['about'] = array(
1343
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1344
      layout. If you want to configure the specific sites layout visit the
1345
      respective configuration site for taxon, search or media.') . '</p>',
1346
  );
1347

    
1348
  // ---- footnotes --- //
1349
  $form['footnotes'] = array(
1350
    '#type' => 'fieldset',
1351
    '#title' => t('Footnotes'),
1352
    '#collapsible' => FALSE,
1353
    '#collapsed' => FALSE,
1354
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1355
      media or distribution areas may have annotations or footnotes. When the
1356
      footnotes are enabled they will be visible (if they exist).'),
1357
  );
1358

    
1359
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1360
    '#type' => 'checkbox',
1361
    '#title' => t('Do not show footnotes'),
1362
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1363
    '#description' => t('Check this if you do not want to show any footnotes'),
1364
  );
1365

    
1366
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1367
    '#type' => 'checkbox',
1368
    '#title' => t('Do not show annotation footnotes'),
1369
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1370
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1371
  );
1372

    
1373
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1374
  // Additional option for the NULL case.
1375
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1376
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1377
    '#type' => 'checkboxes',
1378
    '#title' => t('Annotation types as footnotes'),
1379
    '#description' => t("Only annotations of the selected type will be displayed
1380
       as footnotes. You may want to turn 'technical annotations' off."),
1381
    '#options' => $annotationTypeOptions,
1382
  );
1383
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1384
  if (!empty($annotationsTypesAsFootnotes)) {
1385
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1386
  }
1387

    
1388
  // ---- original source --- //
1389
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1390
      '#type' => 'fieldset',
1391
      '#tree' => TRUE,
1392
      '#title' => t('Source Citations'),
1393
      '#collapsible' => FALSE,
1394
      '#collapsed' => FALSE,
1395
  );
1396

    
1397
  $bibliography_settings = get_bibliography_settings(true);
1398

    
1399
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1400
      '#type' => 'checkbox',
1401
      '#title' => t('Original Source in bibliography'),
1402
      '#default_value' => $bibliography_settings['enabled'],
1403
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1404
       annotations in each feature block.'),
1405
  );
1406

    
1407
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1408
    '#type' => 'select',
1409
    '#title' => t('The format of the key numerals'),
1410
    '#default_value' => $bibliography_settings['key_format'],
1411
    '#options' => array('latin' => 'Latin',
1412
      'ROMAN' => 'Roman (upper case)',
1413
      'roman' => 'Roman (lower case)',
1414
      'ALPHA'=> 'Alphabet (upper case)',
1415
      'alpha' => 'Alphabet (lower case)')
1416
  );
1417

    
1418
  // --- Advanced Search --- //
1419
  $form['asearch'] = array(
1420
      '#type' => 'fieldset',
1421
      '#title' => t('Advanced search'),
1422
      '#collapsible' => FALSE,
1423
      '#collapsed' => FALSE,
1424
  );
1425
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1426
      '#type' => 'checkbox',
1427
      '#title' => t('Show advanced search link'),
1428
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1429
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1430
  );
1431

    
1432
  // ---- Taxon Name Rendering --- //
1433
  $form['taxon_name'] = array(
1434
      '#type' => 'fieldset',
1435
      '#title' => t('Taxon name display'),
1436
      '#collapsible' => TRUE,
1437
      '#collapsed' => TRUE,
1438
      '#description' => t('The display of taxon names is configured by two parts.'
1439
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
1440
          . 'The name parts are defined in the <stong>part definitions</strong>'),
1441
  );
1442

    
1443
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1444
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1445
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1446
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1447

    
1448
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1449
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1450
    $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.)';
1451
  } else if($is_custom_part_definition){
1452
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1453
  } else  {
1454
    $which_version_message = '(These are the default part definition.)';
1455
  }
1456

    
1457
  $diff_viewer_markup = '';
1458
  if($is_custom_part_definition){
1459
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1460
  }
1461

    
1462
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1463
    . $which_version_message
1464
    . '</div>'
1465
    . $diff_viewer_markup;
1466

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

    
1556
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1557
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1558
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1559
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1560
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1561

    
1562
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1563
    $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.)';
1564
  } else if($is_custom_render_template){
1565
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1566
  } else {
1567
    $which_version_message = '(These are the default render templates.)';
1568
  }
1569

    
1570
  $diff_viewer_markup = '';
1571
  if($is_custom_render_template){
1572
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1573
  }
1574

    
1575
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1576
    . $which_version_message
1577
    . '</div>'
1578
    . $diff_viewer_markup;
1579

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

    
1620
  // @WA: D7 form api does not support reset buttons,
1621
  // so to mimic the D5 reset button we add one like this.
1622
  $form['actions']['reset'] = array(
1623
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1624
    '#weight' => 1000,
1625
  );
1626

    
1627
  $form['#submit'] = array('submit_json_as_php_array');
1628
  // #json_elements especially defined for submit_json_as_php_array()
1629
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1630
  return system_settings_form($form);
1631
}
1632

    
1633

    
1634

    
1635
  /**
1636
 * @todo Please document this function.
1637
 * @see http://drupal.org/node/1354
1638
 */
1639
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1640
  $form[$form_name] = array(
1641
    '#type' => 'fieldset',
1642
    '#title' => t($form_title),
1643
    '#collapsible' => TRUE,
1644
    '#collapsed' => $collapsed,
1645
    '#tree' => TRUE,
1646
    '#description' => t($form_description),
1647
  );
1648

    
1649
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1650
  $gallery_settings = variable_get($form_name, $default_values);
1651
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1652
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1653
    /*
1654
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1655
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1656
    '#type' => 'textfield',
1657
    '#title' => t('Search Page Size'),
1658
    '#default_value' => $test,
1659
    '#description' => t('Number of Names to display per page in search results.')
1660
    );
1661
    */
1662
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1663
      '#type' => 'checkbox',
1664
      '#title' => t('Show media thumbnails for accepted taxa'),
1665
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1666
    );
1667

    
1668
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1669
      '#type' => 'checkbox',
1670
      '#title' => t('Show media thumbnails for synonyms'),
1671
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1672
      '#description' => '',
1673
    );
1674
  }
1675

    
1676
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1677
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1678
    '#type' => 'checkbox',
1679
    '#title' => t('Show captions under thumbnails'),
1680
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1681
    '#description' => '',
1682
  );
1683

    
1684
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1685
    '#type' => 'textfield',
1686
    '#title' => t('Thumbnail size') . ':',
1687
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1688
    '#description' => t('Select the size of each individual thumbnail.'),
1689
  );
1690

    
1691
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1692
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1693
      '#type' => 'textfield',
1694
      '#title' => t('Number of columns') . ':',
1695
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1696
      '#description' => t('Group the thumbnails in columns: select how many
1697
        columns the gallery should display.'),
1698
    );
1699
  }
1700

    
1701
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1702
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1703
      '#type' => 'textfield',
1704
      '#title' => t('Maximum number of rows') . ':',
1705
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1706
      '#description' => t('You can group the thumbnails in rows, select in how
1707
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1708
        If you want an unlimited number of rows please set to 0.'),
1709
    );
1710
  }
1711

    
1712
  return $form;
1713
}
1714

    
1715
/**
1716
 * @todo document this function.
1717
 */
1718
function cdm_settings_layout_taxon() {
1719
  $collapsed = FALSE;
1720
  $form = array();
1721

    
1722
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1723

    
1724
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1725
      '#type' => 'checkbox',
1726
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1727
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1728
      '#description' => t('<p>If checked the link to search results is rendered at
1729
       the top of the taxon site. Clicking on the link the last search performed
1730
       is rendered again.</p>'),
1731
  );
1732

    
1733
  // --------- TABBED TAXON ------- //
1734
  $form['taxon_tabs'] = array(
1735
    '#type' => 'fieldset',
1736
    '#title' => t('Taxon tabs'),
1737
    '#collapsible' => TRUE,
1738
    '#collapsed' => TRUE,
1739
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1740
      be splitted in four diferent tabs; General, Synonymy, Images and
1741
      Specimens. If the taxon has no information for any of the tabs/sections
1742
      such tab will be not displayed.'),
1743
  );
1744

    
1745
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1746
    '#type' => 'checkbox',
1747
    '#title' => t('Tabbed taxon page'),
1748
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1749
    '#description' => t('<p>If selected split the taxon page into individual
1750
      tabs for description, images, synonymy and specimens. If not the taxon
1751
      data is rendered as a long single page without tabs.</p>'),
1752
  );
1753

    
1754
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1755
    '#type' => 'checkboxes',
1756
    '#title' => t('Tabs visibility options') . ':',
1757
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1758
    '#options' => get_taxon_options_list(),
1759
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1760
  );
1761

    
1762
  // WEIGHT
1763
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1764
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1765
      '#tree' => true
1766
  );
1767
  // Weights range from -delta to +delta, so delta should be at least half
1768
  // of the amount of tabs present.
1769
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1770
  foreach (get_taxon_tabs_list() as $label) {
1771
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1772
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1773
        '#title' => $label,
1774
        '#type'  => 'weight',
1775
        '#default_value' => $taxontabs_weights[$key],
1776
        '#delta' => $tab_weight_delta
1777
    );
1778
  }
1779

    
1780
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1781
    '#type' => 'select',
1782
    '#title' => t('Default tab to display') . ':',
1783
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1784
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1785
    '#description' => t('<p>Select the default tab to display when visiting a
1786
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1787
      <strong>Note:</strong> After performing a search and clicking in any
1788
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1789
      taxon and not the above selected tab.'),
1790
  );
1791

    
1792
  /* ======  TAXON_PROFILE ====== */
1793
  $form['taxon_profile'] = array(
1794
    '#type' => 'fieldset',
1795
    '#title' => t('Taxon profile (tab)'),
1796
    '#description' => t('<p>This section covers the settings related to the taxon
1797
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1798
    '#collapsible' => TRUE,
1799
    '#collapsed' => TRUE,
1800
  );
1801

    
1802
  // ---- PROFILE PICTURE ----//
1803

    
1804
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1805
    '#type' => 'fieldset',
1806
    '#tree' => TRUE,
1807
    '#title' => t('Taxon profile picture'),
1808
    '#collapsible' => TRUE,
1809
    '#collapsed' => FALSE,
1810
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1811
  );
1812

    
1813
  //FIXME migrate variables:
1814
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1815
  // FIXME
1816
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1817

    
1818
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1819

    
1820
  /*
1821
   * 'show' => 1,
1822
   * 'maxextend' => 184,
1823
   * 'media_uri_query' => ''
1824
   * 'custom_placeholder_image_on' => 1,
1825
   * 'custom_placeholder_image_fid' => ''
1826
   */
1827
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1828
    '#type' => 'checkbox',
1829
    '#title' => t('Enable profile picture'),
1830
    '#description' => t('Show the profile picture.'),
1831
    '#default_value' => $taxon_profile_image_settings['show'],
1832
  );
1833

    
1834
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1835
      '#type' => 'textfield',
1836
      '#tree' => TRUE,
1837
      '#title' => t('Profile picture maximum extend'),
1838
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1839
      '#field_suffix' => 'px',
1840
      '#maxlength' => 4,
1841
      '#size' => 4,
1842
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1843
  );
1844

    
1845
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1846
      '#type' => 'textfield',
1847
      '#tree' => TRUE,
1848
      '#title' => t('Additional URI query parameter'),
1849
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1850
      '#maxlength' => 1024,
1851
      '#size' => 60,
1852
      '#description' => t('Additional query parameters to be used when requesting for the '
1853
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1854
          . 'The query parameters will be appended to the uri of the media representation part'
1855
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1856
  );
1857

    
1858
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1859
    '#type' => 'checkbox',
1860
    '#title' => t('Show the placeholder image'),
1861
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
1862
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1863
  );
1864

    
1865
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1866
      '#type' => 'checkbox',
1867
      '#title' => t('Use a custom placeholder image'),
1868
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1869
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1870
  );
1871

    
1872
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1873
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1874
        '#type' => 'managed_file',
1875
        '#title' => t('Custom placeholder image file'),
1876
        '#progress_indicator' => 'bar',
1877
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1878
    //       '#name' => 'custom_placeholder_image',
1879
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1880
    );
1881

    
1882
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1883
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1884
      $url = file_create_url($profile_image_file->uri);
1885
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1886
                '#type' => 'item',
1887
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1888
      );
1889
    }
1890
  } else {
1891
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1892
      '#type' => 'hidden',
1893
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1894
    );
1895
  }
1896

    
1897
  $options = cdm_rankVocabulary_as_option();
1898
  array_unshift($options, '-- DISABLED --');
1899
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1900
    '#type' => 'select',
1901
    '#title' => t('Hide profile picture for higher ranks') . ':',
1902
    '#default_value' => variable_get('image_hide_rank', '0'),
1903
    '#options' => $options,
1904
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1905
  );
1906

    
1907
  // -- MEDIA THUMBNAILS -- //
1908
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1909
  $form_title = 'Taxon Profile Images';
1910
  $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>';
1911
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1912

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

    
1941
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
1942
  $profile_feature_tree = get_profile_feature_tree();
1943

    
1944
  if (isset($profile_feature_tree->root->childNodes)) {
1945

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

    
1985

    
1986
    $feature_list_layout_settings_disabled = FALSE;
1987

    
1988
    // creating helper object to retrieve the default settings
1989
    $featureNode = new stdClass();
1990
    $featureNode->feature = new stdClass();
1991
    $featureNode->feature->uuid="DEFAULT";
1992
    $featureNode->feature->representation_L10n = "Default";
1993
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
1994

    
1995
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
1996

    
1997
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1998

    
1999
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2000
        $subform_id = $featureNode->feature->uuid;
2001
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2002

    
2003
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2004

    
2005
        $form_feature_block_layout[$subform_id] = array(
2006
          '#type' => 'fieldset',
2007
          '#tree' => TRUE,
2008
          '#title' => $featureNode->feature->representation_L10n,
2009
          '#collapsible' => FALSE,
2010
          '#collapsed' => FALSE,
2011
        );
2012
        if($featureNode->feature->uuid == "DEFAULT"){
2013
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2014
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2015
          references</em> and <em>names in source</em> is only possible in the defaults';
2016
        }
2017

    
2018
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2019
          '#type' => 'select',
2020
          '#title' => 'List type',
2021
          '#default_value' => $feature_block_setting['as_list'],
2022
          '#options' => array(
2023
            'div' => 'not as list',
2024
            'ul' => 'bullet list',
2025
            'ol' => 'numbered list',
2026
            'dl' => 'definition list'
2027
          ),
2028
        );
2029

    
2030
        if($featureNode->feature->uuid == "DEFAULT"){
2031
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2032
            '#type' => 'checkbox',
2033
            '#title' => t('Link to reference'),
2034
            '#default_value' => $feature_block_setting['link_to_reference'],
2035
          );
2036

    
2037
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2038
            '#type' => 'checkbox',
2039
            '#title' => 'Link to name used in source',
2040
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2041
          );
2042
        }
2043

    
2044
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2045
          '#type' => 'checkbox',
2046
          '#title' => 'Sources as content',
2047
          '#default_value' => $feature_block_setting['sources_as_content'],
2048
        );
2049

    
2050
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2051
          '#type' => 'checkbox',
2052
          '#title' => 'Put sources also as content to bibliography',
2053
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2054
        );
2055

    
2056
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2057
          '#type' => 'select',
2058
          '#title' => t('Sort elements'),
2059
          '#default_value' => $feature_block_setting['sort_elements'],
2060
          '#options' => array(
2061
            NO_SORT => 'No sorting',
2062
            SORT_ASC => 'Ascending',
2063
            SORT_DESC => 'Descending',
2064
            SORT_HIERARCHICAL => 'Hierarchical'
2065
          ),
2066
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2067
          <dl>
2068
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2069
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2070
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2071
          <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>
2072
          </dl>',
2073
        );
2074

    
2075
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2076
          '#type' => 'select',
2077
          '#title' => t('Element tag'),
2078
          '#options' => array(
2079
            'span' => 'span',
2080
            'div' => 'div'
2081
          ),
2082
          '#default_value' => $feature_block_setting['element_tag'],
2083
        );
2084
      }
2085
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2086
    }
2087
  }
2088

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

    
2114

    
2115

    
2116
  // ---- DISTRIBUTION LAYOUT ---- //
2117
  $form['taxon_profile']['distribution_layout'] = array(
2118
    '#title' => t('Distribution'),
2119
    '#collapsible' => TRUE,
2120
    '#collapsed' => FALSE,
2121
    '#type' => 'fieldset',
2122
    '#description' => 'This section covers general settings regarding the textual representation of distributions.
2123
        Map related settings are found in the '
2124
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2125
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2126
      . l(
2127
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2128
        array('fragment' => 'edit-feature-block-settings')
2129
      )
2130
      . ' More general settings regrading the filtering of Distributions are found at '
2131
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2132
      . '. (These settings here will be merged in future releases into the feature block settings)',
2133

    
2134
  );
2135

    
2136
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2137
    '#type' => 'checkbox',
2138
    '#title' => t('Condensed distribution'),
2139
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2140
    '#description' => 'This option enables the display of a very compact representation
2141
    of the distribution which includes also information on the status.',
2142
  );
2143

    
2144
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2145
    '#type' => 'select',
2146
    '#title' => t('Condensed distribution recipe'),
2147
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2148
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2149
    '#description' => 'Recipe for creating the condensed distribution.',
2150
  );
2151

    
2152
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2153
    '#type' => 'textfield',
2154
    '#title' => t('Condensed distribution info path'),
2155
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2156
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2157
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2158
  );
2159

    
2160

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

    
2178
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, SORT_ASC);
2179
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2180
    '#type' => 'checkboxes',
2181
    '#title' => 'Omit area levels',
2182
    '#options' => $level_options,
2183
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2184
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2185
    Areas which belong to the selected area levels will be hidden in the portal.',
2186
  );
2187

    
2188
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2189
    '#type' => 'checkbox',
2190
    '#title' => t('Show TextData elements on top of the map'),
2191
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2192
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2193
      elements on top of the map. Otherwise all <code>TextData</code>
2194
      distribution elements will be listed below the other area elements.
2195
      This option is useful if you need to have descriptive texts for each
2196
      distribution map.'),
2197
  );
2198

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

    
2226
AbsenceTerm
2227
a	absent
2228
f	reported in error
2229
nf	native: reported in error
2230
if	introduced: reported in error
2231
cf	cultivated: reported in error
2232
ne	native: formerly native
2233
ie	introduced: formerly introduced
2234

    
2235
</pre>'),
2236
  );
2237

    
2238

    
2239
  /* ====== SYNONYMY ====== */
2240
  $form['taxon_synonymy'] = array(
2241
    '#type' => 'fieldset',
2242
    '#title' => t('Taxon synonymy (tab)'),
2243
    '#collapsible' => TRUE,
2244
    '#collapsed' => TRUE,
2245
    '#description' => t('This section covers the settings related to the taxon
2246
      <strong>synonymy</strong> tab.'),
2247
  );
2248

    
2249
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2250
    '#type' => 'checkbox',
2251
    '#title' => t('Show accepted taxon on top of the synonymy'),
2252
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2253
    '#description' => t('If checked, the first homotypic taxon is a repetition
2254
      of the accepted taxon most likely with the full nomenclatural reference
2255
      (depending on the currently chosen theme).'),
2256
  );
2257

    
2258
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2259
    '#type' => 'checkbox',
2260
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2261
      coming from a synonym link.'),
2262
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2263
    '#description' => t('Check this if after doing a search and clicking on a
2264
      synonym you want to see the "accept of" text for the accepted synonym.'),
2265
  );
2266

    
2267
  /* === currently unused ===
2268
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2269
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2270
    '#type' => 'checkboxes',
2271
    '#title' => t('Display name relationships') . ':',
2272
    '#default_value' => variable_get('name_relationships_to_show', 0),
2273
    '#options' => $nameRelationshipTypeOptions,
2274
    '#description' => t('Select the name relationships you want to show for the
2275
      accepted taxa.'),
2276
  );
2277
 */
2278

    
2279
  $form['taxon_synonymy']['taxon_relations'] = array(
2280
    '#type' => 'fieldset',
2281
    '#title' => t('Taxon relationships'),
2282
    '#collapsible' => FALSE,
2283
    '#collapsed' => FALSE
2284
  );
2285

    
2286
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2287
    '#type' => 'checkbox',
2288
    '#title' => t('Show taxon relations ships of accepted taxon'),
2289
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2290
    '#description' => t('If this option is enabled the synonymy will show the
2291
      below selected taxon relationships of accepted taxa.'),
2292
  );
2293

    
2294
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2295
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2296
    '#type' => 'checkboxes',
2297
    '#title' => t('Taxon relationship types') . ':',
2298
    '#description' => t('Only taxon relationships of the selected type will be
2299
      displayed'),
2300
    '#options' => $taxonRelationshipTypeOptions,
2301
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2302
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2303
  );
2304

    
2305
  $form['taxon_synonymy']['name_relations'] = array(
2306
    '#type' => 'fieldset',
2307
    '#title' => t('Name relationships'),
2308
    '#collapsible' => FALSE,
2309
    '#collapsed' => FALSE
2310
  );
2311

    
2312
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2313
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2314
    '#type' => 'checkboxes',
2315
    '#title' => t('Name relationship types') . ':',
2316
    '#description' => t('Only name relationships of the selected type will be
2317
      displayed'),
2318
    '#options' => $taxonRelationshipTypeOptions,
2319
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2320
  );
2321

    
2322
  // ====== SPECIMENS ====== //
2323
  $form['taxon_specimens'] = array(
2324
    '#type' => 'fieldset',
2325
    '#title' => t('Taxon specimens (tab)'),
2326
    '#collapsible' => TRUE,
2327
    '#collapsed' => TRUE,
2328
    '#description' => t('This section covers the settings related to the taxon
2329
      <strong>specimens</strong> tab.'),
2330
  );
2331

    
2332
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2333
        '#type' => 'checkbox',
2334
        '#title' => t('Show specimen derivatives in a compressed table'),
2335
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2336
        '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2337
        a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2338
    );
2339
    
2340
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2341
        '#type' => 'checkbox',
2342
        '#title' => t('Show "Associated with" in specimen table.'),
2343
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2344
    );
2345

    
2346
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2347
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2348
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2349
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2350
  }
2351
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2352
      '#type' => 'radios',
2353
      '#title' => t('Specimen description feature tree') . ':',
2354
      '#default_value' => $profile_feature_tree_uuid,
2355
      '#options' =>  $featureTrees['options'],
2356
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2357
      '#options_suffixes' => $featureTrees['treeRepresentations'],
2358
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2359
      ),
2360
  );
2361

    
2362
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2363
  $form_title = t('Specimen media');
2364
  $form_description = t('Specimens may have media which is displayed at the
2365
     Specimen tab/section as a gallery. It is possible to configure the
2366
     thumbnails gallery here, however for configuring how a single media should
2367
     be displayed please go to !url.</p>',
2368
     array(
2369
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2370
     ));
2371
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2372

    
2373
  // --- MEDIA GALLERY ---- //
2374
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2375
  $form_title = 'Media gallery (tab)';
2376
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2377
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2378
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2379
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2380
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2381
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2382
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2383

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

    
2393
/**
2394
 * @todo document this function.
2395
 */
2396
function cdm_settings_layout_search() {
2397

    
2398
  $form = array();
2399

    
2400
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2401

    
2402
  $form['search_settings'] = array(
2403
    '#type' => 'fieldset',
2404
    '#title' => t('Taxa Search'),
2405
    '#collapsible' => FALSE,
2406
    '#collapsed' => FALSE,
2407
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2408
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2409
         where they can write the text to be searched. You can find Drupal block configuration
2410
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2411
  );
2412

    
2413
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2414
      '#type' => 'checkbox',
2415
      '#title' => t('Ignore the chosen classification in simple search'),
2416
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2417
      '#description' => t('The simple search, which can be executed via the search block,
2418
          will by default search on the classification selected in the classification browser
2419
          selector. Set the tick if you want your portal to search on all classifications.'),
2420
  );
2421

    
2422
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2423
    '#type' => 'checkbox',
2424
    '#title' => t('Run simple search with free-text search backend.'),
2425
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2426
    '#description' => t('The simple search uses by default another search
2427
      backend as the advances search. By checking this option the simple search can be
2428
      configured to also use the free-text search backend.'),
2429
  );
2430

    
2431
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2432
    '#type' => 'textfield',
2433
    '#title' => t('Results per page') . ':',
2434
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2435
    '#description' => t('Number of results to display per page.'),
2436
  );
2437

    
2438
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2439
    '#type' => 'checkbox',
2440
    '#title' => t('Show the <i>Show Image Thumbnails</i> button') . ':',
2441
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2442
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2443
  );
2444

    
2445
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2446
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2447
      '#type' => 'checkboxes',
2448
      '#title' => 'Search mode',
2449
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2450
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2451
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2452
          defaults set here.',
2453
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2454
      '#default_value' => $search_mode_default
2455
      );
2456

    
2457
  // --- SEARCH TAXA GALLERY ---- //
2458
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2459
  $collapsed = FALSE;
2460
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2461
  $form_title = 'Taxa Search thumbnails';
2462
  $form_description = 'Search results may show thumbnails. ';
2463
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2464

    
2465
  // Comment @WA: D7 form api does not support reset buttons,
2466
  // so to mimic the D5 reset button we add one like this.
2467
  $form['actions']['reset'] = array(
2468
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2469
    '#weight' => 1000,
2470
  );
2471
  return system_settings_form($form);
2472
}
2473

    
2474
/**
2475
 * @todo document this function.
2476
 */
2477
function cdm_settings_layout_media() {
2478

    
2479
  $form = array();
2480

    
2481
  $form['media_settings'] = array(
2482
    '#type' => 'fieldset',
2483
    '#title' => t('Media settings'),
2484
    '#collapsible' => FALSE,
2485
    '#collapsed' => FALSE,
2486
    '#description' => 'This section covers layout settings for media pages.'
2487
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2488
  );
2489

    
2490
  $form['media_settings']['image_gallery_viewer'] = array(
2491
    '#type' => 'select',
2492
    '#title' => t('Image viewer') . ':',
2493
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2494
    '#options' => array(
2495
      'default' => t('Standard image viewer'),
2496
      'fsi' => t('FSI viewer (requires FSI server!)'),
2497
    ),
2498
  );
2499

    
2500
  // --- MEDIA GALLERY ---- //
2501
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2502
  $form_title = 'Standard viewer';
2503
  $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>';
2504
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2505
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2506

    
2507
  // @WA: D7 form api does not support reset buttons,
2508
  // so to mimic the D5 reset button we add one like this.
2509
  $form['actions']['reset'] = array(
2510
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2511
    '#weight' => 1000,
2512
  );
2513
  return system_settings_form($form);
2514
}
2515

    
2516
/**
2517
 * GEOSERVICE and Map settings.
2518
 */
2519
function cdm_settings_geo($form, &$form_state) {
2520

    
2521
  $current_geoserver_settings = get_edit_map_service_settings();
2522
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2523

    
2524

    
2525
  $form = array();
2526

    
2527
  $dummy_distribution_query = NULL;
2528
  if($map_distribution['map_type'] != 1){
2529
    // we need to apply a dummy query since the map service requires for image maps
2530
    // at least as and ad to be defined
2531
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2532
  }
2533

    
2534
  $form['map_preview'] = array(
2535
      '#type' => 'fieldset',
2536
      '#tree' => FALSE,
2537
      '#title' => t('Map preview'),
2538
      '#collapsible' => FALSE,
2539
      '#description' => 'The preview of the map'
2540
       . ($dummy_distribution_query != null ?
2541
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2542
           '.<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.')
2543
  );
2544
  $form['map_preview']['openlayers_map'] = compose_map(NULL, $dummy_distribution_query, NULL,
2545
    array(
2546
      'move' => "this.cdmOpenlayersMap.printInfo",
2547
      '#execute' => "this.cdmOpenlayersMap.printInfo"
2548
    ),
2549
    true // resizable
2550
  );
2551

    
2552
  /*
2553
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2554
  );
2555
  */
2556

    
2557
  /*
2558
   * GEO SERVER
2559
   */
2560
  $form['edit_map_server'] = array(
2561
    '#type' => 'fieldset',
2562
    '#tree' => true,
2563
    '#title' => t('EDIT map service'),
2564
    '#collapsible' => TRUE,
2565
    '#collapsed' => TRUE,
2566
    '#description' => t('Configuration and selection of your geo server.
2567
      The Geo Server is responsible for generating the maps.'),
2568
  );
2569

    
2570
  $form['edit_map_server']['base_uri'] = array(
2571
    '#type' => 'select',
2572
    '#title' => t('EDIT map service') . ':',
2573
    '#default_value' => $current_geoserver_settings['base_uri'],
2574
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2575
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2576
  );
2577
  $form['edit_map_server']['version'] = array(
2578
      '#type' => 'select',
2579
      '#title' => t('Version') . ':',
2580
      '#default_value' => $current_geoserver_settings['version'],
2581
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2582
      '#description' => t('The version of the EDIT map services'),
2583
  );
2584

    
2585
  /*
2586
   * MAP SETTINGS
2587
   */
2588

    
2589
  $form[CDM_MAP_DISTRIBUTION] = array(
2590
    '#type' => 'fieldset',
2591
    '#tree' => TRUE,
2592
    '#title' => t('Maps settings'),
2593
    '#collapsible' => TRUE,
2594
    '#collapsed' => TRUE,
2595
    '#description' => t('General configuration for all map types.'),
2596
  );
2597

    
2598
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2599
    '#type' => 'radios',
2600
    '#title' => 'Map types',
2601
    '#options' => array(
2602
      1 => "OpenLayers dynamic map viewer",
2603
      0 => "Plain image",
2604
    ),
2605
    '#default_value' => $map_distribution['map_type'],
2606
    '#description' => 'Two different map types are available :
2607
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2608
      which allows zooming and panning. If enabled you can configure the default layer
2609
      (background of your maps) below.</li>
2610
      <li><em>Plain image</em>: The map will be static non interactive
2611
      image.</li></ul>',
2612
  );
2613
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2614

    
2615
  /*
2616
   * settings for the distribution map are used also for specimens map!!!!
2617
   */
2618

    
2619
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2620
      '#type' => 'textfield',
2621
      '#title' => 'Aspect ratio',
2622
      '#default_value' => $map_distribution['aspect_ratio'],
2623
      '#maxlength' => 4,
2624
      '#size' => 4,
2625
      '#element_validate' => array('element_validate_number'),
2626
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2627
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2628
      width by the height:</br>
2629
      <pre>aspect ratio = w / h</pre>
2630
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2631
      for a square map use <strong>1</strong>.',
2632
  );
2633

    
2634
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2635
    '#type' => 'textfield',
2636
    '#title' => 'Bounding box',
2637
    '#default_value' => $map_distribution['bbox'],
2638
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2639
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2640
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2641
      <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.
2642
      (Maybe you need to change the map base layer to OpeLayers.)
2643
      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
2644
      below the map from where you can copy the bbox string.</p>'),
2645
  );
2646

    
2647
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2648
    '#type' => 'checkbox',
2649
    '#title' => 'Display area labels',
2650
    '#default_value' => $map_distribution['show_labels'],
2651
    '#description' => t('The map will show name labels of the areas'),
2652
  );
2653

    
2654
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2655
    '#type' => 'textfield',
2656
    '#title' => 'Map caption',
2657
    '#default_value' => $map_distribution['caption'],
2658
    '#description' => t('The caption will be shown below the map.'),
2659
  );
2660

    
2661
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2662
    '#type' => 'textfield',
2663
    '#title' => 'Distribution layer opacity',
2664
    '#default_value' => $map_distribution['distribution_opacity'],
2665
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2666
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2667
  );
2668

    
2669
  // --- Plain Image Settings --- //
2670
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2671
    '#type' => 'fieldset',
2672
    '#title' => 'Plain image map settings',
2673
    '#tree' => TRUE,
2674
    '#collapsible' => TRUE,
2675
    '#collapsed' => $open_layers_is_enabled,
2676
    '#description' => 'The settings in this section are still expertimental
2677
      and can only be used with the EDIT map service version 1.1 or above.',
2678
  );
2679
  $edit_mapserver_version = get_edit_map_service_version_number();
2680
  if ($edit_mapserver_version < 1.1) {
2681
    $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>'
2682
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2683
  }
2684

    
2685
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2686
    '#type' => 'textfield',
2687
    '#title' => 'Width',
2688
    '#default_value' => $map_distribution['image_map']['width'],
2689
    '#maxlength' => 4,
2690
    '#size' => 4,
2691
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2692
  );
2693

    
2694
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2695
    '#type' => 'textfield',
2696
    '#title' => 'Background layer',
2697
    '#default_value' => $map_distribution['image_map']['base_layer'],
2698
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2699
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2700
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2701
    )),
2702
  );
2703

    
2704
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2705
    '#type' => 'textfield',
2706
    '#title' => 'Background color',
2707
    '#default_value' => $map_distribution['image_map']['bg_color'],
2708
  );
2709

    
2710
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2711
    '#type' => 'textfield',
2712
    '#title' => 'Background layer style',
2713
     // Only line color by now.
2714
    '#default_value' => $map_distribution['image_map']['layer_style'],
2715
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2716
  );
2717

    
2718
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2719
      '#type' => 'textfield',
2720
      '#title' => 'Projection',
2721
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2722
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2723
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2724
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2725
  );
2726

    
2727

    
2728
  // --- OpenLayers Settings --- //
2729
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2730
    '#type' => 'fieldset',
2731
    '#title' => 'OpenLayers settings',
2732
    '#tree' => TRUE,
2733
    '#collapsible' => TRUE,
2734
    '#collapsed' => !$open_layers_is_enabled,
2735
    '#description' => '',
2736
  );
2737

    
2738

    
2739
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2740
      '#type' => 'checkbox',
2741
      '#title' => 'Display outside max extent',
2742
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2743
      '#description' => t('Allows the map to display parts of the layers which are outside
2744
         the max extent if the aspect ratio of the map and of the baselayer
2745
         are not equal.'),
2746
  );
2747

    
2748

    
2749
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2750
      '#type' => 'checkbox',
2751
      '#title' => 'Show Layer Switcher',
2752
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2753
      '#description' => 'The Layer Switcher control displays a table of contents
2754
      for the map.  This allows the user interface to switch between
2755
      base layers and to show or hide overlays.  By default the switcher is
2756
      shown minimized on the right edge of the map, the user may expand it
2757
      by clicking on the handle.',
2758
  );
2759

    
2760
  if (!$open_layers_is_enabled) {
2761
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2762
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2763
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2764
  }
2765

    
2766
  // The default layer must always be enabled
2767
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2768
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2769

    
2770
  $baselayer_options = array(
2771
    /*
2772
   NOTICE: must correspond to the layers defined in
2773
   js/openlayers_,ap.js#getLayersByName()
2774
   */
2775
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
2776
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
2777
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
2778
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
2779
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2780
    // all others EPSG:900913
2781
    'mapnik' => 'OpenStreetMap',
2782
    'mapquest_open' => "MapQuest",
2783
    'mapquest_sat' => "MapQuest Sattelite",
2784
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2785
//    'gmap' => 'Google Streets',
2786
//    'gsat' => 'Google Satellite',
2787
//    'ghyb' => 'Google Hybrid',
2788
//     'veroad' => 'Virtual Earth Roads',
2789
//     'veaer' => 'Virtual Earth Aerial',
2790
//     'vehyb' => 'Virtual Earth Hybrid',
2791
    // 'yahoo' => 'Yahoo Street',
2792
    // 'yahoosat' => 'Yahoo Satellite',
2793
    // 'yahoohyb' => 'Yahoo Hybrid',
2794
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2795
  );
2796

    
2797
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2798
    '#type' => 'checkboxes_preferred',
2799
    '#title' => 'Base Layers',
2800
    '#options' => $baselayer_options,
2801
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2802
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2803
  );
2804

    
2805
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2806
      '#type' => 'fieldset',
2807
      '#title' => 'Custom WMS base layer',
2808
      '#tree' => TRUE,
2809
      '#collapsible' => FALSE,
2810
      '#collapsed' => FALSE,
2811
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2812
  );
2813

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

    
2910
  /*
2911
   * Map Legend
2912
   */
2913
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2914
    '#type' => 'fieldset',
2915
    '#title' => 'Map legend',
2916
    '#tree' => TRUE,
2917
    '#collapsible' => TRUE,
2918
    '#collapsed' => TRUE,
2919
    '#description' => 'Configure the maps legend.',
2920
  );
2921

    
2922
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2923
    '#type' => 'checkbox',
2924
    '#title' => 'Display a map legend',
2925
    '#default_value' => $map_distribution['legend']['show'],
2926
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2927
  );
2928

    
2929
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2930
    '#type' => 'textfield',
2931
    '#title' => 'Legend opacity',
2932
    '#default_value' => $map_distribution['legend']['opacity'],
2933
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2934
                         to 0.0 will be not much visible.',
2935
  );
2936

    
2937
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2938
    '#type' => 'textfield',
2939
    '#title' => 'Font size',
2940
    '#default_value' => $map_distribution['legend']['font_size'],
2941
    '#description' => 'Font size in pixels.',
2942
  );
2943

    
2944
  $fontStyles = array(
2945
    0 => "plane",
2946
    1 => "italic",
2947
  );
2948
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2949
    '#type' => 'select',
2950
    '#title' => 'Available font styles',
2951
    '#default_value' => $map_distribution['legend']['font_style'],
2952
    '#options' => $fontStyles,
2953
    '#description' => 'Select a font style for the map legend.',
2954
  );
2955

    
2956
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2957
    '#type' => 'textfield',
2958
    '#title' => 'Icon width',
2959
    '#default_value' => $map_distribution['legend']['icon_width'],
2960
    '#description' => 'Legend icon width in pixels.',
2961
  );
2962
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2963
    '#type' => 'textfield',
2964
    '#title' => 'Icon height',
2965
    '#default_value' => $map_distribution['legend']['icon_height'],
2966
    '#description' => 'Legend icon height in pixels.',
2967
  );
2968

    
2969
  // @WA: D7 form api does not support reset buttons,
2970
  // so to mimic the D5 reset button we add one like this.
2971
  $form['actions']['reset'] = array(
2972
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2973
    '#weight' => 1000,
2974
  );
2975

    
2976
  return system_settings_form($form);
2977
}
2978

    
2979

    
2980
/**
2981
 * @todo document this function.
2982
 */
2983
function cdm_settings_cache() {
2984

    
2985
  $form = array();
2986

    
2987
  $form['cache_settings'] = array(
2988
    '#type' => 'fieldset',
2989
    '#title' => t('Cache Settings'),
2990
    '#collapsible' => FALSE,
2991
    '#collapsed' => FALSE,
2992
    '#description' => t('<p>When caching is enabled all single taxon sites are
2993
      stored in an internal drupal cache doing the portal response of taxa pages
2994
      faster. This is possible because the sites are loaded from the cache and
2995
      are not created from scratch.</p>'),
2996
  );
2997

    
2998
  $form['cache_settings']['cdm_webservice_cache'] = array(
2999
    '#type' => 'checkbox',
3000
    '#title' => t('<strong>Enable caching</strong>'),
3001
    '#options' => cdm_help_general_cache(),
3002
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3003
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3004
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3005
       application the changes will be not visible till the cache is erased.
3006
       Therefore developers should deactived this feature when they are working
3007
       on the CDM Dataportal Module.</p>'),
3008
  );
3009

    
3010
  $form['cache_settings']['cdm_run_cache'] = array(
3011
    '#markup' => cdm_view_cache_site(),
3012
  );
3013

    
3014
  // @WA: D7 form api does not support reset buttons,
3015
  // so to mimic the D5 reset button we add one like this.
3016
  $form['actions']['reset'] = array(
3017
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3018
    '#weight' => 1000,
3019
  );
3020
  return system_settings_form($form);
3021
}
3022

    
3023
/**
3024
 * Walk and cache all taxon pages.
3025
 */
3026
function cdm_view_cache_site() {
3027

    
3028
  $out = '';
3029

    
3030
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3031

    
3032
  $request_params = array();
3033
  $request_params['class'] = "Taxon";
3034

    
3035
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3036
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3037
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3038

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

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

    
3048
  // Comment @WA: A form within a form is not valid html and not needed here.
3049
  // Also, it would be recommended just to include this part of the form in the
3050
  // rest of the form array in cdm_settings_cache().
3051
  // $out .= '<form id="cache_site">';
3052
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3053
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3054
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3055
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3056
  // $out .= '</form>';
3057
  $out .= '</div>';
3058
  /*
3059
  foreach($taxonPager->records as $taxon){
3060
    cdm_dataportal_taxon_view($uuid);
3061
  }
3062
  */
3063
  return $out;
3064
}
3065

    
3066

    
3067
function cdm_settings_layout_taxon_submit($form, &$form_state){
3068
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3069
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3070
    if(is_object($file)){
3071
      $file->status = FILE_STATUS_PERMANENT;
3072
      file_save($file);
3073
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3074
    }
3075
  }
3076
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
3077
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
3078
    // we first need to set the variable to persist the changes setting
3079
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3080
    menu_rebuild();
3081
  }
3082
}
3083

    
3084
function cdm_settings_layout_search_submit($form, &$form_state){
3085
  // the visibility of media thumbnails also affects the ui of the search results
3086
  // so reset the according session variable
3087
  //    1. in order to give the user immediate
3088
  //       feedback on potential setting changes
3089
  //    2. let refresh the default if it has changed
3090
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3091
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3092
  }
3093
}
3094

    
3095
/**
3096
 * Form validation handler for cdm_settings_general
3097
 *
3098
 * @param $form
3099
 * @param $form_state
3100
 */
3101
function cdm_settings_general_validate($form, &$form_state) {
3102

    
3103
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3104
    $form_state['values']['cdm_webservice_url'] .= '/';
3105
  }
3106

    
3107
}
3108

    
3109
/**
3110
 * Form submit handler for settings general.
3111
 *
3112
 * tasks performed:
3113
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3114
 *
3115
 * @param $form
3116
 * @param $form_state
3117
 */
3118
function cdm_settings_general_submit($form, &$form_state){
3119
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3120
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3121
}
3122

    
3123
/**
3124
 * Form validation handler for cdm_settings_cache
3125
 */
3126
function cdm_settings_cache_validate($form, &$form_state) {
3127
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3128
    cache_clear_all(NULL, 'cache_cdm_ws');
3129
    // Better clear secref_cache since I can not be sure if the cache has not
3130
    // be used during this response.
3131
    cdm_api_secref_cache_clear();
3132
  }
3133

    
3134
}
3135

    
3136
/**
3137
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3138
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3139
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3140
 *  - version: the version, e.g.: v1.1
3141
 *
3142
 * @return array
3143
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3144
 */
3145
function get_edit_map_service_settings() {
3146

    
3147
  $settings = variable_get('edit_map_server', array(
3148
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3149
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3150
      )
3151
  );
3152

    
3153
  return $settings;
3154
}
3155

    
3156
/**
3157
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3158
 *
3159
 * @return string
3160
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3161
 */
3162
function get_edit_map_service_full_uri() {
3163
  $settings = get_edit_map_service_settings();
3164
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3165
}
3166

    
3167

    
3168
/**
3169
 * Returns the version number of the currently selected edit mapserver as a float
3170
 *
3171
 * @return float
3172
 *   The version number of the currently selected edit mapserver as a float.
3173
 *   Returns 0 on error.
3174
 */
3175
function get_edit_map_service_version_number() {
3176

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

    
3179
  $settings = get_edit_map_service_settings();
3180
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3181
  if (isset($matches[1])) {
3182
    // Convert string to float.
3183
    $version = 1 + $matches[1][0] - 1;
3184
    return $version;
3185
  }
3186
  else {
3187
    // Report error.
3188
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3189
        array(
3190
          '!version' => $settings['version'],
3191
          'warning')
3192
        )
3193
      );
3194
    return 0;
3195
  }
3196
}
3197

    
3198
/**
3199
 * Returns the array of selected items in a options array
3200
 *
3201
 * @param array $options
3202
 *   An options array as generated by a form element like checkoxes, select ...,
3203
 */
3204
function get_selection($options) {
3205
  $selection = array();
3206
  foreach ($options as $key=>$val) {
3207
    if (!empty($val)) {
3208
      $selection[] = $val;
3209
    }
3210
  }
3211
  return $selection;
3212
}
3213

    
3214

    
3215
/**
3216
 * Implements hook_element_info().
3217
 *
3218
 * Allows modules to declare their own Form API element types and specify their default values.
3219
 *
3220
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3221
 */
3222
function cdm_dataportal_element_info() {
3223
  $type['checkboxes_preferred'] = array(
3224
    '#input' => TRUE,
3225
    '#process' => array('checkboxes_preferred_expand'),
3226
    '#after_build' => array('checkboxes_preferred_after_build'),
3227
    '#theme' => array('checkboxes_preferred'),
3228
    // '#theme_wrapper' => array('form_element'),
3229
  );
3230
  return $type;
3231
}
3232

    
3233
/**
3234
 * #process callback function for the custom form element type 'checkbox_preferred'
3235
 *
3236
 *
3237
 */
3238
function checkboxes_preferred_expand($element, &$form_state, $form) {
3239

    
3240
  // First of all create checkboxes for each of the elements
3241
  $element = form_process_checkboxes($element);
3242

    
3243
  // compose the element name
3244
  $parents = array();
3245
  array_deep_copy($element['#parents'], $parents);
3246
  $parents[count($parents) -1 ] .= '_preferred';
3247
  $element_name = $parents[0];
3248
  for ($i=1; $i < count($parents); $i++){
3249
    $element_name .= '[' . $parents[$i] . ']';
3250
  }
3251

    
3252
  $children = element_children($element);
3253

    
3254
  $element['table_start'] = array(
3255
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3256
    '#weight' => -1,
3257
  );
3258

    
3259
  // prepare first part each of the table rows which contains the row label
3260
  $weight = 0;
3261
  foreach ($children as $key) {
3262
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3263
    $element[$key]['#weight'] = $weight;
3264
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
3265
    $element[$key]['#suffix'] = '</td>';
3266
    unset($element[$key]['#title']);
3267
    $weight += 2;
3268
  }
3269
  $weight = 0;
3270

    
3271
  // add a radio button to each of the checkboxes, the
3272
  // check boxes have already been created at the beginning
3273
  // of this function
3274
  if (count($element['#options']) > 0) {
3275
    foreach ($element['#options'] as $key => $choice) {
3276
      if (!isset($element[$key . '_preferred'])) {
3277
        $element[$key . '_preferred'] = array(
3278
          '#type' => 'radio',
3279
          '#name' => $element_name,
3280
          '#return_value' => check_plain($key),
3281
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3282
          '#attributes' => $element['#attributes'],
3283
          '#parents' => $element['#parents'],
3284
          // '#spawned' => TRUE,
3285
          '#weight' => $weight + 1,
3286
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3287
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3288
        );
3289
      }
3290
      $weight += 2;
3291
    }
3292
  }
3293

    
3294
  // end the table
3295
  $element['table_end'] = array(
3296
    '#markup' => '</table>',
3297
    '#weight' => $weight++,
3298
  );
3299

    
3300
  return $element;
3301
}
3302

    
3303
/**
3304
 * Theme function for the custom form field 'checkboxes_preferred'.
3305
 */
3306
function theme_checkboxes_preferred($variables) {
3307
  $element = $variables['element'];
3308
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3309
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3310
  $out .= drupal_render_children($element);
3311
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3312
  $out .= '</div>';
3313
  return $out;
3314
}
3315

    
3316
/**
3317
 * Callback for checkboxes preferred for widget which will
3318
 * be called after the form or element is built. The call
3319
 * back is configured in the form element by setting it as
3320
 * #after_build parameter.
3321
 *
3322
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3323
 *
3324
 * @param $element
3325
 *   Nested array of form elements that comprise the form.
3326
 * @param $form_state
3327
 *   A keyed array containing the current state of the form.
3328
 *   This includes the current persistent storage data for the form.
3329
 *   Additional information, like the sanitized $_POST data,
3330
 *   is also accumulated here in $form_state['input']
3331
 *
3332
 * @return the modified form array
3333
 */
3334
function checkboxes_preferred_after_build($element, &$form_state) {
3335

    
3336
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3337

    
3338
  if ($_POST && count($_POST) > 0) {
3339
    // TODO use  $form_state['input'] instead of POST !!!
3340
    // First pass of form processing.
3341
    $parents = array();
3342
    array_deep_copy($element['#parents'], $parents);
3343
    $parents[count($parents) - 1] .= '_preferred';
3344
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3345
    $element['#value']['PREFERRED'] = $preferred_layer;
3346
//     $form_state[$parent_id] = $element['#value'];
3347
//     $form_state['values']['baselayers'] = $element['#value'];
3348
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3349
    $form_state_element_values = $element['#value'];
3350
  }
3351
  else {
3352
    // Second pass of form processing.
3353
    $preferred_layer = $element['#value']['PREFERRED'];
3354
  }
3355

    
3356
  // Also set the chosen value (not sure if this is good Drupal style ....).
3357
  foreach ($children = element_children($element) as $key) {
3358
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3359
      $element[$key]['#value'] = $preferred_layer;
3360
    }
3361
  }
3362
  // The default layer must always be enabled.
3363
  $element[$preferred_layer]['#value'] = $preferred_layer;
3364

    
3365
  return $element;
3366
}
3367

    
3368
function radios_prepare_options_suffix(&$elements){
3369

    
3370
  $childrenKeys = element_children($elements);
3371
  foreach($childrenKeys as $key){
3372
    if(!is_array($elements[$key]['#theme_wrappers'])){
3373
      $elements[$key]['#theme_wrappers'] = array();
3374
    }
3375
    if(isset($elements['#options_suffixes'][$key])){
3376
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3377
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3378
    }
3379
  }
3380
  return $elements;
3381

    
3382
}
3383

    
3384
/**
3385
 * TODO
3386
 * @param unknown $variables
3387
 */
3388
function theme_radio_options_suffix($variables) {
3389
  $element = $variables['element'];
3390
  if(isset($element['#options_suffix'])) {
3391
    $element['#children'] .= $element['#options_suffix'];
3392
  }
3393
  return $element['#children'];
3394
}
3395

    
3396

    
3397
/**
3398
 * Element validate callback for text field and arrays containing json.
3399
 *
3400
 * @param $element
3401
 *   The form element to validate
3402
 * @param $form_state
3403
 *   A keyed array containing the current state of the form.
3404
 * @param $form
3405
 *   Nested array of form elements that comprise the form.
3406
 */
3407
function form_element_validate_json($element, &$form_state, $form) {
3408
   if (!empty($element['#value'])) {
3409
     json_decode($element['#value']);
3410
     if(json_last_error() != JSON_ERROR_NONE){
3411
       form_error($element, t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title'])) . l('JSONLint', 'http://jsonlint.com/'));
3412
     }
3413
   }
3414
}
3415

    
3416
/**
3417
 * Form submission handler for textareas and textfields containing JSON.
3418
 *
3419
 * The contained JSON will be converted into an php array
3420
 * or object and will be stored in the variables as such.
3421
 *
3422
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3423
 *
3424
 * @param $form
3425
 *   Nested array of form elements that comprise the form.
3426
 * @param $form_state
3427
 *   A keyed array containing the current state of the form.
3428
 *
3429
 */
3430
function submit_json_as_php_array($form, &$form_state) {
3431
  if (is_array($form['#json_elements'])) {
3432
    foreach ($form['#json_elements'] as $element){
3433
      if (trim($form_state['values'][$element])) {
3434
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3435
      } else {
3436
        $form_state['values'][$element] = NULL;
3437
      }
3438
    }
3439
  }
3440
}
(16-16/16)