Project

General

Profile

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