Project

General

Profile

Download (145 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?php
2
/**
3
 * @file
4
 * CDM Dataportal settings.
5
 */
6
7 b2b9e057 Andreas Kohlbecker
8 642b323b Andreas Kohlbecker
  // TODO Genus UUID.
9
10 aaa81689 Andreas Kohlbecker
  define('TAXONTREE_RANKLIMIT', 'cdm_taxontree_ranklimit');
11
  define('TAXONTREE_RANKLIMIT_DEFAULT', 0);
12 642b323b Andreas Kohlbecker
  define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
13
  define('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
14
15
  define('NO_SORT', -1);
16
  define('SORT_HIERARCHICAL', 9);
17
18
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
19 1d69a96c Andreas Kohlbecker
20
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
21
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
22
23 642b323b Andreas Kohlbecker
  define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
24
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
25 35bea66c Patrick Plitzner
  define('CDM_DATAPORTAL_TAXON_AUTO_SUGGEST', 0);
26 642b323b Andreas Kohlbecker
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 1);
27
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
28
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
29
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
30
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
31
32
  /* annotationTypeKeys */
33 7ca5ef1e Andreas Kohlbecker
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
34 642b323b Andreas Kohlbecker
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
35
    $annotationTypeKeys = array_flip($annotationTypeKeys);
36
37
    // Technical annotation are off by default.
38
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
39
    $annotationTypeKeys = array_flip($annotationTypeKeys);
40
    // Additional value for the NULL case.
41
    $annotationTypeKeys[] = 'NULL_VALUE';
42
  }
43
  define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
44 6657531f Andreas Kohlbecker
45 642b323b Andreas Kohlbecker
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
46
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
47
    'enabled' => 0,
48
    'key_format' => 'ALPHA'
49
  )));
50 f19f47fa Andreas Kohlbecker
51 642b323b Andreas Kohlbecker
  /* taxonRelationshipTypes */
52
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
53 6657531f Andreas Kohlbecker
54 6280e639 Andreas Kohlbecker
55 1ce9afb7 Patric Plitzner
56 642b323b Andreas Kohlbecker
    /* ---- MAP SETTING CONSTANTS ---- */
57
  /**
58
   * @var array of URIs eg. http://edit.africamuseum.be"
59
   *   An options array
60
   */
61
  define('EDIT_MAPSERVER_URI', serialize(
62
      array(
63
        'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)',
64
        'http://edit.br.fgov.be'=>'Secondary (http://edit.br.fgov.be)',
65
      )
66 ba706bf0 Andreas Kohlbecker
    )
67 642b323b Andreas Kohlbecker
  );
68
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
69
  /**
70
   * @var array of versions eg. "v1.2"
71
   *   An options array
72
   */
73
  define('EDIT_MAPSERVER_VERSION', serialize(
74
      array(
75 fb9c2a03 Andreas Kohlbecker
//        'v1' => 'v1' ,           // no longer recommended
76
//        'v1.1' => 'v1.1',        // no longer recommended
77
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
78 642b323b Andreas Kohlbecker
        'v1.2' => 'v1.2',
79 fb9c2a03 Andreas Kohlbecker
        'v1.3_dev' => 'v1.3_dev (not recommended)',
80
        'v1.4_dev' => 'v1.4_dev (experimental features)'
81 642b323b Andreas Kohlbecker
      )
82 f19f47fa Andreas Kohlbecker
    )
83 642b323b Andreas Kohlbecker
  );
84
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
85
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
86 6657531f Andreas Kohlbecker
87 642b323b Andreas Kohlbecker
    // --- Taxon profile settings --- /
88
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
89
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
90
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
91
      array(
92
          'show' => 0,
93
          'maxextend' => 184,
94
          'media_uri_query' => '',
95 ca47ea76 Andreas Kohlbecker
          'custom_placeholder_enabled' => 1,
96 642b323b Andreas Kohlbecker
          'custom_placeholder_image_on' => 0,
97
          'custom_placeholder_image_fid' => ''
98
      )
99 9c92cd84 Andreas Kohlbecker
    )
100 642b323b Andreas Kohlbecker
  );
101 ba706bf0 Andreas Kohlbecker
102 846c0606 Andreas Kohlbecker
103
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
104
105
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
106
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
107
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
108
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
109
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
110
111
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
112
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
113
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
114
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
115 c6ee8193 Andreas Kohlbecker
116 6657531f Andreas Kohlbecker
/**
117 b54cbda1 Andreas Kohlbecker
 * Returns the array of implemented taxon page tabs.
118
 * The array has fixed integer keys which must not be changed.
119 6657531f Andreas Kohlbecker
 */
120
function get_taxon_tabs_list() {
121
  return array(
122
    0 => 'General',
123
    1 => 'Synonymy',
124
    2 => 'Images',
125
    3 => 'Specimens',
126
    4 => 'Keys',
127 7663cd0b Andreas Kohlbecker
    5 => 'Experts',
128 6657531f Andreas Kohlbecker
  );
129
}
130
131 b54cbda1 Andreas Kohlbecker
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
132 d9763fd3 Andreas Kohlbecker
  array(
133
    'general' => '-3',
134
    'synonymy' => '-2',
135
    'images' => '0',
136
    'specimens' => '1',
137
    'keys' => '3',
138
    'experts' => '5',
139
    )
140 b54cbda1 Andreas Kohlbecker
));
141
142 6657531f Andreas Kohlbecker
$taxon_tab_options = get_taxon_tabs_list();
143
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
144
145
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
146
147
/**
148
 * @todo document this function.
149
 */
150
function get_taxon_options_list() {
151
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
152
  foreach ($taxon_tab_options as $key => $value) {
153 7cc085da Andreas Kohlbecker
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
154 6657531f Andreas Kohlbecker
  }
155
  return $taxon_tab_options;
156
157
}
158
159 0f5f1c12 Andreas Kohlbecker
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
160
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
161 f19f47fa Andreas Kohlbecker
  array(
162
      'ZoologicalName' => array(
163 501347df Andreas Kohlbecker
        'namePart' => array('name' => TRUE),
164 f19f47fa Andreas Kohlbecker
        'nameAuthorPart' => array('name' => TRUE),
165
        'referencePart' => array('authors' => TRUE),
166
        'microreferencePart' => array('microreference' => TRUE),
167 e24d373b Andreas Kohlbecker
        'secReferencePart' => array('secReference' => TRUE,),
168 f19f47fa Andreas Kohlbecker
        'statusPart' => array('status' => TRUE),
169
        'descriptionPart' => array('description' => TRUE),
170
      ),
171 0f5f1c12 Andreas Kohlbecker
      'BotanicalName'=> array(
172
        'namePart' => array('name' => TRUE),
173
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
174
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
175 43998144 Andreas Kohlbecker
        'secReferencePart' => array('secReference' => TRUE,),
176 51b04faf Andreas Kohlbecker
        'referenceYearPart' => array('reference.year' => TRUE),
177 0f5f1c12 Andreas Kohlbecker
        'statusPart' => array('status' => TRUE),
178
        'descriptionPart' => array('description' => TRUE),
179 f19f47fa Andreas Kohlbecker
      ),
180
     '#DEFAULT' => array(
181
        'namePart' => array(
182
            'name' => TRUE
183 501347df Andreas Kohlbecker
        ),
184
        'nameAuthorPart' => array(
185
            'name' => TRUE,
186
            'authors' => TRUE
187 f19f47fa Andreas Kohlbecker
        ),
188 43998144 Andreas Kohlbecker
       'referencePart' => array(
189
         'reference' => TRUE
190 f19f47fa Andreas Kohlbecker
        ),
191 43998144 Andreas Kohlbecker
       'secReferencePart' => array(
192
         'secReference' => TRUE,
193
       ),
194
       'microreferencePart' => array(
195
          'microreference' => TRUE,
196 f19f47fa Andreas Kohlbecker
        ),
197 43998144 Andreas Kohlbecker
       'statusPart' => array(
198
          'status' => TRUE,
199 f19f47fa Andreas Kohlbecker
        ),
200 43998144 Andreas Kohlbecker
       'descriptionPart' => array(
201
          'description' => TRUE,
202 f19f47fa Andreas Kohlbecker
        ),
203
      )
204 0f5f1c12 Andreas Kohlbecker
    )
205
  )
206
);
207 1a01f6dd Andreas Kohlbecker
  define('CDM_PART_DEFINITIONS_DEFAULT_PRE_380', serialize(
208
    array(
209
      'ZoologicalName' => array(
210
        'namePart' => array('name' => TRUE),
211
        'nameAuthorPart' => array('name' => TRUE),
212
        'referencePart' => array('authors' => TRUE),
213
        'microreferencePart' => array('microreference' => TRUE),
214
        'statusPart' => array('status' => TRUE),
215
        'descriptionPart' => array('description' => TRUE),
216
      ),
217
      'BotanicalName'=> array(
218
        'namePart' => array('name' => TRUE),
219
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
220
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
221
        'referenceYearPart' => array('reference.year' => TRUE),
222
        'statusPart' => array('status' => TRUE),
223
        'descriptionPart' => array('description' => TRUE),
224
      ),
225
      '#DEFAULT' => array(
226
        'namePart' => array(
227
          'name' => TRUE
228
        ),
229
        'nameAuthorPart' => array(
230
          'name' => TRUE,
231
          'authors' => TRUE
232
        ),
233
        'referencePart' => array(
234
          'reference' => TRUE
235
        ),
236
        'microreferencePart' => array(
237
          'microreference' => TRUE,
238
        ),
239
        'statusPart' => array(
240
          'status' => TRUE,
241
        ),
242
        'descriptionPart' => array(
243
          'description' => TRUE,
244
        ),
245
      )
246
    )
247
  )
248
  );
249
250 f19f47fa Andreas Kohlbecker
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
251 0f5f1c12 Andreas Kohlbecker
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
252 e24d373b Andreas Kohlbecker
  array (
253
    'taxon_page_title,polytomousKey'=> array(
254 1a01f6dd Andreas Kohlbecker
        'namePart' => array('#uri' => TRUE),
255
      ),
256 e24d373b Andreas Kohlbecker
    'not_in_current_classification' => array(
257
     'nameAuthorPart' => TRUE,
258
     'referencePart' => TRUE,
259
     'statusPart' => TRUE,
260
     'secReferencePart' => TRUE,
261
    ),
262
    'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy'=> array(
263
      'nameAuthorPart' => array('#uri' => TRUE),
264
      'referencePart' => TRUE,
265
      'statusPart' => TRUE,
266
      'descriptionPart' => TRUE,
267
    ),
268 df6226aa Andreas Kohlbecker
    'related_taxon.other_taxon_relationship.taxon_relationships.taxon_page_synonymy'=> array(
269 e24d373b Andreas Kohlbecker
      'nameAuthorPart' => array('#uri' => TRUE),
270
      'referencePart' => TRUE,
271
      'statusPart' => TRUE,
272
      'secReferencePart' => TRUE,
273
      'descriptionPart' => TRUE,
274
    ),
275 df6226aa Andreas Kohlbecker
    'related_taxon.misapplied_name_for.taxon_relationships.taxon_page_synonymy' => array(
276
      'nameAuthorPart' => array('#uri' => TRUE),
277
      'referencePart' => TRUE,
278
      'statusPart' => TRUE,
279
      /* no sec ref in this case, misapplied names are
280
       * de-duplicated and the sec ref is shown as footnote */
281
      'descriptionPart' => TRUE,
282
    ),
283 e24d373b Andreas Kohlbecker
    'homonym'=> array(
284 1a01f6dd Andreas Kohlbecker
        'nameAuthorPart' => array('#uri' => TRUE),
285
        'referenceYearPart' => TRUE,
286 c97cae85 Andreas Kohlbecker
        'statusPart' => TRUE,
287 e24d373b Andreas Kohlbecker
    ),
288
    'acceptedFor,typedesignations,list_of_taxa' => array(
289 1a01f6dd Andreas Kohlbecker
        'nameAuthorPart' => array('#uri' => TRUE),
290
        'referencePart' => TRUE,
291
      ),
292 e24d373b Andreas Kohlbecker
    '#DEFAULT' => array(
293 1a01f6dd Andreas Kohlbecker
        'nameAuthorPart' => array('#uri' => TRUE),
294
        'referencePart' => TRUE,
295 e24d373b Andreas Kohlbecker
     )
296
  )
297
));
298
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
299
  array (
300
    'taxon_page_title,polytomousKey'=> array(
301
      'namePart' => array('#uri' => TRUE),
302
    ),
303
    'taxon_page_synonymy,related_taxon'=> array(
304
      'nameAuthorPart' => array('#uri' => TRUE),
305
      'referencePart' => TRUE,
306
      'statusPart' => TRUE,
307
      'descriptionPart' => TRUE,
308
    ),
309
    'homonym'=> array(
310
      'nameAuthorPart' => array('#uri' => TRUE),
311
      'referenceYearPart' => TRUE,
312
    ),
313
    'acceptedFor,typedesignations,list_of_taxa' => array(
314
      'nameAuthorPart' => array('#uri' => TRUE),
315
      'referencePart' => TRUE,
316
    ),
317
    '#DEFAULT' => array(
318
      'nameAuthorPart' => array('#uri' => TRUE),
319
      'referencePart' => TRUE,
320 1a01f6dd Andreas Kohlbecker
    )
321 e24d373b Andreas Kohlbecker
  )
322
));
323 0f5f1c12 Andreas Kohlbecker
324 6280e639 Andreas Kohlbecker
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
325
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
326
    // to unset a default enntry set the value to 0
327
    array(
328
      'doTaxa'=>'doTaxa',
329
      'doSynonyms' => 'doSynonyms',
330
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
331
      'doMisappliedNames' => 'doMisappliedNames'
332
    )
333
  )
334
);
335
336 072122ee Andreas Kohlbecker
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
337
338 2d0d855a Andreas Kohlbecker
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
339 90a6166e Andreas Kohlbecker
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
340 2d0d855a Andreas Kohlbecker
341 6280e639 Andreas Kohlbecker
/* Gallery variables. */
342
$gallery_settings = array(
343
    "cdm_dataportal_show_taxon_thumbnails" => 1,
344
    "cdm_dataportal_show_synonym_thumbnails" => 0,
345
    "cdm_dataportal_show_thumbnail_captions" => 1,
346
    "cdm_dataportal_media_maxextend" => 120,
347
    "cdm_dataportal_media_cols" => 3,
348
    "cdm_dataportal_media_maxRows" => 1,
349
);
350
351 6657531f Andreas Kohlbecker
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
352
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
353
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
354
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
355
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
356
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
357
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
358
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
359
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
360
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
361
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
362
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
363 6421984d Andreas Kohlbecker
364 30f78c59 Andreas Kohlbecker
/**
365
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
366
 * the snonymy.
367
 *
368
 * @var string
369
 */
370 6657531f Andreas Kohlbecker
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
371 6421984d Andreas Kohlbecker
372
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
373
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
374
    array(
375 e4ccc0a0 Andreas Kohlbecker
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
376
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
377
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
378 6421984d Andreas Kohlbecker
    )
379
  )
380
);
381
382 30f78c59 Andreas Kohlbecker
/**
383
 * The drupal variable for the configuration of the information aggregation along
384
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
385
 *    - direct: the uuids of the taxon relationship types to take into account in invers
386
 *      direction.
387
 *    - invers: the uuids of the taxon relationship types to take into account in direct
388
 *      direction.
389
 *
390
 * @var String
391
 */
392
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
393
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
394
    array(
395
        'direct'=>array(),
396
        'invers'=>array()
397
     )
398
   ));
399 6657531f Andreas Kohlbecker
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
400 bfb2b81a Andreas Kohlbecker
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
401 6657531f Andreas Kohlbecker
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
402
403 aa63dfb4 Andreas Kohlbecker
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
404
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
405
      array(
406
      'filter_rules' => array(
407
        'statusOrderPreference' => 0,
408
        'subAreaPreference' => 0,
409
      ),
410 6fbf1bd3 Andreas Kohlbecker
      'hiddenAreaMarkerType' => array()
411 aa63dfb4 Andreas Kohlbecker
     )
412
));
413
414 38dd933d Andreas Kohlbecker
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
415
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
416
  "level_0" => array(
417
    'label_suffix' => ':',
418 3de12c0d Andreas Kohlbecker
    'status_glue' => '',
419 38dd933d Andreas Kohlbecker
    'item_glue' => ' ',
420
    'item_group_prefix' => '',
421
    'item_group_postfix' => ''
422
  ),
423
  "level_1" => array(
424 3de12c0d Andreas Kohlbecker
    'label_suffix' => '',
425
    'status_glue' => '‒ ', // '&#8210; '
426 38dd933d Andreas Kohlbecker
    'item_glue' => '; ',
427
    'item_group_prefix' => ', ',
428
    'item_group_postfix' => ''
429
  ),
430
  "level_2" => array(
431 3de12c0d Andreas Kohlbecker
    'label_suffix' => '',
432
    'status_glue' => '‒ ', // '&#8210; '
433 38dd933d Andreas Kohlbecker
    'item_glue' => ', ',
434
    'item_group_prefix' => ' (',
435
    'item_group_postfix' => ')'
436
  )
437
)));
438 aa63dfb4 Andreas Kohlbecker
439 378bc1ce Andreas Kohlbecker
/**
440
 * Constant for the drupal variable key distribution_map_visibility
441
 *
442
 * possible values:
443
 *  - never
444
 *  - automatic
445
 *  - always
446
 */
447
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
448
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
449
450
/**
451
 * Constant for the drupal variable key specimen_map_visibility
452
 *
453
 * possible values:
454
 *  - never
455
 *  - automatic
456
 *  - always
457
 */
458
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
459
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
460
461 a950f2f9 Andreas Kohlbecker
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
462
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
463
    array(
464
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
465
        'includeOccurrences' => 0,
466
        'includeTaxonNameDescriptions' => 0
467
     )
468
  ));
469
470 cc3c9807 Andreas Kohlbecker
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
471
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
472
  // needs to be merged with user setting by drupal_array_merge_deep()
473 b4503332 Andreas Kohlbecker
  // 'width' => 512, // optimum size for OSM layers is 512
474
  // 'height' => 512 / 2, // optimum size for OSM layers 256
475
  'aspect_ratio' => 2,
476 cc3c9807 Andreas Kohlbecker
  'bbox' => '', // empty to allow automatic zooming to extend
477
  'show_labels' => FALSE,
478
  'caption' => '',
479
  'distribution_opacity' => '0.5',
480
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
481
  'image_map' => array(
482
    'base_layer' => '', // none, formerly this was cyprusdivs
483
    'bg_color' => '1874CD',
484
    'layer_style' => 'ffffff,606060,,',
485
  ),
486
  'openlayers' => array(
487
    'base_layers' =>  array(
488
      // A layer MUST NOT BE SET in the defaults,
489
      // otherwise it can not be overidden by the user settings:
490 5cef0b6d Andreas Kohlbecker
      // 'mapproxy_vmap0' => 'mapproxy_vmap0',
491 cc3c9807 Andreas Kohlbecker
      // it is sufficient to define the preferred layer,
492
      // since it will automatically be enabled:
493 5cef0b6d Andreas Kohlbecker
      'PREFERRED' => 'mapproxy_vmap0'),
494 fb9c2a03 Andreas Kohlbecker
    'custom_wms_base_layer' => array(
495
      'name' => NULL,
496
      'url' => NULL,
497
      'params' =>  NULL,
498
      'projection' => NULL,
499
      'proj4js_def' => NULL,
500
      'max_extent' => NULL,
501
      'units' => NULL
502
    ),
503 2bbc28c8 Andreas Kohlbecker
    'show_layer_switcher' => TRUE,
504 2b83cc8b Andreas Kohlbecker
    'display_outside_max_extent' => FALSE,
505
    'google_maps_api_key' => NULL,
506 cc3c9807 Andreas Kohlbecker
  ),
507
  'legend' => array(
508
    'show' => TRUE,
509
    'opacity' => '0.5',
510
    'font_size' => 10,
511
    'font_style' => FALSE,
512
    'icon_width' => 35,
513
    'icon_height' => 15
514
  )
515
)));
516
517
/**
518
 * Merges the named array variable with the array of defaults.
519
 *
520 5611d467 Andreas Kohlbecker
 * IMPORTANT: The array keys must be strings. When the keys are integers
521
 * the merging will not take place for these entities. Number keyed entities
522 b54cbda1 Andreas Kohlbecker
 * are just appended to the result array.
523
 *
524 cc3c9807 Andreas Kohlbecker
 * @param string $variable_name
525
 *     The variable name
526
 * @param string | array $default
527
 *     The array containing the default values either as array or serialized as string.
528 5611d467 Andreas Kohlbecker
 *     Unserialization is cared for if necessary
529 cc3c9807 Andreas Kohlbecker
 * @return array
530 5611d467 Andreas Kohlbecker
 *     The merged array as returned by drupal_array_merge_deep()
531 8c962983 Andreas Kohlbecker
 *
532 0f7c9d15 Andreas Kohlbecker
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
533
 * TODO force $default being an array
534 cc3c9807 Andreas Kohlbecker
 */
535
function get_array_variable_merged($variable_name, $default){
536
537
    // unserialize if nessecary
538
    if(!is_array($default)){
539
      $default = unserialize($default);
540
    }
541
    $variable = variable_get($variable_name, array());
542 b54cbda1 Andreas Kohlbecker
    $result = drupal_array_merge_deep($default, $variable);
543
    return $result;
544 cc3c9807 Andreas Kohlbecker
}
545
546 6657531f Andreas Kohlbecker
/**
547
 * @todo document this function.
548
 */
549
function getGallerySettings($gallery_config_form_name) {
550 cc3c9807 Andreas Kohlbecker
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
551 6657531f Andreas Kohlbecker
}
552
553
/**
554
 * Returns the string representation of the default tab.
555
 *
556
 * @param bool $returnTabIndex
557
 *   Defaults to FALSE, if set true this function will return the index number
558
 *   of the default tab. (used to supply default values to form elements).
559
 */
560
function get_default_taxon_tab($returnTabIndex = FALSE) {
561
562
  global $user;
563
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
564
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
565
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
566
  // Get the user value if the used has chosen to overwrite the system settings.
567
  $user_tab_on = variable_get($user_tab_active, FALSE);
568
  if ($user_tab_on) {
569
    $user_value = variable_get($user_tab, 0);
570
    $index_value = $user_value;
571
    // Get the system value.
572
  }
573
  else {
574
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
575
    $index_value = $system_value;
576
  }
577
578
  // Return the index value or the string representation.
579
  if ($returnTabIndex) {
580
    return $index_value;
581
  }
582
  else {
583
    return ($values[$index_value]);
584 22f5e82d Andreas Kohlbecker
  }
585 6657531f Andreas Kohlbecker
}
586
587 22f5e82d Andreas Kohlbecker
588 f3a04cfa Andreas Kohlbecker
  /**
589 8c962983 Andreas Kohlbecker
   * Provides the feature block settings for a specific feature which matches the $feature_uuid parameter.
590 f3a04cfa Andreas Kohlbecker
   *
591 8c962983 Andreas Kohlbecker
   * In case specifically configured settings array, like these which are stored in the drupal variables, is missing
592
   * one or more fields these fields are taken from the default. That is the specific settings are always merges
593
   * with the default.
594 f3a04cfa Andreas Kohlbecker
   *
595
   * Note: These settings only apply to feature blocks which do not have a special rendering
596 abacccbf Andreas Kohlbecker
   * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
597 f3a04cfa Andreas Kohlbecker
   * 'special' element of the settings
598
   *
599
   * @param $feature_uuid
600
   *   The uuid string representation of the feature to return the settings for
601
   *
602
   * @return array
603
   *  an associative array of settings, with the following fields:
604
   *    - as_list: string
605 c651d3b1 Andreas Kohlbecker
   *        this setting will be used in compose_feature_block_wrap_elements() as $enclosing_tag
606 f3a04cfa Andreas Kohlbecker
   *        possible values are:
607
   *          div: not as list,
608
   *          ul: as bullet list,
609
   *          ol: as numbered list,
610
   *          dl: as definition list
611 08a339ec Andreas Kohlbecker
   *        The tag used for the inner element, thus depends on the value of this field. The
612
   *        inner tag name can be retrieved by the function cdm_feature_block_element_tag_name()
613 f3a04cfa Andreas Kohlbecker
   *    - link_to_reference: boolean,
614
   *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
615
   *    - link_to_name_used_in_source": boolean
616
   *        whether to show name is source information as link which will point to the according name page
617
   *    - sources_as_content (boolean)
618 642b323b Andreas Kohlbecker
   *        TRUE (int: 1):
619 159cd9bb Andreas Kohlbecker
   *          1. If element is of the CDM type TextData and the text is not empty the source references will be
620 44d445c0 Andreas Kohlbecker
   *             appended in brackets like "text (source references)". If the original source has name in source
621
   *             information it will be appended to the citation string,
622
   *             like : "(citation, as name in source; citation, as name in source)"
623
   *          2. if the text of the TextData is empty, the original source citations are the only content
624
   *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
625
   *             prepended to the citation string like: "name in source: citation"
626 642b323b Andreas Kohlbecker
   *        FALSE (int: 0):
627 dcf17487 Andreas Kohlbecker
   *          Original sources are put into the bibliography(=references) pseudo feature block. If the original source
628 159cd9bb Andreas Kohlbecker
   *          citations are the only content, the resulting feature block content would only consist of footnotes.
629
   *          In this case the display of the respective feature block is suppressed.
630 dcf17487 Andreas Kohlbecker
   *          TODO if the bibliography is not enabled the sources will be treated as footnotes like annotations,
631
   *               in future however they will in this case be shown in a separate references section for each
632
   *               feature block.
633 f3a04cfa Andreas Kohlbecker
   *    - sources_as_content_to_bibliography  (boolean)
634
   *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
635 159cd9bb Andreas Kohlbecker
   *        in the bibliography.
636 f3a04cfa Andreas Kohlbecker
   *    - sort_elements
637
   *        whether and how to sort the elements
638 dcf17487 Andreas Kohlbecker
   *        possible values are the constants SORT_ASC, SORT_DESC, NULL,
639 642b323b Andreas Kohlbecker
   *        some feature types (Distribution) also support: SORT_HIERARCHICAL (
640
   *        TODO option to exclude levels, put in special?,
641 c651d3b1 Andreas Kohlbecker
   *        TODO make use of this setting in compose_feature_block_wrap_elements())
642 f3a04cfa Andreas Kohlbecker
   *    - element_tag
643
   *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
644 f2e44165 Andreas Kohlbecker
   *        possible values are span | div. the proper inner tag name can be retrieved by the function
645
   *        cdm_feature_block_element_tag_name()
646 f3a04cfa Andreas Kohlbecker
   *    - special: array()
647
   *        an array with further settings, this field can be used for special
648
   *        settings for specialized rendering like for distributions
649
   *  }
650
   *
651
   */
652 642b323b Andreas Kohlbecker
  function get_feature_block_settings($feature_uuid = 'DEFAULT') {
653 f3a04cfa Andreas Kohlbecker
    // the default must conform to the default parameter values of
654 c651d3b1 Andreas Kohlbecker
    // compose_feature_block_wrap_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
655 0ef9a709 Andreas Kohlbecker
    // compose_description_element_text_data() : asListElement = NULL
656 f3a04cfa Andreas Kohlbecker
657
    // see #3257 (implement means to define the features to show up in the taxonprofile and in the specimen descriptions)
658
659 642b323b Andreas Kohlbecker
    // ---- DEFAULTS settings
660
661 6776a5bc Andreas Kohlbecker
    // only needed as final option, when the settings are not having a default
662 f3a04cfa Andreas Kohlbecker
    $default = array(
663 6776a5bc Andreas Kohlbecker
      'DEFAULT' => array(
664 6882da59 Andreas Kohlbecker
        'as_list' => 'div',
665 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
666
        'link_to_name_used_in_source' => 1,
667 8c962983 Andreas Kohlbecker
        'sources_as_content' => 0,
668 642b323b Andreas Kohlbecker
        'sources_as_content_to_bibliography' => 0,
669
        'sort_elements' => NO_SORT,
670 6776a5bc Andreas Kohlbecker
        'glue' => '',
671 642b323b Andreas Kohlbecker
        'element_tag' => NULL
672 6776a5bc Andreas Kohlbecker
      )
673
    );
674
675
    // will be used as preset in the settings
676
    $other_themes_default = array(
677 f3a04cfa Andreas Kohlbecker
      'DEFAULT' => array(
678 6882da59 Andreas Kohlbecker
        'as_list' => 'div',
679 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
680
        'link_to_name_used_in_source' => 1,
681
        'sources_as_content' => 0,
682
        'sources_as_content_to_bibliography' => 0,
683
        'sort_elements' => NO_SORT,
684 f3a04cfa Andreas Kohlbecker
        'glue' => '',
685 642b323b Andreas Kohlbecker
        'element_tag' => NULL
686 f3a04cfa Andreas Kohlbecker
      ),
687
      UUID_CITATION => array(
688
        'as_list' => 'div',
689 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
690
        'link_to_name_used_in_source' => 0,
691
        'sources_as_content' => 1,
692
        'sources_as_content_to_bibliography' => 0,
693 dcf17487 Andreas Kohlbecker
        'sort_elements' => SORT_ASC,
694 f3a04cfa Andreas Kohlbecker
        'glue' => '',
695 642b323b Andreas Kohlbecker
        'element_tag' => 'div'
696 dcf17487 Andreas Kohlbecker
      ),
697
      UUID_DISTRIBUTION => array(
698
        'as_list' => 'div', // currently ignored
699 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
700
        'link_to_name_used_in_source' => 0,
701
        'sources_as_content' => 0,
702
        'sources_as_content_to_bibliography' => 0,
703
        'sort_elements' => NO_SORT, // will cause ...
704 dcf17487 Andreas Kohlbecker
        'glue' => '',
705 642b323b Andreas Kohlbecker
        'element_tag' => 'div',
706
        'special' => array()
707 dcf17487 Andreas Kohlbecker
      ),
708 f2e44165 Andreas Kohlbecker
      UUID_COMMON_NAME => array(
709 6a3b101a Andreas Kohlbecker
        'as_list' => 'div',
710 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
711
        'link_to_name_used_in_source' => 1,
712
        'sources_as_content' => 0,
713
        'sources_as_content_to_bibliography' => 0,
714
        'sort_elements' => NO_SORT,
715 f2e44165 Andreas Kohlbecker
        'glue' => '',
716 642b323b Andreas Kohlbecker
        'element_tag' => 'span'
717 f2e44165 Andreas Kohlbecker
      ),
718 f3a04cfa Andreas Kohlbecker
    );
719
720 642b323b Andreas Kohlbecker
    // ---- Special DEFAULTS for existing portals
721
    // TODO:
722
    // this can be removed once the feature block
723
    // settings have been deployed for the first time to these portals
724
725 f3a04cfa Andreas Kohlbecker
    $cichorieae_default = array(
726
      'DEFAULT' => array(
727
        'as_list' => 'div',
728 642b323b Andreas Kohlbecker
        'link_to_reference' => 1,
729
        'link_to_name_used_in_source' => 1,
730
        'sources_as_content' => 1,
731
        'sources_as_content_to_bibliography' => 0,
732
        'sort_elements' => NO_SORT,
733 f3a04cfa Andreas Kohlbecker
        'glue' => '',
734 642b323b Andreas Kohlbecker
        'element_tag' => 'div'
735 f3a04cfa Andreas Kohlbecker
      ),
736
      UUID_CITATION => array(
737
        'as_list' => 'div',
738 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
739
        'link_to_name_used_in_source' => 0,
740
        'sources_as_content' => 1,
741
        'sources_as_content_to_bibliography' => 0,
742 dcf17487 Andreas Kohlbecker
        'sort_elements' => SORT_ASC,
743 f3a04cfa Andreas Kohlbecker
        'glue' => '',
744 642b323b Andreas Kohlbecker
        'element_tag' => 'div'
745 f3a04cfa Andreas Kohlbecker
      ),
746
      UUID_CHROMOSOMES_NUMBERS => array(
747
        'as_list' => 'ul',
748 642b323b Andreas Kohlbecker
        'link_to_reference' => 1,
749
        'link_to_name_used_in_source' => 1,
750
        'sources_as_content' => 1,
751
        'sources_as_content_to_bibliography' => 0,
752
        'sort_elements' => NO_SORT,
753 f3a04cfa Andreas Kohlbecker
        'glue' => '',
754 642b323b Andreas Kohlbecker
        'element_tag' => 'div'
755 f3a04cfa Andreas Kohlbecker
      ),
756
      UUID_CHROMOSOMES => array(
757
        'as_list' => 'ul',
758 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
759
        'link_to_name_used_in_source' => 1,
760
        'sources_as_content' => 1,
761
        'sources_as_content_to_bibliography' => 0,
762
        'sort_elements' => NO_SORT,
763 f3a04cfa Andreas Kohlbecker
        'glue' => '',
764 642b323b Andreas Kohlbecker
        'element_tag' => 'div'
765 f3a04cfa Andreas Kohlbecker
      ),
766 f2e44165 Andreas Kohlbecker
      UUID_COMMON_NAME => array(
767
        'as_list' => 'div',
768 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
769
        'link_to_name_used_in_source' => 1,
770
        'sources_as_content' => 0,
771
        'sources_as_content_to_bibliography' => 0,
772
        'sort_elements' => NO_SORT,
773 f2e44165 Andreas Kohlbecker
        'glue' => '',
774 642b323b Andreas Kohlbecker
        'element_tag' => 'span'
775 f2e44165 Andreas Kohlbecker
      ),
776 f3a04cfa Andreas Kohlbecker
    );
777
778
    $palmweb_default = array(
779
      'DEFAULT' => array(
780
        'as_list' => 'ul',
781 642b323b Andreas Kohlbecker
        'link_to_reference' => 1,
782
        'link_to_name_used_in_source' => 1,
783
        'sources_as_content' => 1,
784
        'sources_as_content_to_bibliography' => 1,
785
        'sort_elements' => NO_SORT,
786 f3a04cfa Andreas Kohlbecker
        'glue' => '',
787 642b323b Andreas Kohlbecker
        'element_tag' => NULL
788 f3a04cfa Andreas Kohlbecker
      ),
789
      UUID_CITATION => array(
790
        'as_list' => 'ul',
791 642b323b Andreas Kohlbecker
        'link_to_reference' => 1,
792
        'link_to_name_used_in_source' => 1,
793
        'sources_as_content' => 0,
794
        'sources_as_content_to_bibliography' => 1,
795 dcf17487 Andreas Kohlbecker
        'sort_elements' => SORT_ASC,
796 f3a04cfa Andreas Kohlbecker
        'glue' => '',
797 642b323b Andreas Kohlbecker
        'element_tag' => 'div'
798 a009927b Andreas Kohlbecker
      ),
799
      UUID_DISTRIBUTION => array(
800
        'as_list' => 'div', // currently ignored
801 642b323b Andreas Kohlbecker
        'link_to_reference' => 1,
802
        'link_to_name_used_in_source' => 1,
803
        'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
804
        'sources_as_content_to_bibliography' => 1,
805
        'sort_elements' => NO_SORT, // will cause ...
806 a009927b Andreas Kohlbecker
        'glue' => '',
807 642b323b Andreas Kohlbecker
        'element_tag' => 'div',
808
        'special' => array()
809 a009927b Andreas Kohlbecker
      ),
810 f3a04cfa Andreas Kohlbecker
    );
811
812 6776a5bc Andreas Kohlbecker
    $cyprus_default = $cichorieae_default;
813 642b323b Andreas Kohlbecker
    $cyprus_default[UUID_DISTRIBUTION] = array(
814 6776a5bc Andreas Kohlbecker
      'as_list' => 'div', // currently ignored
815 642b323b Andreas Kohlbecker
      'link_to_reference' => 0,
816
      'link_to_name_used_in_source' => 0,
817
      'sources_as_content' => 0,
818
      'sources_as_content_to_bibliography' => 0,
819
      'sort_elements' => NO_SORT, // will cause ...
820 6776a5bc Andreas Kohlbecker
      'glue' => '',
821 642b323b Andreas Kohlbecker
      'element_tag' => 'div',
822
      'special' => array()
823 6776a5bc Andreas Kohlbecker
    );
824
825 f3a04cfa Andreas Kohlbecker
    $default_theme = variable_get('theme_default', NULL);
826
827 642b323b Andreas Kohlbecker
    switch ($default_theme) {
828 f3a04cfa Andreas Kohlbecker
      case 'garland_cichorieae':
829 6776a5bc Andreas Kohlbecker
        $settings_for_theme = $cichorieae_default;
830
        break;
831 f3a04cfa Andreas Kohlbecker
      case 'cyprus':
832
        // cyprus: no longer used in production,
833
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
834 6776a5bc Andreas Kohlbecker
        $settings_for_theme = $cyprus_default;
835 f3a04cfa Andreas Kohlbecker
        break;
836
      case 'flore_afrique_centrale':
837
      case 'flora_malesiana':
838
      case 'flore_gabon':
839
        $settings_for_theme = $cichorieae_default;
840
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
841
        break;
842
      case 'palmweb_2':
843
        $settings_for_theme = $palmweb_default;
844
        break;
845
      default:
846 642b323b Andreas Kohlbecker
        $settings_for_theme = $other_themes_default;
847 f3a04cfa Andreas Kohlbecker
    }
848 642b323b Andreas Kohlbecker
    // ---- END of DEFAULTS
849 c367b0ab Andreas Kohlbecker
850 642b323b Andreas Kohlbecker
    $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
851
852 57d513cb Andreas Kohlbecker
    $feature_block_setting = null;
853 642b323b Andreas Kohlbecker
854
    if (isset($saved_settings[$feature_uuid])) {
855
      $feature_block_setting = $saved_settings[$feature_uuid];
856
    }
857
    else if (isset($settings_for_theme[$feature_uuid])) {
858
      $feature_block_setting = $settings_for_theme[$feature_uuid];
859 f3a04cfa Andreas Kohlbecker
    }
860 642b323b Andreas Kohlbecker
    else if (isset($settings_for_theme['DEFAULT'])) {
861
      $feature_block_setting = $settings_for_theme['DEFAULT'];
862
    }
863
864 57d513cb Andreas Kohlbecker
    // now merge the default and specific settings
865
    $settings_to_merge = array($default['DEFAULT']);
866
    if(is_array($saved_settings)){
867
      $settings_to_merge[] = $saved_settings['DEFAULT'];
868
    }
869
    if(isset($feature_block_setting)){
870
      $settings_to_merge[] = $feature_block_setting;
871
    }
872
    $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
873 642b323b Andreas Kohlbecker
874
    return $feature_block_setting;
875 1ce9afb7 Patric Plitzner
}
876 22f5e82d Andreas Kohlbecker
  /**
877 5611d467 Andreas Kohlbecker
 * returns the current setting for the original source bibliography
878
 *
879
 * Caches internally
880
 *
881
 * @return array
882
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
883
 *   - 'enabled': 1|0
884
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
885
 */
886 800ff2b0 Andreas Kohlbecker
function get_bibliography_settings($clear_cache = false){
887 5611d467 Andreas Kohlbecker
  static $bibliography_settings = null;
888 800ff2b0 Andreas Kohlbecker
  if(!$bibliography_settings || $clear_cache){
889 f3a04cfa Andreas Kohlbecker
    $bibliography_settings = get_array_variable_merged(
890
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
891
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
892
    );
893 5611d467 Andreas Kohlbecker
  }
894
  return $bibliography_settings;
895
}
896
897 6657531f Andreas Kohlbecker
/**
898
 * @todo Please document this function.
899
 * @see http://drupal.org/node/1354
900
 */
901
function cdm_dataportal_menu_admin(&$items) {
902
  // Display section on admin/config page.
903
  $items['admin/config/cdm_dataportal'] = array(
904
    'title' => 'CDM Dataportal',
905
    'description' => 'Settings for the CDM DataPortal.',
906
    'position' => 'right',
907
    'weight' => 10,
908
    'page callback' => 'system_admin_menu_block_page',
909 e014414c Andreas Kohlbecker
    'access arguments' => array('administer cdm_dataportal'),
910 6657531f Andreas Kohlbecker
    'file' => 'system.admin.inc',
911
    'file path' => drupal_get_path('module', 'system'),
912
  );
913
  $items['admin/config/cdm_dataportal/settings'] = array(
914
    'title' => 'Settings',
915
    'description' => 'Settings for the CDM DataPortal.',
916
    'weight' => 0,
917
    'page callback' => 'drupal_get_form',
918
    'page arguments' => array('cdm_settings_general'),
919
    'access arguments' => array('administer cdm_dataportal'),
920
    'type' => MENU_NORMAL_ITEM,
921
  );
922
  $items['admin/config/cdm_dataportal/settings/general'] = array(
923
    'title' => 'General',
924
    'description' => 'General',
925
    'weight' => 0,
926
    'page callback' => 'drupal_get_form',
927
    'page arguments' => array('cdm_settings_general'),
928
    'access arguments' => array('administer cdm_dataportal'),
929
    'type' => MENU_DEFAULT_LOCAL_TASK,
930
  );
931
932
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
933
    'title' => 'Cache',
934
    'description' => 'Cache',
935
    'access arguments' => array('administer cdm_dataportal'),
936
    'page callback' => 'drupal_get_form',
937
    'page arguments' => array('cdm_settings_cache'),
938
    'weight' => 10,
939
    'type' => MENU_LOCAL_TASK,
940
  );
941
942
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
943
    'title' => 'Geo & Map',
944
    'description' => 'Geo & Map',
945
    'access arguments' => array('administer cdm_dataportal'),
946
    'page callback' => 'drupal_get_form',
947
    'page arguments' => array('cdm_settings_geo'),
948
    'weight' => 1,
949
    'type' => MENU_LOCAL_TASK,
950
  );
951
952
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
953
    'title' => 'Layout',
954
    'description' => 'Configure and adjust the layout of your DataPortal ',
955
    'access arguments' => array('administer cdm_dataportal'),
956
    'page callback' => 'drupal_get_form',
957
    'page arguments' => array('cdm_settings_layout'),
958
    'weight' => 2,
959
    'type' => MENU_LOCAL_TASK,
960
  );
961
962
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
963
    'title' => 'Taxon',
964
    'description' => 'Configure and adjust the layout of your DataPortal ',
965
    'access arguments' => array('administer cdm_dataportal'),
966
    'page callback' => 'drupal_get_form',
967
    'page arguments' => array('cdm_settings_layout_taxon'),
968
    'weight' => 1,
969
    'type' => MENU_LOCAL_TASK,
970
  );
971
  /*
972
  $items[] = array(
973
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
974
  'title' => t('Synonymy'),
975
  'description' => t('Configure and adjust the layout of your DataPortal '),
976
  'access' => user_access('administer cdm_dataportal'),
977
  'callback' => 'drupal_get_form',
978
  'callback arguments' => array('cdm_settings_layout_synonymy'),
979
  'weight' => 1,
980
  'type' => MENU_LOCAL_TASK,
981
  );
982
983
  $items[] = array(
984
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
985
  'title' => t('Specimens'),
986
  'description' => t('Configure and adjust the layout of your DataPortal '),
987
  'access' => user_access('administer cdm_dataportal'),
988
  'callback' => 'drupal_get_form',
989
  'callback arguments' => array('cdm_settings_layout_specimens'),
990
  'weight' => 1,
991
  'type' => MENU_LOCAL_TASK,
992
  );
993
  */
994
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
995
    'title' => 'Search',
996
    'description' => 'Configure and adjust the layout of your DataPortal ',
997
    'access arguments' => array('administer cdm_dataportal'),
998
    'page callback' => 'drupal_get_form',
999
    'page arguments' => array('cdm_settings_layout_search'),
1000
    'weight' => 2,
1001
    'type' => MENU_LOCAL_TASK,
1002
  );
1003
1004
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1005
    'title' => 'Media',
1006
    'description' => 'Configure and adjust the layout of your DataPortal ',
1007
    'access arguments' => array('administer cdm_dataportal'),
1008
    'page callback' => 'drupal_get_form',
1009
    'page arguments' => array('cdm_settings_layout_media'),
1010
    'weight' => 3,
1011
    'type' => MENU_LOCAL_TASK,
1012
  );
1013 947c6a8d Andreas Kohlbecker
1014 6657531f Andreas Kohlbecker
}
1015
1016
/**
1017
 * @todo document this function.
1018
 */
1019
function cdm_help_general_cache() {
1020
  $form = array();
1021
  $form['cache_help'] = array(
1022
    '#type' => 'fieldset',
1023
    '#title' => t('Help'),
1024
    '#collapsible' => TRUE,
1025
    '#collapsed' => TRUE,
1026
  );
1027
  $form['cache_help']['test'] = array('#value' => t('probando'));
1028
  return drupal_render($form);
1029
  $res = array();
1030
  $res['default'] = drupal_render($help);
1031
  return $res;
1032
}
1033
1034
/**
1035
 * Configures the settings form for the CDM-API module.
1036
 *
1037
 * @return array
1038
 *   Drupal settings form.
1039
 */
1040
function cdm_settings_general() {
1041
1042
  $form['cdm_webservice'] = array(
1043
    '#type' => 'fieldset',
1044
    '#title' => t('CDM Server'),
1045
    '#collapsible' => FALSE,
1046
    '#collapsed' => FALSE,
1047 9438ad3a Andreas Kohlbecker
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1048
        CDM data base to the web via RESTful web services and thus is the source of the data
1049
        to be displayed by a CDM DataPotal.'),
1050 6657531f Andreas Kohlbecker
  );
1051
1052
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1053
    '#type' => 'textfield',
1054
    '#title' => t('CDM web service URL') . ':',
1055
    '#description' => t('This is the URL to the CDM-Server exposing your data
1056 d1eb0a8c Andreas Kohlbecker
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1057 6657531f Andreas Kohlbecker
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1058
  );
1059
1060
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1061 17c3d760 Andreas Kohlbecker
    '#type' => 'markup',
1062 d1e3ac25 Andreas Kohlbecker
    '#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')
1063
      . ' visible only for administrators',
1064 6657531f Andreas Kohlbecker
  );
1065
1066
  $form['cdm_webservice']['freetext_index'] = array(
1067
    '#type' => 'fieldset',
1068
    '#title' => t('Freetext index'),
1069
    '#collapsible' => FALSE,
1070
    '#collapsed' => FALSE,
1071
  );
1072
1073
  // Check the cdmserver port number and display a waring if it is not port 80
1074
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1075
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1076
    $form['cdm_webservice']['freetext_index']['message'] = array(
1077
      '#markup' => "<div class=\"description\">"
1078 7cc085da Andreas Kohlbecker
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1079
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1080
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1081
          array('!port' => $portNumberMatch[1][0])
1082
        )
1083 6657531f Andreas Kohlbecker
      . "</div>",
1084
    );
1085
  };
1086
1087
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1088
  $trigger_link_options = array(
1089
    'attributes' => array(
1090
      'class' => 'index-trigger',
1091
    ),
1092
  );
1093
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1094
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1095
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1096
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1097
      ))
1098
    . '<div id="index-progress"></div></div>',
1099
  );
1100
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1101
1102 35bea66c Patrick Plitzner
    $form['cdm_webservice']['freetext_index']['cdm_dataportal_taxon_auto_suggest'] = array(
1103
        '#type' => 'checkbox',
1104 6a5d84e2 Patrick Plitzner
        '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
1105 35bea66c Patrick Plitzner
        '#default_value' => variable_get('cdm_dataportal_taxon_auto_suggest', CDM_DATAPORTAL_TAXON_AUTO_SUGGEST),
1106
        '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
1107
        This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
1108
    );
1109
1110 6657531f Andreas Kohlbecker
  $form['cdm_webservice']['proxy'] = array(
1111
    '#type' => 'fieldset',
1112
    '#title' => t('Proxy'),
1113
    '#collapsible' => TRUE,
1114
    '#collapsed' => TRUE,
1115
  );
1116
1117
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1118
    '#type' => 'textfield',
1119
    '#title' => t('Proxy URL') . ':',
1120
    '#description' => t('If this proxy url is set the cdm api tries
1121
    to connect the web service over the given proxy server.
1122
    Otherwise proxy usage is deactivated.'),
1123
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1124
  );
1125
1126
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1127
    '#type' => 'textfield',
1128
    '#title' => t('Proxy port') . ':',
1129
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1130
  );
1131
1132
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1133
    '#type' => 'textfield',
1134
    '#title' => t('Login') . ':',
1135
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1136
  );
1137
1138
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1139
    '#type' => 'textfield',
1140
    '#title' => t('Password') . ':',
1141
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1142
  );
1143
1144
  // TODO: settings are still incomplete, compare with
1145
  // trunk/dataportal/inc/config_default.php.inc.
1146 9438ad3a Andreas Kohlbecker
  $form['taxon_tree'] = array(
1147 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1148
    '#title' => t('Taxon Tree'),
1149
    '#collapsible' => FALSE,
1150
    '#collapsed' => TRUE,
1151
    '#description' => t('<p>When you explore your collection, you can navigate
1152
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1153
      able to navigate through your collection the
1154
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1155
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1156
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1157
      </a></p>'),
1158
  );
1159
1160 9438ad3a Andreas Kohlbecker
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1161 6657531f Andreas Kohlbecker
    '#type' => 'select',
1162
    '#title' => t('Available classifications') . ':',
1163
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1164
    '#options' => cdm_get_taxontrees_as_options(),
1165
    '#description' => t('Select the default taxa classification for your
1166
      <em>taxon tree</em>, the other classifications will be also available but
1167
      with a manual user change.'),
1168
  );
1169
1170 aaa81689 Andreas Kohlbecker
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1171 6657531f Andreas Kohlbecker
    '#type' => 'select',
1172
    '#title' => t('Rank of highest displayed taxon') . ':',
1173
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1174 aaa81689 Andreas Kohlbecker
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1175 6657531f Andreas Kohlbecker
    '#options' => cdm_rankVocabulary_as_option(),
1176
    '#description' => t('This is the rank of the highest displayed taxon in the
1177
      <em>taxon tree</em>. You can select here which rank should be at the top
1178
      level of the tree structure.'),
1179
  );
1180
1181 26fb3778 Andreas Kohlbecker
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1182
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1183
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1184
      '#type' => 'checkboxes',
1185
      '#title' => t('Included Classifications') . ':',
1186
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1187
      '#options' => cdm_get_taxontrees_as_options(),
1188
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1189
  );
1190
1191 aa63dfb4 Andreas Kohlbecker
  $form['distribution'] = array(
1192
      '#type' => 'fieldset',
1193
      '#title' => t('Distributions'),
1194
      '#collapsible' => FALSE,
1195
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1196
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1197 562a6ac4 Andreas Kohlbecker
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1198
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1199
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1200 aa63dfb4 Andreas Kohlbecker
          '<p>
1201
          </p>',
1202
  );
1203
1204
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1205
      '#type' => 'fieldset',
1206
      '#title' => 'Distribution filter',
1207
      '#collapsible' => FALSE,
1208
      '#collapsed' => FALSE,
1209
      '#tree' => TRUE,
1210
      '#description' => 'The Distribution filter offers the following options
1211
      <ul>
1212 0eef1621 Andreas Kohlbecker
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1213
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1214
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1215
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1216
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1217
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1218
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1219
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1220
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1221
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1222 aa63dfb4 Andreas Kohlbecker
      </ul>'
1223
  );
1224
1225
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1226
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1227
      '#type' => 'checkboxes',
1228
      '#title' => 'Filter rules',
1229
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1230
      '#options' => array(
1231
          'statusOrderPreference' => 'Status order preference rule',
1232
          'subAreaPreference' => 'Sub area preference rule'
1233
      ),
1234
  );
1235
1236 7ca5ef1e Andreas Kohlbecker
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1237 6fbf1bd3 Andreas Kohlbecker
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1238 aa63dfb4 Andreas Kohlbecker
      '#type' => 'checkboxes',
1239
      '#title' => 'Hide marked area filter',
1240 6fbf1bd3 Andreas Kohlbecker
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1241 aa63dfb4 Andreas Kohlbecker
      '#options' => $marker_type_options,
1242
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1243
  );
1244
1245 f19f47fa Andreas Kohlbecker
  $form['aggregation'] = array(
1246
      '#type' => 'fieldset',
1247
      '#title' => t('Aggregation of data'),
1248
      '#collapsible' => FALSE,
1249 aa63dfb4 Andreas Kohlbecker
      '#description' => 'This section covers the different aspects of aggregating information.
1250 9438ad3a Andreas Kohlbecker
          <p>
1251 f19f47fa Andreas Kohlbecker
          </p>',
1252 9438ad3a Andreas Kohlbecker
  );
1253
1254 ccde8251 Andreas Kohlbecker
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1255
      '#type' => 'checkboxes',
1256
      '#title' => 'Taxon media filter',
1257
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1258
      '#options' => array(
1259
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1260
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1261
          'includeOccurrences' => 'Media related to specimens and occurrences',
1262
      ),
1263
      '#description' => 'This filter configures which images should be taken into account.',
1264
  );
1265
1266
  $form['aggregation']['notice'] = array(
1267 3a874294 Andreas Kohlbecker
      '#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
1268 ccde8251 Andreas Kohlbecker
          want to make use of the caching capabilities of the dataportal.',
1269
  );
1270
1271 f19f47fa Andreas Kohlbecker
  $form['aggregation']['media_aggregation'] = array(
1272
      '#type' => 'fieldset',
1273
      '#title' => t('Media aggregation'),
1274
      '#collapsible' => FALSE,
1275 9438ad3a Andreas Kohlbecker
      '#collapsed' => TRUE,
1276 f19f47fa Andreas Kohlbecker
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1277
1278 9438ad3a Andreas Kohlbecker
  );
1279 f19f47fa Andreas Kohlbecker
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1280
      '#type' => 'select',
1281
      '#title' => t('Aggregation of taxon pictures') . ':',
1282
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1283
      '#options' => array(
1284
          0 => "Show only pictures of the current taxon",
1285
          1 => "Include pictures of taxonomic children",
1286
      ),
1287
      '#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."),
1288 9438ad3a Andreas Kohlbecker
  );
1289
1290 f19f47fa Andreas Kohlbecker
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1291 30f78c59 Andreas Kohlbecker
      '#type' => 'fieldset',
1292 38dd933d Andreas Kohlbecker
      '#attributes' => array('class' => array('clearfix')),
1293 9438ad3a Andreas Kohlbecker
      '#title' => t('Aggregation via taxon relationsships'),
1294 30f78c59 Andreas Kohlbecker
      '#collapsible' => TRUE,
1295
      '#collapsed' => TRUE,
1296 f19f47fa Andreas Kohlbecker
      '#tree' => TRUE,
1297 30f78c59 Andreas Kohlbecker
      '#description' => t('Information on taxa will be aggregated along the below chosen
1298
          taxon relation ships. This will affect images and occurrences (specimens).
1299
          Taxon relation ships are directed and point form one taxon to another. The taxon
1300
          relationships to be taken into accunt can therefore configured for the direct direction
1301 f19f47fa Andreas Kohlbecker
          and for the inverse.'),
1302
  );
1303
1304 7ca5ef1e Andreas Kohlbecker
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1305 30f78c59 Andreas Kohlbecker
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1306 f19f47fa Andreas Kohlbecker
1307
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1308
      '#type' => 'checkboxes',
1309
      '#title' => t('Direct'),
1310
      '#options' => $taxonRelationshipTypeOptions,
1311
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1312 30f78c59 Andreas Kohlbecker
  );
1313 f19f47fa Andreas Kohlbecker
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1314
      '#type' => 'checkboxes',
1315
      '#title' => t('Invers'),
1316
      '#options' => $taxonRelationshipTypeOptions,
1317
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1318 30f78c59 Andreas Kohlbecker
  );
1319
1320 06c2b3e2 Andreas Kohlbecker
  $form['drupal_integration'] = array(
1321
    '#type' => 'fieldset',
1322 38dd933d Andreas Kohlbecker
    '#attributes' => array('class'=> array('clearfix')),
1323 06c2b3e2 Andreas Kohlbecker
    '#title' => t('Drupal integration'),
1324
    '#collapsible' => FALSE,
1325
    '#collapsed' => FALSE,
1326
    '#tree' => FALSE
1327
  );
1328
1329
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1330
    '#type' => 'checkbox',
1331
    '#title' => 'Create drupal nodes',
1332
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1333 944d793a Andreas Kohlbecker
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1334 06c2b3e2 Andreas Kohlbecker
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1335
    cdm pages it is required that drupal nodes are created and stored in the database.'
1336
  );
1337
1338
1339
1340
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1341
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1342
    <div class="description">Using this button, you will lose all content associated with the cdm drupal nodes which is stored in the drupal data base.</div>',
1343
  );
1344
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1345
    '#type' => 'submit',
1346
    '#value' => t('Drop all cdm nodes'),
1347
    '#submit' => array('drop_all_cdm_nodes_submit')
1348
  );
1349
1350
  $form['drupal_integration']['drop_all_cdm_nodes_warning_post'] = array(
1351
    '#markup' => '<div class="description">All Drupal nodes created for cdm content can be deleted at once using this button.</div>',
1352
  );
1353
1354
    // ----------------------
1355 5ea8b301 Andreas Kohlbecker
  $form['cdm_js_devel_mode'] = array(
1356
      '#type' => 'checkbox',
1357
      '#title' => 'Java-script developer mode',
1358
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1359
      '#description' => 'In production envirionments the java script libraries
1360
      the cdm_dataportal is making use of are compressed and optimized. This
1361
      is good for performance but a caveat if you need to debug java-script. When the
1362
      java-script developer mode is enabled the uncompressed and commented developer
1363
      versions of java-script libraries will be used where possible.
1364
      <br/><strong>Do not use this option in production!</strong>'
1365
  );
1366 2dd59bb5 Andreas Kohlbecker
  // ----------------------
1367
  $form['cdm_debug_mode'] = array(
1368
      '#type' => 'checkbox',
1369
      '#title' => 'CDM page debug mode',
1370
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1371
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1372 b5deb531 Andreas Kohlbecker
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1373
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1374
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1375 2dd59bb5 Andreas Kohlbecker
      The log is written by the drupal devel module function <code>dd()</code>.
1376 b5deb531 Andreas Kohlbecker
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1377 2dd59bb5 Andreas Kohlbecker
  );
1378 5ea8b301 Andreas Kohlbecker
1379 6657531f Andreas Kohlbecker
  // Comment @WA: D7 form api does not support reset buttons,
1380
  // so to mimic the D5 reset button we add one like this.
1381
  $form['actions']['reset'] = array(
1382
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1383
    '#weight' => 1000,
1384
  );
1385
1386 22eb20d7 Andreas Kohlbecker
  $form['#submit'][] = 'cdm_settings_general_submit';
1387
1388 6657531f Andreas Kohlbecker
  return system_settings_form($form);
1389
}
1390
1391 06c2b3e2 Andreas Kohlbecker
/**
1392
 * Submit callback; drops all cdm nodes.
1393
 *
1394
 * @ingroup forms
1395
 */
1396
function drop_all_cdm_nodes_submit($form, &$form_state) {
1397
  cdm_delete_all_cdm_nodes();
1398
  drupal_set_message(t('All cdm nodes dropped.'));
1399
}
1400
1401 6657531f Andreas Kohlbecker
1402
/**
1403
 * LAYOUT settings
1404 cf839840 Andreas Kohlbecker
 * @return
1405 6657531f Andreas Kohlbecker
 *   todo
1406
 */
1407
function cdm_settings_layout() {
1408
1409
  $form = array();
1410 0f5f1c12 Andreas Kohlbecker
1411
  $form['about'] = array(
1412
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1413 6657531f Andreas Kohlbecker
      layout. If you want to configure the specific sites layout visit the
1414 0f5f1c12 Andreas Kohlbecker
      respective configuration site for taxon, search or media.') . '</p>',
1415 6657531f Andreas Kohlbecker
  );
1416
1417
  // ---- footnotes --- //
1418 0f5f1c12 Andreas Kohlbecker
  $form['footnotes'] = array(
1419 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1420
    '#title' => t('Footnotes'),
1421
    '#collapsible' => FALSE,
1422
    '#collapsed' => FALSE,
1423
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1424
      media or distribution areas may have annotations or footnotes. When the
1425
      footnotes are enabled they will be visible (if they exist).'),
1426
  );
1427
1428 0f5f1c12 Andreas Kohlbecker
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1429 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1430
    '#title' => t('Do not show footnotes'),
1431
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1432
    '#description' => t('Check this if you do not want to show any footnotes'),
1433
  );
1434
1435 0f5f1c12 Andreas Kohlbecker
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1436 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1437 10055120 Andreas Kohlbecker
    '#title' => t('Do not show annotation footnotes'),
1438 6657531f Andreas Kohlbecker
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1439
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1440
  );
1441
1442 7ca5ef1e Andreas Kohlbecker
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1443 6657531f Andreas Kohlbecker
  // Additional option for the NULL case.
1444
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1445 0f5f1c12 Andreas Kohlbecker
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1446 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
1447
    '#title' => t('Annotation types as footnotes'),
1448
    '#description' => t("Only annotations of the selected type will be displayed
1449
       as footnotes. You may want to turn 'technical annotations' off."),
1450
    '#options' => $annotationTypeOptions,
1451
  );
1452
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1453
  if (!empty($annotationsTypesAsFootnotes)) {
1454 0f5f1c12 Andreas Kohlbecker
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1455 6657531f Andreas Kohlbecker
  }
1456
1457 5611d467 Andreas Kohlbecker
  // ---- original source --- //
1458
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1459
      '#type' => 'fieldset',
1460
      '#tree' => TRUE,
1461
      '#title' => t('Source Citations'),
1462
      '#collapsible' => FALSE,
1463
      '#collapsed' => FALSE,
1464
  );
1465 f19f47fa Andreas Kohlbecker
1466 800ff2b0 Andreas Kohlbecker
  $bibliography_settings = get_bibliography_settings(true);
1467 5611d467 Andreas Kohlbecker
1468 800ff2b0 Andreas Kohlbecker
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1469 5611d467 Andreas Kohlbecker
      '#type' => 'checkbox',
1470
      '#title' => t('Original Source in bibliography'),
1471
      '#default_value' => $bibliography_settings['enabled'],
1472
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1473
       annotations in each feature block.'),
1474
  );
1475
1476
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1477
    '#type' => 'select',
1478
    '#title' => t('The format of the key numerals'),
1479
    '#default_value' => $bibliography_settings['key_format'],
1480
    '#options' => array('latin' => 'Latin',
1481
      'ROMAN' => 'Roman (upper case)',
1482
      'roman' => 'Roman (lower case)',
1483
      'ALPHA'=> 'Alphabet (upper case)',
1484
      'alpha' => 'Alphabet (lower case)')
1485
  );
1486 f19f47fa Andreas Kohlbecker
1487
  // --- Advanced Search --- //
1488
  $form['asearch'] = array(
1489 1ce9afb7 Patric Plitzner
      '#type' => 'fieldset',
1490
      '#title' => t('Advanced search'),
1491
      '#collapsible' => FALSE,
1492
      '#collapsed' => FALSE,
1493 f19f47fa Andreas Kohlbecker
  );
1494
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1495 1ce9afb7 Patric Plitzner
      '#type' => 'checkbox',
1496
      '#title' => t('Show advanced search link'),
1497
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1498
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1499 f19f47fa Andreas Kohlbecker
  );
1500
1501
  // ---- Taxon Name Rendering --- //
1502
  $form['taxon_name'] = array(
1503
      '#type' => 'fieldset',
1504
      '#title' => t('Taxon name display'),
1505
      '#collapsible' => TRUE,
1506
      '#collapsed' => TRUE,
1507 7cc085da Andreas Kohlbecker
      '#description' => t('The display of taxon names is configured by two parts.
1508
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1509
          The name parts are defined in the <stong>part definitions</strong>'),
1510 0f5f1c12 Andreas Kohlbecker
  );
1511
1512 78292e72 Andreas Kohlbecker
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1513 b2b9e057 Andreas Kohlbecker
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1514
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1515
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1516 1a01f6dd Andreas Kohlbecker
1517 b2b9e057 Andreas Kohlbecker
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1518 2eaa13b4 Andreas Kohlbecker
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1519 b2b9e057 Andreas Kohlbecker
    $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.)';
1520
  } else if($is_custom_part_definition){
1521
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1522 2eaa13b4 Andreas Kohlbecker
  } else  {
1523 1a01f6dd Andreas Kohlbecker
    $which_version_message = '(These are the default part definition.)';
1524
  }
1525
1526 b2b9e057 Andreas Kohlbecker
  $diff_viewer_markup = '';
1527
  if($is_custom_part_definition){
1528
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1529
  }
1530
1531
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1532
    . $which_version_message
1533
    . '</div>'
1534
    . $diff_viewer_markup;
1535
1536 0f5f1c12 Andreas Kohlbecker
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1537
      '#type' => 'textarea',
1538
      '#title' => t('Part definitions'),
1539
      '#element_validate' => array('form_element_validate_json'),
1540 43998144 Andreas Kohlbecker
      '#default_value' =>  $current_part_definition_json,
1541 0f5f1c12 Andreas Kohlbecker
      '#description' => '
1542 1a01f6dd Andreas Kohlbecker
          <p>' . $which_version_message . '</p>
1543 0f5f1c12 Andreas Kohlbecker
          <p>
1544
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1545
          </p>
1546
          <p>
1547
           A full taxon name plus additional information can consist of the following elements:
1548
          <ul>
1549
             <li>name: the taxon name inclugin rank nbut without author</li>
1550
             <li>authors:  The authors of a reference, also used in taxon names</li>
1551
             <li>reference: the nomenclatural reference,</li>
1552
             <li>microreference:  Volume, page number etc.</li>
1553
             <li>status:  The nomenclatural status of a name</li>
1554
             <li>description: name descriptions like protologues etc ...</li>
1555
          </ul>
1556
          </p>
1557
          <p>
1558
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1559
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1560 51b04faf Andreas Kohlbecker
           The following parts can be formed and are recognized by the system:
1561 0f5f1c12 Andreas Kohlbecker
          <ul>
1562 51b04faf Andreas Kohlbecker
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1563
            <li>authorshipPart: the author (for example: "L.")</li>
1564
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1565 0f5f1c12 Andreas Kohlbecker
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1566
               be combined when a link to the taxon is rendered.</li>
1567 51b04faf Andreas Kohlbecker
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1568
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1569
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1570 0f5f1c12 Andreas Kohlbecker
            <li>statusPart: the nomenclatorical status</li>
1571
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1572
          </ul>
1573
          </p>
1574
          <p>
1575
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1576
           specific parts part definitions:
1577
          <ul>
1578
            <li>BotanicalName</li>
1579
            <li>ZoologicalName</li>
1580
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1581
          </ul>
1582
           An example:
1583
          <pre>
1584
           {
1585
            "ZoologicalName": {
1586
              "namePart": {
1587
                "name": true
1588
              },
1589
              "referencePart": {
1590 b5519d3a Andreas Kohlbecker
                "authors": true
1591 0f5f1c12 Andreas Kohlbecker
              },
1592
              "microreferencePart": {
1593
                "microreference": true
1594
              },
1595
              "statusPart": {
1596
                "status": true
1597
              },
1598
              "descriptionPart": {
1599
                "description": true
1600
              }
1601
            },
1602
            "BotanicalName": {
1603
              "namePart": {
1604
                "name": true,
1605
                "authors": true
1606
              },
1607
              "referencePart": {
1608
                "reference": true,
1609
                "microreference": true
1610
              },
1611 43998144 Andreas Kohlbecker
              "secReferencePart": {
1612
                "secReference": true
1613
              },
1614 0f5f1c12 Andreas Kohlbecker
              "statusPart": {
1615
                "status": true
1616
              },
1617
              "descriptionPart": {
1618
                "description": true
1619
              }
1620
            }
1621
          }
1622
           </pre>',
1623
  );
1624
1625 78292e72 Andreas Kohlbecker
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1626 b2b9e057 Andreas Kohlbecker
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1627
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1628
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1629
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1630 1a01f6dd Andreas Kohlbecker
1631 2eaa13b4 Andreas Kohlbecker
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1632 b2b9e057 Andreas Kohlbecker
    $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.)';
1633
  } else if($is_custom_render_template){
1634
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1635 1a01f6dd Andreas Kohlbecker
  } else {
1636
    $which_version_message = '(These are the default render templates.)';
1637
  }
1638
1639 b2b9e057 Andreas Kohlbecker
  $diff_viewer_markup = '';
1640
  if($is_custom_render_template){
1641
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1642
  }
1643
1644
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1645
    . $which_version_message
1646
    . '</div>'
1647
    . $diff_viewer_markup;
1648
1649 f19f47fa Andreas Kohlbecker
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1650
      '#type' => 'textarea',
1651 0f5f1c12 Andreas Kohlbecker
      '#title' => t('Name render templates'),
1652 f19f47fa Andreas Kohlbecker
      '#element_validate' => array('form_element_validate_json'),
1653 1a01f6dd Andreas Kohlbecker
      '#default_value' =>  $current_render_templates_json,
1654 0f5f1c12 Andreas Kohlbecker
      '#description' => '
1655 1a01f6dd Andreas Kohlbecker
          <p>' . $which_version_message . '</p>
1656 0f5f1c12 Andreas Kohlbecker
          <p>
1657
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1658 f695daf4 Andreas Kohlbecker
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1659
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1660
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1661
          The following render Path keys are currently recognized:
1662 0f5f1c12 Andreas Kohlbecker
          <ul>
1663 51b04faf Andreas Kohlbecker
            <li>list_of_taxa</li>
1664
            <li>acceptedFor</li>
1665
            <li>homonym</li>
1666 0f5f1c12 Andreas Kohlbecker
            <li>taxon_page_synonymy</li>
1667
            <li>typedesignations</li>
1668
            <li>taxon_page_title</li>
1669
            <li>polytomousKey</li>
1670
            <li>na: name + authorship</li>
1671
            <li>nar:name + authorship + reference</li>
1672
            <li>#DEFAULT</li>
1673
          </ul>
1674
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1675
          array element should be a comma separated list of render paths, without any whitespace!.
1676
          </p>
1677
          <p>
1678
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1679
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1680
          <p>
1681
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1682 43998144 Andreas Kohlbecker
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1683
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1684 0f5f1c12 Andreas Kohlbecker
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1685
          links if the paramters $nameLink or $refenceLink are given to the name render function
1686 f19f47fa Andreas Kohlbecker
          (this is hard coded and cannot be configured here).',
1687 6657531f Andreas Kohlbecker
  );
1688
1689
  // @WA: D7 form api does not support reset buttons,
1690
  // so to mimic the D5 reset button we add one like this.
1691
  $form['actions']['reset'] = array(
1692
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1693
    '#weight' => 1000,
1694
  );
1695 f19f47fa Andreas Kohlbecker
1696 0f5f1c12 Andreas Kohlbecker
  $form['#submit'] = array('submit_json_as_php_array');
1697
  // #json_elements especially defined for submit_json_as_php_array()
1698
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1699 6657531f Andreas Kohlbecker
  return system_settings_form($form);
1700
}
1701
1702
1703 b2b9e057 Andreas Kohlbecker
1704
  /**
1705 6657531f Andreas Kohlbecker
 * @todo Please document this function.
1706
 * @see http://drupal.org/node/1354
1707
 */
1708
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1709
  $form[$form_name] = array(
1710
    '#type' => 'fieldset',
1711 7cc085da Andreas Kohlbecker
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1712 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
1713
    '#collapsed' => $collapsed,
1714
    '#tree' => TRUE,
1715 7cc085da Andreas Kohlbecker
    '#description' => t('@$form-description', array('@$form-description' => $form_description)),
1716 6657531f Andreas Kohlbecker
  );
1717
1718
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1719
  $gallery_settings = variable_get($form_name, $default_values);
1720
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1721
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1722
    /*
1723
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1724
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1725
    '#type' => 'textfield',
1726
    '#title' => t('Search Page Size'),
1727
    '#default_value' => $test,
1728
    '#description' => t('Number of Names to display per page in search results.')
1729
    );
1730
    */
1731
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1732
      '#type' => 'checkbox',
1733
      '#title' => t('Show media thumbnails for accepted taxa'),
1734
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1735
    );
1736
1737
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1738
      '#type' => 'checkbox',
1739
      '#title' => t('Show media thumbnails for synonyms'),
1740
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1741
      '#description' => '',
1742
    );
1743
  }
1744
1745
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1746
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1747
    '#type' => 'checkbox',
1748
    '#title' => t('Show captions under thumbnails'),
1749
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1750
    '#description' => '',
1751
  );
1752
1753
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1754
    '#type' => 'textfield',
1755
    '#title' => t('Thumbnail size') . ':',
1756
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1757
    '#description' => t('Select the size of each individual thumbnail.'),
1758
  );
1759
1760
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1761
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1762
      '#type' => 'textfield',
1763
      '#title' => t('Number of columns') . ':',
1764
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1765
      '#description' => t('Group the thumbnails in columns: select how many
1766
        columns the gallery should display.'),
1767
    );
1768
  }
1769
1770
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1771
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1772
      '#type' => 'textfield',
1773
      '#title' => t('Maximum number of rows') . ':',
1774
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1775
      '#description' => t('You can group the thumbnails in rows, select in how
1776
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1777
        If you want an unlimited number of rows please set to 0.'),
1778
    );
1779
  }
1780
1781
  return $form;
1782
}
1783
1784
/**
1785
 * @todo document this function.
1786
 */
1787
function cdm_settings_layout_taxon() {
1788
  $collapsed = FALSE;
1789
  $form = array();
1790
1791 7df1be04 Andreas Kohlbecker
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1792
1793 6657531f Andreas Kohlbecker
  // --------- TABBED TAXON ------- //
1794
  $form['taxon_tabs'] = array(
1795
    '#type' => 'fieldset',
1796
    '#title' => t('Taxon tabs'),
1797
    '#collapsible' => TRUE,
1798 6421984d Andreas Kohlbecker
    '#collapsed' => TRUE,
1799 6657531f Andreas Kohlbecker
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1800
      be splitted in four diferent tabs; General, Synonymy, Images and
1801
      Specimens. If the taxon has no information for any of the tabs/sections
1802
      such tab will be not displayed.'),
1803
  );
1804
1805
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1806
    '#type' => 'checkbox',
1807
    '#title' => t('Tabbed taxon page'),
1808
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1809
    '#description' => t('<p>If selected split the taxon page into individual
1810
      tabs for description, images, synonymy and specimens. If not the taxon
1811
      data is rendered as a long single page without tabs.</p>'),
1812
  );
1813
1814
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1815
    '#type' => 'checkboxes',
1816
    '#title' => t('Tabs visibility options') . ':',
1817
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1818
    '#options' => get_taxon_options_list(),
1819
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1820
  );
1821
1822 b54cbda1 Andreas Kohlbecker
  // WEIGHT
1823
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1824
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1825
      '#tree' => true
1826
  );
1827
  // Weights range from -delta to +delta, so delta should be at least half
1828
  // of the amount of tabs present.
1829
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1830
  foreach (get_taxon_tabs_list() as $label) {
1831
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1832
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1833
        '#title' => $label,
1834
        '#type'  => 'weight',
1835
        '#default_value' => $taxontabs_weights[$key],
1836
        '#delta' => $tab_weight_delta
1837
    );
1838
  }
1839
1840 6657531f Andreas Kohlbecker
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1841
    '#type' => 'select',
1842
    '#title' => t('Default tab to display') . ':',
1843
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1844
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1845
    '#description' => t('<p>Select the default tab to display when visiting a
1846
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1847
      <strong>Note:</strong> After performing a search and clicking in any
1848
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1849
      taxon and not the above selected tab.'),
1850
  );
1851
1852
  /* ======  TAXON_PROFILE ====== */
1853
  $form['taxon_profile'] = array(
1854
    '#type' => 'fieldset',
1855
    '#title' => t('Taxon profile (tab)'),
1856 9438ad3a Andreas Kohlbecker
    '#description' => t('<p>This section covers the settings related to the taxon
1857 6657531f Andreas Kohlbecker
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1858
    '#collapsible' => TRUE,
1859 6421984d Andreas Kohlbecker
    '#collapsed' => TRUE,
1860 6657531f Andreas Kohlbecker
  );
1861
1862
  // ---- PROFILE PICTURE ----//
1863 9c92cd84 Andreas Kohlbecker
1864
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1865 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1866 9c92cd84 Andreas Kohlbecker
    '#tree' => TRUE,
1867 9438ad3a Andreas Kohlbecker
    '#title' => t('Taxon profile picture'),
1868 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
1869
    '#collapsed' => FALSE,
1870 9438ad3a Andreas Kohlbecker
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1871 6657531f Andreas Kohlbecker
  );
1872
1873 9c92cd84 Andreas Kohlbecker
  //FIXME migrate variables:
1874
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1875
  // FIXME
1876 9aff46e4 Andreas Kohlbecker
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1877 9c92cd84 Andreas Kohlbecker
1878
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1879 9506fd1f Andreas Kohlbecker
1880 9c92cd84 Andreas Kohlbecker
  /*
1881
   * 'show' => 1,
1882
   * 'maxextend' => 184,
1883 053a92ec Andreas Kohlbecker
   * 'media_uri_query' => ''
1884 9c92cd84 Andreas Kohlbecker
   * 'custom_placeholder_image_on' => 1,
1885
   * 'custom_placeholder_image_fid' => ''
1886
   */
1887
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1888 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1889 6421984d Andreas Kohlbecker
    '#title' => t('Enable profile picture'),
1890
    '#description' => t('Show the profile picture.'),
1891 9c92cd84 Andreas Kohlbecker
    '#default_value' => $taxon_profile_image_settings['show'],
1892 6657531f Andreas Kohlbecker
  );
1893
1894 9c92cd84 Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1895 d9c55e6c Andreas Kohlbecker
      '#type' => 'textfield',
1896
      '#tree' => TRUE,
1897 6421984d Andreas Kohlbecker
      '#title' => t('Profile picture maximum extend'),
1898 9c92cd84 Andreas Kohlbecker
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1899 d9c55e6c Andreas Kohlbecker
      '#field_suffix' => 'px',
1900
      '#maxlength' => 4,
1901
      '#size' => 4,
1902 7cc085da Andreas Kohlbecker
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
1903 d9c55e6c Andreas Kohlbecker
  );
1904
1905 053a92ec Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1906
      '#type' => 'textfield',
1907
      '#tree' => TRUE,
1908
      '#title' => t('Additional URI query parameter'),
1909
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1910
      '#maxlength' => 1024,
1911
      '#size' => 60,
1912 7cc085da Andreas Kohlbecker
      '#description' => t('Additional query parameters to be used when requesting for the  
1913
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
1914
            The query parameters will be appended to the uri of the media representation part
1915
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1916 053a92ec Andreas Kohlbecker
  );
1917
1918 ca47ea76 Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1919
    '#type' => 'checkbox',
1920
    '#title' => t('Show the placeholder image'),
1921
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
1922
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1923
  );
1924
1925 9c92cd84 Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1926
      '#type' => 'checkbox',
1927
      '#title' => t('Use a custom placeholder image'),
1928 7df1be04 Andreas Kohlbecker
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1929 9c92cd84 Andreas Kohlbecker
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1930 7df1be04 Andreas Kohlbecker
  );
1931
1932 9c92cd84 Andreas Kohlbecker
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1933
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1934
        '#type' => 'managed_file',
1935
        '#title' => t('Custom placeholder image file'),
1936
        '#progress_indicator' => 'bar',
1937
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1938
    //       '#name' => 'custom_placeholder_image',
1939
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1940
    );
1941
1942
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1943
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1944
      $url = file_create_url($profile_image_file->uri);
1945
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1946
                '#type' => 'item',
1947
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1948
      );
1949
    }
1950
  } else {
1951
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1952 642b323b Andreas Kohlbecker
      '#type' => 'hidden',
1953
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1954 9c92cd84 Andreas Kohlbecker
    );
1955
  }
1956
1957 6657531f Andreas Kohlbecker
  $options = cdm_rankVocabulary_as_option();
1958
  array_unshift($options, '-- DISABLED --');
1959
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1960
    '#type' => 'select',
1961 9438ad3a Andreas Kohlbecker
    '#title' => t('Hide profile picture for higher ranks') . ':',
1962 6657531f Andreas Kohlbecker
    '#default_value' => variable_get('image_hide_rank', '0'),
1963
    '#options' => $options,
1964 9438ad3a Andreas Kohlbecker
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1965 6657531f Andreas Kohlbecker
  );
1966
1967
  // -- MEDIA THUMBNAILS -- //
1968
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1969
  $form_title = 'Taxon Profile Images';
1970
  $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>';
1971
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1972
1973 642b323b Andreas Kohlbecker
  // ---- FEATURE TREE BLOCKS ---- //
1974
  $form['taxon_profile']['feature_blocks'] = array(
1975 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1976 642b323b Andreas Kohlbecker
    '#title' => t('Feature Blocks'),
1977 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
1978
    '#collapsed' => FALSE,
1979
    '#description' => t("This section covers settings related to the taxon's
1980
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1981 642b323b Andreas Kohlbecker
      features such as description, distribution, common names"),
1982 6657531f Andreas Kohlbecker
  );
1983
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1984 642b323b Andreas Kohlbecker
  $profile_feature_tree = get_profile_feature_tree();
1985
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
1986
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
1987
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
1988 854e1d99 Andreas Kohlbecker
  }
1989 642b323b Andreas Kohlbecker
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
1990 6657531f Andreas Kohlbecker
    '#type' => 'radios',
1991 642b323b Andreas Kohlbecker
    '#title' => t('Taxon profile feature tree') . ':',
1992
    '#default_value' => $profile_feature_tree_uuid,
1993 6657531f Andreas Kohlbecker
    '#options' =>  $featureTrees['options'],
1994 3f485c6d Andreas Kohlbecker
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1995
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1996 642b323b Andreas Kohlbecker
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
1997
      profile page.'
1998 6657531f Andreas Kohlbecker
    ),
1999
  );
2000
2001 642b323b Andreas Kohlbecker
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2002
  $profile_feature_tree = get_profile_feature_tree();
2003
2004
  if (isset($profile_feature_tree->root->childNodes)) {
2005 6657531f Andreas Kohlbecker
2006 642b323b Andreas Kohlbecker
    $form_feature_block_layout = array(
2007
      '#type' => 'fieldset',
2008
      '#tree' => true,
2009
      '#title' => t('Taxon profile feature block settings'),
2010 6657531f Andreas Kohlbecker
      '#collapsible' => TRUE,
2011
      '#collapsed' => FALSE,
2012 642b323b Andreas Kohlbecker
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2013
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
2014
      The subforms have the following settings in common:<br />
2015
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2016
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2017
      <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>
2018
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2019
            <ol>
2020
            <li>If element is of the CDM type TextData and the text is not empty the source references will be
2021
                appended in brackets like "text (source references)". If the original source has name in source
2022
                information it will be appended to the citation string,
2023
                like : "(citation, as name in source; citation, as name in source)"</li>
2024
             <li>if the text of the TextData is empty, the original source citations are the only content
2025
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2026
                prepended to the citation string like: "name in source: citation"</li>
2027
            </ol>
2028
            <strong>If disabled:</strong><br />
2029
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2030
             citations are the only content, the resulting feature block content would only consist of footnotes.
2031
             In this case the display of the respective feature block is suppressed.</div>
2032
      </dl>
2033
      <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
2034 0686f307 Andreas Kohlbecker
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2035
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2036
        . '</em></div>
2037 642b323b Andreas Kohlbecker
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2038
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2039
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2040
      <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>
2041
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2042
           cdm_feature_block_element_tag_name()</div>',
2043 6657531f Andreas Kohlbecker
    );
2044
2045 642b323b Andreas Kohlbecker
2046
    $feature_list_layout_settings_disabled = FALSE;
2047 8c962983 Andreas Kohlbecker
2048
    // creating helper object to retrieve the default settings
2049
    $featureNode = new stdClass();
2050
    $featureNode->feature = new stdClass();
2051
    $featureNode->feature->uuid="DEFAULT";
2052
    $featureNode->feature->representation_L10n = "Default";
2053
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2054
2055 642b323b Andreas Kohlbecker
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2056 6657531f Andreas Kohlbecker
2057
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2058
2059 642b323b Andreas Kohlbecker
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2060
        $subform_id = $featureNode->feature->uuid;
2061
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2062 6657531f Andreas Kohlbecker
2063 642b323b Andreas Kohlbecker
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2064
2065
        $form_feature_block_layout[$subform_id] = array(
2066
          '#type' => 'fieldset',
2067 6657531f Andreas Kohlbecker
          '#tree' => TRUE,
2068 642b323b Andreas Kohlbecker
          '#title' => $featureNode->feature->representation_L10n,
2069 6657531f Andreas Kohlbecker
          '#collapsible' => FALSE,
2070
          '#collapsed' => FALSE,
2071
        );
2072 8c962983 Andreas Kohlbecker
        if($featureNode->feature->uuid == "DEFAULT"){
2073
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2074
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2075
          references</em> and <em>names in source</em> is only possible in the defaults';
2076
        }
2077 6657531f Andreas Kohlbecker
2078 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2079
          '#type' => 'select',
2080
          '#title' => 'List type',
2081
          '#default_value' => $feature_block_setting['as_list'],
2082
          '#options' => array(
2083
            'div' => 'not as list',
2084
            'ul' => 'bullet list',
2085
            'ol' => 'numbered list',
2086
            'dl' => 'definition list'
2087
          ),
2088
        );
2089
2090 8c962983 Andreas Kohlbecker
        if($featureNode->feature->uuid == "DEFAULT"){
2091
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2092
            '#type' => 'checkbox',
2093
            '#title' => t('Link to reference'),
2094
            '#default_value' => $feature_block_setting['link_to_reference'],
2095
          );
2096 642b323b Andreas Kohlbecker
2097 8c962983 Andreas Kohlbecker
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2098
            '#type' => 'checkbox',
2099
            '#title' => 'Link to name used in source',
2100
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2101
          );
2102
        }
2103 6657531f Andreas Kohlbecker
2104 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2105
          '#type' => 'checkbox',
2106
          '#title' => 'Sources as content',
2107
          '#default_value' => $feature_block_setting['sources_as_content'],
2108 6657531f Andreas Kohlbecker
        );
2109
2110 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2111
          '#type' => 'checkbox',
2112 8c962983 Andreas Kohlbecker
          '#title' => 'Put sources also as content to bibliography',
2113 642b323b Andreas Kohlbecker
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2114 6657531f Andreas Kohlbecker
        );
2115
2116 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2117
          '#type' => 'select',
2118
          '#title' => t('Sort elements'),
2119
          '#default_value' => $feature_block_setting['sort_elements'],
2120
          '#options' => array(
2121
            NO_SORT => 'No sorting',
2122
            SORT_ASC => 'Ascending',
2123
            SORT_DESC => 'Descending',
2124 3eccfdb9 Andreas Kohlbecker
            SORT_HIERARCHICAL => 'Hierarchical'
2125 642b323b Andreas Kohlbecker
          ),
2126 3eccfdb9 Andreas Kohlbecker
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2127
          <dl>
2128
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2129
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2130
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2131
          <dr><dt>Hierarchical</dt><dd>Use the order of items and their hierarchy. This is not possible for all feature and item types.</dd></dr>
2132
          </dl>',
2133 6657531f Andreas Kohlbecker
        );
2134
2135 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2136
          '#type' => 'select',
2137
          '#title' => t('Element tag'),
2138
          '#options' => array(
2139
            'span' => 'span',
2140
            'div' => 'div'
2141
          ),
2142
          '#default_value' => $feature_block_setting['element_tag'],
2143
        );
2144 6657531f Andreas Kohlbecker
      }
2145 642b323b Andreas Kohlbecker
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2146 6657531f Andreas Kohlbecker
    }
2147
  }
2148
2149 642b323b Andreas Kohlbecker
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2150
  $form['taxon_profile']['structured_description_featuretree'] = array(
2151
    '#type' => 'fieldset',
2152
    '#title' => t('Structured Description Feature Tree'),
2153
    '#collapsible' => TRUE,
2154
    '#collapsed' => FALSE,
2155
  );
2156
  $featureTrees = cdm_get_featureTrees_as_options();
2157
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2158
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2159
    $profile_feature_tree_uuid = NULL;
2160
  }
2161
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2162
    '#type' => 'radios',
2163
    '#title' => t('Natural language representation of structured descriptions') . ':',
2164
    '#default_value' => $profile_feature_tree_uuid,
2165
    '#options' => $featureTrees['options'],
2166
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2167
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2168
    '#description' => t('Taxon descriptions can be stored in a highly structured
2169
      form. The feature tree selected here will be used to generate textual
2170
      representation in natural language.'
2171
    ),
2172
  );
2173
2174
2175
2176 6657531f Andreas Kohlbecker
  // ---- DISTRIBUTION LAYOUT ---- //
2177
  $form['taxon_profile']['distribution_layout'] = array(
2178
    '#title' => t('Distribution'),
2179
    '#collapsible' => TRUE,
2180
    '#collapsed' => FALSE,
2181
    '#type' => 'fieldset',
2182 378bc1ce Andreas Kohlbecker
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2183
        Map settings regarding the geometry, layers, etc are found in the '
2184 562a6ac4 Andreas Kohlbecker
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2185
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2186
      . l(
2187
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2188
        array('fragment' => 'edit-feature-block-settings')
2189
      )
2190
      . ' More general settings regrading the filtering of Distributions are found at '
2191
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2192
      . '. (These settings here will be merged in future releases into the feature block settings)',
2193
2194 6657531f Andreas Kohlbecker
  );
2195
2196 378bc1ce Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2197
2198 bda17f32 Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2199
    '#type' => 'checkbox',
2200
    '#title' => t('Condensed distribution'),
2201
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2202
    '#description' => 'This option enables the display of a very compact representation
2203
    of the distribution which includes also information on the status.',
2204
  );
2205
2206 846c0606 Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2207
    '#type' => 'select',
2208
    '#title' => t('Condensed distribution recipe'),
2209
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2210
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2211
    '#description' => 'Recipe for creating the condensed distribution.',
2212
  );
2213
2214 6858b474 Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2215
    '#type' => 'textfield',
2216
    '#title' => t('Condensed distribution info path'),
2217
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2218
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2219
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2220
  );
2221
2222 bda17f32 Andreas Kohlbecker
2223 f5bc56a0 Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2224 6657531f Andreas Kohlbecker
    '#type' => 'radios',
2225 c359043a Andreas Kohlbecker
    '#title' => t('Display mode') . ':',
2226 97ac3d38 Andreas Kohlbecker
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2227 6657531f Andreas Kohlbecker
    '#options' => array(
2228 f5bc56a0 Andreas Kohlbecker
      'FLAT_ALPHA' => t('Flat list'),
2229
      'TREE' => t('Hierarchically ordered'),
2230 6657531f Andreas Kohlbecker
    ),
2231 0eef1621 Andreas Kohlbecker
    '#description' => 'Taxon distribution information is displayed with
2232 f5bc56a0 Andreas Kohlbecker
    focus on the area of the distribution. The list of areas can either be shown
2233 0eef1621 Andreas Kohlbecker
    as flat list ordered alphabetically or in the hierarchical of the parent
2234
    area and subarea relationship. Fall back areas areas with no Distribution data
2235
    are hidden from the area hierarchy so that their sub areas will move one level up.
2236
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2237 40420110 Andreas Kohlbecker
    ' for details on the <em>Marked area filter</em>.',
2238 6657531f Andreas Kohlbecker
  );
2239
2240 38dd933d Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2241
    '#type' => 'fieldset',
2242
    '#tree' => true,
2243
    '#title' => t('Distribution hierarchy style')
2244
  );
2245
2246
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2247
  foreach(array_keys($hierarchy_styles) as $level) {
2248
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2249
      '#type' => 'fieldset',
2250
      '#tree' => true,
2251 7cc085da Andreas Kohlbecker
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2252 38dd933d Andreas Kohlbecker
      '#attributes' => array('class' => array('fieldset-float'))
2253
    );
2254
    foreach ($hierarchy_styles[$level] as $key => $value) {
2255
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2256
        '#type' => 'textfield',
2257 7cc085da Andreas Kohlbecker
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2258 38dd933d Andreas Kohlbecker
        '#default_value' => $hierarchy_styles[$level][$key],
2259
        '#maxlength' => 4,
2260
        '#size' => 4
2261
      );
2262
    }
2263
  }
2264
2265 b3b63fc8 Andreas Kohlbecker
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2266 f5bc56a0 Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2267
    '#type' => 'checkboxes',
2268
    '#title' => 'Omit area levels',
2269
    '#options' => $level_options,
2270
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2271 284fb36d Andreas Kohlbecker
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2272
    Areas which belong to the selected area levels will be hidden in the portal.',
2273 f5bc56a0 Andreas Kohlbecker
  );
2274
2275 6657531f Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2276
    '#type' => 'checkbox',
2277
    '#title' => t('Show TextData elements on top of the map'),
2278
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2279
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2280
      elements on top of the map. Otherwise all <code>TextData</code>
2281
      distribution elements will be listed below the other area elements.
2282
      This option is useful if you need to have descriptive texts for each
2283
      distribution map.'),
2284
  );
2285
2286 c6ee8193 Andreas Kohlbecker
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2287
      '#type' => 'textarea',
2288
      '#title' => t('Custom status colors'),
2289
      '#element_validate' => array('form_element_validate_json'),
2290
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2291
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2292
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2293 eb961cb9 Andreas Kohlbecker
          reference list of the idInVocabulary values of absence and presence terms:
2294 c6ee8193 Andreas Kohlbecker
<pre>
2295 eb961cb9 Andreas Kohlbecker
Presence Term
2296
p	present
2297
pd	present: doubtfully present
2298
n	native
2299
nq	native: presence questionable
2300
nd	native: doubtfully native
2301
c	cultivated
2302
i	introduced
2303
iq	introduced: presence questionable
2304
id	introduced: doubtfully introduced (perhaps cultivated only)
2305
ip	introduced: uncertain degree of naturalisation
2306
ia	introduced: adventitious (casual)
2307
in	introduced: naturalized
2308
ic	introduced: cultivated
2309
e	endemic for the relevant area
2310
na	naturalised
2311
iv	invasive
2312
2313
AbsenceTerm
2314
a	absent
2315
f	reported in error
2316
nf	native: reported in error
2317
if	introduced: reported in error
2318
cf	cultivated: reported in error
2319
ne	native: formerly native
2320
ie	introduced: formerly introduced
2321
2322 c6ee8193 Andreas Kohlbecker
</pre>'),
2323
  );
2324
2325 6657531f Andreas Kohlbecker
2326
  /* ====== SYNONYMY ====== */
2327
  $form['taxon_synonymy'] = array(
2328
    '#type' => 'fieldset',
2329
    '#title' => t('Taxon synonymy (tab)'),
2330
    '#collapsible' => TRUE,
2331
    '#collapsed' => TRUE,
2332
    '#description' => t('This section covers the settings related to the taxon
2333 501347df Andreas Kohlbecker
      <strong>synonymy</strong> tab.'),
2334 6657531f Andreas Kohlbecker
  );
2335
2336
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2337
    '#type' => 'checkbox',
2338
    '#title' => t('Show accepted taxon on top of the synonymy'),
2339
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2340
    '#description' => t('If checked, the first homotypic taxon is a repetition
2341
      of the accepted taxon most likely with the full nomenclatural reference
2342
      (depending on the currently chosen theme).'),
2343
  );
2344
2345
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2346
    '#type' => 'checkbox',
2347
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2348
      coming from a synonym link.'),
2349
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2350
    '#description' => t('Check this if after doing a search and clicking on a
2351
      synonym you want to see the "accept of" text for the accepted synonym.'),
2352
  );
2353
2354 24058570 Andreas Kohlbecker
  /* === currently unused ===
2355 7ca5ef1e Andreas Kohlbecker
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2356 5014bf09 Andreas Kohlbecker
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2357 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
2358
    '#title' => t('Display name relationships') . ':',
2359
    '#default_value' => variable_get('name_relationships_to_show', 0),
2360
    '#options' => $nameRelationshipTypeOptions,
2361
    '#description' => t('Select the name relationships you want to show for the
2362
      accepted taxa.'),
2363
  );
2364 24058570 Andreas Kohlbecker
 */
2365 6657531f Andreas Kohlbecker
2366 6421984d Andreas Kohlbecker
  $form['taxon_synonymy']['taxon_relations'] = array(
2367
    '#type' => 'fieldset',
2368
    '#title' => t('Taxon relationships'),
2369
    '#collapsible' => FALSE,
2370
    '#collapsed' => FALSE
2371
  );
2372
2373
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2374 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
2375
    '#title' => t('Show taxon relations ships of accepted taxon'),
2376
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2377
    '#description' => t('If this option is enabled the synonymy will show the
2378
      below selected taxon relationships of accepted taxa.'),
2379
  );
2380
2381 7ca5ef1e Andreas Kohlbecker
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2382 6421984d Andreas Kohlbecker
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2383 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
2384
    '#title' => t('Taxon relationship types') . ':',
2385
    '#description' => t('Only taxon relationships of the selected type will be
2386
      displayed'),
2387
    '#options' => $taxonRelationshipTypeOptions,
2388
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2389
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2390
  );
2391
2392 6421984d Andreas Kohlbecker
  $form['taxon_synonymy']['name_relations'] = array(
2393
    '#type' => 'fieldset',
2394
    '#title' => t('Name relationships'),
2395
    '#collapsible' => FALSE,
2396
    '#collapsed' => FALSE
2397
  );
2398
2399 7ca5ef1e Andreas Kohlbecker
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2400 6421984d Andreas Kohlbecker
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2401
    '#type' => 'checkboxes',
2402
    '#title' => t('Name relationship types') . ':',
2403
    '#description' => t('Only name relationships of the selected type will be
2404
      displayed'),
2405
    '#options' => $taxonRelationshipTypeOptions,
2406
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2407
  );
2408
2409 6657531f Andreas Kohlbecker
  // ====== SPECIMENS ====== //
2410
  $form['taxon_specimens'] = array(
2411
    '#type' => 'fieldset',
2412
    '#title' => t('Taxon specimens (tab)'),
2413
    '#collapsible' => TRUE,
2414
    '#collapsed' => TRUE,
2415
    '#description' => t('This section covers the settings related to the taxon
2416
      <strong>specimens</strong> tab.'),
2417
  );
2418
2419 378bc1ce Andreas Kohlbecker
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2420
2421
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2422
    '#type' => 'checkbox',
2423
    '#title' => t('Show specimen derivatives in a compressed table'),
2424
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2425
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2426
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2427
  );
2428
2429
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2430
    '#type' => 'checkbox',
2431
    '#title' => t('Show "Associated with" in specimen table.'),
2432
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2433
  );
2434 1ce9afb7 Patric Plitzner
2435 854e1d99 Andreas Kohlbecker
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2436 642b323b Andreas Kohlbecker
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2437
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2438
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2439 f19f47fa Andreas Kohlbecker
  }
2440
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2441 378bc1ce Andreas Kohlbecker
    '#type' => 'radios',
2442
    '#title' => t('Specimen description feature tree') . ':',
2443
    '#default_value' => $profile_feature_tree_uuid,
2444
    '#options' =>  $featureTrees['options'],
2445
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2446
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2447
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2448
    ),
2449 bfb2b81a Andreas Kohlbecker
  );
2450
2451 6657531f Andreas Kohlbecker
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2452
  $form_title = t('Specimen media');
2453
  $form_description = t('Specimens may have media which is displayed at the
2454
     Specimen tab/section as a gallery. It is possible to configure the
2455
     thumbnails gallery here, however for configuring how a single media should
2456
     be displayed please go to !url.</p>',
2457
     array(
2458
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2459
     ));
2460
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2461
2462
  // --- MEDIA GALLERY ---- //
2463
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2464
  $form_title = 'Media gallery (tab)';
2465 43034365 Patrick Plitzner
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2466
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2467 6657531f Andreas Kohlbecker
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2468
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2469
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2470
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2471
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2472
2473
  // Comment @WA: D7 form api does not support reset buttons,
2474
  // so to mimic the D5 reset button we add one like this.
2475
  $form['actions']['reset'] = array(
2476
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2477
    '#weight' => 1000,
2478
  );
2479
  return system_settings_form($form);
2480
}
2481
2482 378bc1ce Andreas Kohlbecker
/**
2483
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2484
 *
2485
 * @param $map_id
2486
 * @param $form
2487
 * @return mixed
2488
 */
2489
function _cdm_map_visibility_setting($map_id)
2490
{
2491
  return array(
2492
    '#type' => 'select',
2493
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2494
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2495
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2496
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2497
        The map also can forced to show up <b>always</b> or <b>never</b>."
2498
  );
2499
}
2500
2501 6657531f Andreas Kohlbecker
/**
2502
 * @todo document this function.
2503
 */
2504
function cdm_settings_layout_search() {
2505
2506
  $form = array();
2507
2508 c5ed6357 Andreas Kohlbecker
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2509
2510 6657531f Andreas Kohlbecker
  $form['search_settings'] = array(
2511
    '#type' => 'fieldset',
2512
    '#title' => t('Taxa Search'),
2513 61b6ee11 Andreas Kohlbecker
    '#collapsible' => FALSE,
2514
    '#collapsed' => FALSE,
2515 6657531f Andreas Kohlbecker
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2516
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2517
         where they can write the text to be searched. You can find Drupal block configuration
2518
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2519
  );
2520
2521 90a6166e Andreas Kohlbecker
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2522 f19f47fa Andreas Kohlbecker
      '#type' => 'checkbox',
2523
      '#title' => t('Ignore the chosen classification in simple search'),
2524 90a6166e Andreas Kohlbecker
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2525 61b6ee11 Andreas Kohlbecker
      '#description' => t('The simple search, which can be executed via the search block,
2526 90a6166e Andreas Kohlbecker
          will by default search on the classification selected in the classification browser
2527
          selector. Set the tick if you want your portal to search on all classifications.'),
2528 61b6ee11 Andreas Kohlbecker
  );
2529
2530 2d0d855a Andreas Kohlbecker
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2531
    '#type' => 'checkbox',
2532
    '#title' => t('Run simple search with free-text search backend.'),
2533 90a6166e Andreas Kohlbecker
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2534 2d0d855a Andreas Kohlbecker
    '#description' => t('The simple search uses by default another search
2535
      backend as the advances search. By checking this option the simple search can be
2536
      configured to also use the free-text search backend.'),
2537
  );
2538
2539 6657531f Andreas Kohlbecker
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2540
    '#type' => 'textfield',
2541
    '#title' => t('Results per page') . ':',
2542
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2543
    '#description' => t('Number of results to display per page.'),
2544
  );
2545
2546 1d69a96c Andreas Kohlbecker
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2547
    '#type' => 'checkbox',
2548
    '#title' => t('Show the <i>Show Image Thumbnails</i> button') . ':',
2549
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2550
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2551
  );
2552
2553 6280e639 Andreas Kohlbecker
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2554
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2555
      '#type' => 'checkboxes',
2556
      '#title' => 'Search mode',
2557
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2558
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2559
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2560
          defaults set here.',
2561
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2562
      '#default_value' => $search_mode_default
2563
      );
2564 6657531f Andreas Kohlbecker
2565 072122ee Andreas Kohlbecker
  $form['search_settings'][CDM_SEARCH_AREA_FILTER_PRESET] = array(
2566 f4cc620d Andreas Kohlbecker
    '#type' => 'textarea',
2567 072122ee Andreas Kohlbecker
    '#title' => t('area_filter_preset') . ':',
2568
    '#default_value' => variable_get(CDM_SEARCH_AREA_FILTER_PRESET, ''), // '05b0dd06-30f8-477d-bf4c-30d9def56320' =>  Caucasia (Ab + Ar + Gg + Rf(CS)) (Cc)
2569
2570
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2571
  );
2572
2573 6657531f Andreas Kohlbecker
  // --- SEARCH TAXA GALLERY ---- //
2574
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2575
  $collapsed = FALSE;
2576
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2577
  $form_title = 'Taxa Search thumbnails';
2578
  $form_description = 'Search results may show thumbnails. ';
2579
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2580
2581
  // Comment @WA: D7 form api does not support reset buttons,
2582
  // so to mimic the D5 reset button we add one like this.
2583
  $form['actions']['reset'] = array(
2584
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2585
    '#weight' => 1000,
2586
  );
2587
  return system_settings_form($form);
2588
}
2589
2590
/**
2591
 * @todo document this function.
2592
 */
2593
function cdm_settings_layout_media() {
2594
2595
  $form = array();
2596
2597
  $form['media_settings'] = array(
2598
    '#type' => 'fieldset',
2599 a950f2f9 Andreas Kohlbecker
    '#title' => t('Media settings'),
2600
    '#collapsible' => FALSE,
2601 6657531f Andreas Kohlbecker
    '#collapsed' => FALSE,
2602 ccde8251 Andreas Kohlbecker
    '#description' => 'This section covers layout settings for media pages.'
2603
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2604 6657531f Andreas Kohlbecker
  );
2605
2606
  $form['media_settings']['image_gallery_viewer'] = array(
2607
    '#type' => 'select',
2608
    '#title' => t('Image viewer') . ':',
2609
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2610
    '#options' => array(
2611
      'default' => t('Standard image viewer'),
2612
      'fsi' => t('FSI viewer (requires FSI server!)'),
2613
    ),
2614
  );
2615
2616
  // --- MEDIA GALLERY ---- //
2617
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2618
  $form_title = 'Standard viewer';
2619
  $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>';
2620
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2621
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2622
2623
  // @WA: D7 form api does not support reset buttons,
2624
  // so to mimic the D5 reset button we add one like this.
2625
  $form['actions']['reset'] = array(
2626
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2627
    '#weight' => 1000,
2628
  );
2629
  return system_settings_form($form);
2630
}
2631
2632
/**
2633
 * GEOSERVICE and Map settings.
2634
 */
2635 1d39ec64 w.addink
function cdm_settings_geo($form, &$form_state) {
2636 6657531f Andreas Kohlbecker
2637 cc3c9807 Andreas Kohlbecker
  $current_geoserver_settings = get_edit_map_service_settings();
2638
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2639 ff965d76 Andreas Kohlbecker
2640 cc3c9807 Andreas Kohlbecker
2641 6657531f Andreas Kohlbecker
  $form = array();
2642
2643 cc3c9807 Andreas Kohlbecker
  $dummy_distribution_query = NULL;
2644
  if($map_distribution['map_type'] != 1){
2645 ff965d76 Andreas Kohlbecker
    // we need to apply a dummy query since the map service requires for image maps
2646 cc3c9807 Andreas Kohlbecker
    // at least as and ad to be defined
2647
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2648
  }
2649 087bb473 Andreas Kohlbecker
2650 d2fd2a4c Andreas Kohlbecker
  $form['map_preview'] = array(
2651
      '#type' => 'fieldset',
2652
      '#tree' => FALSE,
2653
      '#title' => t('Map preview'),
2654
      '#collapsible' => FALSE,
2655 cc3c9807 Andreas Kohlbecker
      '#description' => 'The preview of the map'
2656 2bbc28c8 Andreas Kohlbecker
       . ($dummy_distribution_query != null ?
2657 ff965d76 Andreas Kohlbecker
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2658 d5661a4c Andreas Kohlbecker
           '.<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.')
2659 d2fd2a4c Andreas Kohlbecker
  );
2660 4c21ffdb Andreas Kohlbecker
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2661 653e9c6b Andreas Kohlbecker
    'move' => "this.cdmOpenlayersMap.printInfo",
2662
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2663
  ), true // resizable
2664 d2fd2a4c Andreas Kohlbecker
  );
2665 087bb473 Andreas Kohlbecker
2666 6f718d1b Andreas Kohlbecker
  /*
2667
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2668
  );
2669
  */
2670 cc3c9807 Andreas Kohlbecker
2671 6657531f Andreas Kohlbecker
  /*
2672 d2fd2a4c Andreas Kohlbecker
   * GEO SERVER
2673
   */
2674 ba706bf0 Andreas Kohlbecker
  $form['edit_map_server'] = array(
2675 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2676 ba706bf0 Andreas Kohlbecker
    '#tree' => true,
2677
    '#title' => t('EDIT map service'),
2678 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
2679
    '#collapsed' => TRUE,
2680
    '#description' => t('Configuration and selection of your geo server.
2681
      The Geo Server is responsible for generating the maps.'),
2682
  );
2683
2684 f19f47fa Andreas Kohlbecker
  $form['edit_map_server']['base_uri'] = array(
2685 6657531f Andreas Kohlbecker
    '#type' => 'select',
2686 ba706bf0 Andreas Kohlbecker
    '#title' => t('EDIT map service') . ':',
2687
    '#default_value' => $current_geoserver_settings['base_uri'],
2688
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2689
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2690 6657531f Andreas Kohlbecker
  );
2691 f19f47fa Andreas Kohlbecker
  $form['edit_map_server']['version'] = array(
2692
      '#type' => 'select',
2693
      '#title' => t('Version') . ':',
2694
      '#default_value' => $current_geoserver_settings['version'],
2695
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2696
      '#description' => t('The version of the EDIT map services'),
2697 6657531f Andreas Kohlbecker
  );
2698
2699
  /*
2700 d2fd2a4c Andreas Kohlbecker
   * MAP SETTINGS
2701
   */
2702 cc3c9807 Andreas Kohlbecker
2703
  $form[CDM_MAP_DISTRIBUTION] = array(
2704 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2705 cc3c9807 Andreas Kohlbecker
    '#tree' => TRUE,
2706 6657531f Andreas Kohlbecker
    '#title' => t('Maps settings'),
2707
    '#collapsible' => TRUE,
2708
    '#collapsed' => TRUE,
2709
    '#description' => t('General configuration for all map types.'),
2710
  );
2711
2712 6f718d1b Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2713
    '#type' => 'radios',
2714
    '#title' => 'Map types',
2715
    '#options' => array(
2716
      1 => "OpenLayers dynamic map viewer",
2717
      0 => "Plain image",
2718
    ),
2719
    '#default_value' => $map_distribution['map_type'],
2720
    '#description' => 'Two different map types are available :
2721
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2722
      which allows zooming and panning. If enabled you can configure the default layer
2723
      (background of your maps) below.</li>
2724
      <li><em>Plain image</em>: The map will be static non interactive
2725
      image.</li></ul>',
2726
  );
2727
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2728
2729 cc3c9807 Andreas Kohlbecker
  /*
2730
   * settings for the distribution map are used also for specimens map!!!!
2731
   */
2732
2733 b4503332 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2734 cc3c9807 Andreas Kohlbecker
      '#type' => 'textfield',
2735 b4503332 Andreas Kohlbecker
      '#title' => 'Aspect ratio',
2736
      '#default_value' => $map_distribution['aspect_ratio'],
2737 cc3c9807 Andreas Kohlbecker
      '#maxlength' => 4,
2738
      '#size' => 4,
2739 ff965d76 Andreas Kohlbecker
      '#element_validate' => array('element_validate_number'),
2740 b4503332 Andreas Kohlbecker
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2741
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2742
      width by the height:</br>
2743
      <pre>aspect ratio = w / h</pre>
2744
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2745
      for a square map use <strong>1</strong>.',
2746 cc3c9807 Andreas Kohlbecker
  );
2747 6657531f Andreas Kohlbecker
2748 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2749 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2750 cc3c9807 Andreas Kohlbecker
    '#title' => 'Bounding box',
2751
    '#default_value' => $map_distribution['bbox'],
2752 b4503332 Andreas Kohlbecker
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2753 6657531f Andreas Kohlbecker
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2754 2bbc28c8 Andreas Kohlbecker
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2755 087bb473 Andreas Kohlbecker
      <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.
2756 b4503332 Andreas Kohlbecker
      (Maybe you need to change the map base layer to OpeLayers.)
2757 d5661a4c Andreas Kohlbecker
      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
2758 2bbc28c8 Andreas Kohlbecker
      below the map from where you can copy the bbox string.</p>'),
2759 6657531f Andreas Kohlbecker
  );
2760
2761 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2762 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
2763 cc3c9807 Andreas Kohlbecker
    '#title' => 'Display area labels',
2764
    '#default_value' => $map_distribution['show_labels'],
2765
    '#description' => t('The map will show name labels of the areas'),
2766 6657531f Andreas Kohlbecker
  );
2767
2768 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2769 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2770 cc3c9807 Andreas Kohlbecker
    '#title' => 'Map caption',
2771
    '#default_value' => $map_distribution['caption'],
2772
    '#description' => t('The caption will be shown below the map.'),
2773 6657531f Andreas Kohlbecker
  );
2774
2775 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2776 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2777 cc3c9807 Andreas Kohlbecker
    '#title' => 'Distribution layer opacity',
2778
    '#default_value' => $map_distribution['distribution_opacity'],
2779 b4503332 Andreas Kohlbecker
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2780
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2781 6657531f Andreas Kohlbecker
  );
2782
2783
  // --- Plain Image Settings --- //
2784 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2785 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2786 cc3c9807 Andreas Kohlbecker
    '#title' => 'Plain image map settings',
2787
    '#tree' => TRUE,
2788 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
2789 cc3c9807 Andreas Kohlbecker
    '#collapsed' => $open_layers_is_enabled,
2790
    '#description' => 'The settings in this section are still expertimental
2791
      and can only be used with the EDIT map service version 1.1 or above.',
2792 6657531f Andreas Kohlbecker
  );
2793 ba706bf0 Andreas Kohlbecker
  $edit_mapserver_version = get_edit_map_service_version_number();
2794 6657531f Andreas Kohlbecker
  if ($edit_mapserver_version < 1.1) {
2795 7cc085da Andreas Kohlbecker
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2796
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2797
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2798 cc3c9807 Andreas Kohlbecker
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2799 6657531f Andreas Kohlbecker
  }
2800
2801 b4503332 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2802
    '#type' => 'textfield',
2803
    '#title' => 'Width',
2804
    '#default_value' => $map_distribution['image_map']['width'],
2805
    '#maxlength' => 4,
2806
    '#size' => 4,
2807 50791e51 Andreas Kohlbecker
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2808 b4503332 Andreas Kohlbecker
  );
2809
2810 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2811 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2812 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background layer',
2813
    '#default_value' => $map_distribution['image_map']['base_layer'],
2814 6657531f Andreas Kohlbecker
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2815 cc3c9807 Andreas Kohlbecker
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2816
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2817 6657531f Andreas Kohlbecker
    )),
2818
  );
2819
2820 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2821 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2822 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background color',
2823
    '#default_value' => $map_distribution['image_map']['bg_color'],
2824 6657531f Andreas Kohlbecker
  );
2825
2826 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2827 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2828 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background layer style',
2829 6657531f Andreas Kohlbecker
     // Only line color by now.
2830 cc3c9807 Andreas Kohlbecker
    '#default_value' => $map_distribution['image_map']['layer_style'],
2831
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2832 6657531f Andreas Kohlbecker
  );
2833
2834 4bef194f Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2835
      '#type' => 'textfield',
2836
      '#title' => 'Projection',
2837
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2838
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2839
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2840
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2841
  );
2842
2843 6657531f Andreas Kohlbecker
2844
  // --- OpenLayers Settings --- //
2845 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2846 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2847 cc3c9807 Andreas Kohlbecker
    '#title' => 'OpenLayers settings',
2848
    '#tree' => TRUE,
2849 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
2850 cc3c9807 Andreas Kohlbecker
    '#collapsed' => !$open_layers_is_enabled,
2851 6657531f Andreas Kohlbecker
    '#description' => '',
2852
  );
2853
2854 2bbc28c8 Andreas Kohlbecker
2855
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2856
      '#type' => 'checkbox',
2857
      '#title' => 'Display outside max extent',
2858
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2859
      '#description' => t('Allows the map to display parts of the layers which are outside
2860
         the max extent if the aspect ratio of the map and of the baselayer
2861
         are not equal.'),
2862
  );
2863
2864 570f0e73 Andreas Kohlbecker
2865 2bbc28c8 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2866
      '#type' => 'checkbox',
2867
      '#title' => 'Show Layer Switcher',
2868
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2869
      '#description' => 'The Layer Switcher control displays a table of contents
2870
      for the map.  This allows the user interface to switch between
2871
      base layers and to show or hide overlays.  By default the switcher is
2872
      shown minimized on the right edge of the map, the user may expand it
2873
      by clicking on the handle.',
2874
  );
2875
2876 cc3c9807 Andreas Kohlbecker
  if (!$open_layers_is_enabled) {
2877
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2878
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2879
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2880 6657531f Andreas Kohlbecker
  }
2881
2882 ff965d76 Andreas Kohlbecker
  // The default layer must always be enabled
2883
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2884
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2885
2886 6657531f Andreas Kohlbecker
  $baselayer_options = array(
2887
    /*
2888
   NOTICE: must correspond to the layers defined in
2889
   js/openlayers_,ap.js#getLayersByName()
2890
   */
2891 1f3c62f9 Andreas Kohlbecker
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
2892
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
2893
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
2894
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
2895 6657531f Andreas Kohlbecker
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2896 1f3c62f9 Andreas Kohlbecker
    // all others EPSG:900913
2897 6657531f Andreas Kohlbecker
    'mapnik' => 'OpenStreetMap',
2898 2bbc28c8 Andreas Kohlbecker
    'mapquest_open' => "MapQuest",
2899
    'mapquest_sat' => "MapQuest Sattelite",
2900 2b83cc8b Andreas Kohlbecker
    'groadmap' => 'Google Roadmap',
2901
    'gsatellite' => 'Google Satellite',
2902 f619ffbf Andreas Kohlbecker
    'ghybrid' => 'Google Hybrid',
2903 2b83cc8b Andreas Kohlbecker
    'gterrain' => 'Google Terrain',
2904 cc3c9807 Andreas Kohlbecker
//     'veroad' => 'Virtual Earth Roads',
2905
//     'veaer' => 'Virtual Earth Aerial',
2906
//     'vehyb' => 'Virtual Earth Hybrid',
2907 6657531f Andreas Kohlbecker
    // 'yahoo' => 'Yahoo Street',
2908
    // 'yahoosat' => 'Yahoo Satellite',
2909
    // 'yahoohyb' => 'Yahoo Hybrid',
2910 2bbc28c8 Andreas Kohlbecker
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2911 6657531f Andreas Kohlbecker
  );
2912
2913 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2914 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes_preferred',
2915 cc3c9807 Andreas Kohlbecker
    '#title' => 'Base Layers',
2916 6657531f Andreas Kohlbecker
    '#options' => $baselayer_options,
2917 cc3c9807 Andreas Kohlbecker
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2918
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2919 6657531f Andreas Kohlbecker
  );
2920
2921 2b83cc8b Andreas Kohlbecker
  $google_maps_api_key = null;
2922
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
2923
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
2924
  }
2925
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
2926
    '#type' => 'textfield',
2927
    '#title' => 'Google Maps API Key',
2928
    '#default_value' => $google_maps_api_key,
2929
    '#description' => 'In order to use any of the Google map layers you need to provide 
2930
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
2931
  );
2932
2933 2bbc28c8 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2934
      '#type' => 'fieldset',
2935
      '#title' => 'Custom WMS base layer',
2936
      '#tree' => TRUE,
2937
      '#collapsible' => FALSE,
2938
      '#collapsed' => FALSE,
2939
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2940
  );
2941
2942
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2943
      '#type' => 'textfield',
2944
      '#title' => 'Layer name',
2945
      // Only line color by now.
2946
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2947
      '#description' => 'A arbitrary name for the layer.',
2948
  );
2949
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2950
      '#type' => 'textfield',
2951
      '#title' => 'WMS url',
2952
      // Only line color by now.
2953
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2954 ff965d76 Andreas Kohlbecker
      '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
2955 2bbc28c8 Andreas Kohlbecker
  );
2956
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2957
      '#type' => 'textarea',
2958
      '#title' => 'WMS parameters',
2959
      '#element_validate' => array('form_element_validate_json'),
2960
      // Only line color by now.
2961
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2962 570f0e73 Andreas Kohlbecker
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2963
<pre> {
2964
  "Layers": "topp:em_tiny_jan2003",
2965
  "Format": "image/png",
2966
  "BGCOLOR": "0xe0faff"
2967
}
2968
</pre>'
2969 2bbc28c8 Andreas Kohlbecker
  );
2970
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2971
      '#type' => 'textfield',
2972
      '#title' => 'Projection',
2973
      // Only line color by now.
2974
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2975
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2976
  );
2977 e3026d72 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2978
      '#type' => 'textfield',
2979 14339c2a Andreas Kohlbecker
      '#maxlength' => 256,
2980 e3026d72 Andreas Kohlbecker
      '#title' => 'proj4js definition',
2981
      // Only line color by now.
2982
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2983
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2984
            The definitions for
2985
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2986
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2987
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2988
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2989
            choose to display the proj4js definition string.
2990 7f71136d Andreas Kohlbecker
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2991
            <pre>
2992
+a         Semimajor radius of the ellipsoid axis
2993
+alpha     ? Used with Oblique Mercator and possibly a few others
2994
+axis      Axis orientation (new in 4.8.0)
2995
+b         Semiminor radius of the ellipsoid axis
2996
+datum     Datum name (see `proj -ld`)
2997
+ellps     Ellipsoid name (see `proj -le`)
2998
+k         Scaling factor (old name)
2999
+k_0       Scaling factor (new name)
3000
+lat_0     Latitude of origin
3001
+lat_1     Latitude of first standard parallel
3002
+lat_2     Latitude of second standard parallel
3003
+lat_ts    Latitude of true scale
3004
+lon_0     Central meridian
3005
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
3006
+lon_wrap  Center longitude to use for wrapping (see below)
3007
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
3008
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
3009
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
3010
+pm        Alternate prime meridian (typically a city name, see below)
3011
+proj      Projection name (see `proj -l`)
3012
+south     Denotes southern hemisphere UTM zone
3013
+to_meter  Multiplier to convert map units to 1.0m
3014
+towgs84   3 or 7 term datum transform parameters (see below)
3015
+units     meters, US survey feet, etc.
3016
+vto_meter vertical conversion to meters.
3017
+vunits    vertical units.
3018
+x_0       False easting
3019
+y_0       False northing
3020
+zone      UTM zone
3021
            </pre>
3022
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
3023 e3026d72 Andreas Kohlbecker
  );
3024 2bbc28c8 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
3025
      '#type' => 'textfield',
3026
      '#title' => 'Maximum extent',
3027
      // Only line color by now.
3028
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
3029 14339c2a Andreas Kohlbecker
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
3030 2bbc28c8 Andreas Kohlbecker
  );
3031
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
3032
      '#type' => 'textfield',
3033
      '#title' => 'Units',
3034
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
3035
      '#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.'
3036 6657531f Andreas Kohlbecker
  );
3037
3038 cc3c9807 Andreas Kohlbecker
  /*
3039
   * Map Legend
3040
   */
3041
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3042 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
3043 cc3c9807 Andreas Kohlbecker
    '#title' => 'Map legend',
3044
    '#tree' => TRUE,
3045 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
3046
    '#collapsed' => TRUE,
3047 cc3c9807 Andreas Kohlbecker
    '#description' => 'Configure the maps legend.',
3048 6657531f Andreas Kohlbecker
  );
3049
3050 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3051 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
3052 cc3c9807 Andreas Kohlbecker
    '#title' => 'Display a map legend',
3053
    '#default_value' => $map_distribution['legend']['show'],
3054
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3055 6657531f Andreas Kohlbecker
  );
3056
3057 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3058 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
3059 cc3c9807 Andreas Kohlbecker
    '#title' => 'Legend opacity',
3060
    '#default_value' => $map_distribution['legend']['opacity'],
3061
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3062
                         to 0.0 will be not much visible.',
3063 6657531f Andreas Kohlbecker
  );
3064
3065 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3066 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
3067 cc3c9807 Andreas Kohlbecker
    '#title' => 'Font size',
3068
    '#default_value' => $map_distribution['legend']['font_size'],
3069
    '#description' => 'Font size in pixels.',
3070 6657531f Andreas Kohlbecker
  );
3071
3072
  $fontStyles = array(
3073
    0 => "plane",
3074
    1 => "italic",
3075
  );
3076 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3077 6657531f Andreas Kohlbecker
    '#type' => 'select',
3078 cc3c9807 Andreas Kohlbecker
    '#title' => 'Available font styles',
3079
    '#default_value' => $map_distribution['legend']['font_style'],
3080 6657531f Andreas Kohlbecker
    '#options' => $fontStyles,
3081 cc3c9807 Andreas Kohlbecker
    '#description' => 'Select a font style for the map legend.',
3082 6657531f Andreas Kohlbecker
  );
3083
3084 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3085 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
3086 cc3c9807 Andreas Kohlbecker
    '#title' => 'Icon width',
3087
    '#default_value' => $map_distribution['legend']['icon_width'],
3088
    '#description' => 'Legend icon width in pixels.',
3089 6657531f Andreas Kohlbecker
  );
3090 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3091 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
3092 cc3c9807 Andreas Kohlbecker
    '#title' => 'Icon height',
3093
    '#default_value' => $map_distribution['legend']['icon_height'],
3094
    '#description' => 'Legend icon height in pixels.',
3095 6657531f Andreas Kohlbecker
  );
3096
3097
  // @WA: D7 form api does not support reset buttons,
3098
  // so to mimic the D5 reset button we add one like this.
3099
  $form['actions']['reset'] = array(
3100
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3101
    '#weight' => 1000,
3102
  );
3103 1d39ec64 w.addink
3104 6657531f Andreas Kohlbecker
  return system_settings_form($form);
3105
}
3106
3107 ff965d76 Andreas Kohlbecker
3108 6657531f Andreas Kohlbecker
/**
3109
 * @todo document this function.
3110
 */
3111
function cdm_settings_cache() {
3112
3113
  $form = array();
3114
3115
  $form['cache_settings'] = array(
3116
    '#type' => 'fieldset',
3117
    '#title' => t('Cache Settings'),
3118
    '#collapsible' => FALSE,
3119
    '#collapsed' => FALSE,
3120
    '#description' => t('<p>When caching is enabled all single taxon sites are
3121
      stored in an internal drupal cache doing the portal response of taxa pages
3122
      faster. This is possible because the sites are loaded from the cache and
3123
      are not created from scratch.</p>'),
3124
  );
3125
3126
  $form['cache_settings']['cdm_webservice_cache'] = array(
3127
    '#type' => 'checkbox',
3128
    '#title' => t('<strong>Enable caching</strong>'),
3129
    '#options' => cdm_help_general_cache(),
3130
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3131
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3132
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3133
       application the changes will be not visible till the cache is erased.
3134
       Therefore developers should deactived this feature when they are working
3135
       on the CDM Dataportal Module.</p>'),
3136
  );
3137
3138
  $form['cache_settings']['cdm_run_cache'] = array(
3139
    '#markup' => cdm_view_cache_site(),
3140
  );
3141
3142
  // @WA: D7 form api does not support reset buttons,
3143
  // so to mimic the D5 reset button we add one like this.
3144
  $form['actions']['reset'] = array(
3145
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3146
    '#weight' => 1000,
3147
  );
3148
  return system_settings_form($form);
3149
}
3150
3151
/**
3152
 * Walk and cache all taxon pages.
3153
 */
3154
function cdm_view_cache_site() {
3155
3156
  $out = '';
3157
3158
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3159
3160
  $request_params = array();
3161 7d828d59 Andreas Kohlbecker
  $request_params['class'] = "Taxon";
3162 6657531f Andreas Kohlbecker
3163 7d828d59 Andreas Kohlbecker
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3164
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3165
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3166 6657531f Andreas Kohlbecker
3167
  $out .= t('<p><strong>Cache all taxon pages</strong></p>');
3168
  $out .= '<p>When you launch the cache process the cache is filled and ready to be enabled.<br/>
3169
  Remember that when you load the taxa from the cache last changes on taxa will be not visible till you erase
3170
  the cache and fill it again.</p>';
3171
  $out .= '<p>Before  running the cache bot you have to empty the cache manually.</p>';
3172
3173
  $out .= '<div>' . t('This caching process may take long time and could cause heavy load on your server') . '</div>';
3174
  $out .= '<div id="progress"></div>';
3175
3176
  // Comment @WA: A form within a form is not valid html and not needed here.
3177
  // Also, it would be recommended just to include this part of the form in the
3178
  // rest of the form array in cdm_settings_cache().
3179
  // $out .= '<form id="cache_site">';
3180 0516e3d0 Andreas Kohlbecker
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3181 7d828d59 Andreas Kohlbecker
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3182 6657531f Andreas Kohlbecker
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3183
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3184
  // $out .= '</form>';
3185
  $out .= '</div>';
3186
  /*
3187
  foreach($taxonPager->records as $taxon){
3188
    cdm_dataportal_taxon_view($uuid);
3189
  }
3190
  */
3191
  return $out;
3192
}
3193
3194 7df1be04 Andreas Kohlbecker
3195
function cdm_settings_layout_taxon_submit($form, &$form_state){
3196 9c92cd84 Andreas Kohlbecker
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3197
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3198
    if(is_object($file)){
3199
      $file->status = FILE_STATUS_PERMANENT;
3200
      file_save($file);
3201
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3202
    }
3203 7df1be04 Andreas Kohlbecker
  }
3204 d5403dc4 Andreas Kohlbecker
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
3205
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
3206
    // we first need to set the variable to persist the changes setting
3207
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3208
    menu_rebuild();
3209
  }
3210 7df1be04 Andreas Kohlbecker
}
3211
3212 c5ed6357 Andreas Kohlbecker
function cdm_settings_layout_search_submit($form, &$form_state){
3213
  // the visibility of media thumbnails also affects the ui of the search results
3214
  // so reset the according session variable
3215
  //    1. in order to give the user immediate
3216
  //       feedback on potential setting changes
3217
  //    2. let refresh the default if it has changed
3218
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3219
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3220
  }
3221
}
3222
3223 6657531f Andreas Kohlbecker
/**
3224 d1eb0a8c Andreas Kohlbecker
 * Form validation handler for cdm_settings_general
3225 6657531f Andreas Kohlbecker
 *
3226 22eb20d7 Andreas Kohlbecker
 * @param $form
3227
 * @param $form_state
3228 6657531f Andreas Kohlbecker
 */
3229 d1eb0a8c Andreas Kohlbecker
function cdm_settings_general_validate($form, &$form_state) {
3230 6657531f Andreas Kohlbecker
3231
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3232
    $form_state['values']['cdm_webservice_url'] .= '/';
3233
  }
3234
3235 d1eb0a8c Andreas Kohlbecker
}
3236
3237 22eb20d7 Andreas Kohlbecker
/**
3238
 * Form submit handler for settings general.
3239
 *
3240
 * tasks performed:
3241
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3242
 *
3243
 * @param $form
3244
 * @param $form_state
3245
 */
3246
function cdm_settings_general_submit($form, &$form_state){
3247
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3248
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3249
}
3250
3251 d1eb0a8c Andreas Kohlbecker
/**
3252
 * Form validation handler for cdm_settings_cache
3253
 */
3254 847bb49e Andreas Kohlbecker
function cdm_settings_cache_validate($form, &$form_state) {
3255 6657531f Andreas Kohlbecker
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3256
    cache_clear_all(NULL, 'cache_cdm_ws');
3257
    // Better clear secref_cache since I can not be sure if the cache has not
3258
    // be used during this response.
3259
    cdm_api_secref_cache_clear();
3260
  }
3261 d1eb0a8c Andreas Kohlbecker
3262 6657531f Andreas Kohlbecker
}
3263
3264
/**
3265 ba706bf0 Andreas Kohlbecker
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3266
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3267
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3268
 *  - version: the version, e.g.: v1.1
3269
 *
3270
 * @return array
3271
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3272 6657531f Andreas Kohlbecker
 */
3273 ba706bf0 Andreas Kohlbecker
function get_edit_map_service_settings() {
3274
3275
  $settings = variable_get('edit_map_server', array(
3276
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3277
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3278
      )
3279
  );
3280 6657531f Andreas Kohlbecker
3281 ba706bf0 Andreas Kohlbecker
  return $settings;
3282 6657531f Andreas Kohlbecker
}
3283
3284
/**
3285 ba706bf0 Andreas Kohlbecker
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3286
 *
3287
 * @return string
3288
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3289
 */
3290
function get_edit_map_service_full_uri() {
3291
  $settings = get_edit_map_service_settings();
3292
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3293
}
3294
3295
3296
/**
3297
 * Returns the version number of the currently selected edit mapserver as a float
3298 6657531f Andreas Kohlbecker
 *
3299
 * @return float
3300
 *   The version number of the currently selected edit mapserver as a float.
3301
 *   Returns 0 on error.
3302
 */
3303 ba706bf0 Andreas Kohlbecker
function get_edit_map_service_version_number() {
3304 6657531f Andreas Kohlbecker
3305 ba706bf0 Andreas Kohlbecker
  $pattern = '/v([\d\.]+).*$/';
3306 6657531f Andreas Kohlbecker
3307 ba706bf0 Andreas Kohlbecker
  $settings = get_edit_map_service_settings();
3308
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3309 6657531f Andreas Kohlbecker
  if (isset($matches[1])) {
3310
    // Convert string to float.
3311
    $version = 1 + $matches[1][0] - 1;
3312
    return $version;
3313
  }
3314
  else {
3315
    // Report error.
3316 ba706bf0 Andreas Kohlbecker
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3317
        array(
3318
          '!version' => $settings['version'],
3319
          'warning')
3320
        )
3321
      );
3322 6657531f Andreas Kohlbecker
    return 0;
3323
  }
3324
}
3325
3326 30f78c59 Andreas Kohlbecker
/**
3327 ba706bf0 Andreas Kohlbecker
 * Returns the array of selected items in a options array
3328 30f78c59 Andreas Kohlbecker
 *
3329
 * @param array $options
3330
 *   An options array as generated by a form element like checkoxes, select ...,
3331
 */
3332
function get_selection($options) {
3333
  $selection = array();
3334
  foreach ($options as $key=>$val) {
3335
    if (!empty($val)) {
3336
      $selection[] = $val;
3337
    }
3338
  }
3339
  return $selection;
3340
}
3341
3342 bfb2b81a Andreas Kohlbecker
3343 6657531f Andreas Kohlbecker
/**
3344
 * Implements hook_element_info().
3345
 *
3346 14feebe9 Andreas Kohlbecker
 * Allows modules to declare their own Form API element types and specify their default values.
3347
 *
3348
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3349 6657531f Andreas Kohlbecker
 */
3350
function cdm_dataportal_element_info() {
3351
  $type['checkboxes_preferred'] = array(
3352
    '#input' => TRUE,
3353 14feebe9 Andreas Kohlbecker
    '#process' => array('checkboxes_preferred_expand'),
3354 6657531f Andreas Kohlbecker
    '#after_build' => array('checkboxes_preferred_after_build'),
3355
    '#theme' => array('checkboxes_preferred'),
3356
    // '#theme_wrapper' => array('form_element'),
3357
  );
3358
  return $type;
3359
}
3360
3361
/**
3362 14feebe9 Andreas Kohlbecker
 * #process callback function for the custom form element type 'checkbox_preferred'
3363
 *
3364
 *
3365 6657531f Andreas Kohlbecker
 */
3366 14feebe9 Andreas Kohlbecker
function checkboxes_preferred_expand($element, &$form_state, $form) {
3367
3368
  // First of all create checkboxes for each of the elements
3369 6657531f Andreas Kohlbecker
  $element = form_process_checkboxes($element);
3370
3371 cc3c9807 Andreas Kohlbecker
  // compose the element name
3372
  $parents = array();
3373
  array_deep_copy($element['#parents'], $parents);
3374
  $parents[count($parents) -1 ] .= '_preferred';
3375
  $element_name = $parents[0];
3376
  for ($i=1; $i < count($parents); $i++){
3377
    $element_name .= '[' . $parents[$i] . ']';
3378
  }
3379
3380 6657531f Andreas Kohlbecker
  $children = element_children($element);
3381
3382
  $element['table_start'] = array(
3383
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3384
    '#weight' => -1,
3385
  );
3386
3387 14feebe9 Andreas Kohlbecker
  // prepare first part each of the table rows which contains the row label
3388 6657531f Andreas Kohlbecker
  $weight = 0;
3389
  foreach ($children as $key) {
3390
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3391
    $element[$key]['#weight'] = $weight;
3392 7cc085da Andreas Kohlbecker
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3393 6657531f Andreas Kohlbecker
    $element[$key]['#suffix'] = '</td>';
3394
    unset($element[$key]['#title']);
3395
    $weight += 2;
3396
  }
3397
  $weight = 0;
3398
3399 14feebe9 Andreas Kohlbecker
  // add a radio button to each of the checkboxes, the
3400
  // check boxes have already been created at the beginning
3401
  // of this function
3402 6657531f Andreas Kohlbecker
  if (count($element['#options']) > 0) {
3403
    foreach ($element['#options'] as $key => $choice) {
3404
      if (!isset($element[$key . '_preferred'])) {
3405
        $element[$key . '_preferred'] = array(
3406
          '#type' => 'radio',
3407 cc3c9807 Andreas Kohlbecker
          '#name' => $element_name,
3408 6657531f Andreas Kohlbecker
          '#return_value' => check_plain($key),
3409
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3410
          '#attributes' => $element['#attributes'],
3411 1d39ec64 w.addink
          '#parents' => $element['#parents'],
3412 6657531f Andreas Kohlbecker
          // '#spawned' => TRUE,
3413
          '#weight' => $weight + 1,
3414 14feebe9 Andreas Kohlbecker
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3415
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3416 6657531f Andreas Kohlbecker
        );
3417
      }
3418
      $weight += 2;
3419
    }
3420
  }
3421
3422 14feebe9 Andreas Kohlbecker
  // end the table
3423 6657531f Andreas Kohlbecker
  $element['table_end'] = array(
3424
    '#markup' => '</table>',
3425
    '#weight' => $weight++,
3426
  );
3427
3428
  return $element;
3429
}
3430
3431
/**
3432
 * Theme function for the custom form field 'checkboxes_preferred'.
3433
 */
3434
function theme_checkboxes_preferred($variables) {
3435
  $element = $variables['element'];
3436
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3437
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3438
  $out .= drupal_render_children($element);
3439
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3440
  $out .= '</div>';
3441
  return $out;
3442
}
3443
3444
/**
3445 14feebe9 Andreas Kohlbecker
 * Callback for checkboxes preferred for widget which will
3446
 * be called after the form or element is built. The call
3447
 * back is configured in the form element by setting it as
3448
 * #after_build parameter.
3449
 *
3450
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3451
 *
3452 cc3c9807 Andreas Kohlbecker
 * @param $element
3453 14feebe9 Andreas Kohlbecker
 *   Nested array of form elements that comprise the form.
3454
 * @param $form_state
3455
 *   A keyed array containing the current state of the form.
3456 cc3c9807 Andreas Kohlbecker
 *   This includes the current persistent storage data for the form.
3457
 *   Additional information, like the sanitized $_POST data,
3458
 *   is also accumulated here in $form_state['input']
3459 14feebe9 Andreas Kohlbecker
 *
3460
 * @return the modified form array
3461 6657531f Andreas Kohlbecker
 */
3462 cc3c9807 Andreas Kohlbecker
function checkboxes_preferred_after_build($element, &$form_state) {
3463 6657531f Andreas Kohlbecker
3464 cc3c9807 Andreas Kohlbecker
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3465 6657531f Andreas Kohlbecker
3466
  if ($_POST && count($_POST) > 0) {
3467 cc3c9807 Andreas Kohlbecker
    // TODO use  $form_state['input'] instead of POST !!!
3468 6657531f Andreas Kohlbecker
    // First pass of form processing.
3469 cc3c9807 Andreas Kohlbecker
    $parents = array();
3470
    array_deep_copy($element['#parents'], $parents);
3471
    $parents[count($parents) - 1] .= '_preferred';
3472
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3473
    $element['#value']['PREFERRED'] = $preferred_layer;
3474
//     $form_state[$parent_id] = $element['#value'];
3475
//     $form_state['values']['baselayers'] = $element['#value'];
3476
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3477
    $form_state_element_values = $element['#value'];
3478 6657531f Andreas Kohlbecker
  }
3479
  else {
3480
    // Second pass of form processing.
3481 cc3c9807 Andreas Kohlbecker
    $preferred_layer = $element['#value']['PREFERRED'];
3482 6657531f Andreas Kohlbecker
  }
3483
3484
  // Also set the chosen value (not sure if this is good Drupal style ....).
3485 cc3c9807 Andreas Kohlbecker
  foreach ($children = element_children($element) as $key) {
3486
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3487
      $element[$key]['#value'] = $preferred_layer;
3488 6657531f Andreas Kohlbecker
    }
3489
  }
3490
  // The default layer must always be enabled.
3491 cc3c9807 Andreas Kohlbecker
  $element[$preferred_layer]['#value'] = $preferred_layer;
3492 6657531f Andreas Kohlbecker
3493 cc3c9807 Andreas Kohlbecker
  return $element;
3494 6657531f Andreas Kohlbecker
}
3495 0f5f1c12 Andreas Kohlbecker
3496 3f485c6d Andreas Kohlbecker
function radios_prepare_options_suffix(&$elements){
3497
3498
  $childrenKeys = element_children($elements);
3499
  foreach($childrenKeys as $key){
3500
    if(!is_array($elements[$key]['#theme_wrappers'])){
3501
      $elements[$key]['#theme_wrappers'] = array();
3502
    }
3503
    if(isset($elements['#options_suffixes'][$key])){
3504
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3505
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3506
    }
3507
  }
3508
  return $elements;
3509
3510
}
3511
3512
/**
3513
 * TODO
3514
 * @param unknown $variables
3515
 */
3516
function theme_radio_options_suffix($variables) {
3517
  $element = $variables['element'];
3518
  if(isset($element['#options_suffix'])) {
3519
    $element['#children'] .= $element['#options_suffix'];
3520
  }
3521
  return $element['#children'];
3522
}
3523
3524
3525 0f5f1c12 Andreas Kohlbecker
/**
3526
 * Element validate callback for text field and arrays containing json.
3527
 *
3528
 * @param $element
3529
 *   The form element to validate
3530
 * @param $form_state
3531
 *   A keyed array containing the current state of the form.
3532 cc3c9807 Andreas Kohlbecker
 * @param $form
3533
 *   Nested array of form elements that comprise the form.
3534 0f5f1c12 Andreas Kohlbecker
 */
3535
function form_element_validate_json($element, &$form_state, $form) {
3536
   if (!empty($element['#value'])) {
3537
     json_decode($element['#value']);
3538
     if(json_last_error() != JSON_ERROR_NONE){
3539 7cc085da Andreas Kohlbecker
       form_error($element,
3540
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3541
         . l('JSONLint', 'http://jsonlint.com/')
3542
       );
3543 0f5f1c12 Andreas Kohlbecker
     }
3544
   }
3545
}
3546
3547
/**
3548
 * Form submission handler for textareas and textfields containing JSON.
3549
 *
3550
 * The contained JSON will be converted into an php array
3551 2bbc28c8 Andreas Kohlbecker
 * or object and will be stored in the variables as such.
3552 0f5f1c12 Andreas Kohlbecker
 *
3553
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3554
 *
3555
 * @param $form
3556
 *   Nested array of form elements that comprise the form.
3557
 * @param $form_state
3558
 *   A keyed array containing the current state of the form.
3559
 *
3560
 */
3561
function submit_json_as_php_array($form, &$form_state) {
3562
  if (is_array($form['#json_elements'])) {
3563
    foreach ($form['#json_elements'] as $element){
3564 80370786 Andreas Kohlbecker
      if (trim($form_state['values'][$element])) {
3565
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3566
      } else {
3567
        $form_state['values'][$element] = NULL;
3568
      }
3569 0f5f1c12 Andreas Kohlbecker
    }
3570
  }
3571
}