Project

General

Profile

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