Project

General

Profile

Download (137 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
        'secReferencePart' => array('secReference' => TRUE,),
166
        'microreferencePart' => array('microreference' => 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
      'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy'=> array(
256
          'nameAuthorPart' => array('#uri' => TRUE),
257
          'referencePart' => TRUE,
258
          'statusPart' => TRUE,
259
          'descriptionPart' => TRUE,
260
        ),
261
       'related_taxon'=> array(
262
         'nameAuthorPart' => array('#uri' => TRUE),
263
         'referencePart' => TRUE,
264
         'statusPart' => TRUE,
265
         'secReferencePart' => TRUE,
266
         'descriptionPart' => TRUE,
267
       ),
268
       'homonym'=> array(
269
            'nameAuthorPart' => array('#uri' => TRUE),
270
            'referenceYearPart' => TRUE,
271
        ),
272
      'acceptedFor,typedesignations,list_of_taxa' => array(
273
          'nameAuthorPart' => array('#uri' => TRUE),
274
          'referencePart' => TRUE,
275
        ),
276
      '#DEFAULT' => array(
277
          'nameAuthorPart' => array('#uri' => TRUE),
278
          'referencePart' => TRUE,
279
       )
280
    )
281
));
282
  define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
283
    array (
284
      'taxon_page_title,polytomousKey'=> array(
285
        'namePart' => array('#uri' => TRUE),
286
      ),
287
      'taxon_page_synonymy,related_taxon'=> array(
288
        'nameAuthorPart' => array('#uri' => TRUE),
289
        'referencePart' => TRUE,
290
        'statusPart' => TRUE,
291
        'descriptionPart' => TRUE,
292
      ),
293
      'homonym'=> array(
294
        'nameAuthorPart' => array('#uri' => TRUE),
295
        'referenceYearPart' => TRUE,
296
      ),
297
      'acceptedFor,typedesignations,list_of_taxa' => array(
298
        'nameAuthorPart' => array('#uri' => TRUE),
299
        'referencePart' => TRUE,
300
      ),
301
      '#DEFAULT' => array(
302
        'nameAuthorPart' => array('#uri' => TRUE),
303
        'referencePart' => TRUE,
304
      )
305
    )
306
  ));
307

    
308
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
309
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
310
    // to unset a default enntry set the value to 0
311
    array(
312
      'doTaxa'=>'doTaxa',
313
      'doSynonyms' => 'doSynonyms',
314
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
315
      'doMisappliedNames' => 'doMisappliedNames'
316
    )
317
  )
318
);
319

    
320
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
321
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
322

    
323
/* Gallery variables. */
324
$gallery_settings = array(
325
    "cdm_dataportal_show_taxon_thumbnails" => 1,
326
    "cdm_dataportal_show_synonym_thumbnails" => 0,
327
    "cdm_dataportal_show_thumbnail_captions" => 1,
328
    "cdm_dataportal_media_maxextend" => 120,
329
    "cdm_dataportal_media_cols" => 3,
330
    "cdm_dataportal_media_maxRows" => 1,
331
);
332

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

    
373
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
374
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
375
      array(
376
      'filter_rules' => array(
377
        'statusOrderPreference' => 0,
378
        'subAreaPreference' => 0,
379
      ),
380
      'hiddenAreaMarkerType' => array()
381
     )
382
));
383

    
384

    
385
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
386
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
387
    array(
388
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
389
        'includeOccurrences' => 0,
390
        'includeTaxonNameDescriptions' => 0
391
     )
392
  ));
393

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

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

    
460
    // unserialize if nessecary
461
    if(!is_array($default)){
462
      $default = unserialize($default);
463
    }
464
    $variable = variable_get($variable_name, array());
465
    $result = drupal_array_merge_deep($default, $variable);
466
    return $result;
467
}
468

    
469
/**
470
 * @todo document this function.
471
 */
472
function getGallerySettings($gallery_config_form_name) {
473
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
474
}
475

    
476
/**
477
 * Returns the string representation of the default tab.
478
 *
479
 * @param bool $returnTabIndex
480
 *   Defaults to FALSE, if set true this function will return the index number
481
 *   of the default tab. (used to supply default values to form elements).
482
 */
483
function get_default_taxon_tab($returnTabIndex = FALSE) {
484

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

    
501
  // Return the index value or the string representation.
502
  if ($returnTabIndex) {
503
    return $index_value;
504
  }
505
  else {
506
    return ($values[$index_value]);
507
  }
508
}
509

    
510

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

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

    
582
    // ---- DEFAULTS settings
583

    
584
    // only needed as final option, when the settings are not having a default
585
    $default = array(
586
      'DEFAULT' => array(
587
        'as_list' => 'div',
588
        'link_to_reference' => 0,
589
        'link_to_name_used_in_source' => 1,
590
        'sources_as_content' => 0,
591
        'sources_as_content_to_bibliography' => 0,
592
        'sort_elements' => NO_SORT,
593
        'glue' => '',
594
        'element_tag' => NULL
595
      )
596
    );
597

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

    
643
    // ---- Special DEFAULTS for existing portals
644
    // TODO:
645
    // this can be removed once the feature block
646
    // settings have been deployed for the first time to these portals
647

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

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

    
735
    $cyprus_default = $cichorieae_default;
736
    $cyprus_default[UUID_DISTRIBUTION] = array(
737
      'as_list' => 'div', // currently ignored
738
      'link_to_reference' => 0,
739
      'link_to_name_used_in_source' => 0,
740
      'sources_as_content' => 0,
741
      'sources_as_content_to_bibliography' => 0,
742
      'sort_elements' => NO_SORT, // will cause ...
743
      'glue' => '',
744
      'element_tag' => 'div',
745
      'special' => array()
746
    );
747

    
748
    $default_theme = variable_get('theme_default', NULL);
749

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

    
773
    $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
774

    
775
    $feature_block_setting = null;
776

    
777
    if (isset($saved_settings[$feature_uuid])) {
778
      $feature_block_setting = $saved_settings[$feature_uuid];
779
    }
780
    else if (isset($settings_for_theme[$feature_uuid])) {
781
      $feature_block_setting = $settings_for_theme[$feature_uuid];
782
    }
783
    else if (isset($settings_for_theme['DEFAULT'])) {
784
      $feature_block_setting = $settings_for_theme['DEFAULT'];
785
    }
786

    
787
    // now merge the default and specific settings
788
    $settings_to_merge = array($default['DEFAULT']);
789
    if(is_array($saved_settings)){
790
      $settings_to_merge[] = $saved_settings['DEFAULT'];
791
    }
792
    if(isset($feature_block_setting)){
793
      $settings_to_merge[] = $feature_block_setting;
794
    }
795
    $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
796

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

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

    
855
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
856
    'title' => 'Cache',
857
    'description' => 'Cache',
858
    'access arguments' => array('administer cdm_dataportal'),
859
    'page callback' => 'drupal_get_form',
860
    'page arguments' => array('cdm_settings_cache'),
861
    'weight' => 10,
862
    'type' => MENU_LOCAL_TASK,
863
  );
864

    
865
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
866
    'title' => 'Geo & Map',
867
    'description' => 'Geo & Map',
868
    'access arguments' => array('administer cdm_dataportal'),
869
    'page callback' => 'drupal_get_form',
870
    'page arguments' => array('cdm_settings_geo'),
871
    'weight' => 1,
872
    'type' => MENU_LOCAL_TASK,
873
  );
874

    
875
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
876
    'title' => 'Layout',
877
    'description' => 'Configure and adjust the layout of your DataPortal ',
878
    'access arguments' => array('administer cdm_dataportal'),
879
    'page callback' => 'drupal_get_form',
880
    'page arguments' => array('cdm_settings_layout'),
881
    'weight' => 2,
882
    'type' => MENU_LOCAL_TASK,
883
  );
884

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

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

    
927
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
928
    'title' => 'Media',
929
    'description' => 'Configure and adjust the layout of your DataPortal ',
930
    'access arguments' => array('administer cdm_dataportal'),
931
    'page callback' => 'drupal_get_form',
932
    'page arguments' => array('cdm_settings_layout_media'),
933
    'weight' => 3,
934
    'type' => MENU_LOCAL_TASK,
935
  );
936

    
937
}
938

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

    
957
/**
958
 * Configures the settings form for the CDM-API module.
959
 *
960
 * @return array
961
 *   Drupal settings form.
962
 */
963
function cdm_settings_general() {
964

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

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

    
983
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
984
    '#type' => 'markup',
985
    '#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')
986
      . ' visible only for administrators',
987
  );
988

    
989
  $form['cdm_webservice']['freetext_index'] = array(
990
    '#type' => 'fieldset',
991
    '#title' => t('Freetext index'),
992
    '#collapsible' => FALSE,
993
    '#collapsed' => FALSE,
994
  );
995

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

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

    
1023
  $form['cdm_webservice']['proxy'] = array(
1024
    '#type' => 'fieldset',
1025
    '#title' => t('Proxy'),
1026
    '#collapsible' => TRUE,
1027
    '#collapsed' => TRUE,
1028
  );
1029

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

    
1039
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1040
    '#type' => 'textfield',
1041
    '#title' => t('Proxy port') . ':',
1042
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1043
  );
1044

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

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

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

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

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

    
1094
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1095
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1096
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1097
      '#type' => 'checkboxes',
1098
      '#title' => t('Included Classifications') . ':',
1099
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1100
      '#options' => cdm_get_taxontrees_as_options(),
1101
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1102
  );
1103

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

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

    
1138
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1139
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1140
      '#type' => 'checkboxes',
1141
      '#title' => 'Filter rules',
1142
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1143
      '#options' => array(
1144
          'statusOrderPreference' => 'Status order preference rule',
1145
          'subAreaPreference' => 'Sub area preference rule'
1146
      ),
1147
  );
1148

    
1149
  $marker_type_options = cdm_terms_as_options( cdm_ws_fetch_all('term', array('class' => 'MarkerType' )) );
1150
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1151
      '#type' => 'checkboxes',
1152
      '#title' => 'Hide marked area filter',
1153
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1154
      '#options' => $marker_type_options,
1155
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1156
  );
1157

    
1158
  $form['aggregation'] = array(
1159
      '#type' => 'fieldset',
1160
      '#title' => t('Aggregation of data'),
1161
      '#collapsible' => FALSE,
1162
      '#description' => 'This section covers the different aspects of aggregating information.
1163
          <p>
1164
          </p>',
1165
  );
1166

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

    
1179
  $form['aggregation']['notice'] = array(
1180
      '#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
1181
          want to make use of the caching capabilities of the dataportal.',
1182
  );
1183

    
1184
  $form['aggregation']['media_aggregation'] = array(
1185
      '#type' => 'fieldset',
1186
      '#title' => t('Media aggregation'),
1187
      '#collapsible' => FALSE,
1188
      '#collapsed' => TRUE,
1189
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1190

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

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

    
1217
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1218
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1219

    
1220
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1221
      '#type' => 'checkboxes',
1222
      '#title' => t('Direct'),
1223
      '#options' => $taxonRelationshipTypeOptions,
1224
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1225
  );
1226
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1227
      '#type' => 'checkboxes',
1228
      '#title' => t('Invers'),
1229
      '#options' => $taxonRelationshipTypeOptions,
1230
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1231
  );
1232

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

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

    
1265
  $form['#submit'][] = 'cdm_settings_general_submit';
1266

    
1267
  return system_settings_form($form);
1268
}
1269

    
1270

    
1271
/**
1272
 * LAYOUT settings
1273
 * @return
1274
 *   todo
1275
 */
1276
function cdm_settings_layout() {
1277

    
1278
  $form = array();
1279

    
1280
  $form['about'] = array(
1281
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1282
      layout. If you want to configure the specific sites layout visit the
1283
      respective configuration site for taxon, search or media.') . '</p>',
1284
  );
1285

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

    
1297
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1298
    '#type' => 'checkbox',
1299
    '#title' => t('Do not show footnotes'),
1300
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1301
    '#description' => t('Check this if you do not want to show any footnotes'),
1302
  );
1303

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

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

    
1326
  // ---- original source --- //
1327
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1328
      '#type' => 'fieldset',
1329
      '#tree' => TRUE,
1330
      '#title' => t('Source Citations'),
1331
      '#collapsible' => FALSE,
1332
      '#collapsed' => FALSE,
1333
  );
1334

    
1335
  $bibliography_settings = get_bibliography_settings(true);
1336

    
1337
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1338
      '#type' => 'checkbox',
1339
      '#title' => t('Original Source in bibliography'),
1340
      '#default_value' => $bibliography_settings['enabled'],
1341
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1342
       annotations in each feature block.'),
1343
  );
1344

    
1345
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1346
    '#type' => 'select',
1347
    '#title' => t('The format of the key numerals'),
1348
    '#default_value' => $bibliography_settings['key_format'],
1349
    '#options' => array('latin' => 'Latin',
1350
      'ROMAN' => 'Roman (upper case)',
1351
      'roman' => 'Roman (lower case)',
1352
      'ALPHA'=> 'Alphabet (upper case)',
1353
      'alpha' => 'Alphabet (lower case)')
1354
  );
1355

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

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

    
1381
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1382
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1383
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1384
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1385

    
1386
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1387
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1388
    $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.)';
1389
  } else if($is_custom_part_definition){
1390
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1391
  } else  {
1392
    $which_version_message = '(These are the default part definition.)';
1393
  }
1394

    
1395
  $diff_viewer_markup = '';
1396
  if($is_custom_part_definition){
1397
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1398
  }
1399

    
1400
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1401
    . $which_version_message
1402
    . '</div>'
1403
    . $diff_viewer_markup;
1404

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

    
1494
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1495
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1496
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1497
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1498
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1499

    
1500
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1501
    $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.)';
1502
  } else if($is_custom_render_template){
1503
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1504
  } else {
1505
    $which_version_message = '(These are the default render templates.)';
1506
  }
1507

    
1508
  $diff_viewer_markup = '';
1509
  if($is_custom_render_template){
1510
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1511
  }
1512

    
1513
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1514
    . $which_version_message
1515
    . '</div>'
1516
    . $diff_viewer_markup;
1517

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

    
1556
  // @WA: D7 form api does not support reset buttons,
1557
  // so to mimic the D5 reset button we add one like this.
1558
  $form['actions']['reset'] = array(
1559
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1560
    '#weight' => 1000,
1561
  );
1562

    
1563
  $form['#submit'] = array('submit_json_as_php_array');
1564
  // #json_elements especially defined for submit_json_as_php_array()
1565
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1566
  return system_settings_form($form);
1567
}
1568

    
1569

    
1570

    
1571
  /**
1572
 * @todo Please document this function.
1573
 * @see http://drupal.org/node/1354
1574
 */
1575
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1576
  $form[$form_name] = array(
1577
    '#type' => 'fieldset',
1578
    '#title' => t($form_title),
1579
    '#collapsible' => TRUE,
1580
    '#collapsed' => $collapsed,
1581
    '#tree' => TRUE,
1582
    '#description' => t($form_description),
1583
  );
1584

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

    
1604
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1605
      '#type' => 'checkbox',
1606
      '#title' => t('Show media thumbnails for synonyms'),
1607
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1608
      '#description' => '',
1609
    );
1610
  }
1611

    
1612
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1613
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1614
    '#type' => 'checkbox',
1615
    '#title' => t('Show captions under thumbnails'),
1616
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1617
    '#description' => '',
1618
  );
1619

    
1620
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1621
    '#type' => 'textfield',
1622
    '#title' => t('Thumbnail size') . ':',
1623
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1624
    '#description' => t('Select the size of each individual thumbnail.'),
1625
  );
1626

    
1627
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1628
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1629
      '#type' => 'textfield',
1630
      '#title' => t('Number of columns') . ':',
1631
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1632
      '#description' => t('Group the thumbnails in columns: select how many
1633
        columns the gallery should display.'),
1634
    );
1635
  }
1636

    
1637
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1638
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1639
      '#type' => 'textfield',
1640
      '#title' => t('Maximum number of rows') . ':',
1641
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1642
      '#description' => t('You can group the thumbnails in rows, select in how
1643
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1644
        If you want an unlimited number of rows please set to 0.'),
1645
    );
1646
  }
1647

    
1648
  return $form;
1649
}
1650

    
1651
/**
1652
 * @todo document this function.
1653
 */
1654
function cdm_settings_layout_taxon() {
1655
  $collapsed = FALSE;
1656
  $form = array();
1657

    
1658
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1659

    
1660
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1661
      '#type' => 'checkbox',
1662
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1663
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1664
      '#description' => t('<p>If checked the link to search results is rendered at
1665
       the top of the taxon site. Clicking on the link the last search performed
1666
       is rendered again.</p>'),
1667
  );
1668

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

    
1681
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1682
    '#type' => 'checkbox',
1683
    '#title' => t('Tabbed taxon page'),
1684
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1685
    '#description' => t('<p>If selected split the taxon page into individual
1686
      tabs for description, images, synonymy and specimens. If not the taxon
1687
      data is rendered as a long single page without tabs.</p>'),
1688
  );
1689

    
1690
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1691
    '#type' => 'checkboxes',
1692
    '#title' => t('Tabs visibility options') . ':',
1693
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1694
    '#options' => get_taxon_options_list(),
1695
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1696
  );
1697

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

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

    
1728
  /* ======  TAXON_PROFILE ====== */
1729
  $form['taxon_profile'] = array(
1730
    '#type' => 'fieldset',
1731
    '#title' => t('Taxon profile (tab)'),
1732
    '#description' => t('<p>This section covers the settings related to the taxon
1733
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1734
    '#collapsible' => TRUE,
1735
    '#collapsed' => FALSE,
1736
  );
1737

    
1738
  // ---- PROFILE PICTURE ----//
1739

    
1740
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1741
    '#type' => 'fieldset',
1742
    '#tree' => TRUE,
1743
    '#title' => t('Taxon profile picture'),
1744
    '#collapsible' => TRUE,
1745
    '#collapsed' => FALSE,
1746
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1747
  );
1748

    
1749
  //FIXME migrate variables:
1750
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1751
  // FIXME
1752
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1753

    
1754
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1755

    
1756
  /*
1757
   * 'show' => 1,
1758
   * 'maxextend' => 184,
1759
   * 'media_uri_query' => ''
1760
   * 'custom_placeholder_image_on' => 1,
1761
   * 'custom_placeholder_image_fid' => ''
1762
   */
1763
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1764
    '#type' => 'checkbox',
1765
    '#title' => t('Enable profil picture'),
1766
    '#description' => t('Show the profil picture.'),
1767
    '#default_value' => $taxon_profile_image_settings['show'],
1768
  );
1769

    
1770
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1771
      '#type' => 'textfield',
1772
      '#tree' => TRUE,
1773
      '#title' => t('Profil picture maximum extend'),
1774
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1775
      '#field_suffix' => 'px',
1776
      '#maxlength' => 4,
1777
      '#size' => 4,
1778
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1779
  );
1780

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

    
1794
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1795
    '#type' => 'checkbox',
1796
    '#title' => t('Show the placeholder image'),
1797
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
1798
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1799
  );
1800

    
1801
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1802
      '#type' => 'checkbox',
1803
      '#title' => t('Use a custom placeholder image'),
1804
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1805
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1806
  );
1807

    
1808
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1809
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1810
        '#type' => 'managed_file',
1811
        '#title' => t('Custom placeholder image file'),
1812
        '#progress_indicator' => 'bar',
1813
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1814
    //       '#name' => 'custom_placeholder_image',
1815
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1816
    );
1817

    
1818
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1819
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1820
      $url = file_create_url($profile_image_file->uri);
1821
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1822
                '#type' => 'item',
1823
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1824
      );
1825
    }
1826
  } else {
1827
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1828
      '#type' => 'hidden',
1829
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1830
    );
1831
  }
1832

    
1833
  $options = cdm_rankVocabulary_as_option();
1834
  array_unshift($options, '-- DISABLED --');
1835
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1836
    '#type' => 'select',
1837
    '#title' => t('Hide profile picture for higher ranks') . ':',
1838
    '#default_value' => variable_get('image_hide_rank', '0'),
1839
    '#options' => $options,
1840
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1841
  );
1842

    
1843
  // -- MEDIA THUMBNAILS -- //
1844
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1845
  $form_title = 'Taxon Profile Images';
1846
  $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>';
1847
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1848

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

    
1877
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
1878
  $profile_feature_tree = get_profile_feature_tree();
1879

    
1880
  if (isset($profile_feature_tree->root->childNodes)) {
1881

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

    
1921

    
1922
    $feature_list_layout_settings_disabled = FALSE;
1923

    
1924
    // creating helper object to retrieve the default settings
1925
    $featureNode = new stdClass();
1926
    $featureNode->feature = new stdClass();
1927
    $featureNode->feature->uuid="DEFAULT";
1928
    $featureNode->feature->representation_L10n = "Default";
1929
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
1930

    
1931
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
1932

    
1933
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1934

    
1935
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
1936
        $subform_id = $featureNode->feature->uuid;
1937
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
1938

    
1939
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1940

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

    
1954
        $form_feature_block_layout[$subform_id]['as_list'] = array(
1955
          '#type' => 'select',
1956
          '#title' => 'List type',
1957
          '#default_value' => $feature_block_setting['as_list'],
1958
          '#options' => array(
1959
            'div' => 'not as list',
1960
            'ul' => 'bullet list',
1961
            'ol' => 'numbered list',
1962
            'dl' => 'definition list'
1963
          ),
1964
        );
1965

    
1966
        if($featureNode->feature->uuid == "DEFAULT"){
1967
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
1968
            '#type' => 'checkbox',
1969
            '#title' => t('Link to reference'),
1970
            '#default_value' => $feature_block_setting['link_to_reference'],
1971
          );
1972

    
1973
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
1974
            '#type' => 'checkbox',
1975
            '#title' => 'Link to name used in source',
1976
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
1977
          );
1978
        }
1979

    
1980
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
1981
          '#type' => 'checkbox',
1982
          '#title' => 'Sources as content',
1983
          '#default_value' => $feature_block_setting['sources_as_content'],
1984
        );
1985

    
1986
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
1987
          '#type' => 'checkbox',
1988
          '#title' => 'Put sources also as content to bibliography',
1989
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
1990
        );
1991

    
1992
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
1993
          '#type' => 'select',
1994
          '#title' => t('Sort elements'),
1995
          '#default_value' => $feature_block_setting['sort_elements'],
1996
          '#options' => array(
1997
            NO_SORT => 'No sorting',
1998
            SORT_ASC => 'Ascending',
1999
            SORT_DESC => 'Descending',
2000
            SORT_HIERARCHICAL => 'Hierarchical'
2001
          ),
2002
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2003
          <dl>
2004
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2005
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2006
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2007
          <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>
2008
          </dl>',
2009
        );
2010

    
2011
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2012
          '#type' => 'select',
2013
          '#title' => t('Element tag'),
2014
          '#options' => array(
2015
            'span' => 'span',
2016
            'div' => 'div'
2017
          ),
2018
          '#default_value' => $feature_block_setting['element_tag'],
2019
        );
2020
      }
2021
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2022
    }
2023
  }
2024

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

    
2050

    
2051

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

    
2070
  );
2071

    
2072
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2073
    '#type' => 'checkbox',
2074
    '#title' => t('Condensed distribution'),
2075
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2076
    '#description' => 'This option enables the display of a very compact representation
2077
    of the distribution which includes also information on the status.',
2078
  );
2079

    
2080
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2081
    '#type' => 'select',
2082
    '#title' => t('Condensed distribution recipe'),
2083
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2084
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2085
    '#description' => 'Recipe for creating the condensed distribution.',
2086
  );
2087

    
2088
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2089
    '#type' => 'textfield',
2090
    '#title' => t('Condensed distribution info path'),
2091
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2092
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2093
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2094
  );
2095

    
2096

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

    
2114
  $level_options = cdm_Vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, SORT_ASC);
2115
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2116
    '#type' => 'checkboxes',
2117
    '#title' => 'Omit area levels',
2118
    '#options' => $level_options,
2119
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2120
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2121
    Areas which belong to the selected area levels will be hidden in the portal.',
2122
  );
2123

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

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

    
2162
AbsenceTerm
2163
a	absent
2164
f	reported in error
2165
nf	native: reported in error
2166
if	introduced: reported in error
2167
cf	cultivated: reported in error
2168
ne	native: formerly native
2169
ie	introduced: formerly introduced
2170

    
2171
</pre>'),
2172
  );
2173

    
2174

    
2175
  /* ====== SYNONYMY ====== */
2176
  $form['taxon_synonymy'] = array(
2177
    '#type' => 'fieldset',
2178
    '#title' => t('Taxon synonymy (tab)'),
2179
    '#collapsible' => TRUE,
2180
    '#collapsed' => TRUE,
2181
    '#description' => t('This section covers the settings related to the taxon
2182
      <strong>synonymy</strong> tab.'),
2183
  );
2184

    
2185
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2186
    '#type' => 'checkbox',
2187
    '#title' => t('Show accepted taxon on top of the synonymy'),
2188
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2189
    '#description' => t('If checked, the first homotypic taxon is a repetition
2190
      of the accepted taxon most likely with the full nomenclatural reference
2191
      (depending on the currently chosen theme).'),
2192
  );
2193

    
2194
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2195
    '#type' => 'checkbox',
2196
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2197
      coming from a synonym link.'),
2198
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2199
    '#description' => t('Check this if after doing a search and clicking on a
2200
      synonym you want to see the "accept of" text for the accepted synonym.'),
2201
  );
2202

    
2203
  /* === currently unused ===
2204
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2205
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2206
    '#type' => 'checkboxes',
2207
    '#title' => t('Display name relationships') . ':',
2208
    '#default_value' => variable_get('name_relationships_to_show', 0),
2209
    '#options' => $nameRelationshipTypeOptions,
2210
    '#description' => t('Select the name relationships you want to show for the
2211
      accepted taxa.'),
2212
  );
2213
 */
2214

    
2215
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2216
    '#type' => 'checkbox',
2217
    '#title' => t('Show taxon relations ships of accepted taxon'),
2218
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2219
    '#description' => t('If this option is enabled the synonymy will show the
2220
      below selected taxon relationships of accepted taxa.'),
2221
  );
2222

    
2223
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2224
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2225
    '#type' => 'checkboxes',
2226
    '#title' => t('Taxon relationship types') . ':',
2227
    '#description' => t('Only taxon relationships of the selected type will be
2228
      displayed'),
2229
    '#options' => $taxonRelationshipTypeOptions,
2230
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2231
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2232
  );
2233

    
2234
  // ====== SPECIMENS ====== //
2235
  $form['taxon_specimens'] = array(
2236
    '#type' => 'fieldset',
2237
    '#title' => t('Taxon specimens (tab)'),
2238
    '#collapsible' => TRUE,
2239
    '#collapsed' => TRUE,
2240
    '#description' => t('This section covers the settings related to the taxon
2241
      <strong>specimens</strong> tab.'),
2242
  );
2243

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

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

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

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

    
2296
  // Comment @WA: D7 form api does not support reset buttons,
2297
  // so to mimic the D5 reset button we add one like this.
2298
  $form['actions']['reset'] = array(
2299
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2300
    '#weight' => 1000,
2301
  );
2302
  return system_settings_form($form);
2303
}
2304

    
2305
/**
2306
 * @todo document this function.
2307
 */
2308
function cdm_settings_layout_search() {
2309

    
2310
  $form = array();
2311

    
2312
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2313

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

    
2325
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2326
      '#type' => 'checkbox',
2327
      '#title' => t('Ignore the chosen classification in simple search'),
2328
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2329
      '#description' => t('The simple search, which can be executed via the search block,
2330
          will by default search on the classification selected in the classification browser
2331
          selector. Set the tick if you want your portal to search on all classifications.'),
2332
  );
2333

    
2334
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2335
    '#type' => 'checkbox',
2336
    '#title' => t('Run simple search with free-text search backend.'),
2337
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2338
    '#description' => t('The simple search uses by default another search
2339
      backend as the advances search. By checking this option the simple search can be
2340
      configured to also use the free-text search backend.'),
2341
  );
2342

    
2343
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2344
    '#type' => 'textfield',
2345
    '#title' => t('Results per page') . ':',
2346
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2347
    '#description' => t('Number of results to display per page.'),
2348
  );
2349

    
2350
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2351
    '#type' => 'checkbox',
2352
    '#title' => t('Show the <i>Show Image Thumbnails</i> button') . ':',
2353
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2354
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2355
  );
2356

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

    
2369
  // --- SEARCH TAXA GALLERY ---- //
2370
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2371
  $collapsed = FALSE;
2372
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2373
  $form_title = 'Taxa Search thumbnails';
2374
  $form_description = 'Search results may show thumbnails. ';
2375
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2376

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

    
2386
/**
2387
 * @todo document this function.
2388
 */
2389
function cdm_settings_layout_media() {
2390

    
2391
  $form = array();
2392

    
2393
  $form['media_settings'] = array(
2394
    '#type' => 'fieldset',
2395
    '#title' => t('Media settings'),
2396
    '#collapsible' => FALSE,
2397
    '#collapsed' => FALSE,
2398
    '#description' => 'This section covers layout settings for media pages.'
2399
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2400
  );
2401

    
2402
  $form['media_settings']['image_gallery_viewer'] = array(
2403
    '#type' => 'select',
2404
    '#title' => t('Image viewer') . ':',
2405
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2406
    '#options' => array(
2407
      'default' => t('Standard image viewer'),
2408
      'fsi' => t('FSI viewer (requires FSI server!)'),
2409
    ),
2410
  );
2411

    
2412
  // --- MEDIA GALLERY ---- //
2413
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2414
  $form_title = 'Standard viewer';
2415
  $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>';
2416
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2417
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2418

    
2419
  // @WA: D7 form api does not support reset buttons,
2420
  // so to mimic the D5 reset button we add one like this.
2421
  $form['actions']['reset'] = array(
2422
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2423
    '#weight' => 1000,
2424
  );
2425
  return system_settings_form($form);
2426
}
2427

    
2428
/**
2429
 * GEOSERVICE and Map settings.
2430
 */
2431
function cdm_settings_geo($form, &$form_state) {
2432

    
2433
  $current_geoserver_settings = get_edit_map_service_settings();
2434
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2435

    
2436

    
2437
  $form = array();
2438

    
2439
  $dummy_distribution_query = NULL;
2440
  if($map_distribution['map_type'] != 1){
2441
    // we need to apply a dummy query since the map service requires for image maps
2442
    // at least as and ad to be defined
2443
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2444
  }
2445

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

    
2464
  /*
2465
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2466
  );
2467
  */
2468

    
2469
  /*
2470
   * GEO SERVER
2471
   */
2472
  $form['edit_map_server'] = array(
2473
    '#type' => 'fieldset',
2474
    '#tree' => true,
2475
    '#title' => t('EDIT map service'),
2476
    '#collapsible' => TRUE,
2477
    '#collapsed' => TRUE,
2478
    '#description' => t('Configuration and selection of your geo server.
2479
      The Geo Server is responsible for generating the maps.'),
2480
  );
2481

    
2482
  $form['edit_map_server']['base_uri'] = array(
2483
    '#type' => 'select',
2484
    '#title' => t('EDIT map service') . ':',
2485
    '#default_value' => $current_geoserver_settings['base_uri'],
2486
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2487
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2488
  );
2489
  $form['edit_map_server']['version'] = array(
2490
      '#type' => 'select',
2491
      '#title' => t('Version') . ':',
2492
      '#default_value' => $current_geoserver_settings['version'],
2493
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2494
      '#description' => t('The version of the EDIT map services'),
2495
  );
2496

    
2497
  /*
2498
   * MAP SETTINGS
2499
   */
2500

    
2501
  $form[CDM_MAP_DISTRIBUTION] = array(
2502
    '#type' => 'fieldset',
2503
    '#tree' => TRUE,
2504
    '#title' => t('Maps settings'),
2505
    '#collapsible' => TRUE,
2506
    '#collapsed' => TRUE,
2507
    '#description' => t('General configuration for all map types.'),
2508
  );
2509

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

    
2527
  /*
2528
   * settings for the distribution map are used also for specimens map!!!!
2529
   */
2530

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

    
2546
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2547
    '#type' => 'textfield',
2548
    '#title' => 'Bounding box',
2549
    '#default_value' => $map_distribution['bbox'],
2550
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2551
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2552
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2553
      <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.
2554
      (Maybe you need to change the map base layer to OpeLayers.)
2555
      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
2556
      below the map from where you can copy the bbox string.</p>'),
2557
  );
2558

    
2559
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2560
    '#type' => 'checkbox',
2561
    '#title' => 'Display area labels',
2562
    '#default_value' => $map_distribution['show_labels'],
2563
    '#description' => t('The map will show name labels of the areas'),
2564
  );
2565

    
2566
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2567
    '#type' => 'textfield',
2568
    '#title' => 'Map caption',
2569
    '#default_value' => $map_distribution['caption'],
2570
    '#description' => t('The caption will be shown below the map.'),
2571
  );
2572

    
2573
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2574
    '#type' => 'textfield',
2575
    '#title' => 'Distribution layer opacity',
2576
    '#default_value' => $map_distribution['distribution_opacity'],
2577
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2578
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2579
  );
2580

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

    
2597
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2598
    '#type' => 'textfield',
2599
    '#title' => 'Width',
2600
    '#default_value' => $map_distribution['image_map']['width'],
2601
    '#maxlength' => 4,
2602
    '#size' => 4,
2603
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2604
  );
2605

    
2606
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2607
    '#type' => 'textfield',
2608
    '#title' => 'Background layer',
2609
    '#default_value' => $map_distribution['image_map']['base_layer'],
2610
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2611
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2612
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2613
    )),
2614
  );
2615

    
2616
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2617
    '#type' => 'textfield',
2618
    '#title' => 'Background color',
2619
    '#default_value' => $map_distribution['image_map']['bg_color'],
2620
  );
2621

    
2622
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2623
    '#type' => 'textfield',
2624
    '#title' => 'Background layer style',
2625
     // Only line color by now.
2626
    '#default_value' => $map_distribution['image_map']['layer_style'],
2627
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2628
  );
2629

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

    
2639

    
2640
  // --- OpenLayers Settings --- //
2641
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2642
    '#type' => 'fieldset',
2643
    '#title' => 'OpenLayers settings',
2644
    '#tree' => TRUE,
2645
    '#collapsible' => TRUE,
2646
    '#collapsed' => !$open_layers_is_enabled,
2647
    '#description' => '',
2648
  );
2649

    
2650

    
2651
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2652
      '#type' => 'checkbox',
2653
      '#title' => 'Display outside max extent',
2654
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2655
      '#description' => t('Allows the map to display parts of the layers which are outside
2656
         the max extent if the aspect ratio of the map and of the baselayer
2657
         are not equal.'),
2658
  );
2659

    
2660

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

    
2672
  if (!$open_layers_is_enabled) {
2673
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2674
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2675
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2676
  }
2677

    
2678
  // The default layer must always be enabled
2679
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2680
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2681

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

    
2709
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2710
    '#type' => 'checkboxes_preferred',
2711
    '#title' => 'Base Layers',
2712
    '#options' => $baselayer_options,
2713
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2714
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2715
  );
2716

    
2717
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2718
      '#type' => 'fieldset',
2719
      '#title' => 'Custom WMS base layer',
2720
      '#tree' => TRUE,
2721
      '#collapsible' => FALSE,
2722
      '#collapsed' => FALSE,
2723
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2724
  );
2725

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

    
2822
  /*
2823
   * Map Legend
2824
   */
2825
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2826
    '#type' => 'fieldset',
2827
    '#title' => 'Map legend',
2828
    '#tree' => TRUE,
2829
    '#collapsible' => TRUE,
2830
    '#collapsed' => TRUE,
2831
    '#description' => 'Configure the maps legend.',
2832
  );
2833

    
2834
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2835
    '#type' => 'checkbox',
2836
    '#title' => 'Display a map legend',
2837
    '#default_value' => $map_distribution['legend']['show'],
2838
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2839
  );
2840

    
2841
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2842
    '#type' => 'textfield',
2843
    '#title' => 'Legend opacity',
2844
    '#default_value' => $map_distribution['legend']['opacity'],
2845
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2846
                         to 0.0 will be not much visible.',
2847
  );
2848

    
2849
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2850
    '#type' => 'textfield',
2851
    '#title' => 'Font size',
2852
    '#default_value' => $map_distribution['legend']['font_size'],
2853
    '#description' => 'Font size in pixels.',
2854
  );
2855

    
2856
  $fontStyles = array(
2857
    0 => "plane",
2858
    1 => "italic",
2859
  );
2860
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2861
    '#type' => 'select',
2862
    '#title' => 'Available font styles',
2863
    '#default_value' => $map_distribution['legend']['font_style'],
2864
    '#options' => $fontStyles,
2865
    '#description' => 'Select a font style for the map legend.',
2866
  );
2867

    
2868
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2869
    '#type' => 'textfield',
2870
    '#title' => 'Icon width',
2871
    '#default_value' => $map_distribution['legend']['icon_width'],
2872
    '#description' => 'Legend icon width in pixels.',
2873
  );
2874
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2875
    '#type' => 'textfield',
2876
    '#title' => 'Icon height',
2877
    '#default_value' => $map_distribution['legend']['icon_height'],
2878
    '#description' => 'Legend icon height in pixels.',
2879
  );
2880

    
2881
  // @WA: D7 form api does not support reset buttons,
2882
  // so to mimic the D5 reset button we add one like this.
2883
  $form['actions']['reset'] = array(
2884
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2885
    '#weight' => 1000,
2886
  );
2887

    
2888
  return system_settings_form($form);
2889
}
2890

    
2891

    
2892
/**
2893
 * @todo document this function.
2894
 */
2895
function cdm_settings_cache() {
2896

    
2897
  $form = array();
2898

    
2899
  $form['cache_settings'] = array(
2900
    '#type' => 'fieldset',
2901
    '#title' => t('Cache Settings'),
2902
    '#collapsible' => FALSE,
2903
    '#collapsed' => FALSE,
2904
    '#description' => t('<p>When caching is enabled all single taxon sites are
2905
      stored in an internal drupal cache doing the portal response of taxa pages
2906
      faster. This is possible because the sites are loaded from the cache and
2907
      are not created from scratch.</p>'),
2908
  );
2909

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

    
2922
  $form['cache_settings']['cdm_run_cache'] = array(
2923
    '#markup' => cdm_view_cache_site(),
2924
  );
2925

    
2926
  // @WA: D7 form api does not support reset buttons,
2927
  // so to mimic the D5 reset button we add one like this.
2928
  $form['actions']['reset'] = array(
2929
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2930
    '#weight' => 1000,
2931
  );
2932
  return system_settings_form($form);
2933
}
2934

    
2935
/**
2936
 * Walk and cache all taxon pages.
2937
 */
2938
function cdm_view_cache_site() {
2939

    
2940
  $out = '';
2941

    
2942
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2943

    
2944
  $request_params = array();
2945
  $request_params['class'] = "Taxon";
2946

    
2947
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2948
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2949
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2950

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

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

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

    
2978

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

    
2996
function cdm_settings_layout_search_submit($form, &$form_state){
2997
  // the visibility of media thumbnails also affects the ui of the search results
2998
  // so reset the according session variable
2999
  //    1. in order to give the user immediate
3000
  //       feedback on potential setting changes
3001
  //    2. let refresh the default if it has changed
3002
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3003
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3004
  }
3005
}
3006

    
3007
/**
3008
 * Form validation handler for cdm_settings_general
3009
 *
3010
 * @param $form
3011
 * @param $form_state
3012
 */
3013
function cdm_settings_general_validate($form, &$form_state) {
3014

    
3015
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3016
    $form_state['values']['cdm_webservice_url'] .= '/';
3017
  }
3018

    
3019
}
3020

    
3021
/**
3022
 * Form submit handler for settings general.
3023
 *
3024
 * tasks performed:
3025
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3026
 *
3027
 * @param $form
3028
 * @param $form_state
3029
 */
3030
function cdm_settings_general_submit($form, &$form_state){
3031
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3032
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3033
}
3034

    
3035
/**
3036
 * Form validation handler for cdm_settings_cache
3037
 */
3038
function cdm_settings_cache_validate($form, &$form_state) {
3039
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3040
    cache_clear_all(NULL, 'cache_cdm_ws');
3041
    // Better clear secref_cache since I can not be sure if the cache has not
3042
    // be used during this response.
3043
    cdm_api_secref_cache_clear();
3044
  }
3045

    
3046
}
3047

    
3048
/**
3049
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3050
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3051
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3052
 *  - version: the version, e.g.: v1.1
3053
 *
3054
 * @return array
3055
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3056
 */
3057
function get_edit_map_service_settings() {
3058

    
3059
  $settings = variable_get('edit_map_server', array(
3060
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3061
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3062
      )
3063
  );
3064

    
3065
  return $settings;
3066
}
3067

    
3068
/**
3069
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3070
 *
3071
 * @return string
3072
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3073
 */
3074
function get_edit_map_service_full_uri() {
3075
  $settings = get_edit_map_service_settings();
3076
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3077
}
3078

    
3079

    
3080
/**
3081
 * Returns the version number of the currently selected edit mapserver as a float
3082
 *
3083
 * @return float
3084
 *   The version number of the currently selected edit mapserver as a float.
3085
 *   Returns 0 on error.
3086
 */
3087
function get_edit_map_service_version_number() {
3088

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

    
3091
  $settings = get_edit_map_service_settings();
3092
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3093
  if (isset($matches[1])) {
3094
    // Convert string to float.
3095
    $version = 1 + $matches[1][0] - 1;
3096
    return $version;
3097
  }
3098
  else {
3099
    // Report error.
3100
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3101
        array(
3102
          '!version' => $settings['version'],
3103
          'warning')
3104
        )
3105
      );
3106
    return 0;
3107
  }
3108
}
3109

    
3110
/**
3111
 * Returns the array of selected items in a options array
3112
 *
3113
 * @param array $options
3114
 *   An options array as generated by a form element like checkoxes, select ...,
3115
 */
3116
function get_selection($options) {
3117
  $selection = array();
3118
  foreach ($options as $key=>$val) {
3119
    if (!empty($val)) {
3120
      $selection[] = $val;
3121
    }
3122
  }
3123
  return $selection;
3124
}
3125

    
3126

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

    
3145
/**
3146
 * #process callback function for the custom form element type 'checkbox_preferred'
3147
 *
3148
 *
3149
 */
3150
function checkboxes_preferred_expand($element, &$form_state, $form) {
3151

    
3152
  // First of all create checkboxes for each of the elements
3153
  $element = form_process_checkboxes($element);
3154

    
3155
  // compose the element name
3156
  $parents = array();
3157
  array_deep_copy($element['#parents'], $parents);
3158
  $parents[count($parents) -1 ] .= '_preferred';
3159
  $element_name = $parents[0];
3160
  for ($i=1; $i < count($parents); $i++){
3161
    $element_name .= '[' . $parents[$i] . ']';
3162
  }
3163

    
3164
  $children = element_children($element);
3165

    
3166
  $element['table_start'] = array(
3167
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3168
    '#weight' => -1,
3169
  );
3170

    
3171
  // prepare first part each of the table rows which contains the row label
3172
  $weight = 0;
3173
  foreach ($children as $key) {
3174
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3175
    $element[$key]['#weight'] = $weight;
3176
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
3177
    $element[$key]['#suffix'] = '</td>';
3178
    unset($element[$key]['#title']);
3179
    $weight += 2;
3180
  }
3181
  $weight = 0;
3182

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

    
3206
  // end the table
3207
  $element['table_end'] = array(
3208
    '#markup' => '</table>',
3209
    '#weight' => $weight++,
3210
  );
3211

    
3212
  return $element;
3213
}
3214

    
3215
/**
3216
 * Theme function for the custom form field 'checkboxes_preferred'.
3217
 */
3218
function theme_checkboxes_preferred($variables) {
3219
  $element = $variables['element'];
3220
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3221
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3222
  $out .= drupal_render_children($element);
3223
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3224
  $out .= '</div>';
3225
  return $out;
3226
}
3227

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

    
3248
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3249

    
3250
  if ($_POST && count($_POST) > 0) {
3251
    // TODO use  $form_state['input'] instead of POST !!!
3252
    // First pass of form processing.
3253
    $parents = array();
3254
    array_deep_copy($element['#parents'], $parents);
3255
    $parents[count($parents) - 1] .= '_preferred';
3256
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3257
    $element['#value']['PREFERRED'] = $preferred_layer;
3258
//     $form_state[$parent_id] = $element['#value'];
3259
//     $form_state['values']['baselayers'] = $element['#value'];
3260
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3261
    $form_state_element_values = $element['#value'];
3262
  }
3263
  else {
3264
    // Second pass of form processing.
3265
    $preferred_layer = $element['#value']['PREFERRED'];
3266
  }
3267

    
3268
  // Also set the chosen value (not sure if this is good Drupal style ....).
3269
  foreach ($children = element_children($element) as $key) {
3270
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3271
      $element[$key]['#value'] = $preferred_layer;
3272
    }
3273
  }
3274
  // The default layer must always be enabled.
3275
  $element[$preferred_layer]['#value'] = $preferred_layer;
3276

    
3277
  return $element;
3278
}
3279

    
3280
function radios_prepare_options_suffix(&$elements){
3281

    
3282
  $childrenKeys = element_children($elements);
3283
  foreach($childrenKeys as $key){
3284
    if(!is_array($elements[$key]['#theme_wrappers'])){
3285
      $elements[$key]['#theme_wrappers'] = array();
3286
    }
3287
    if(isset($elements['#options_suffixes'][$key])){
3288
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3289
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3290
    }
3291
  }
3292
  return $elements;
3293

    
3294
}
3295

    
3296
/**
3297
 * TODO
3298
 * @param unknown $variables
3299
 */
3300
function theme_radio_options_suffix($variables) {
3301
  $element = $variables['element'];
3302
  if(isset($element['#options_suffix'])) {
3303
    $element['#children'] .= $element['#options_suffix'];
3304
  }
3305
  return $element['#children'];
3306
}
3307

    
3308

    
3309
/**
3310
 * Element validate callback for text field and arrays containing json.
3311
 *
3312
 * @param $element
3313
 *   The form element to validate
3314
 * @param $form_state
3315
 *   A keyed array containing the current state of the form.
3316
 * @param $form
3317
 *   Nested array of form elements that comprise the form.
3318
 */
3319
function form_element_validate_json($element, &$form_state, $form) {
3320
   if (!empty($element['#value'])) {
3321
     json_decode($element['#value']);
3322
     if(json_last_error() != JSON_ERROR_NONE){
3323
       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/'));
3324
     }
3325
   }
3326
}
3327

    
3328
/**
3329
 * Form submission handler for textareas and textfields containing JSON.
3330
 *
3331
 * The contained JSON will be converted into an php array
3332
 * or object and will be stored in the variables as such.
3333
 *
3334
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3335
 *
3336
 * @param $form
3337
 *   Nested array of form elements that comprise the form.
3338
 * @param $form_state
3339
 *   A keyed array containing the current state of the form.
3340
 *
3341
 */
3342
function submit_json_as_php_array($form, &$form_state) {
3343
  if (is_array($form['#json_elements'])) {
3344
    foreach ($form['#json_elements'] as $element){
3345
      if (trim($form_state['values'][$element])) {
3346
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3347
      } else {
3348
        $form_state['values'][$element] = NULL;
3349
      }
3350
    }
3351
  }
3352
}
(15-15/15)