Project

General

Profile

Download (136 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
  define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
100
  define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
101
  define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
102
  define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
103

    
104
  define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
105
  define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
106
  define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
107
  define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
108

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

    
124
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
125
  array(
126
    'general' => '-3',
127
    'synonymy' => '-2',
128
    'images' => '0',
129
    'specimens' => '1',
130
    'keys' => '3',
131
    'experts' => '5',
132
    )
133
));
134

    
135
$taxon_tab_options = get_taxon_tabs_list();
136
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
137

    
138
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
139

    
140
/**
141
 * @todo document this function.
142
 */
143
function get_taxon_options_list() {
144
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
145
  foreach ($taxon_tab_options as $key => $value) {
146
    $taxon_tab_options[$key] = t($key);
147
  }
148
  return $taxon_tab_options;
149

    
150
}
151

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

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

    
302
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
303
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
304
    // to unset a default enntry set the value to 0
305
    array(
306
      'doTaxa'=>'doTaxa',
307
      'doSynonyms' => 'doSynonyms',
308
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
309
      'doMisappliedNames' => 'doMisappliedNames'
310
    )
311
  )
312
);
313

    
314
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
315
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
316

    
317
/* Gallery variables. */
318
$gallery_settings = array(
319
    "cdm_dataportal_show_taxon_thumbnails" => 1,
320
    "cdm_dataportal_show_synonym_thumbnails" => 0,
321
    "cdm_dataportal_show_thumbnail_captions" => 1,
322
    "cdm_dataportal_media_maxextend" => 120,
323
    "cdm_dataportal_media_cols" => 3,
324
    "cdm_dataportal_media_maxRows" => 1,
325
);
326

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

    
367
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
368
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
369
      array(
370
      'filter_rules' => array(
371
        'statusOrderPreference' => 0,
372
        'subAreaPreference' => 0,
373
      ),
374
      'hiddenAreaMarkerType' => array()
375
     )
376
));
377

    
378

    
379
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
380
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
381
    array(
382
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
383
        'includeOccurrences' => 0,
384
        'includeTaxonNameDescriptions' => 0
385
     )
386
  ));
387

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

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

    
454
    // unserialize if nessecary
455
    if(!is_array($default)){
456
      $default = unserialize($default);
457
    }
458
    $variable = variable_get($variable_name, array());
459
    $result = drupal_array_merge_deep($default, $variable);
460
    return $result;
461
}
462

    
463
/**
464
 * @todo document this function.
465
 */
466
function getGallerySettings($gallery_config_form_name) {
467
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
468
}
469

    
470
/**
471
 * Returns the string representation of the default tab.
472
 *
473
 * @param bool $returnTabIndex
474
 *   Defaults to FALSE, if set true this function will return the index number
475
 *   of the default tab. (used to supply default values to form elements).
476
 */
477
function get_default_taxon_tab($returnTabIndex = FALSE) {
478

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

    
495
  // Return the index value or the string representation.
496
  if ($returnTabIndex) {
497
    return $index_value;
498
  }
499
  else {
500
    return ($values[$index_value]);
501
  }
502
}
503

    
504

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

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

    
576
    // ---- DEFAULTS settings
577

    
578
    // only needed as final option, when the settings are not having a default
579
    $default = array(
580
      'DEFAULT' => array(
581
        'as_list' => 'div',
582
        'link_to_reference' => 0,
583
        'link_to_name_used_in_source' => 1,
584
        'sources_as_content' => 0,
585
        'sources_as_content_to_bibliography' => 0,
586
        'sort_elements' => NO_SORT,
587
        'glue' => '',
588
        'element_tag' => NULL
589
      )
590
    );
591

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

    
637
    // ---- Special DEFAULTS for existing portals
638
    // TODO:
639
    // this can be removed once the feature block
640
    // settings have been deployed for the first time to these portals
641

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

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

    
729
    $cyprus_default = $cichorieae_default;
730
    $cyprus_default[UUID_DISTRIBUTION] = array(
731
      'as_list' => 'div', // currently ignored
732
      'link_to_reference' => 0,
733
      'link_to_name_used_in_source' => 0,
734
      'sources_as_content' => 0,
735
      'sources_as_content_to_bibliography' => 0,
736
      'sort_elements' => NO_SORT, // will cause ...
737
      'glue' => '',
738
      'element_tag' => 'div',
739
      'special' => array()
740
    );
741

    
742
    $default_theme = variable_get('theme_default', NULL);
743

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

    
767
    $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
768

    
769
    $feature_block_setting = null;
770

    
771
    if (isset($saved_settings[$feature_uuid])) {
772
      $feature_block_setting = $saved_settings[$feature_uuid];
773
    }
774
    else if (isset($settings_for_theme[$feature_uuid])) {
775
      $feature_block_setting = $settings_for_theme[$feature_uuid];
776
    }
777
    else if (isset($settings_for_theme['DEFAULT'])) {
778
      $feature_block_setting = $settings_for_theme['DEFAULT'];
779
    }
780

    
781
    // now merge the default and specific settings
782
    $settings_to_merge = array($default['DEFAULT']);
783
    if(is_array($saved_settings)){
784
      $settings_to_merge[] = $saved_settings['DEFAULT'];
785
    }
786
    if(isset($feature_block_setting)){
787
      $settings_to_merge[] = $feature_block_setting;
788
    }
789
    $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
790

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

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

    
849
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
850
    'title' => 'Cache',
851
    'description' => 'Cache',
852
    'access arguments' => array('administer cdm_dataportal'),
853
    'page callback' => 'drupal_get_form',
854
    'page arguments' => array('cdm_settings_cache'),
855
    'weight' => 10,
856
    'type' => MENU_LOCAL_TASK,
857
  );
858

    
859
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
860
    'title' => 'Geo & Map',
861
    'description' => 'Geo & Map',
862
    'access arguments' => array('administer cdm_dataportal'),
863
    'page callback' => 'drupal_get_form',
864
    'page arguments' => array('cdm_settings_geo'),
865
    'weight' => 1,
866
    'type' => MENU_LOCAL_TASK,
867
  );
868

    
869
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
870
    'title' => 'Layout',
871
    'description' => 'Configure and adjust the layout of your DataPortal ',
872
    'access arguments' => array('administer cdm_dataportal'),
873
    'page callback' => 'drupal_get_form',
874
    'page arguments' => array('cdm_settings_layout'),
875
    'weight' => 2,
876
    'type' => MENU_LOCAL_TASK,
877
  );
878

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

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

    
921
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
922
    'title' => 'Media',
923
    'description' => 'Configure and adjust the layout of your DataPortal ',
924
    'access arguments' => array('administer cdm_dataportal'),
925
    'page callback' => 'drupal_get_form',
926
    'page arguments' => array('cdm_settings_layout_media'),
927
    'weight' => 3,
928
    'type' => MENU_LOCAL_TASK,
929
  );
930

    
931
}
932

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

    
951
/**
952
 * Configures the settings form for the CDM-API module.
953
 *
954
 * @return array
955
 *   Drupal settings form.
956
 */
957
function cdm_settings_general() {
958

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

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

    
977
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
978
    '#type' => 'markup',
979
    '#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')
980
      . ' visible only for administrators',
981
  );
982

    
983
  $form['cdm_webservice']['freetext_index'] = array(
984
    '#type' => 'fieldset',
985
    '#title' => t('Freetext index'),
986
    '#collapsible' => FALSE,
987
    '#collapsed' => FALSE,
988
  );
989

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

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

    
1017
  $form['cdm_webservice']['proxy'] = array(
1018
    '#type' => 'fieldset',
1019
    '#title' => t('Proxy'),
1020
    '#collapsible' => TRUE,
1021
    '#collapsed' => TRUE,
1022
  );
1023

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

    
1033
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1034
    '#type' => 'textfield',
1035
    '#title' => t('Proxy port') . ':',
1036
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1037
  );
1038

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

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

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

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

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

    
1088
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1089
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1090
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1091
      '#type' => 'checkboxes',
1092
      '#title' => t('Included Classifications') . ':',
1093
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1094
      '#options' => cdm_get_taxontrees_as_options(),
1095
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1096
  );
1097

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

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

    
1132
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1133
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1134
      '#type' => 'checkboxes',
1135
      '#title' => 'Filter rules',
1136
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1137
      '#options' => array(
1138
          'statusOrderPreference' => 'Status order preference rule',
1139
          'subAreaPreference' => 'Sub area preference rule'
1140
      ),
1141
  );
1142

    
1143
  $marker_type_options = cdm_terms_as_options( cdm_ws_fetch_all('term', array('class' => 'MarkerType' )) );
1144
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1145
      '#type' => 'checkboxes',
1146
      '#title' => 'Hide marked area filter',
1147
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1148
      '#options' => $marker_type_options,
1149
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1150
  );
1151

    
1152
  $form['aggregation'] = array(
1153
      '#type' => 'fieldset',
1154
      '#title' => t('Aggregation of data'),
1155
      '#collapsible' => FALSE,
1156
      '#description' => 'This section covers the different aspects of aggregating information.
1157
          <p>
1158
          </p>',
1159
  );
1160

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

    
1173
  $form['aggregation']['notice'] = array(
1174
      '#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
1175
          want to make use of the caching capabilities of the dataportal.',
1176
  );
1177

    
1178
  $form['aggregation']['media_aggregation'] = array(
1179
      '#type' => 'fieldset',
1180
      '#title' => t('Media aggregation'),
1181
      '#collapsible' => FALSE,
1182
      '#collapsed' => TRUE,
1183
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1184

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

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

    
1211
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1212
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1213

    
1214
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1215
      '#type' => 'checkboxes',
1216
      '#title' => t('Direct'),
1217
      '#options' => $taxonRelationshipTypeOptions,
1218
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1219
  );
1220
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1221
      '#type' => 'checkboxes',
1222
      '#title' => t('Invers'),
1223
      '#options' => $taxonRelationshipTypeOptions,
1224
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1225
  );
1226

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

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

    
1259
  $form['#submit'][] = 'cdm_settings_general_submit';
1260

    
1261
  return system_settings_form($form);
1262
}
1263

    
1264

    
1265
/**
1266
 * LAYOUT settings
1267
 * @return
1268
 *   todo
1269
 */
1270
function cdm_settings_layout() {
1271

    
1272
  $form = array();
1273

    
1274
  $form['about'] = array(
1275
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1276
      layout. If you want to configure the specific sites layout visit the
1277
      respective configuration site for taxon, search or media.') . '</p>',
1278
  );
1279

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

    
1291
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1292
    '#type' => 'checkbox',
1293
    '#title' => t('Do not show footnotes'),
1294
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1295
    '#description' => t('Check this if you do not want to show any footnotes'),
1296
  );
1297

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

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

    
1320
  // ---- original source --- //
1321
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1322
      '#type' => 'fieldset',
1323
      '#tree' => TRUE,
1324
      '#title' => t('Source Citations'),
1325
      '#collapsible' => FALSE,
1326
      '#collapsed' => FALSE,
1327
  );
1328

    
1329
  $bibliography_settings = get_bibliography_settings(true);
1330

    
1331
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1332
      '#type' => 'checkbox',
1333
      '#title' => t('Original Source in bibliography'),
1334
      '#default_value' => $bibliography_settings['enabled'],
1335
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1336
       annotations in each feature block.'),
1337
  );
1338

    
1339
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1340
    '#type' => 'select',
1341
    '#title' => t('The format of the key numerals'),
1342
    '#default_value' => $bibliography_settings['key_format'],
1343
    '#options' => array('latin' => 'Latin',
1344
      'ROMAN' => 'Roman (upper case)',
1345
      'roman' => 'Roman (lower case)',
1346
      'ALPHA'=> 'Alphabet (upper case)',
1347
      'alpha' => 'Alphabet (lower case)')
1348
  );
1349

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

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

    
1375
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1376
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1377
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1378
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1379

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

    
1389
  $diff_viewer_markup = '';
1390
  if($is_custom_part_definition){
1391
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1392
  }
1393

    
1394
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1395
    . $which_version_message
1396
    . '</div>'
1397
    . $diff_viewer_markup;
1398

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

    
1488
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1489
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1490
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1491
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1492
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1493

    
1494
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1495
    $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.)';
1496
  } else if($is_custom_render_template){
1497
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1498
  } else {
1499
    $which_version_message = '(These are the default render templates.)';
1500
  }
1501

    
1502
  $diff_viewer_markup = '';
1503
  if($is_custom_render_template){
1504
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1505
  }
1506

    
1507
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1508
    . $which_version_message
1509
    . '</div>'
1510
    . $diff_viewer_markup;
1511

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

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

    
1557
  $form['#submit'] = array('submit_json_as_php_array');
1558
  // #json_elements especially defined for submit_json_as_php_array()
1559
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1560
  return system_settings_form($form);
1561
}
1562

    
1563

    
1564

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

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

    
1598
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1599
      '#type' => 'checkbox',
1600
      '#title' => t('Show media thumbnails for synonyms'),
1601
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1602
      '#description' => '',
1603
    );
1604
  }
1605

    
1606
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1607
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1608
    '#type' => 'checkbox',
1609
    '#title' => t('Show captions under thumbnails'),
1610
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1611
    '#description' => '',
1612
  );
1613

    
1614
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1615
    '#type' => 'textfield',
1616
    '#title' => t('Thumbnail size') . ':',
1617
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1618
    '#description' => t('Select the size of each individual thumbnail.'),
1619
  );
1620

    
1621
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1622
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1623
      '#type' => 'textfield',
1624
      '#title' => t('Number of columns') . ':',
1625
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1626
      '#description' => t('Group the thumbnails in columns: select how many
1627
        columns the gallery should display.'),
1628
    );
1629
  }
1630

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

    
1642
  return $form;
1643
}
1644

    
1645
/**
1646
 * @todo document this function.
1647
 */
1648
function cdm_settings_layout_taxon() {
1649
  $collapsed = FALSE;
1650
  $form = array();
1651

    
1652
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1653

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

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

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

    
1684
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1685
    '#type' => 'checkboxes',
1686
    '#title' => t('Tabs visibility options') . ':',
1687
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1688
    '#options' => get_taxon_options_list(),
1689
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1690
  );
1691

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

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

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

    
1732
  // ---- PROFILE PICTURE ----//
1733

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

    
1743
  //FIXME migrate variables:
1744
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1745
  // FIXME
1746
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1747

    
1748
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1749

    
1750
  /*
1751
   * 'show' => 1,
1752
   * 'maxextend' => 184,
1753
   * 'media_uri_query' => ''
1754
   * 'custom_placeholder_image_on' => 1,
1755
   * 'custom_placeholder_image_fid' => ''
1756
   */
1757
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1758
    '#type' => 'checkbox',
1759
    '#title' => t('Enable profil picture'),
1760
    '#description' => t('Show the profil picture.'),
1761
    '#default_value' => $taxon_profile_image_settings['show'],
1762
  );
1763

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

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

    
1788
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1789
    '#type' => 'checkbox',
1790
    '#title' => t('Show the placeholder image'),
1791
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
1792
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1793
  );
1794

    
1795
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1796
      '#type' => 'checkbox',
1797
      '#title' => t('Use a custom placeholder image'),
1798
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1799
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1800
  );
1801

    
1802
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1803
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1804
        '#type' => 'managed_file',
1805
        '#title' => t('Custom placeholder image file'),
1806
        '#progress_indicator' => 'bar',
1807
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1808
    //       '#name' => 'custom_placeholder_image',
1809
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1810
    );
1811

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

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

    
1837
  // -- MEDIA THUMBNAILS -- //
1838
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1839
  $form_title = 'Taxon Profile Images';
1840
  $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>';
1841
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1842

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

    
1871
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
1872
  $profile_feature_tree = get_profile_feature_tree();
1873

    
1874
  if (isset($profile_feature_tree->root->childNodes)) {
1875

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

    
1915

    
1916
    $feature_list_layout_settings_disabled = FALSE;
1917

    
1918
    // creating helper object to retrieve the default settings
1919
    $featureNode = new stdClass();
1920
    $featureNode->feature = new stdClass();
1921
    $featureNode->feature->uuid="DEFAULT";
1922
    $featureNode->feature->representation_L10n = "Default";
1923
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
1924

    
1925
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
1926

    
1927
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1928

    
1929
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
1930
        $subform_id = $featureNode->feature->uuid;
1931
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
1932

    
1933
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1934

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

    
1948
        $form_feature_block_layout[$subform_id]['as_list'] = array(
1949
          '#type' => 'select',
1950
          '#title' => 'List type',
1951
          '#default_value' => $feature_block_setting['as_list'],
1952
          '#options' => array(
1953
            'div' => 'not as list',
1954
            'ul' => 'bullet list',
1955
            'ol' => 'numbered list',
1956
            'dl' => 'definition list'
1957
          ),
1958
        );
1959

    
1960
        if($featureNode->feature->uuid == "DEFAULT"){
1961
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
1962
            '#type' => 'checkbox',
1963
            '#title' => t('Link to reference'),
1964
            '#default_value' => $feature_block_setting['link_to_reference'],
1965
          );
1966

    
1967
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
1968
            '#type' => 'checkbox',
1969
            '#title' => 'Link to name used in source',
1970
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
1971
          );
1972
        }
1973

    
1974
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
1975
          '#type' => 'checkbox',
1976
          '#title' => 'Sources as content',
1977
          '#default_value' => $feature_block_setting['sources_as_content'],
1978
        );
1979

    
1980
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
1981
          '#type' => 'checkbox',
1982
          '#title' => 'Put sources also as content to bibliography',
1983
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
1984
        );
1985

    
1986
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
1987
          '#type' => 'select',
1988
          '#title' => t('Sort elements'),
1989
          '#default_value' => $feature_block_setting['sort_elements'],
1990
          '#options' => array(
1991
            NO_SORT => 'No sorting',
1992
            SORT_ASC => 'Ascending',
1993
            SORT_DESC => 'Descending',
1994
            SORT_HIERARCHICAL => 'Hierachical'
1995
          ),
1996
          '#description' => 'NOT YET USED! only in preparation',
1997
        );
1998

    
1999
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2000
          '#type' => 'select',
2001
          '#title' => t('Element tag'),
2002
          '#options' => array(
2003
            'span' => 'span',
2004
            'div' => 'div'
2005
          ),
2006
          '#default_value' => $feature_block_setting['element_tag'],
2007
        );
2008
      }
2009
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2010
    }
2011
  }
2012

    
2013
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2014
  $form['taxon_profile']['structured_description_featuretree'] = array(
2015
    '#type' => 'fieldset',
2016
    '#title' => t('Structured Description Feature Tree'),
2017
    '#collapsible' => TRUE,
2018
    '#collapsed' => FALSE,
2019
  );
2020
  $featureTrees = cdm_get_featureTrees_as_options();
2021
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2022
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2023
    $profile_feature_tree_uuid = NULL;
2024
  }
2025
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2026
    '#type' => 'radios',
2027
    '#title' => t('Natural language representation of structured descriptions') . ':',
2028
    '#default_value' => $profile_feature_tree_uuid,
2029
    '#options' => $featureTrees['options'],
2030
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2031
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2032
    '#description' => t('Taxon descriptions can be stored in a highly structured
2033
      form. The feature tree selected here will be used to generate textual
2034
      representation in natural language.'
2035
    ),
2036
  );
2037

    
2038

    
2039

    
2040
  // ---- DISTRIBUTION LAYOUT ---- //
2041
  $form['taxon_profile']['distribution_layout'] = array(
2042
    '#title' => t('Distribution'),
2043
    '#collapsible' => TRUE,
2044
    '#collapsed' => FALSE,
2045
    '#type' => 'fieldset',
2046
    '#description' => 'This section covers general settings regarding the textual representation of distributions.
2047
        Map related settings are found in the '
2048
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2049
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2050
      . l(
2051
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2052
        array('fragment' => 'edit-feature-block-settings')
2053
      )
2054
      . ' More general settings regrading the filtering of Distributions are found at '
2055
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2056
      . '. (These settings here will be merged in future releases into the feature block settings)',
2057

    
2058
  );
2059

    
2060
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2061
    '#type' => 'checkbox',
2062
    '#title' => t('Condensed distribution'),
2063
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2064
    '#description' => 'This option enables the display of a very compact representation
2065
    of the distribution which includes also information on the status.',
2066
  );
2067

    
2068
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2069
    '#type' => 'textfield',
2070
    '#title' => t('Condensed distribution info path'),
2071
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2072
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2073
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2074
  );
2075

    
2076

    
2077
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2078
    '#type' => 'radios',
2079
    '#title' => t('Order mode') . ':',
2080
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2081
    '#options' => array(
2082
      'FLAT_ALPHA' => t('Flat list'),
2083
      'TREE' => t('Hierarchically ordered'),
2084
    ),
2085
    '#description' => 'Taxon distribution information is displayed with
2086
    focus on the area of the distribution. The list of areas can either be shown
2087
    as flat list ordered alphabetically or in the hierarchical of the parent
2088
    area and subarea relationship. Fall back areas areas with no Distribution data
2089
    are hidden from the area hierarchy so that their sub areas will move one level up.
2090
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2091
    ' for details on the <em>Maked area filter</em>.',
2092
  );
2093

    
2094
  $level_options = cdm_Vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, SORT_ASC);
2095
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2096
    '#type' => 'checkboxes',
2097
    '#title' => 'Omit area levels',
2098
    '#options' => $level_options,
2099
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2100
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2101
    Areas which belong to the selected area levels will be hidden in the portal.',
2102
  );
2103

    
2104
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2105
    '#type' => 'checkbox',
2106
    '#title' => t('Show TextData elements on top of the map'),
2107
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2108
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2109
      elements on top of the map. Otherwise all <code>TextData</code>
2110
      distribution elements will be listed below the other area elements.
2111
      This option is useful if you need to have descriptive texts for each
2112
      distribution map.'),
2113
  );
2114

    
2115
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2116
      '#type' => 'textarea',
2117
      '#title' => t('Custom status colors'),
2118
      '#element_validate' => array('form_element_validate_json'),
2119
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2120
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2121
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2122
          reference list of the idInVocabulary values of absence and presence terms:
2123
<pre>
2124
Presence Term
2125
p	present
2126
pd	present: doubtfully present
2127
n	native
2128
nq	native: presence questionable
2129
nd	native: doubtfully native
2130
c	cultivated
2131
i	introduced
2132
iq	introduced: presence questionable
2133
id	introduced: doubtfully introduced (perhaps cultivated only)
2134
ip	introduced: uncertain degree of naturalisation
2135
ia	introduced: adventitious (casual)
2136
in	introduced: naturalized
2137
ic	introduced: cultivated
2138
e	endemic for the relevant area
2139
na	naturalised
2140
iv	invasive
2141

    
2142
AbsenceTerm
2143
a	absent
2144
f	reported in error
2145
nf	native: reported in error
2146
if	introduced: reported in error
2147
cf	cultivated: reported in error
2148
ne	native: formerly native
2149
ie	introduced: formerly introduced
2150

    
2151
</pre>'),
2152
  );
2153

    
2154

    
2155
  /* ====== SYNONYMY ====== */
2156
  $form['taxon_synonymy'] = array(
2157
    '#type' => 'fieldset',
2158
    '#title' => t('Taxon synonymy (tab)'),
2159
    '#collapsible' => TRUE,
2160
    '#collapsed' => TRUE,
2161
    '#description' => t('This section covers the settings related to the taxon
2162
      <strong>synonymy</strong> tab.'),
2163
  );
2164

    
2165
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2166
    '#type' => 'checkbox',
2167
    '#title' => t('Show accepted taxon on top of the synonymy'),
2168
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2169
    '#description' => t('If checked, the first homotypic taxon is a repetition
2170
      of the accepted taxon most likely with the full nomenclatural reference
2171
      (depending on the currently chosen theme).'),
2172
  );
2173

    
2174
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2175
    '#type' => 'checkbox',
2176
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2177
      coming from a synonym link.'),
2178
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2179
    '#description' => t('Check this if after doing a search and clicking on a
2180
      synonym you want to see the "accept of" text for the accepted synonym.'),
2181
  );
2182

    
2183
  /* === currently unused ===
2184
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2185
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2186
    '#type' => 'checkboxes',
2187
    '#title' => t('Display name relationships') . ':',
2188
    '#default_value' => variable_get('name_relationships_to_show', 0),
2189
    '#options' => $nameRelationshipTypeOptions,
2190
    '#description' => t('Select the name relationships you want to show for the
2191
      accepted taxa.'),
2192
  );
2193
 */
2194

    
2195
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2196
    '#type' => 'checkbox',
2197
    '#title' => t('Show taxon relations ships of accepted taxon'),
2198
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2199
    '#description' => t('If this option is enabled the synonymy will show the
2200
      below selected taxon relationships of accepted taxa.'),
2201
  );
2202

    
2203
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2204
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2205
    '#type' => 'checkboxes',
2206
    '#title' => t('Taxon relationship types') . ':',
2207
    '#description' => t('Only taxon relationships of the selected type will be
2208
      displayed'),
2209
    '#options' => $taxonRelationshipTypeOptions,
2210
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2211
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2212
  );
2213

    
2214
  // ====== SPECIMENS ====== //
2215
  $form['taxon_specimens'] = array(
2216
    '#type' => 'fieldset',
2217
    '#title' => t('Taxon specimens (tab)'),
2218
    '#collapsible' => TRUE,
2219
    '#collapsed' => TRUE,
2220
    '#description' => t('This section covers the settings related to the taxon
2221
      <strong>specimens</strong> tab.'),
2222
  );
2223

    
2224
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2225
        '#type' => 'checkbox',
2226
        '#title' => t('Show specimen derivatives in a compressed table'),
2227
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2228
        '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2229
        a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2230
    );
2231
    
2232
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2233
        '#type' => 'checkbox',
2234
        '#title' => t('Show "Associated with" in specimen table.'),
2235
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2236
    );
2237

    
2238
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2239
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2240
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2241
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2242
  }
2243
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2244
      '#type' => 'radios',
2245
      '#title' => t('Specimen description feature tree') . ':',
2246
      '#default_value' => $profile_feature_tree_uuid,
2247
      '#options' =>  $featureTrees['options'],
2248
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2249
      '#options_suffixes' => $featureTrees['treeRepresentations'],
2250
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2251
      ),
2252
  );
2253

    
2254
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2255
  $form_title = t('Specimen media');
2256
  $form_description = t('Specimens may have media which is displayed at the
2257
     Specimen tab/section as a gallery. It is possible to configure the
2258
     thumbnails gallery here, however for configuring how a single media should
2259
     be displayed please go to !url.</p>',
2260
     array(
2261
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2262
     ));
2263
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2264

    
2265
  // --- MEDIA GALLERY ---- //
2266
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2267
  $form_title = 'Media gallery (tab)';
2268
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2269
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2270
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2271
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2272
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2273
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2274
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2275

    
2276
  // Comment @WA: D7 form api does not support reset buttons,
2277
  // so to mimic the D5 reset button we add one like this.
2278
  $form['actions']['reset'] = array(
2279
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2280
    '#weight' => 1000,
2281
  );
2282
  return system_settings_form($form);
2283
}
2284

    
2285
/**
2286
 * @todo document this function.
2287
 */
2288
function cdm_settings_layout_search() {
2289

    
2290
  $form = array();
2291

    
2292
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2293

    
2294
  $form['search_settings'] = array(
2295
    '#type' => 'fieldset',
2296
    '#title' => t('Taxa Search'),
2297
    '#collapsible' => FALSE,
2298
    '#collapsed' => FALSE,
2299
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2300
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2301
         where they can write the text to be searched. You can find Drupal block configuration
2302
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2303
  );
2304

    
2305
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2306
      '#type' => 'checkbox',
2307
      '#title' => t('Ignore the chosen classification in simple search'),
2308
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2309
      '#description' => t('The simple search, which can be executed via the search block,
2310
          will by default search on the classification selected in the classification browser
2311
          selector. Set the tick if you want your portal to search on all classifications.'),
2312
  );
2313

    
2314
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2315
    '#type' => 'checkbox',
2316
    '#title' => t('Run simple search with free-text search backend.'),
2317
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2318
    '#description' => t('The simple search uses by default another search
2319
      backend as the advances search. By checking this option the simple search can be
2320
      configured to also use the free-text search backend.'),
2321
  );
2322

    
2323
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2324
    '#type' => 'textfield',
2325
    '#title' => t('Results per page') . ':',
2326
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2327
    '#description' => t('Number of results to display per page.'),
2328
  );
2329

    
2330
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2331
    '#type' => 'checkbox',
2332
    '#title' => t('Show the <i>Show Image Thumbnails</i> button') . ':',
2333
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2334
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2335
  );
2336

    
2337
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2338
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2339
      '#type' => 'checkboxes',
2340
      '#title' => 'Search mode',
2341
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2342
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2343
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2344
          defaults set here.',
2345
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2346
      '#default_value' => $search_mode_default
2347
      );
2348

    
2349
  // --- SEARCH TAXA GALLERY ---- //
2350
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2351
  $collapsed = FALSE;
2352
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2353
  $form_title = 'Taxa Search thumbnails';
2354
  $form_description = 'Search results may show thumbnails. ';
2355
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2356

    
2357
  // Comment @WA: D7 form api does not support reset buttons,
2358
  // so to mimic the D5 reset button we add one like this.
2359
  $form['actions']['reset'] = array(
2360
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2361
    '#weight' => 1000,
2362
  );
2363
  return system_settings_form($form);
2364
}
2365

    
2366
/**
2367
 * @todo document this function.
2368
 */
2369
function cdm_settings_layout_media() {
2370

    
2371
  $form = array();
2372

    
2373
  $form['media_settings'] = array(
2374
    '#type' => 'fieldset',
2375
    '#title' => t('Media settings'),
2376
    '#collapsible' => FALSE,
2377
    '#collapsed' => FALSE,
2378
    '#description' => 'This section covers layout settings for media pages.'
2379
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2380
  );
2381

    
2382
  $form['media_settings']['image_gallery_viewer'] = array(
2383
    '#type' => 'select',
2384
    '#title' => t('Image viewer') . ':',
2385
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2386
    '#options' => array(
2387
      'default' => t('Standard image viewer'),
2388
      'fsi' => t('FSI viewer (requires FSI server!)'),
2389
    ),
2390
  );
2391

    
2392
  // --- MEDIA GALLERY ---- //
2393
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2394
  $form_title = 'Standard viewer';
2395
  $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>';
2396
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2397
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2398

    
2399
  // @WA: D7 form api does not support reset buttons,
2400
  // so to mimic the D5 reset button we add one like this.
2401
  $form['actions']['reset'] = array(
2402
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2403
    '#weight' => 1000,
2404
  );
2405
  return system_settings_form($form);
2406
}
2407

    
2408
/**
2409
 * GEOSERVICE and Map settings.
2410
 */
2411
function cdm_settings_geo($form, &$form_state) {
2412

    
2413
  $current_geoserver_settings = get_edit_map_service_settings();
2414
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2415

    
2416

    
2417
  $form = array();
2418

    
2419
  $dummy_distribution_query = NULL;
2420
  if($map_distribution['map_type'] != 1){
2421
    // we need to apply a dummy query since the map service requires for image maps
2422
    // at least as and ad to be defined
2423
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2424
  }
2425

    
2426
  $form['map_preview'] = array(
2427
      '#type' => 'fieldset',
2428
      '#tree' => FALSE,
2429
      '#title' => t('Map preview'),
2430
      '#collapsible' => FALSE,
2431
      '#description' => 'The preview of the map'
2432
       . ($dummy_distribution_query != null ?
2433
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2434
           '.<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.')
2435
  );
2436
  $form['map_preview']['openlayers_map'] = compose_map(NULL, $dummy_distribution_query, NULL,
2437
    array(
2438
      'move' => "this.cdmOpenlayersMap.printInfo",
2439
      '#execute' => "this.cdmOpenlayersMap.printInfo"
2440
    ),
2441
    true // resizable
2442
  );
2443

    
2444
  /*
2445
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2446
  );
2447
  */
2448

    
2449
  /*
2450
   * GEO SERVER
2451
   */
2452
  $form['edit_map_server'] = array(
2453
    '#type' => 'fieldset',
2454
    '#tree' => true,
2455
    '#title' => t('EDIT map service'),
2456
    '#collapsible' => TRUE,
2457
    '#collapsed' => TRUE,
2458
    '#description' => t('Configuration and selection of your geo server.
2459
      The Geo Server is responsible for generating the maps.'),
2460
  );
2461

    
2462
  $form['edit_map_server']['base_uri'] = array(
2463
    '#type' => 'select',
2464
    '#title' => t('EDIT map service') . ':',
2465
    '#default_value' => $current_geoserver_settings['base_uri'],
2466
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2467
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2468
  );
2469
  $form['edit_map_server']['version'] = array(
2470
      '#type' => 'select',
2471
      '#title' => t('Version') . ':',
2472
      '#default_value' => $current_geoserver_settings['version'],
2473
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2474
      '#description' => t('The version of the EDIT map services'),
2475
  );
2476

    
2477
  /*
2478
   * MAP SETTINGS
2479
   */
2480

    
2481
  $form[CDM_MAP_DISTRIBUTION] = array(
2482
    '#type' => 'fieldset',
2483
    '#tree' => TRUE,
2484
    '#title' => t('Maps settings'),
2485
    '#collapsible' => TRUE,
2486
    '#collapsed' => TRUE,
2487
    '#description' => t('General configuration for all map types.'),
2488
  );
2489

    
2490
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2491
    '#type' => 'radios',
2492
    '#title' => 'Map types',
2493
    '#options' => array(
2494
      1 => "OpenLayers dynamic map viewer",
2495
      0 => "Plain image",
2496
    ),
2497
    '#default_value' => $map_distribution['map_type'],
2498
    '#description' => 'Two different map types are available :
2499
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2500
      which allows zooming and panning. If enabled you can configure the default layer
2501
      (background of your maps) below.</li>
2502
      <li><em>Plain image</em>: The map will be static non interactive
2503
      image.</li></ul>',
2504
  );
2505
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2506

    
2507
  /*
2508
   * settings for the distribution map are used also for specimens map!!!!
2509
   */
2510

    
2511
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2512
      '#type' => 'textfield',
2513
      '#title' => 'Aspect ratio',
2514
      '#default_value' => $map_distribution['aspect_ratio'],
2515
      '#maxlength' => 4,
2516
      '#size' => 4,
2517
      '#element_validate' => array('element_validate_number'),
2518
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2519
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2520
      width by the height:</br>
2521
      <pre>aspect ratio = w / h</pre>
2522
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2523
      for a square map use <strong>1</strong>.',
2524
  );
2525

    
2526
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2527
    '#type' => 'textfield',
2528
    '#title' => 'Bounding box',
2529
    '#default_value' => $map_distribution['bbox'],
2530
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2531
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2532
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2533
      <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.
2534
      (Maybe you need to change the map base layer to OpeLayers.)
2535
      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
2536
      below the map from where you can copy the bbox string.</p>'),
2537
  );
2538

    
2539
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2540
    '#type' => 'checkbox',
2541
    '#title' => 'Display area labels',
2542
    '#default_value' => $map_distribution['show_labels'],
2543
    '#description' => t('The map will show name labels of the areas'),
2544
  );
2545

    
2546
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2547
    '#type' => 'textfield',
2548
    '#title' => 'Map caption',
2549
    '#default_value' => $map_distribution['caption'],
2550
    '#description' => t('The caption will be shown below the map.'),
2551
  );
2552

    
2553
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2554
    '#type' => 'textfield',
2555
    '#title' => 'Distribution layer opacity',
2556
    '#default_value' => $map_distribution['distribution_opacity'],
2557
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2558
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2559
  );
2560

    
2561
  // --- Plain Image Settings --- //
2562
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2563
    '#type' => 'fieldset',
2564
    '#title' => 'Plain image map settings',
2565
    '#tree' => TRUE,
2566
    '#collapsible' => TRUE,
2567
    '#collapsed' => $open_layers_is_enabled,
2568
    '#description' => 'The settings in this section are still expertimental
2569
      and can only be used with the EDIT map service version 1.1 or above.',
2570
  );
2571
  $edit_mapserver_version = get_edit_map_service_version_number();
2572
  if ($edit_mapserver_version < 1.1) {
2573
    $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>'
2574
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2575
  }
2576

    
2577
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2578
    '#type' => 'textfield',
2579
    '#title' => 'Width',
2580
    '#default_value' => $map_distribution['image_map']['width'],
2581
    '#maxlength' => 4,
2582
    '#size' => 4,
2583
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2584
  );
2585

    
2586
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2587
    '#type' => 'textfield',
2588
    '#title' => 'Background layer',
2589
    '#default_value' => $map_distribution['image_map']['base_layer'],
2590
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2591
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2592
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2593
    )),
2594
  );
2595

    
2596
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2597
    '#type' => 'textfield',
2598
    '#title' => 'Background color',
2599
    '#default_value' => $map_distribution['image_map']['bg_color'],
2600
  );
2601

    
2602
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2603
    '#type' => 'textfield',
2604
    '#title' => 'Background layer style',
2605
     // Only line color by now.
2606
    '#default_value' => $map_distribution['image_map']['layer_style'],
2607
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2608
  );
2609

    
2610
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2611
      '#type' => 'textfield',
2612
      '#title' => 'Projection',
2613
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2614
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2615
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2616
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2617
  );
2618

    
2619

    
2620
  // --- OpenLayers Settings --- //
2621
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2622
    '#type' => 'fieldset',
2623
    '#title' => 'OpenLayers settings',
2624
    '#tree' => TRUE,
2625
    '#collapsible' => TRUE,
2626
    '#collapsed' => !$open_layers_is_enabled,
2627
    '#description' => '',
2628
  );
2629

    
2630

    
2631
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2632
      '#type' => 'checkbox',
2633
      '#title' => 'Display outside max extent',
2634
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2635
      '#description' => t('Allows the map to display parts of the layers which are outside
2636
         the max extent if the aspect ratio of the map and of the baselayer
2637
         are not equal.'),
2638
  );
2639

    
2640

    
2641
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2642
      '#type' => 'checkbox',
2643
      '#title' => 'Show Layer Switcher',
2644
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2645
      '#description' => 'The Layer Switcher control displays a table of contents
2646
      for the map.  This allows the user interface to switch between
2647
      base layers and to show or hide overlays.  By default the switcher is
2648
      shown minimized on the right edge of the map, the user may expand it
2649
      by clicking on the handle.',
2650
  );
2651

    
2652
  if (!$open_layers_is_enabled) {
2653
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2654
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2655
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2656
  }
2657

    
2658
  // The default layer must always be enabled
2659
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2660
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2661

    
2662
  $baselayer_options = array(
2663
    /*
2664
   NOTICE: must correspond to the layers defined in
2665
   js/openlayers_,ap.js#getLayersByName()
2666
   */
2667
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
2668
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
2669
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
2670
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
2671
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2672
    // all others EPSG:900913
2673
    'mapnik' => 'OpenStreetMap',
2674
    'mapquest_open' => "MapQuest",
2675
    'mapquest_sat' => "MapQuest Sattelite",
2676
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2677
//    'gmap' => 'Google Streets',
2678
//    'gsat' => 'Google Satellite',
2679
//    'ghyb' => 'Google Hybrid',
2680
//     'veroad' => 'Virtual Earth Roads',
2681
//     'veaer' => 'Virtual Earth Aerial',
2682
//     'vehyb' => 'Virtual Earth Hybrid',
2683
    // 'yahoo' => 'Yahoo Street',
2684
    // 'yahoosat' => 'Yahoo Satellite',
2685
    // 'yahoohyb' => 'Yahoo Hybrid',
2686
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2687
  );
2688

    
2689
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2690
    '#type' => 'checkboxes_preferred',
2691
    '#title' => 'Base Layers',
2692
    '#options' => $baselayer_options,
2693
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2694
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2695
  );
2696

    
2697
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2698
      '#type' => 'fieldset',
2699
      '#title' => 'Custom WMS base layer',
2700
      '#tree' => TRUE,
2701
      '#collapsible' => FALSE,
2702
      '#collapsed' => FALSE,
2703
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2704
  );
2705

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

    
2802
  /*
2803
   * Map Legend
2804
   */
2805
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2806
    '#type' => 'fieldset',
2807
    '#title' => 'Map legend',
2808
    '#tree' => TRUE,
2809
    '#collapsible' => TRUE,
2810
    '#collapsed' => TRUE,
2811
    '#description' => 'Configure the maps legend.',
2812
  );
2813

    
2814
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2815
    '#type' => 'checkbox',
2816
    '#title' => 'Display a map legend',
2817
    '#default_value' => $map_distribution['legend']['show'],
2818
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2819
  );
2820

    
2821
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2822
    '#type' => 'textfield',
2823
    '#title' => 'Legend opacity',
2824
    '#default_value' => $map_distribution['legend']['opacity'],
2825
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2826
                         to 0.0 will be not much visible.',
2827
  );
2828

    
2829
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2830
    '#type' => 'textfield',
2831
    '#title' => 'Font size',
2832
    '#default_value' => $map_distribution['legend']['font_size'],
2833
    '#description' => 'Font size in pixels.',
2834
  );
2835

    
2836
  $fontStyles = array(
2837
    0 => "plane",
2838
    1 => "italic",
2839
  );
2840
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2841
    '#type' => 'select',
2842
    '#title' => 'Available font styles',
2843
    '#default_value' => $map_distribution['legend']['font_style'],
2844
    '#options' => $fontStyles,
2845
    '#description' => 'Select a font style for the map legend.',
2846
  );
2847

    
2848
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2849
    '#type' => 'textfield',
2850
    '#title' => 'Icon width',
2851
    '#default_value' => $map_distribution['legend']['icon_width'],
2852
    '#description' => 'Legend icon width in pixels.',
2853
  );
2854
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2855
    '#type' => 'textfield',
2856
    '#title' => 'Icon height',
2857
    '#default_value' => $map_distribution['legend']['icon_height'],
2858
    '#description' => 'Legend icon height in pixels.',
2859
  );
2860

    
2861
  // @WA: D7 form api does not support reset buttons,
2862
  // so to mimic the D5 reset button we add one like this.
2863
  $form['actions']['reset'] = array(
2864
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2865
    '#weight' => 1000,
2866
  );
2867

    
2868
  return system_settings_form($form);
2869
}
2870

    
2871

    
2872
/**
2873
 * @todo document this function.
2874
 */
2875
function cdm_settings_cache() {
2876

    
2877
  $form = array();
2878

    
2879
  $form['cache_settings'] = array(
2880
    '#type' => 'fieldset',
2881
    '#title' => t('Cache Settings'),
2882
    '#collapsible' => FALSE,
2883
    '#collapsed' => FALSE,
2884
    '#description' => t('<p>When caching is enabled all single taxon sites are
2885
      stored in an internal drupal cache doing the portal response of taxa pages
2886
      faster. This is possible because the sites are loaded from the cache and
2887
      are not created from scratch.</p>'),
2888
  );
2889

    
2890
  $form['cache_settings']['cdm_webservice_cache'] = array(
2891
    '#type' => 'checkbox',
2892
    '#title' => t('<strong>Enable caching</strong>'),
2893
    '#options' => cdm_help_general_cache(),
2894
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2895
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2896
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2897
       application the changes will be not visible till the cache is erased.
2898
       Therefore developers should deactived this feature when they are working
2899
       on the CDM Dataportal Module.</p>'),
2900
  );
2901

    
2902
  $form['cache_settings']['cdm_run_cache'] = array(
2903
    '#markup' => cdm_view_cache_site(),
2904
  );
2905

    
2906
  // @WA: D7 form api does not support reset buttons,
2907
  // so to mimic the D5 reset button we add one like this.
2908
  $form['actions']['reset'] = array(
2909
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2910
    '#weight' => 1000,
2911
  );
2912
  return system_settings_form($form);
2913
}
2914

    
2915
/**
2916
 * Walk and cache all taxon pages.
2917
 */
2918
function cdm_view_cache_site() {
2919

    
2920
  $out = '';
2921

    
2922
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2923

    
2924
  $request_params = array();
2925
  $request_params['class'] = "Taxon";
2926

    
2927
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2928
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2929
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2930

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

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

    
2940
  // Comment @WA: A form within a form is not valid html and not needed here.
2941
  // Also, it would be recommended just to include this part of the form in the
2942
  // rest of the form array in cdm_settings_cache().
2943
  // $out .= '<form id="cache_site">';
2944
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2945
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2946
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2947
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2948
  // $out .= '</form>';
2949
  $out .= '</div>';
2950
  /*
2951
  foreach($taxonPager->records as $taxon){
2952
    cdm_dataportal_taxon_view($uuid);
2953
  }
2954
  */
2955
  return $out;
2956
}
2957

    
2958

    
2959
function cdm_settings_layout_taxon_submit($form, &$form_state){
2960
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2961
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2962
    if(is_object($file)){
2963
      $file->status = FILE_STATUS_PERMANENT;
2964
      file_save($file);
2965
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2966
    }
2967
  }
2968
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2969
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2970
    // we first need to set the variable to persist the changes setting
2971
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
2972
    menu_rebuild();
2973
  }
2974
}
2975

    
2976
function cdm_settings_layout_search_submit($form, &$form_state){
2977
  // the visibility of media thumbnails also affects the ui of the search results
2978
  // so reset the according session variable
2979
  //    1. in order to give the user immediate
2980
  //       feedback on potential setting changes
2981
  //    2. let refresh the default if it has changed
2982
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2983
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
2984
  }
2985
}
2986

    
2987
/**
2988
 * Form validation handler for cdm_settings_general
2989
 *
2990
 * @param $form
2991
 * @param $form_state
2992
 */
2993
function cdm_settings_general_validate($form, &$form_state) {
2994

    
2995
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2996
    $form_state['values']['cdm_webservice_url'] .= '/';
2997
  }
2998

    
2999
}
3000

    
3001
/**
3002
 * Form submit handler for settings general.
3003
 *
3004
 * tasks performed:
3005
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3006
 *
3007
 * @param $form
3008
 * @param $form_state
3009
 */
3010
function cdm_settings_general_submit($form, &$form_state){
3011
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3012
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3013
}
3014

    
3015
/**
3016
 * Form validation handler for cdm_settings_cache
3017
 */
3018
function cdm_settings_cache_validate($form, &$form_state) {
3019
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3020
    cache_clear_all(NULL, 'cache_cdm_ws');
3021
    // Better clear secref_cache since I can not be sure if the cache has not
3022
    // be used during this response.
3023
    cdm_api_secref_cache_clear();
3024
  }
3025

    
3026
}
3027

    
3028
/**
3029
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3030
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3031
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3032
 *  - version: the version, e.g.: v1.1
3033
 *
3034
 * @return array
3035
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3036
 */
3037
function get_edit_map_service_settings() {
3038

    
3039
  $settings = variable_get('edit_map_server', array(
3040
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3041
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3042
      )
3043
  );
3044

    
3045
  return $settings;
3046
}
3047

    
3048
/**
3049
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3050
 *
3051
 * @return string
3052
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3053
 */
3054
function get_edit_map_service_full_uri() {
3055
  $settings = get_edit_map_service_settings();
3056
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3057
}
3058

    
3059

    
3060
/**
3061
 * Returns the version number of the currently selected edit mapserver as a float
3062
 *
3063
 * @return float
3064
 *   The version number of the currently selected edit mapserver as a float.
3065
 *   Returns 0 on error.
3066
 */
3067
function get_edit_map_service_version_number() {
3068

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

    
3071
  $settings = get_edit_map_service_settings();
3072
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3073
  if (isset($matches[1])) {
3074
    // Convert string to float.
3075
    $version = 1 + $matches[1][0] - 1;
3076
    return $version;
3077
  }
3078
  else {
3079
    // Report error.
3080
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3081
        array(
3082
          '!version' => $settings['version'],
3083
          'warning')
3084
        )
3085
      );
3086
    return 0;
3087
  }
3088
}
3089

    
3090
/**
3091
 * Returns the array of selected items in a options array
3092
 *
3093
 * @param array $options
3094
 *   An options array as generated by a form element like checkoxes, select ...,
3095
 */
3096
function get_selection($options) {
3097
  $selection = array();
3098
  foreach ($options as $key=>$val) {
3099
    if (!empty($val)) {
3100
      $selection[] = $val;
3101
    }
3102
  }
3103
  return $selection;
3104
}
3105

    
3106

    
3107
/**
3108
 * Implements hook_element_info().
3109
 *
3110
 * Allows modules to declare their own Form API element types and specify their default values.
3111
 *
3112
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3113
 */
3114
function cdm_dataportal_element_info() {
3115
  $type['checkboxes_preferred'] = array(
3116
    '#input' => TRUE,
3117
    '#process' => array('checkboxes_preferred_expand'),
3118
    '#after_build' => array('checkboxes_preferred_after_build'),
3119
    '#theme' => array('checkboxes_preferred'),
3120
    // '#theme_wrapper' => array('form_element'),
3121
  );
3122
  return $type;
3123
}
3124

    
3125
/**
3126
 * #process callback function for the custom form element type 'checkbox_preferred'
3127
 *
3128
 *
3129
 */
3130
function checkboxes_preferred_expand($element, &$form_state, $form) {
3131

    
3132
  // First of all create checkboxes for each of the elements
3133
  $element = form_process_checkboxes($element);
3134

    
3135
  // compose the element name
3136
  $parents = array();
3137
  array_deep_copy($element['#parents'], $parents);
3138
  $parents[count($parents) -1 ] .= '_preferred';
3139
  $element_name = $parents[0];
3140
  for ($i=1; $i < count($parents); $i++){
3141
    $element_name .= '[' . $parents[$i] . ']';
3142
  }
3143

    
3144
  $children = element_children($element);
3145

    
3146
  $element['table_start'] = array(
3147
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3148
    '#weight' => -1,
3149
  );
3150

    
3151
  // prepare first part each of the table rows which contains the row label
3152
  $weight = 0;
3153
  foreach ($children as $key) {
3154
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3155
    $element[$key]['#weight'] = $weight;
3156
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
3157
    $element[$key]['#suffix'] = '</td>';
3158
    unset($element[$key]['#title']);
3159
    $weight += 2;
3160
  }
3161
  $weight = 0;
3162

    
3163
  // add a radio button to each of the checkboxes, the
3164
  // check boxes have already been created at the beginning
3165
  // of this function
3166
  if (count($element['#options']) > 0) {
3167
    foreach ($element['#options'] as $key => $choice) {
3168
      if (!isset($element[$key . '_preferred'])) {
3169
        $element[$key . '_preferred'] = array(
3170
          '#type' => 'radio',
3171
          '#name' => $element_name,
3172
          '#return_value' => check_plain($key),
3173
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3174
          '#attributes' => $element['#attributes'],
3175
          '#parents' => $element['#parents'],
3176
          // '#spawned' => TRUE,
3177
          '#weight' => $weight + 1,
3178
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3179
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3180
        );
3181
      }
3182
      $weight += 2;
3183
    }
3184
  }
3185

    
3186
  // end the table
3187
  $element['table_end'] = array(
3188
    '#markup' => '</table>',
3189
    '#weight' => $weight++,
3190
  );
3191

    
3192
  return $element;
3193
}
3194

    
3195
/**
3196
 * Theme function for the custom form field 'checkboxes_preferred'.
3197
 */
3198
function theme_checkboxes_preferred($variables) {
3199
  $element = $variables['element'];
3200
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3201
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3202
  $out .= drupal_render_children($element);
3203
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3204
  $out .= '</div>';
3205
  return $out;
3206
}
3207

    
3208
/**
3209
 * Callback for checkboxes preferred for widget which will
3210
 * be called after the form or element is built. The call
3211
 * back is configured in the form element by setting it as
3212
 * #after_build parameter.
3213
 *
3214
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3215
 *
3216
 * @param $element
3217
 *   Nested array of form elements that comprise the form.
3218
 * @param $form_state
3219
 *   A keyed array containing the current state of the form.
3220
 *   This includes the current persistent storage data for the form.
3221
 *   Additional information, like the sanitized $_POST data,
3222
 *   is also accumulated here in $form_state['input']
3223
 *
3224
 * @return the modified form array
3225
 */
3226
function checkboxes_preferred_after_build($element, &$form_state) {
3227

    
3228
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3229

    
3230
  if ($_POST && count($_POST) > 0) {
3231
    // TODO use  $form_state['input'] instead of POST !!!
3232
    // First pass of form processing.
3233
    $parents = array();
3234
    array_deep_copy($element['#parents'], $parents);
3235
    $parents[count($parents) - 1] .= '_preferred';
3236
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3237
    $element['#value']['PREFERRED'] = $preferred_layer;
3238
//     $form_state[$parent_id] = $element['#value'];
3239
//     $form_state['values']['baselayers'] = $element['#value'];
3240
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3241
    $form_state_element_values = $element['#value'];
3242
  }
3243
  else {
3244
    // Second pass of form processing.
3245
    $preferred_layer = $element['#value']['PREFERRED'];
3246
  }
3247

    
3248
  // Also set the chosen value (not sure if this is good Drupal style ....).
3249
  foreach ($children = element_children($element) as $key) {
3250
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3251
      $element[$key]['#value'] = $preferred_layer;
3252
    }
3253
  }
3254
  // The default layer must always be enabled.
3255
  $element[$preferred_layer]['#value'] = $preferred_layer;
3256

    
3257
  return $element;
3258
}
3259

    
3260
function radios_prepare_options_suffix(&$elements){
3261

    
3262
  $childrenKeys = element_children($elements);
3263
  foreach($childrenKeys as $key){
3264
    if(!is_array($elements[$key]['#theme_wrappers'])){
3265
      $elements[$key]['#theme_wrappers'] = array();
3266
    }
3267
    if(isset($elements['#options_suffixes'][$key])){
3268
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3269
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3270
    }
3271
  }
3272
  return $elements;
3273

    
3274
}
3275

    
3276
/**
3277
 * TODO
3278
 * @param unknown $variables
3279
 */
3280
function theme_radio_options_suffix($variables) {
3281
  $element = $variables['element'];
3282
  if(isset($element['#options_suffix'])) {
3283
    $element['#children'] .= $element['#options_suffix'];
3284
  }
3285
  return $element['#children'];
3286
}
3287

    
3288

    
3289
/**
3290
 * Element validate callback for text field and arrays containing json.
3291
 *
3292
 * @param $element
3293
 *   The form element to validate
3294
 * @param $form_state
3295
 *   A keyed array containing the current state of the form.
3296
 * @param $form
3297
 *   Nested array of form elements that comprise the form.
3298
 */
3299
function form_element_validate_json($element, &$form_state, $form) {
3300
   if (!empty($element['#value'])) {
3301
     json_decode($element['#value']);
3302
     if(json_last_error() != JSON_ERROR_NONE){
3303
       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/'));
3304
     }
3305
   }
3306
}
3307

    
3308
/**
3309
 * Form submission handler for textareas and textfields containing JSON.
3310
 *
3311
 * The contained JSON will be converted into an php array
3312
 * or object and will be stored in the variables as such.
3313
 *
3314
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3315
 *
3316
 * @param $form
3317
 *   Nested array of form elements that comprise the form.
3318
 * @param $form_state
3319
 *   A keyed array containing the current state of the form.
3320
 *
3321
 */
3322
function submit_json_as_php_array($form, &$form_state) {
3323
  if (is_array($form['#json_elements'])) {
3324
    foreach ($form['#json_elements'] as $element){
3325
      if (trim($form_state['values'][$element])) {
3326
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3327
      } else {
3328
        $form_state['values'][$element] = NULL;
3329
      }
3330
    }
3331
  }
3332
}
(15-15/15)