Project

General

Profile

Download (164 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * CDM Dataportal settings.
5
 */
6

    
7

    
8
const FEATURE_BLOCK_WEIGHT_INCREMENT = 2;
9
const PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS = 'AGGREGATION_DESCRIPTIONS';
10
const PSEUDO_FEATURE_BIBLIOGRAPHY = 'BIBLIOGRAPHY';
11
const PSEUDO_FEATURE_NUMBER_OF_TAXA = 'NUMBER_OF_TAXA';
12

    
13
const CDM_NAME_PAGE_AUTOREDIRECT = 'cdm_name_page_autoredirect';
14

    
15
const CDM_NAME_PAGE_SECTION_TAXA = 'cdm_name_page_section_taxa';
16
const CDM_NAME_PAGE_SECTION_TAXA_DEFAULT = 1;
17

    
18
const CDM_MEDIA_GALLERY_VIEWER = 'image_gallery_viewer';
19
const CDM_MEDIA_GALLERY_VIEWER_DEFAULT = 'universalviewer';
20
const CDM_MEDIA_GALLERY_VIEWER_SIMPLE = 'default';
21

    
22
const CDM_ADDITIONAL_MEDIA_COPYRIGHT = 'cdm_additional_media_copyright';
23

    
24
const CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES = 'cdm_taxonpage_taxon_node_show_status';
25
define('TAXONTREE_RANKLIMIT', 'cdm_taxontree_ranklimit');
26
define('TAXONTREE_RANKLIMIT_DEFAULT', 0);
27
  define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
28
  define('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
29

    
30
  define('CDM_SUB_TREE_FILTER_UUID', 'cdm_sub_tree_filter_uuid');
31

    
32
  define('NO_SORT', -1);
33
  define('SORT_HIERARCHICAL', 9);
34

    
35
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
36

    
37
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
38
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
39
 const CDM_DATAPORTAL_NOMREF_IN_TITLE = 'cdm_dataportal_nomref_in_title';
40
 const CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT =  1;
41
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
42
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE', 50);
43
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 0);
44
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
45
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE', 'cdm_synonymy_accepted_taxon_sec_separate');
46
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL', 'cdm_synonymy_accepted_taxon_sec_separate_label');
47
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT', 'Source');
48
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
49
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
50
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
51
  define('CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE', 0);
52

    
53
  define('CDM_SEARCH_BLAST_SERVICE_URI', 'http://bgbm-import:9001/api/sequence');
54
  define('CDM_SEARCH_BLAST_ENABLED', 0);
55
  define('CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK', 'cdm_registration_presistent_identifier_as_link');
56

    
57
  /* annotationTypeKeys */
58
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
59
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
60
    $annotationTypeKeys = array_flip($annotationTypeKeys);
61

    
62
    // Technical annotation are off by default.
63
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
64
    $annotationTypeKeys = array_flip($annotationTypeKeys);
65
    // Additional value for the NULL case.
66
    $annotationTypeKeys[] = 'NULL_VALUE';
67
  }
68

    
69
  const ANNOTATION_TYPES_VISIBLE = 'annotations_types_as_footnotes';
70
  define('ANNOTATION_TYPES_VISIBLE_DEFAULT', serialize($annotationTypeKeys));
71

    
72
/* extensionTypeKeys */
73
$extensionTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_EXTENSION_TYPE));
74
if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $extensionTypeKeys)) {
75
  // Additional value for the NULL case.
76
  $extensionTypeKeys[] = 'NULL_VALUE';
77
}
78
const EXTENSION_TYPES_VISIBLE = 'extension_types_visible';
79
define('EXTENSION_TYPES_VISIBLE_DEFAULT', serialize([]));
80

    
81
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
82
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
83
    'enabled' => 0,
84
    'key_format' => 'ALPHA'
85
  )));
86

    
87
  /* taxonRelationshipTypes */
88
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(
89
    array(
90
      UUID_MISAPPLIED_NAME_FOR => UUID_MISAPPLIED_NAME_FOR,
91
      UUID_PROPARTE_MISAPPLIEDNAME_FOR => UUID_PROPARTE_MISAPPLIEDNAME_FOR,
92
      UUID_PARTIAL_MISAPPLIEDNAME_FOR => UUID_PARTIAL_MISAPPLIEDNAME_FOR,
93
      UUID_PROPARTE_SYNONYM_FOR => UUID_PROPARTE_SYNONYM_FOR,
94
      UUID_PARTIAL_SYNONYM_FOR => UUID_PARTIAL_SYNONYM_FOR,
95
      UUID_INVALID_DESIGNATION_FOR => UUID_INVALID_DESIGNATION_FOR
96
    )
97
  ));
98

    
99

    
100
  /* ---- MAP SETTING CONSTANTS ---- */
101
  /**
102
   * @var array of URIs eg. http://edit.africamuseum.be"
103
   *   An options array
104
   */
105
  define('EDIT_MAPSERVER_URI', serialize(
106
      array(
107
        'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)'
108
      )
109
    )
110
  );
111
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
112
  /**
113
   * @var array of versions eg. "v1.2"
114
   *   An options array
115
   */
116
  define('EDIT_MAPSERVER_VERSION', serialize(
117
      array(
118
//        'v1' => 'v1' ,           // no longer recommended
119
//        'v1.1' => 'v1.1',        // no longer recommended
120
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
121
        'v1.2' => 'v1.2',
122
        'v1.3_dev' => 'v1.3_dev (not recommended)',
123
        'v1.4_dev' => 'v1.4_dev (experimental features)'
124
      )
125
    )
126
  );
127
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
128
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
129

    
130
    // --- Taxon profile settings --- /
131
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
132
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
133
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
134
      array(
135
          'show' => 0,
136
          'maxextend' => 184,
137
          'media_uri_query' => '',
138
          'custom_placeholder_enabled' => 1,
139
          'custom_placeholder_image_on' => 0,
140
          'custom_placeholder_image_fid' => ''
141
      )
142
    )
143
  );
144

    
145

    
146
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
147

    
148
define('CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS', 'cdm_pseudo_feature_block_weights');
149
define('CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT', serialize(
150
  [
151
    PSEUDO_FEATURE_NUMBER_OF_TAXA => 0 - FEATURE_BLOCK_WEIGHT_INCREMENT,
152
    PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS => 100,
153
    PSEUDO_FEATURE_BIBLIOGRAPHY => 102
154
  ]
155
));
156

    
157
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
158
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
159
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
160
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
161
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
162

    
163
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
164
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
165
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
166
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
167

    
168
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
169
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
170

    
171
/**
172
 * Returns the array of implemented taxon page tabs.
173
 * The array has fixed integer keys which must not be changed.
174
 */
175
function get_taxon_tabs_list() {
176
  $opts = array(
177
    0 => 'General',
178
    1 => 'Synonymy',
179
    2 => 'Images',
180
    3 => 'Specimens',
181
    4 => 'Keys',
182
    5 => 'Experts',
183
  );
184
  if(variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) !== 1){
185
    // skip the Synonymy if it is shown in  the general tab
186
    unset($opts[1]);
187
  }
188
  return $opts;
189
}
190

    
191
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
192
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
193
  array(
194
    'general' => '-3',
195
    'synonymy' => '-2',
196
    'images' => '0',
197
    'specimens' => '1',
198
    'keys' => '3',
199
    'experts' => '5',
200
    )
201
));
202

    
203

    
204
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
205
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
206
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
207
  array(
208
    'general' => null,
209
    'synonymy' => null,
210
    'images' => null,
211
    'specimens' => null,
212
    'keys' => null,
213
    'experts' => null,
214
  )
215
));
216

    
217
$taxon_tab_options = get_taxon_tabs_list();
218
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
219

    
220
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
221

    
222
/**
223
 * @todo document this function.
224
 */
225
function get_taxon_options_list() {
226
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
227
  foreach ($taxon_tab_options as $key => $value) {
228
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
229
  }
230
  return $taxon_tab_options;
231

    
232
}
233

    
234
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
235
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
236
    array(
237
      'ZoologicalName' => array(
238
        'namePart' => array('name' => TRUE),
239
        'nameAuthorPart' => array('name' => TRUE),
240
        'referencePart' => array('authors' => TRUE),
241
        'microreferencePart' => array('microreference' => TRUE),
242
        'secReferencePart' => array('secReference' => TRUE,),
243
        'statusPart' => array('status' => TRUE),
244
        'descriptionPart' => array('description' => TRUE),
245
      ),
246
      'BotanicalName'=> array(
247
        'namePart' => array('name' => TRUE),
248
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
249
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
250
        'secReferencePart' => array('secReference' => 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
       'secReferencePart' => array(
267
         'secReference' => TRUE,
268
       ),
269
       'microreferencePart' => array(
270
          'microreference' => TRUE,
271
        ),
272
       'statusPart' => array(
273
          'status' => TRUE,
274
        ),
275
       'descriptionPart' => array(
276
          'description' => TRUE,
277
        ),
278
      )
279
    )
280
  )
281
);
282
define('CDM_PART_DEFINITIONS_DEFAULT_PRE_380', serialize(
283
    array(
284
      'ZoologicalName' => array(
285
        'namePart' => array('name' => TRUE),
286
        'nameAuthorPart' => array('name' => TRUE),
287
        'referencePart' => array('authors' => TRUE),
288
        'microreferencePart' => array('microreference' => TRUE),
289
        'statusPart' => array('status' => TRUE),
290
        'descriptionPart' => array('description' => TRUE),
291
      ),
292
      'BotanicalName'=> array(
293
        'namePart' => array('name' => TRUE),
294
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
295
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
296
        'referenceYearPart' => array('reference.year' => TRUE),
297
        'statusPart' => array('status' => TRUE),
298
        'descriptionPart' => array('description' => TRUE),
299
      ),
300
      '#DEFAULT' => array(
301
        'namePart' => array(
302
          'name' => TRUE
303
        ),
304
        'nameAuthorPart' => array(
305
          'name' => TRUE,
306
          'authors' => TRUE
307
        ),
308
        'referencePart' => array(
309
          'reference' => TRUE
310
        ),
311
        'microreferencePart' => array(
312
          'microreference' => TRUE,
313
        ),
314
        'statusPart' => array(
315
          'status' => TRUE,
316
        ),
317
        'descriptionPart' => array(
318
          'description' => TRUE,
319
        ),
320
      )
321
    )
322
  )
323
  );
324

    
325
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
326
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
327
  array (
328
    'taxon_page_title,polytomousKey'=> array(
329
        'namePart' => array('#uri' => TRUE),
330
      ),
331
    'not_in_current_classification' => array(
332
     'nameAuthorPart' => TRUE,
333
     'referencePart' => TRUE,
334
     'statusPart' => TRUE,
335
     'secReferencePart' => TRUE,
336
    ),
337
    'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy,name_page,registration_page'=> array(
338
      'nameAuthorPart' => array('#uri' => TRUE),
339
      'referencePart' => TRUE,
340
      'descriptionPart' => TRUE,
341
      'statusPart' => TRUE,
342
    ),
343
    'related_taxon.other_taxon_relationship.taxon_relationships.taxon_page_synonymy'=> array(
344
      'nameAuthorPart' => array('#uri' => TRUE),
345
      'referencePart' => TRUE,
346
      'descriptionPart' => TRUE,
347
      'statusPart' => TRUE,
348
      'secReferencePart' => TRUE,
349
    ),
350
    'related_taxon.misapplied_name_for.taxon_relationships.taxon_page_synonymy' => array(
351
      'nameAuthorPart' => array('#uri' => TRUE),
352
      'referencePart' => TRUE,
353
      'descriptionPart' => TRUE,
354
      'statusPart' => TRUE,
355
      /* no sec ref in this case, misapplied names are
356
       * de-duplicated and the sec ref is shown as footnote */
357
    ),
358
    'homonym'=> array(
359
        'nameAuthorPart' => array('#uri' => TRUE),
360
        'referenceYearPart' => TRUE,
361
        'statusPart' => TRUE,
362
    ),
363
    'acceptedFor,typedesignations,list_of_taxa' => array(
364
        'nameAuthorPart' => array('#uri' => TRUE),
365
        'referencePart' => TRUE,
366
      ),
367
    '#DEFAULT' => array(
368
        'nameAuthorPart' => array('#uri' => TRUE),
369
        'referencePart' => TRUE,
370
     )
371
  )
372
));
373
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
374
  array (
375
    'taxon_page_title,polytomousKey'=> array(
376
      'namePart' => array('#uri' => TRUE),
377
    ),
378
    'taxon_page_synonymy,related_taxon'=> array(
379
      'nameAuthorPart' => array('#uri' => TRUE),
380
      'referencePart' => TRUE,
381
      'statusPart' => TRUE,
382
      'descriptionPart' => TRUE,
383
    ),
384
    'homonym'=> array(
385
      'nameAuthorPart' => array('#uri' => TRUE),
386
      'referenceYearPart' => TRUE,
387
    ),
388
    'acceptedFor,typedesignations,list_of_taxa' => array(
389
      'nameAuthorPart' => array('#uri' => TRUE),
390
      'referencePart' => TRUE,
391
    ),
392
    '#DEFAULT' => array(
393
      'nameAuthorPart' => array('#uri' => TRUE),
394
      'referencePart' => TRUE,
395
    )
396
  )
397
));
398

    
399
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
400
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
401
    // to unset a default enntry set the value to 0
402
    array(
403
      'doTaxa'=>'doTaxa',
404
      'doSynonyms' => 'doSynonyms',
405
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
406
      'doMisappliedNames' => 'doMisappliedNames'
407
    )
408
  )
409
);
410

    
411
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
412

    
413
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
414
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
415
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
416

    
417
/* Gallery variables. */
418
$gallery_settings = array(
419
    "cdm_dataportal_show_taxon_thumbnails" => 1,
420
    "cdm_dataportal_show_synonym_thumbnails" => 0,
421
    "cdm_dataportal_show_thumbnail_captions" => 1,
422
    "cdm_dataportal_media_maxextend" => 120,
423
    "cdm_dataportal_media_cols" => 3,
424
    "cdm_dataportal_media_maxRows" => 1,
425
);
426

    
427
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
428
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
429
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
430
define('CDM_DATAPORTAL_TYPE_SPECIMEN_GALLERY_NAME', 'type_specimen_gallery');
431
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
432
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
433
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
434
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
435
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
436
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
437
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
438
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
439

    
440
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
441
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
442
  'media_representation_details_enabled' => 0
443
)));
444

    
445
/**
446
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
447
 * the synonymy.
448
 *
449
 * @var string
450
 */
451
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
452

    
453
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES', 'cdm_name_relationship_types');
454
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT', serialize(
455
    array(
456
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
457
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
458
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
459
    )
460
  )
461
);
462

    
463
define('CDM_NAME_RELATIONSHIP_LIST_TYPES', 'cdm_name_relationship_list_types');
464

    
465

    
466
/**
467
 * The drupal variable for the configuration of the information aggregation along
468
 * the taxon relation ships. The mapped array is associative and holds two elements:
469
 *    - direct: the uuids of the taxon relationship types to take into account in invers
470
 *      direction.
471
 *    - invers: the uuids of the taxon relationship types to take into account in direct
472
 *      direction.
473
 *
474
 * @var String
475
 */
476
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
477
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
478
    array(
479
        'direct'=>array(),
480
        'invers'=>array()
481
     )
482
   ));
483
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
484
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
485
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
486

    
487
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
488
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
489
      array(
490
      'filter_rules' => array(
491
        'statusOrderPreference' => 0,
492
        'subAreaPreference' => 0,
493
      ),
494
      'hiddenAreaMarkerType' => array()
495
     )
496
));
497

    
498
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
499
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
500
  "level_0" => array(
501
    'label_suffix' => ':',
502
    'status_glue' => '',
503
    'item_glue' => ' ',
504
    'item_group_prefix' => '',
505
    'item_group_postfix' => ''
506
  ),
507
  "level_1" => array(
508
    'label_suffix' => '',
509
    'status_glue' => '‒ ', // '&#8210; '
510
    'item_glue' => '; ',
511
    'item_group_prefix' => ', ',
512
    'item_group_postfix' => ''
513
  ),
514
  "level_2" => array(
515
    'label_suffix' => '',
516
    'status_glue' => '‒ ', // '&#8210; '
517
    'item_glue' => ', ',
518
    'item_group_prefix' => ' (',
519
    'item_group_postfix' => ')'
520
  )
521
)));
522

    
523
/**
524
 * Constant for the drupal variable key distribution_map_visibility
525
 *
526
 * possible values:
527
 *  - never
528
 *  - automatic
529
 *  - always
530
 */
531
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
532
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
533

    
534
/**
535
 * Constant for the drupal variable key specimen_map_visibility
536
 *
537
 * possible values:
538
 *  - never
539
 *  - automatic
540
 *  - always
541
 */
542
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
543
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
544

    
545
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
546
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
547
    array(
548
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
549
        'includeOccurrences' => 0,
550
        'includeTaxonNameDescriptions' => 0
551
     )
552
  ));
553

    
554
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
555
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
556
  // needs to be merged with user setting by drupal_array_merge_deep()
557
  // 'width' => 512, // optimum size for OSM layers is 512
558
  // 'height' => 512 / 2, // optimum size for OSM layers 256
559
  'aspect_ratio' => 2,
560
  'bbox' => '', // empty to allow automatic zooming to extend
561
  'maxZoom' => 15, // corresponds to the default in cdm_openlayers_map.defaults
562
  'show_labels' => FALSE,
563
  'caption' => '',
564
  'distribution_opacity' => '0.5',
565
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
566
  'image_map' => array(
567
    'base_layer' => '', // none, formerly this was cyprusdivs
568
    'bg_color' => '1874CD',
569
    'layer_style' => 'ffffff,606060,,',
570
  ),
571
  'openlayers' => array(
572
    'base_layers' =>  array(
573
      // A layer MUST NOT BE SET in the defaults,
574
      // otherwise it can not be overidden by the user settings:
575
      // 'mapproxy_vmap0' => 'mapproxy_vmap0',
576
      // it is sufficient to define the preferred layer,
577
      // since it will automatically be enabled:
578
      'PREFERRED' => 'mapproxy_vmap0'),
579
    'custom_wms_base_layer' => array(
580
      'name' => NULL,
581
      'url' => NULL,
582
      'params' =>  NULL,
583
      'projection' => NULL,
584
      'proj4js_def' => NULL,
585
      'max_extent' => NULL,
586
      'units' => NULL,
587
      'untiled' => FALSE
588
    ),
589
    'wms_overlay_layer' => array(
590
      'name' => NULL,
591
      'url' => NULL,
592
      'params' =>  NULL,
593
      'untiled' => FALSE
594
    ),
595
    'show_layer_switcher' => TRUE,
596
    'display_outside_max_extent' => FALSE,
597
    'google_maps_api_key' => NULL,
598
  ),
599
  'legend' => array(
600
    'show' => TRUE,
601
    'opacity' => '0.5',
602
    'font_size' => 10,
603
    'font_style' => FALSE,
604
    'icon_width' => 35,
605
    'icon_height' => 15
606
  )
607
)));
608

    
609
/**
610
 * Merges the named array variable with the array of defaults.
611
 *
612
 * IMPORTANT: The array keys must be strings. When the keys are integers
613
 * the merging will not take place for these entities. Number keyed entities
614
 * are just appended to the result array.
615
 *
616
 * @param string $variable_name
617
 *     The variable name
618
 * @param string | array $default
619
 *     The array containing the default values either as array or serialized as string.
620
 *     Unserialization is cared for if necessary
621
 * @return array
622
 *     The merged array as returned by drupal_array_merge_deep()
623
 *
624
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
625
 * TODO force $default being an array
626
 */
627
function get_array_variable_merged($variable_name, $default){
628

    
629
    // unserialize if nessecary
630
    if(!is_array($default)){
631
      $default = unserialize($default);
632
    }
633
    $variable = variable_get($variable_name, array());
634
    $result = drupal_array_merge_deep($default, $variable);
635
    return $result;
636
}
637

    
638
/**
639
 * @todo document this function.
640
 */
641
function getGallerySettings($gallery_config_form_name) {
642
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
643
}
644

    
645
/**
646
 * Returns the string representation of the default tab.
647
 *
648
 * @param bool $returnTabIndex
649
 *   Defaults to FALSE, if set true this function will return the index number
650
 *   of the default tab. (used to supply default values to form elements).
651
 */
652
function get_default_taxon_tab($returnTabIndex = FALSE) {
653

    
654
  global $user;
655
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
656
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
657
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
658
  // Get the user value if the used has chosen to overwrite the system settings.
659
  $user_tab_on = variable_get($user_tab_active, FALSE);
660
  if ($user_tab_on) {
661
    $user_value = variable_get($user_tab, 0);
662
    $index_value = $user_value;
663
    // Get the system value.
664
  }
665
  else {
666
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
667
    $index_value = $system_value;
668
  }
669

    
670
  // Return the index value or the string representation.
671
  if ($returnTabIndex) {
672
    return $index_value;
673
  }
674
  else {
675
    return ($values[$index_value]);
676
  }
677
}
678

    
679
/**
680
 * Provides the feature block settings for a specific feature which matches the $feature_uuid parameter.
681
 *
682
 * In case specifically configured settings array, like these which are stored in the drupal variables, is missing
683
 * one or more fields these fields are taken from the default. That is the specific settings are always merges
684
 * with the default.
685
 *
686
 * Note: These settings only apply to feature blocks which do not have a special rendering
687
 * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
688
 * 'special' element of the settings
689
 *
690
 * @param $feature_uuid
691
 *   The uuid string representation of the feature to return the settings for
692
 *
693
 * @return array
694
 *  an associative array of settings, with the following fields:
695
 *    - as_list: string
696
 *        this setting will be used in compose_feature_block_wrap_elements() as $enclosing_tag
697
 *        possible values are:
698
 *          div: not as list,
699
 *          ul: as bullet list,
700
 *          ol: as numbered list,
701
 *          dl: as definition list
702
 *        The tag used for the inner element, thus depends on the value of this field. The
703
 *        inner tag name can be retrieved by the function cdm_feature_block_element_tag_name()
704
 *    - link_to_reference: boolean,
705
 *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
706
 *    - link_to_name_used_in_source": boolean
707
 *        whether to show name in source information as link which will point to the according name page
708
 *    - sources_as_content (boolean)
709
 *        TRUE (int: 1):
710
 *          1. If element is of the CDM type TextData and the text is not empty the source references will be
711
 *             appended in brackets like "text (source references)". If the original source has name in source
712
 *             information it will be appended to the citation string,
713
 *             like : "(citation, as name in source; citation, as name in source)"
714
 *          2. if the text of the TextData is empty, the original source citations are the only content
715
 *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
716
 *             prepended to the citation string like: "name in source: citation"
717
 *        FALSE (int: 0):
718
 *          Original sources are put into the bibliography(=references) pseudo feature block. If the original source
719
 *          citations are the only content, the resulting feature block content would only consist of footnotes.
720
 *          In this case the display of the respective feature block is suppressed.
721
 *          TODO if the bibliography is not enabled the sources will be treated as footnotes like annotations,
722
 *               in future however they will in this case be shown in a separate references section for each
723
 *               feature block.
724
 *    - sources_as_content_to_bibliography  (boolean)
725
 *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
726
 *        in the bibliography.
727
 *    - sort_elements
728
 *        whether and how to sort the elements
729
 *        possible values are the constants SORT_ASC, SORT_DESC, NULL,
730
 *        some feature types (Distribution) also support: SORT_HIERARCHICAL (
731
 *        TODO option to exclude levels, put in special?,
732
 *        TODO make use of this setting in compose_feature_block_wrap_elements())
733
 *    - element_tag
734
 *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
735
 *        possible values are span | div. the proper inner tag name can be retrieved by the function
736
 *        cdm_feature_block_element_tag_name()
737
 *    - special: array()
738
 *        an array with further settings, this field can be used for special
739
 *        settings for specialized rendering like for distributions
740
 *  }
741
 *
742
 */
743
function get_feature_block_settings($feature_uuid = 'DEFAULT') {
744
  // the default must conform to the default parameter values of
745
  // compose_feature_block_wrap_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
746
  // compose_description_element_text_data() : asListElement = NULL
747

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

    
750
  // ---- DEFAULTS settings
751

    
752
  // only needed as final option, when the settings are not having a default
753
  $default = array(
754
    'DEFAULT' => array(
755
      'as_list' => 'div',
756
      'link_to_reference' => 0,
757
      'link_to_name_used_in_source' => 1,
758
      'sources_as_content' => 0,
759
      'sources_as_content_to_bibliography' => 0,
760
      'sort_elements' => NO_SORT,
761
      'glue' => '',
762
      'element_tag' => NULL
763
    ),
764
    // settings for pseudo feature bibliography
765
    // only hard coded here
766
    'BIBLIOGRAPHY' => array(
767
      'as_list' => 'div',
768
      'link_to_reference' => 0,
769
      'link_to_name_used_in_source' => 1,
770
      'sources_as_content' => 0,
771
      'sources_as_content_to_bibliography' => 0,
772
      'sort_elements' => NO_SORT,
773
      'glue' => '',
774
      'element_tag' => NULL
775
    )
776
  );
777

    
778
  // will be used as preset in the settings
779
  $other_themes_default = array(
780
    'DEFAULT' => array(
781
      'as_list' => 'div',
782
      'link_to_reference' => 0,
783
      'link_to_name_used_in_source' => 1,
784
      'sources_as_content' => 0,
785
      'sources_as_content_to_bibliography' => 0,
786
      'sort_elements' => NO_SORT,
787
      'glue' => '',
788
      'element_tag' => NULL
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_DISTRIBUTION => array(
801
      'as_list' => 'div', // currently ignored
802
      'link_to_reference' => 0,
803
      'link_to_name_used_in_source' => 0,
804
      'sources_as_content' => 0,
805
      'sources_as_content_to_bibliography' => 0,
806
      'sort_elements' => NO_SORT, // will cause ...
807
      'glue' => '',
808
      'element_tag' => 'div',
809
      'special' => array()
810
    ),
811
    UUID_COMMON_NAME => array(
812
      'as_list' => 'div',
813
      'link_to_reference' => 0,
814
      'link_to_name_used_in_source' => 1,
815
      'sources_as_content' => 0,
816
      'sources_as_content_to_bibliography' => 0,
817
      'sort_elements' => NO_SORT,
818
      'glue' => '',
819
      'element_tag' => 'span'
820
    ),
821
  );
822

    
823
  // ---- Special DEFAULTS for existing portals
824
  // TODO:
825
  // this can be removed once the feature block
826
  // settings have been deployed for the first time to these portals
827

    
828
  $cichorieae_default = array(
829
    'DEFAULT' => array(
830
      'as_list' => 'div',
831
      'link_to_reference' => 1,
832
      'link_to_name_used_in_source' => 1,
833
      'sources_as_content' => 1,
834
      'sources_as_content_to_bibliography' => 0,
835
      'sort_elements' => NO_SORT,
836
      'glue' => '',
837
      'element_tag' => 'div'
838
    ),
839
    UUID_CITATION => array(
840
      'as_list' => 'div',
841
      'link_to_reference' => 0,
842
      'link_to_name_used_in_source' => 0,
843
      'sources_as_content' => 1,
844
      'sources_as_content_to_bibliography' => 0,
845
      'sort_elements' => SORT_ASC,
846
      'glue' => '',
847
      'element_tag' => 'div'
848
    ),
849
    UUID_CHROMOSOMES_NUMBERS => array(
850
      'as_list' => 'ul',
851
      'link_to_reference' => 1,
852
      'link_to_name_used_in_source' => 1,
853
      'sources_as_content' => 1,
854
      'sources_as_content_to_bibliography' => 0,
855
      'sort_elements' => NO_SORT,
856
      'glue' => '',
857
      'element_tag' => 'div'
858
    ),
859
    UUID_CHROMOSOMES => array(
860
      'as_list' => 'ul',
861
      'link_to_reference' => 0,
862
      'link_to_name_used_in_source' => 1,
863
      'sources_as_content' => 1,
864
      'sources_as_content_to_bibliography' => 0,
865
      'sort_elements' => NO_SORT,
866
      'glue' => '',
867
      'element_tag' => 'div'
868
    ),
869
    UUID_COMMON_NAME => array(
870
      'as_list' => 'div',
871
      'link_to_reference' => 0,
872
      'link_to_name_used_in_source' => 1,
873
      'sources_as_content' => 0,
874
      'sources_as_content_to_bibliography' => 0,
875
      'sort_elements' => NO_SORT,
876
      'glue' => '',
877
      'element_tag' => 'span'
878
    ),
879
  );
880

    
881
  $palmweb_default = array(
882
    'DEFAULT' => array(
883
      'as_list' => 'ul',
884
      'link_to_reference' => 1,
885
      'link_to_name_used_in_source' => 1,
886
      'sources_as_content' => 1,
887
      'sources_as_content_to_bibliography' => 1,
888
      'sort_elements' => NO_SORT,
889
      'glue' => '',
890
      'element_tag' => NULL
891
    ),
892
    UUID_CITATION => array(
893
      'as_list' => 'ul',
894
      'link_to_reference' => 1,
895
      'link_to_name_used_in_source' => 1,
896
      'sources_as_content' => 0,
897
      'sources_as_content_to_bibliography' => 1,
898
      'sort_elements' => SORT_ASC,
899
      'glue' => '',
900
      'element_tag' => 'div'
901
    ),
902
    UUID_DISTRIBUTION => array(
903
      'as_list' => 'div', // currently ignored
904
      'link_to_reference' => 1,
905
      'link_to_name_used_in_source' => 1,
906
      'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
907
      'sources_as_content_to_bibliography' => 1,
908
      'sort_elements' => NO_SORT, // will cause ...
909
      'glue' => ', ',
910
      'element_tag' => 'span',
911
      'special' => array()
912
    ),
913
  );
914

    
915
  $cyprus_default = $cichorieae_default;
916
  $cyprus_default[UUID_DISTRIBUTION] = array(
917
    'as_list' => 'div', // currently ignored
918
    'link_to_reference' => 0,
919
    'link_to_name_used_in_source' => 0,
920
    'sources_as_content' => 0,
921
    'sources_as_content_to_bibliography' => 0,
922
    'sort_elements' => NO_SORT, // will cause ...
923
    'glue' => ' ',
924
    'element_tag' => 'div',
925
    'special' => array()
926
  );
927

    
928
  $default_theme = variable_get('theme_default', NULL);
929

    
930
  switch ($default_theme) {
931
    case 'garland_cichorieae':
932
      $settings_for_theme = $cichorieae_default;
933
      break;
934
    case 'cyprus':
935
      // cyprus: no longer used in production,
936
      // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
937
      $settings_for_theme = $cyprus_default;
938
      break;
939
    case 'flore_afrique_centrale':
940
    case 'flora_malesiana':
941
    case 'flore_gabon':
942
      $settings_for_theme = $cichorieae_default;
943
      $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
944
      break;
945
    case 'palmweb_2':
946
      $settings_for_theme = $palmweb_default;
947
      break;
948
    default:
949
      $settings_for_theme = $other_themes_default;
950
  }
951
  // add pseudo feature settings
952
  $settings_for_theme['BIBLIOGRAPHY'] = $default['BIBLIOGRAPHY'];
953

    
954
  // ---- END of DEFAULTS
955

    
956
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
957

    
958
  $feature_block_setting = null;
959

    
960
  if (isset($saved_settings[$feature_uuid])) {
961
    $feature_block_setting = $saved_settings[$feature_uuid];
962
  }
963
  else if (isset($settings_for_theme[$feature_uuid])) {
964
    $feature_block_setting = $settings_for_theme[$feature_uuid];
965
  }
966
  else if (isset($settings_for_theme['DEFAULT'])) {
967
    $feature_block_setting = $settings_for_theme['DEFAULT'];
968
  }
969

    
970
  // now merge the default and specific settings
971
  $settings_to_merge = array($default['DEFAULT']);
972
  if(is_array($saved_settings)){
973
    $settings_to_merge[] = $saved_settings['DEFAULT'];
974
  }
975
  if(isset($feature_block_setting)){
976
    $settings_to_merge[] = $feature_block_setting;
977
  }
978
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
979

    
980
  return $feature_block_setting;
981
}
982

    
983
/**
984
 * returns the current setting for the original source bibliography
985
 *
986
 * Caches internally
987
 *
988
 * @return array
989
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
990
 *   - 'enabled': 1|0
991
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
992
 */
993
function get_bibliography_settings($clear_cache = false){
994
  static $bibliography_settings = null;
995
  if(!$bibliography_settings || $clear_cache){
996
    $bibliography_settings = get_array_variable_merged(
997
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
998
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
999
    );
1000
  }
1001
  return $bibliography_settings;
1002
}
1003

    
1004
/**
1005
 * @todo Please document this function.
1006
 * @see http://drupal.org/node/1354
1007
 */
1008
function cdm_dataportal_menu_admin(&$items) {
1009
  // Display section on admin/config page.
1010
  $items['admin/config/cdm_dataportal'] = array(
1011
    'title' => 'CDM Dataportal',
1012
    'description' => 'Settings for the CDM DataPortal.',
1013
    'position' => 'right',
1014
    'weight' => 10,
1015
    'page callback' => 'system_admin_menu_block_page',
1016
    'access arguments' => array('administer cdm_dataportal'),
1017
    'file' => 'system.admin.inc',
1018
    'file path' => drupal_get_path('module', 'system'),
1019
  );
1020
  $items['admin/config/cdm_dataportal/settings'] = array(
1021
    'title' => 'Settings',
1022
    'description' => 'Settings for the CDM DataPortal.',
1023
    'weight' => 0,
1024
    'page callback' => 'drupal_get_form',
1025
    'page arguments' => array('cdm_settings_general'),
1026
    'access arguments' => array('administer cdm_dataportal'),
1027
    'type' => MENU_NORMAL_ITEM,
1028
  );
1029
  $items['admin/config/cdm_dataportal/settings/general'] = array(
1030
    'title' => 'General',
1031
    'description' => 'General',
1032
    'weight' => 0,
1033
    'page callback' => 'drupal_get_form',
1034
    'page arguments' => array('cdm_settings_general'),
1035
    'access arguments' => array('administer cdm_dataportal'),
1036
    'type' => MENU_DEFAULT_LOCAL_TASK,
1037
  );
1038

    
1039
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
1040
    'title' => 'Cache',
1041
    'description' => 'Cache',
1042
    'access arguments' => array('administer cdm_dataportal'),
1043
    'page callback' => 'drupal_get_form',
1044
    'page arguments' => array('cdm_settings_cache'),
1045
    'weight' => 10,
1046
    'type' => MENU_LOCAL_TASK,
1047
  );
1048

    
1049
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
1050
    'title' => 'Geo & Map',
1051
    'description' => 'Geo & Map',
1052
    'access arguments' => array('administer cdm_dataportal'),
1053
    'page callback' => 'drupal_get_form',
1054
    'page arguments' => array('cdm_settings_geo'),
1055
    'weight' => 1,
1056
    'type' => MENU_LOCAL_TASK,
1057
  );
1058

    
1059
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
1060
    'title' => 'Layout',
1061
    'description' => 'Configure and adjust the layout of your DataPortal ',
1062
    'access arguments' => array('administer cdm_dataportal'),
1063
    'page callback' => 'drupal_get_form',
1064
    'page arguments' => array('cdm_settings_layout'),
1065
    'weight' => 2,
1066
    'type' => MENU_LOCAL_TASK,
1067
  );
1068

    
1069
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
1070
    'title' => 'Taxon page',
1071
    'description' => 'Configure and adjust the layout of your DataPortal ',
1072
    'access arguments' => array('administer cdm_dataportal'),
1073
    'page callback' => 'drupal_get_form',
1074
    'page arguments' => array('cdm_settings_layout_taxon'),
1075
    'weight' => 1,
1076
    'type' => MENU_LOCAL_TASK,
1077
  );
1078
  $items['admin/config/cdm_dataportal/settings/layout/name-page'] = array(
1079
    'title' => 'Name page',
1080
    'description' => 'Configure and adjust the layout of your DataPortal ',
1081
    'access arguments' => array('administer cdm_dataportal'),
1082
    'page callback' => 'drupal_get_form',
1083
    'page arguments' => array('cdm_settings_layout_name_page'),
1084
    'weight' => 1,
1085
    'type' => MENU_LOCAL_TASK,
1086
  );
1087
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1088
    'title' => 'Search',
1089
    'description' => 'Configure and adjust the layout of your DataPortal ',
1090
    'access arguments' => array('administer cdm_dataportal'),
1091
    'page callback' => 'drupal_get_form',
1092
    'page arguments' => array('cdm_settings_layout_search'),
1093
    'weight' => 2,
1094
    'type' => MENU_LOCAL_TASK,
1095
  );
1096

    
1097
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1098
    'title' => 'Media',
1099
    'description' => 'Configure and adjust the layout of your DataPortal ',
1100
    'access arguments' => array('administer cdm_dataportal'),
1101
    'page callback' => 'drupal_get_form',
1102
    'page arguments' => array('cdm_settings_layout_media'),
1103
    'weight' => 3,
1104
    'type' => MENU_LOCAL_TASK,
1105
  );
1106

    
1107
}
1108

    
1109
/**
1110
 * @todo document this function.
1111
 */
1112
function cdm_help_general_cache() {
1113
  $form = array();
1114
  $form['cache_help'] = array(
1115
    '#type' => 'fieldset',
1116
    '#title' => t('Help'),
1117
    '#collapsible' => TRUE,
1118
    '#collapsed' => TRUE,
1119
  );
1120
  $form['cache_help']['test'] = array('#value' => t('probando'));
1121
  return drupal_render($form);
1122
  $res = array();
1123
  $res['default'] = drupal_render($help);
1124
  return $res;
1125
}
1126

    
1127
/**
1128
 * Configures the settings form for the CDM-API module.
1129
 *
1130
 * @return array
1131
 *   Drupal settings form.
1132
 */
1133
function cdm_settings_general() {
1134

    
1135
  $form['cdm_webservice'] = array(
1136
    '#type' => 'fieldset',
1137
    '#title' => t('CDM Server'),
1138
    '#collapsible' => FALSE,
1139
    '#collapsed' => FALSE,
1140
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1141
        CDM data base to the web via RESTful web services and thus is the source of the data
1142
        to be displayed by a CDM DataPotal.'),
1143
  );
1144

    
1145
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1146
    '#type' => 'textfield',
1147
    '#title' => t('CDM web service URL') . ':',
1148
    '#description' => t('This is the URL to the CDM-Server exposing your data
1149
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1150
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1151
  );
1152

    
1153
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1154
    '#type' => 'markup',
1155
    '#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')
1156
      . ' visible only for administrators',
1157
  );
1158

    
1159
  $form['cdm_webservice']['freetext_index'] = array(
1160
    '#type' => 'fieldset',
1161
    '#title' => t('Freetext index'),
1162
    '#collapsible' => FALSE,
1163
    '#collapsed' => FALSE,
1164
  );
1165

    
1166
  // Check the cdmserver port number and display a waring if it is not port 80
1167
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1168
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1169
    $form['cdm_webservice']['freetext_index']['message'] = array(
1170
      '#markup' => "<div class=\"description\">"
1171
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1172
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1173
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1174
          array('!port' => $portNumberMatch[1][0])
1175
        )
1176
      . "</div>",
1177
    );
1178
  };
1179

    
1180
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1181
  $trigger_link_options = array(
1182
    'attributes' => array(
1183
      'class' => 'index-trigger'
1184
    ),
1185
  );
1186
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1187
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1188
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1189
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1190
      ))
1191
    . '<div id="index-progress"></div></div>',
1192
  );
1193

    
1194
  $form['cdm_webservice']['freetext_index']['cdm_login'] = array(
1195
    // this must not be stored, it is only used by the _add_js_cdm_ws_progressbar
1196
    '#type' => 'textfield',
1197
    '#title' => t('Login'),
1198
    '#description' => t('Your cdm user credentials in the following form: <code>user:password</code>')
1199
  );
1200
  drupal_add_js('
1201
        jQuery(document).ready(function() {
1202
             jQuery("#edit-cdm-login").change(function (e) {
1203
                var login = jQuery(e.target).val();
1204
                jQuery("#edit-freetext-index .index-trigger").each(function(index){
1205
                   var url = jQuery(this).attr("href");
1206
                   url = url.replace(/:\/\/[^@]+@|:\/\//, "://" + login + "@");
1207
                   jQuery(this).attr("href", url);
1208
                });
1209
            });
1210
        });
1211
      ',
1212
    array(
1213
      'type' => 'inline',
1214
      'scope' => 'footer'
1215
    )
1216
  );
1217
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1218

    
1219
  $form['cdm_webservice']['proxy'] = array(
1220
    '#type' => 'fieldset',
1221
    '#title' => t('Proxy'),
1222
    '#collapsible' => TRUE,
1223
    '#collapsed' => TRUE,
1224
  );
1225

    
1226
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1227
    '#type' => 'textfield',
1228
    '#title' => t('Proxy URL') . ':',
1229
    '#description' => t('If this proxy url is set the cdm api tries
1230
    to connect the web service over the given proxy server.
1231
    Otherwise proxy usage is deactivated.'),
1232
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1233
  );
1234

    
1235
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1236
    '#type' => 'textfield',
1237
    '#title' => t('Proxy port') . ':',
1238
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1239
  );
1240

    
1241
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1242
    '#type' => 'textfield',
1243
    '#title' => t('Login') . ':',
1244
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1245
  );
1246

    
1247
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1248
    '#type' => 'textfield',
1249
    '#title' => t('Password') . ':',
1250
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1251
  );
1252

    
1253
  $form['sub_tree_filter'] = array(
1254
    '#type' => 'fieldset',
1255
    '#title' => t('Subtree filter'),
1256
    '#collapsible' => FALSE,
1257
    '#collapsed' => TRUE,
1258
    '#description' => t('The Data Portal can be restricted to the taxa which belong to a specific classification subtree. Other taxa will not be shown or accessible otherwise.'),
1259
  );
1260

    
1261
  $sub_tree_filter_uuid_value = variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE);
1262
  $taxon_node_info = '';
1263
  if($sub_tree_filter_uuid_value){
1264
    $taxon_node_dto = cdm_ws_get(CDM_WS_TAXONNODE, array($sub_tree_filter_uuid_value));
1265
    if($taxon_node_dto){
1266
      $taxon_node_info = " Current taxon node: <strong>" . cdm_tagged_text_to_markup($taxon_node_dto->taggedTitle) . " [" . $taxon_node_dto->treeIndex . "]</strong>";
1267
    }
1268
  }
1269
  $form['sub_tree_filter'][CDM_SUB_TREE_FILTER_UUID] = array(
1270
    '#type' => 'textfield',
1271
    '#title' => t('Taxon Node UUID') . ':',
1272
    '#default_value' => variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE),
1273
    '#description' => "The uuid of the TaxonNode entity to be used as filter." . $taxon_node_info
1274
  );
1275

    
1276
  // TODO: settings are still incomplete, compare with
1277
  // trunk/dataportal/inc/config_default.php.inc.
1278
  $form['taxon_tree'] = array(
1279
    '#type' => 'fieldset',
1280
    '#title' => t('Taxon Tree'),
1281
    '#collapsible' => FALSE,
1282
    '#collapsed' => TRUE,
1283
    '#description' => t('<p>When you explore your collection, you can navigate
1284
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1285
      able to navigate through your collection the
1286
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1287
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1288
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1289
      </a></p>'),
1290
  );
1291

    
1292
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1293
    '#type' => 'select',
1294
    '#title' => t('Default classification') . ':',
1295
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1296
    '#options' => cdm_get_taxontrees_as_options(),
1297
    '#description' => t('The default taxa classification to be used in the whole portal. 
1298
      This affects most obviously the classification browser and the search in case it is restricted 
1299
      to a specific classification. See also <i>Included Classifications</i> below.'),
1300
  );
1301

    
1302
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1303
    '#type' => 'select',
1304
    '#title' => t('Rank of highest displayed taxon') . ':',
1305
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1306
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1307
    '#options' => cdm_vocabulary_as_option(UUID_RANK, null, true),
1308
    '#description' => t('This is the rank of the highest displayed taxon in the
1309
      <em>taxon tree</em>. You can select here which rank should be at the top
1310
      level of the tree structure.'),
1311
  );
1312

    
1313
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1314
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1315
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1316
      '#type' => 'checkboxes',
1317
      '#title' => t('Included Classifications') . ':',
1318
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1319
      '#options' => cdm_get_taxontrees_as_options(),
1320
      '#description' => t('Only the checked classifications will be available in the classification chooser.'),
1321
  );
1322

    
1323
  $form['distribution'] = array(
1324
      '#type' => 'fieldset',
1325
      '#title' => t('Distributions'),
1326
      '#collapsible' => FALSE,
1327
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1328
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1329
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1330
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1331
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1332
          '<p>
1333
          </p>',
1334
  );
1335

    
1336
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1337
      '#type' => 'fieldset',
1338
      '#title' => 'Distribution filter',
1339
      '#collapsible' => FALSE,
1340
      '#collapsed' => FALSE,
1341
      '#tree' => TRUE,
1342
      '#description' => 'The Distribution filter offers the following options
1343
      <ul>
1344
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1345
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1346
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1347
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1348
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1349
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1350
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1351
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1352
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1353
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1354
      </ul>'
1355
  );
1356

    
1357
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1358
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1359
      '#type' => 'checkboxes',
1360
      '#title' => 'Filter rules',
1361
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1362
      '#options' => array(
1363
          'statusOrderPreference' => 'Status order preference rule',
1364
          'subAreaPreference' => 'Sub area preference rule'
1365
      ),
1366
  );
1367

    
1368
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1369
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1370
      '#type' => 'checkboxes',
1371
      '#title' => 'Hide marked area filter',
1372
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1373
      '#options' => $marker_type_options,
1374
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1375
  );
1376

    
1377
  $form['aggregation'] = array(
1378
      '#type' => 'fieldset',
1379
      '#title' => t('Aggregation of data'),
1380
      '#collapsible' => FALSE,
1381
      '#description' => 'This section covers the different aspects of aggregating information.
1382
          <p>
1383
          </p>',
1384
  );
1385

    
1386
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1387
      '#type' => 'checkboxes',
1388
      '#title' => 'Taxon media filter',
1389
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1390
      '#options' => array(
1391
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1392
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1393
          'includeOccurrences' => 'Media related to specimens and occurrences',
1394
      ),
1395
      '#description' => 'This filter configures which images should be taken into account.',
1396
  );
1397

    
1398
  $form['aggregation']['notice'] = array(
1399
      '#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
1400
          want to make use of the caching capabilities of the dataportal.',
1401
  );
1402

    
1403
  $form['aggregation']['media_aggregation'] = array(
1404
      '#type' => 'fieldset',
1405
      '#title' => t('Media aggregation'),
1406
      '#collapsible' => FALSE,
1407
      '#collapsed' => TRUE,
1408
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1409

    
1410
  );
1411
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1412
      '#type' => 'select',
1413
      '#title' => t('Aggregation of taxon pictures') . ':',
1414
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1415
      '#options' => array(
1416
          0 => "Show only pictures of the current taxon",
1417
          1 => "Include pictures of taxonomic children",
1418
      ),
1419
      '#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."),
1420
  );
1421

    
1422
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1423
      '#type' => 'fieldset',
1424
      '#attributes' => array('class' => array('clearfix')),
1425
      '#title' => t('Aggregation via taxon relationsships'),
1426
      '#collapsible' => TRUE,
1427
      '#collapsed' => TRUE,
1428
      '#tree' => TRUE,
1429
      '#description' => t('Information on taxa will be aggregated along the below chosen
1430
          taxon relation ships. This will affect images and occurrences (specimens).
1431
          Taxon relation ships are directed and point form one taxon to another. The taxon
1432
          relationships to be taken into accunt can therefore configured for the direct direction
1433
          and for the inverse.'),
1434
  );
1435

    
1436
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1437
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1438

    
1439
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1440
      '#type' => 'checkboxes',
1441
      '#title' => t('Direct'),
1442
      '#options' => $taxonRelationshipTypeOptions,
1443
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1444
  );
1445
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1446
      '#type' => 'checkboxes',
1447
      '#title' => t('Invers'),
1448
      '#options' => $taxonRelationshipTypeOptions,
1449
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1450
  );
1451

    
1452
  $form['drupal_integration'] = array(
1453
    '#type' => 'fieldset',
1454
    '#attributes' => array('class'=> array('clearfix')),
1455
    '#title' => t('Drupal integration'),
1456
    '#collapsible' => FALSE,
1457
    '#collapsed' => FALSE,
1458
    '#tree' => FALSE
1459
  );
1460

    
1461
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1462
    '#type' => 'checkbox',
1463
    '#title' => 'Create drupal nodes',
1464
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1465
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1466
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1467
    cdm pages it is required that drupal nodes are created and stored in the database.'
1468
  );
1469

    
1470

    
1471

    
1472
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1473
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1474
    <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>',
1475
  );
1476
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1477
    '#type' => 'submit',
1478
    '#value' => t('Drop all cdm nodes'),
1479
    '#submit' => array('drop_all_cdm_nodes_submit')
1480
  );
1481

    
1482
  $form['drupal_integration']['drop_all_cdm_nodes_warning_post'] = array(
1483
    '#markup' => '<div class="description">All Drupal nodes created for cdm content can be deleted at once using this button.</div>',
1484
  );
1485

    
1486
    // ----------------------
1487
  $form['cdm_js_devel_mode'] = array(
1488
      '#type' => 'checkbox',
1489
      '#title' => 'Java-script developer mode',
1490
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1491
      '#description' => 'In production envirionments the java script libraries
1492
      the cdm_dataportal is making use of are compressed and optimized. This
1493
      is good for performance but a caveat if you need to debug java-script. When the
1494
      java-script developer mode is enabled the uncompressed and commented developer
1495
      versions of java-script libraries will be used where possible.
1496
      <br/><strong>Do not use this option in production!</strong>'
1497
  );
1498
  // ----------------------
1499
  $form['cdm_debug_mode'] = array(
1500
      '#type' => 'checkbox',
1501
      '#title' => 'CDM page debug mode',
1502
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1503
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1504
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1505
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1506
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1507
      The log is written by the drupal devel module function <code>dd()</code>.
1508
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1509
  );
1510

    
1511
  // Comment @WA: D7 form api does not support reset buttons,
1512
  // so to mimic the D5 reset button we add one like this.
1513
  $form['actions']['reset'] = array(
1514
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1515
    '#weight' => 1000,
1516
  );
1517

    
1518
  $form['#submit'][] = 'cdm_settings_general_submit';
1519

    
1520
  return system_settings_form($form);
1521
}
1522

    
1523
/**
1524
 * Submit callback; drops all cdm nodes.
1525
 *
1526
 * @ingroup forms
1527
 */
1528
function drop_all_cdm_nodes_submit($form, &$form_state) {
1529
  cdm_delete_all_cdm_nodes();
1530
  drupal_set_message(t('All cdm nodes dropped.'));
1531
}
1532

    
1533

    
1534
/**
1535
 * LAYOUT settings
1536
 *
1537
 * @return array
1538
 *   The form structure.
1539
 */
1540
function cdm_settings_layout() {
1541

    
1542
  $form = array();
1543

    
1544
  $form['about'] = array(
1545
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1546
      layout. If you want to configure the specific sites layout visit the
1547
      respective configuration site for taxon, search or media.') . '</p>',
1548
  );
1549

    
1550
  $form['annotations'] = array(
1551
    '#type' => 'fieldset',
1552
    '#title' => t('Annotations'),
1553
    '#collapsible' => FALSE,
1554
    '#collapsed' => FALSE,
1555
    '#description' => t('This sections allows configuring global settings regarding annotations and thus will affect annotations dispayed as footnote and others.'),
1556
  );
1557

    
1558
  $annotation_type_options = cdm_terms_by_type_as_option('AnnotationType');
1559
  // Additional option for the NULL case.
1560
  $annotation_type_options['NULL_VALUE'] = t('untyped');
1561
  $annotations_types_visible = variable_get(ANNOTATION_TYPES_VISIBLE, unserialize(EXTENSION_TYPES_VISIBLE_DEFAULT));
1562
  $form['annotations'][ANNOTATION_TYPES_VISIBLE] = array(
1563
    '#type' => 'checkboxes',
1564
    '#title' => t('Visbility of annotation types'),
1565
    '#description' => t("Only annotations of the selected type will be displayed. You may want to turn 'technical annotations' off."),
1566
    '#options' => $annotation_type_options,
1567
    '#default_value' => $annotations_types_visible
1568
  );
1569

    
1570
  $form['extensions'] = array(
1571
    '#type' => 'fieldset',
1572
    '#title' => t('Extensions'),
1573
    '#collapsible' => FALSE,
1574
    '#collapsed' => FALSE,
1575
    '#description' => t('This sections allows configuring global settings regarding the data type extensions.'),
1576
  );
1577

    
1578
  $extension_type_options = cdm_terms_by_type_as_option('ExtensionType');
1579
  $extension_types_visible = variable_get(EXTENSION_TYPES_VISIBLE, unserialize(EXTENSION_TYPES_VISIBLE_DEFAULT));
1580
  $form['extensions'][EXTENSION_TYPES_VISIBLE] = array(
1581
    '#type' => 'checkboxes',
1582
    '#title' => t('Visbility of extension types'),
1583
    '#description' => t("Only extensions of the selected type will be displayed."),
1584
    '#options' => $extension_type_options,
1585
    '#default_value' => $extension_types_visible
1586
  );
1587

    
1588

    
1589
  // ---- original source --- //
1590
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1591
      '#type' => 'fieldset',
1592
      '#tree' => TRUE,
1593
      '#title' => t('Source Citations'),
1594
      '#collapsible' => FALSE,
1595
      '#collapsed' => FALSE,
1596
  );
1597

    
1598
  $bibliography_settings = get_bibliography_settings(true);
1599

    
1600
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1601
      '#type' => 'checkbox',
1602
      '#title' => t('Original Source in bibliography'),
1603
      '#default_value' => $bibliography_settings['enabled'],
1604
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1605
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1606
       into the bibliography also depends on the settings in the ' .
1607
        l("Taxon profile feature block settings", "admin/config/cdm_dataportal/settings/layout/taxon") .
1608
        '. 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.'),
1609
  );
1610

    
1611
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1612
    '#type' => 'select',
1613
    '#title' => t('The format of the key numerals'),
1614
    '#default_value' => $bibliography_settings['key_format'],
1615
    '#options' => array('latin' => 'Latin',
1616
      'ROMAN' => 'Roman (upper case)',
1617
      'roman' => 'Roman (lower case)',
1618
      'ALPHA'=> 'Alphabet (upper case)',
1619
      'alpha' => 'Alphabet (lower case)')
1620
  );
1621

    
1622
  // --- Advanced Search --- //
1623
  $form['asearch'] = array(
1624
      '#type' => 'fieldset',
1625
      '#title' => t('Advanced search'),
1626
      '#collapsible' => FALSE,
1627
      '#collapsed' => FALSE,
1628
  );
1629
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1630
      '#type' => 'checkbox',
1631
      '#title' => t('Show advanced search link'),
1632
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1633
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1634
  );
1635

    
1636
  // --- Name page autoredirect feature --- //
1637
  $form['name_page'] = array(
1638
    '#type' => 'fieldset',
1639
    '#title' => t('Name page'),
1640
    '#collapsible' => FALSE,
1641
    '#collapsed' => FALSE,
1642
  );
1643
  $form['name_page'][CDM_NAME_PAGE_AUTOREDIRECT] = array(
1644
    '#type' => 'checkbox',
1645
    '#title' => 'Always redirect to taxon',
1646
    '#default_value' => variable_get(CDM_NAME_PAGE_AUTOREDIRECT, 0),
1647
    '#description' => t('By checking this option you can globally enable the redirection behavior of the name page. 
1648
    Depending on the context from which a user navigates to the name page the data portal chooses to show the name page or it redirects to the related taxon if there is only one. 
1649
    This option allows to enable this behavior also for contexts in which the redirection normally is not active.'),
1650
  );
1651

    
1652
  // --- Registrations --- //
1653
  $form['registrations'] = array(
1654
    '#type' => 'fieldset',
1655
    '#title' => t('Registrations'),
1656
    '#collapsible' => FALSE,
1657
    '#collapsed' => FALSE,
1658
  );
1659
  $form['registrations']['cdm_registration_presistent_identifier_as_link'] = array(
1660
    '#type' => 'checkbox',
1661
    '#title' => t('Use the persistent http identifier as link'),
1662
    '#default_value' => variable_get('cdm_registration_presistent_identifier_as_link', 0),
1663
    '#description' => t('Switch the portal from using the drupal path <code>registration/{url encoded persistent http identifier}</code> to using the persistent http identifier directly as link.'),
1664
  );
1665

    
1666
  // ---- Taxon Name Rendering --- //
1667
  $form['taxon_name'] = array(
1668
      '#type' => 'fieldset',
1669
      '#title' => t('Taxon name display'),
1670
      '#collapsible' => TRUE,
1671
      '#collapsed' => TRUE,
1672
      '#description' => t('The display of taxon names is configured by two parts.
1673
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1674
          The name parts are defined in the <stong>part definitions</strong>'),
1675
  );
1676

    
1677
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1678
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1679
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1680
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1681

    
1682
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1683
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1684
    $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.)';
1685
  } else if($is_custom_part_definition){
1686
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1687
  } else  {
1688
    $which_version_message = '(These are the default part definition.)';
1689
  }
1690

    
1691
  $diff_viewer_markup = '';
1692
  if($is_custom_part_definition){
1693
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1694
  }
1695

    
1696
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1697
    . $which_version_message
1698
    . '</div>'
1699
    . $diff_viewer_markup;
1700

    
1701
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1702
      '#type' => 'textarea',
1703
      '#title' => t('Part definitions'),
1704
      '#element_validate' => array('form_element_validate_json'),
1705
      '#default_value' =>  $current_part_definition_json,
1706
      '#description' => '
1707
          <p>' . $which_version_message . '</p>
1708
          <p>
1709
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1710
          </p>
1711
          <p>
1712
           A full taxon name plus additional information can consist of the following elements:
1713
          <ul>
1714
             <li>name: the taxon name inclugin rank nbut without author</li>
1715
             <li>authors:  The authors of a reference, also used in taxon names</li>
1716
             <li>reference: the nomenclatural reference,</li>
1717
             <li>microreference:  Volume, page number etc.</li>
1718
             <li>status:  The nomenclatural status of a name</li>
1719
             <li>description: name descriptions like protologues etc ...</li>
1720
          </ul>
1721
          </p>
1722
          <p>
1723
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1724
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1725
           The following parts can be formed and are recognized by the system:
1726
          <ul>
1727
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1728
            <li>authorshipPart: the author (for example: "L.")</li>
1729
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1730
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1731
               be combined when a link to the taxon is rendered.</li>
1732
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1733
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1734
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1735
            <li>statusPart: the nomenclatorical status</li>
1736
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1737
          </ul>
1738
          </p>
1739
          <p>
1740
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1741
           specific parts part definitions:
1742
          <ul>
1743
            <li>BotanicalName</li>
1744
            <li>ZoologicalName</li>
1745
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1746
          </ul>
1747
           An example:
1748
          <pre>
1749
           {
1750
            "ZoologicalName": {
1751
              "namePart": {
1752
                "name": true
1753
              },
1754
              "referencePart": {
1755
                "authors": true
1756
              },
1757
              "microreferencePart": {
1758
                "microreference": true
1759
              },
1760
              "statusPart": {
1761
                "status": true
1762
              },
1763
              "descriptionPart": {
1764
                "description": true
1765
              }
1766
            },
1767
            "BotanicalName": {
1768
              "namePart": {
1769
                "name": true,
1770
                "authors": true
1771
              },
1772
              "referencePart": {
1773
                "reference": true,
1774
                "microreference": true
1775
              },
1776
              "secReferencePart": {
1777
                "secReference": true
1778
              },
1779
              "statusPart": {
1780
                "status": true
1781
              },
1782
              "descriptionPart": {
1783
                "description": true
1784
              }
1785
            }
1786
          }
1787
           </pre>',
1788
  );
1789

    
1790
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1791
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1792
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1793
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1794
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1795

    
1796
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1797
    $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.)';
1798
  } else if($is_custom_render_template){
1799
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1800
  } else {
1801
    $which_version_message = '(These are the default render templates.)';
1802
  }
1803

    
1804
  $diff_viewer_markup = '';
1805
  if($is_custom_render_template){
1806
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1807
  }
1808

    
1809
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1810
    . $which_version_message
1811
    . '</div>'
1812
    . $diff_viewer_markup;
1813

    
1814
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1815
      '#type' => 'textarea',
1816
      '#title' => t('Name render templates'),
1817
      '#element_validate' => array('form_element_validate_json'),
1818
      '#default_value' =>  $current_render_templates_json,
1819
      '#description' => '
1820
          <p>' . $which_version_message . '</p>
1821
          <p>
1822
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1823
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1824
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1825
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1826
          The following render Path keys are currently recognized:
1827
          <ul>
1828
            <li>list_of_taxa</li>
1829
            <li>acceptedFor</li>
1830
            <li>homonym</li>
1831
            <li>taxon_page_synonymy</li>
1832
            <li>typedesignations</li>
1833
            <li>taxon_page_title</li>
1834
            <li>polytomousKey</li>
1835
            <li>na: name + authorship</li>
1836
            <li>nar:name + authorship + reference</li>
1837
            <li>#DEFAULT</li>
1838
          </ul>
1839
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1840
          array element should be a comma separated list of render paths, without any whitespace!.
1841
          </p>
1842
          <p>
1843
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1844
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1845
          <p>
1846
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1847
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1848
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1849
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1850
          links if the paramters $nameLink or $refenceLink are given to the name render function
1851
          (this is hard coded and cannot be configured here).',
1852
  );
1853

    
1854
  // @WA: D7 form api does not support reset buttons,
1855
  // so to mimic the D5 reset button we add one like this.
1856
  $form['actions']['reset'] = array(
1857
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1858
    '#weight' => 1000,
1859
  );
1860

    
1861
  $form['#submit'] = array('submit_json_as_php_array');
1862
  // #json_elements especially defined for submit_json_as_php_array()
1863
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1864
  return system_settings_form($form);
1865
}
1866

    
1867

    
1868
/**
1869
 * @param $form_name
1870
 * @param $form_title
1871
 * @param $collapsed
1872
 * @param string $form_description
1873
 *   The description for the fieldset of the gallery setting.
1874
 * @return mixed
1875
 */
1876
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1877
  $form[$form_name] = array(
1878
    '#type' => 'fieldset',
1879
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1880
    '#collapsible' => TRUE,
1881
    '#collapsed' => $collapsed,
1882
    '#tree' => TRUE,
1883
    '#description' => $form_description,
1884
  );
1885

    
1886
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1887
  $gallery_settings = variable_get($form_name, $default_values);
1888
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1889
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1890
    /*
1891
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1892
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1893
    '#type' => 'textfield',
1894
    '#title' => t('Search Page Size'),
1895
    '#default_value' => $test,
1896
    '#description' => t('Number of Names to display per page in search results.')
1897
    );
1898
    */
1899
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1900
      '#type' => 'checkbox',
1901
      '#title' => t('Show media thumbnails for accepted taxa'),
1902
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1903
    );
1904

    
1905
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1906
      '#type' => 'checkbox',
1907
      '#title' => t('Show media thumbnails for synonyms'),
1908
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1909
      '#description' => '',
1910
    );
1911
  }
1912

    
1913
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1914
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1915
    '#type' => 'checkbox',
1916
    '#title' => t('Show captions under thumbnails'),
1917
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1918
    '#description' => '',
1919
  );
1920

    
1921
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1922
    '#type' => 'textfield',
1923
    '#title' => t('Thumbnail size (max of width or height)') . ':',
1924
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1925
    '#description' => t('The maximum extend in either dimension, width or height, in pixels for the thumbnail images in the gallery.'),
1926
  );
1927

    
1928
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1929
    '#type' => 'textfield',
1930
    '#title' => t('Number of columns') . ':',
1931
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1932
    '#description' => t('Group the thumbnails in columns: select how many
1933
      columns the gallery should display.'),
1934
  );
1935

    
1936
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1937
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1938
      '#type' => 'textfield',
1939
      '#title' => t('Maximum number of rows') . ':',
1940
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1941
      '#description' => t('You can group the thumbnails in rows, select in how
1942
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1943
        If you want an unlimited number of rows please set to 0.'),
1944
    );
1945
  }
1946

    
1947
  return $form;
1948
}
1949

    
1950
/**
1951
 * @return array
1952
 *   The form structure.
1953
 */
1954
function cdm_settings_layout_taxon() {
1955
  $collapsed = FALSE;
1956
  $form = array();
1957

    
1958
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1959

    
1960
  // --------- TABBED TAXON ------- //
1961
  $form['taxon_node'] = array(
1962
    '#type' => 'fieldset',
1963
    '#title' => t('Taxon node'),
1964
    '#collapsible' => TRUE,
1965
    '#collapsed' => TRUE,
1966
    '#description' => 'Taxa are organized in a classification tree by taxon nodes. Display of taxon node related information like states can be manged here.'
1967
  );
1968
  $form['taxon_node'][CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES] = array(
1969
    '#type' => 'checkbox',
1970
    '#title' => t('Show taxon node states'),
1971
    '#default_value' => variable_get(CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES, 1),
1972
    '#description' => t('Show the taxon node states excluded, unplaced and placement doubtful.'),
1973
  );
1974

    
1975
  // --------- TABBED TAXON ------- //
1976
  $form['taxon_tabs'] = array(
1977
    '#type' => 'fieldset',
1978
    '#title' => t('Taxon tabs'),
1979
    '#collapsible' => TRUE,
1980
    '#collapsed' => TRUE,
1981
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
1982
  );
1983

    
1984
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1985
    '#type' => 'checkbox',
1986
    '#title' => t('Tabbed taxon page'),
1987
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1988
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1989
  );
1990

    
1991
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
1992
    '#type' => 'checkbox',
1993
    '#title' => t('Synonymy as tab'),
1994
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
1995
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
1996
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
1997
  );
1998

    
1999
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
2000
    '#type' => 'checkboxes',
2001
    '#title' => t('Section/Tab visibility') . ':',
2002
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
2003
    '#options' => get_taxon_options_list()
2004
  );
2005

    
2006
  // WEIGHT
2007
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
2008
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
2009
    '#title'  => 'Section/Tab order',
2010
    '#type' => 'fieldset',
2011
    '#collapsible' => false,
2012
    '#tree' => true,
2013
    '#description' => 'The weight value defines the order of the section/tab.'
2014
  );
2015
  // Weights range from -delta to +delta, so delta should be at least half
2016
  // of the amount of tabs present.
2017
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
2018
  foreach (get_taxon_tabs_list() as $label) {
2019
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
2020
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
2021
        '#title' => $label,
2022
        '#type'  => 'weight',
2023
        '#default_value' => $taxon_tabs_weights[$key],
2024
        '#delta' => $tab_weight_delta
2025
    );
2026
  }
2027

    
2028
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
2029
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
2030
    '#title'  => 'Section/Tab label override',
2031
    '#type' => 'fieldset',
2032
    '#collapsible' => false,
2033
    '#tree' => true,
2034
    '#description' => 'Setting a label for a section/tab will override the default label. 
2035
      Please enter the label text in the default language of the portal.'
2036
  );
2037
  foreach (get_taxon_tabs_list() as $label) {
2038
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
2039
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
2040
      '#title' => $label,
2041
      '#type'  => 'textfield',
2042
      '#default_value' => $taxon_tabs_labels[$key]
2043
    );
2044
  }
2045

    
2046
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
2047
    '#type' => 'select',
2048
    '#title' => t('Default tab to display') . ':',
2049
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
2050
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
2051
    '#description' => t('<p>Select the default tab to display when visiting a
2052
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
2053
      <strong>Note:</strong> After performing a search and clicking in any
2054
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
2055
      taxon and not the above selected tab.'),
2056
  );
2057

    
2058
  /* ======  TAXON_PROFILE ====== */
2059
  $form['taxon_profile'] = array(
2060
    '#type' => 'fieldset',
2061
    '#title' => t('Taxon profile (tab)'),
2062
    '#description' => t('<p>This section covers the settings related to the taxon
2063
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
2064
    '#collapsible' => TRUE,
2065
    '#collapsed' => TRUE,
2066
  );
2067

    
2068
  // ---- PROFILE PICTURE ----//
2069

    
2070
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
2071
    '#type' => 'fieldset',
2072
    '#tree' => TRUE,
2073
    '#title' => t('Taxon profile picture'),
2074
    '#collapsible' => TRUE,
2075
    '#collapsed' => FALSE,
2076
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
2077
  );
2078

    
2079
  //FIXME migrate variables:
2080
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
2081
  // FIXME
2082
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
2083

    
2084
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
2085

    
2086
  /*
2087
   * 'show' => 1,
2088
   * 'maxextend' => 184,
2089
   * 'media_uri_query' => ''
2090
   * 'custom_placeholder_image_on' => 1,
2091
   * 'custom_placeholder_image_fid' => ''
2092
   */
2093
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
2094
    '#type' => 'checkbox',
2095
    '#title' => t('Enable profile picture'),
2096
    '#description' => t('Show the profile picture.'),
2097
    '#default_value' => $taxon_profile_image_settings['show'],
2098
  );
2099

    
2100
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
2101
      '#type' => 'textfield',
2102
      '#tree' => TRUE,
2103
      '#title' => t('Profile picture maximum extend'),
2104
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
2105
      '#field_suffix' => 'px',
2106
      '#maxlength' => 4,
2107
      '#size' => 4,
2108
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
2109
  );
2110

    
2111
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
2112
      '#type' => 'textfield',
2113
      '#tree' => TRUE,
2114
      '#title' => t('Additional URI query parameter'),
2115
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
2116
      '#maxlength' => 1024,
2117
      '#size' => 60,
2118
      '#description' => t('Additional query parameters to be used when requesting for the  
2119
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
2120
            The query parameters will be appended to the uri of the media representation part
2121
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
2122
  );
2123

    
2124
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2125
    '#type' => 'checkbox',
2126
    '#title' => t('Show the placeholder image'),
2127
    '#description' => t("A placeholder image will be shown if no taxon profile picture is available."),
2128
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2129
  );
2130

    
2131
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2132
      '#type' => 'checkbox',
2133
      '#title' => t('Use a custom placeholder image'),
2134
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2135
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2136
  );
2137

    
2138
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2139
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2140
        '#type' => 'managed_file',
2141
        '#title' => t('Custom placeholder image file'),
2142
        '#progress_indicator' => 'bar',
2143
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2144
    //       '#name' => 'custom_placeholder_image',
2145
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2146
    );
2147

    
2148
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2149
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2150
      $url = file_create_url($profile_image_file->uri);
2151
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2152
                '#type' => 'item',
2153
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2154
      );
2155
    }
2156
  } else {
2157
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2158
      '#type' => 'hidden',
2159
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2160
    );
2161
  }
2162

    
2163
  $options = cdm_vocabulary_as_option(UUID_RANK, null, true);
2164
  array_unshift($options, '-- DISABLED --');
2165
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2166
    '#type' => 'select',
2167
    '#title' => t('Hide profile picture for higher ranks') . ':',
2168
    '#default_value' => variable_get('image_hide_rank', '0'),
2169
    '#options' => $options,
2170
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2171
  );
2172

    
2173
  // -- MEDIA THUMBNAILS -- //
2174
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2175
  $form_title = 'Taxon Profile Images';
2176
  $form_description = '<p>The different sections 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>';
2177
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2178

    
2179
  // ---- FEATURE TREE BLOCKS ---- //
2180
  $form['taxon_profile']['feature_blocks'] = array(
2181
    '#type' => 'fieldset',
2182
    '#title' => t('Feature Blocks'),
2183
    '#collapsible' => TRUE,
2184
    '#collapsed' => FALSE,
2185
    '#description' => t("This section covers settings related to the taxon's
2186
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2187
      features such as description, distribution, common names"),
2188
  );
2189
  $featureTrees = cdm_get_featureTrees_as_options(TRUE, TRUE);
2190
  $profile_feature_tree = get_profile_feature_tree();
2191
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2192
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2193
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2194
  }
2195
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2196
    '#type' => 'radios',
2197
    '#title' => t('Taxon profile feature tree') . ':',
2198
    '#default_value' => $profile_feature_tree_uuid,
2199
    '#options' =>  $featureTrees['options'],
2200
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2201
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2202
    '#description' => t('The Feature Tree selected defines the type and order 
2203
    of the according feature blocks visible in the taxon profile page. A feature block 
2204
    only is shown if any data for it is present. The block weight is shown after the feature label in brackets'
2205
    ),
2206
  );
2207

    
2208
  $pseudo_feature_weights = get_array_variable_merged(CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS, CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT);
2209
  $form['taxon_profile']['feature_blocks'][CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS] = array(
2210
    '#title'  => 'Pseudo feature block weight',
2211
    '#type' => 'fieldset',
2212
    '#collapsible' => false,
2213
    '#tree' => true,
2214
    '#description' => 'Weights for the pseudo feature blocks. The weight value defines the 
2215
    position in the list of blocks. The weight of normal feature is defined by the position 
2216
    of the according feature. Please see the specific feature details above to find the feature weight.'
2217
  );
2218
  foreach ([PSEUDO_FEATURE_NUMBER_OF_TAXA, PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS, PSEUDO_FEATURE_BIBLIOGRAPHY] as $ps_feature) {
2219
    $form['taxon_profile']['feature_blocks'][CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS][$ps_feature] = array(
2220
      '#title' => $ps_feature,
2221
      '#type'  => 'textfield',
2222
      '#element_validate' => array('element_validate_number'),
2223
      '#size' => 4,
2224
      '#default_value' => $pseudo_feature_weights[$ps_feature]
2225
    );
2226
  }
2227

    
2228

    
2229
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2230
  $profile_feature_tree = get_profile_feature_tree();
2231

    
2232
  if (isset($profile_feature_tree->root->childNodes)) {
2233

    
2234
    $form_feature_block_layout = array(
2235
      '#type' => 'fieldset',
2236
      '#tree' => true,
2237
      '#title' => t('Taxon profile feature block settings'),
2238
      '#collapsible' => TRUE,
2239
      '#collapsed' => FALSE,
2240
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2241
      A sub form for each of the the currently selected feature tree allows to configure each feature block individually.
2242
      The subforms have the following settings in common:<br />
2243
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2244
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2245
      <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>
2246
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2247
            <ol>
2248
            <li>If the element is a CDM TextData instance and if the text is not empty the source references will be
2249
                appended in brackets like "text (source references)". If the original source has name in source
2250
                information it will be appended to the citation string,
2251
                like : "(citation-A, as name-in-source-A; citation-B, as name-in-source-B)"</li>
2252
             <li>if the text of the TextData is empty, the original source citations are the only content
2253
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2254
                prepended to the citation string like: "name in source: citation"</li>
2255
            </ol>
2256
            <strong>If disabled:</strong><br />
2257
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2258
             citations are the only content, the resulting feature block content would only consist of footnotes.
2259
             In this case the display of the respective feature block is suppressed.</div>
2260
      </dl>
2261
      <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
2262
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2263
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2264
        . '</em></div>
2265
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2266
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2267
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2268
      <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>
2269
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2270
           cdm_feature_block_element_tag_name()</div>
2271
       <h6>Element glue:</h6><div>This string is used to concatenate individual items together. The glue is ignored when the items are displayed 
2272
           as list.<b>NOTE:</b>The glue is not yet fully implemented for all features and thus may not work as expected, see '
2273
           . l('#6831', 'https://dev.e-taxonomy.eu/redmine/issues/6831') . '</div>',
2274
    );
2275

    
2276

    
2277
    $feature_list_layout_settings_disabled = FALSE;
2278

    
2279
    // creating helper object to retrieve the default settings
2280
    $featureNode = new stdClass();
2281
    $featureNode->term = new stdClass();
2282
    $featureNode->term->uuid="DEFAULT";
2283
    $featureNode->term->representation_L10n = "Default";
2284
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2285

    
2286
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2287

    
2288
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2289

    
2290
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2291
        $subform_id = $featureNode->term->uuid;
2292
        $feature_block_setting = get_feature_block_settings($featureNode->term->uuid);
2293

    
2294
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2295

    
2296
        $form_feature_block_layout[$subform_id] = array(
2297
          '#type' => 'fieldset',
2298
          '#tree' => TRUE,
2299
          '#title' => $featureNode->term->representation_L10n,
2300
          '#collapsible' => FALSE,
2301
          '#collapsed' => FALSE,
2302
        );
2303
        if($featureNode->term->uuid == "DEFAULT"){
2304
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2305
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2306
          references</em> and <em>names in source</em> is only possible in the defaults';
2307
        }
2308

    
2309
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2310
          '#type' => 'select',
2311
          '#title' => 'List type',
2312
          '#default_value' => $feature_block_setting['as_list'],
2313
          '#options' => array(
2314
            'div' => 'not as list',
2315
            'ul' => 'bullet list',
2316
            'ol' => 'numbered list',
2317
            'dl' => 'definition list'
2318
          ),
2319
        );
2320

    
2321
        if($featureNode->term->uuid == "DEFAULT"){
2322
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2323
            '#type' => 'checkbox',
2324
            '#title' => t('Link to reference'),
2325
            '#default_value' => $feature_block_setting['link_to_reference'],
2326
          );
2327

    
2328
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2329
            '#type' => 'checkbox',
2330
            '#title' => 'Link to name used in source',
2331
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2332
          );
2333
        }
2334

    
2335
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2336
          '#type' => 'checkbox',
2337
          '#title' => 'Sources as content',
2338
          '#default_value' => $feature_block_setting['sources_as_content'],
2339
        );
2340

    
2341
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2342
          '#type' => 'checkbox',
2343
          '#title' => 'Put sources also as content to bibliography',
2344
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2345
        );
2346

    
2347
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2348
          '#type' => 'select',
2349
          '#title' => t('Sort elements'),
2350
          '#default_value' => $feature_block_setting['sort_elements'],
2351
          '#options' => array(
2352
            NO_SORT => 'No sorting',
2353
            SORT_ASC => 'Ascending',
2354
            SORT_DESC => 'Descending',
2355
            SORT_HIERARCHICAL => 'Hierarchical'
2356
          ),
2357
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2358
          <dl>
2359
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2360
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2361
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2362
          <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>
2363
          </dl>',
2364
        );
2365

    
2366
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2367
          '#type' => 'select',
2368
          '#title' => t('Element tag'),
2369
          '#options' => array(
2370
            'span' => 'span',
2371
            'div' => 'div',
2372
            'p' => 'p'
2373
          ),
2374
          '#default_value' => $feature_block_setting['element_tag'],
2375
        );
2376
        $form_feature_block_layout[$subform_id]['glue'] = array(
2377
          '#type' => 'textfield',
2378
          '#title' => t('Element glue'),
2379
          '#default_value' => $feature_block_setting['glue'],
2380
          '#size' => 10
2381
      );
2382

    
2383
      }
2384
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2385
    }
2386
  }
2387

    
2388
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2389
  $form['taxon_profile']['structured_description_featuretree'] = array(
2390
    '#type' => 'fieldset',
2391
    '#title' => t('Structured Description Feature Tree'),
2392
    '#collapsible' => TRUE,
2393
    '#collapsed' => FALSE,
2394
  );
2395
  $featureTrees = cdm_get_featureTrees_as_options();
2396
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2397
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2398
    $profile_feature_tree_uuid = NULL;
2399
  }
2400
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2401
    '#type' => 'radios',
2402
    '#title' => t('Natural language representation of structured descriptions') . ':',
2403
    '#default_value' => $profile_feature_tree_uuid,
2404
    '#options' => $featureTrees['options'],
2405
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2406
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2407
    '#description' => t('Taxon descriptions can be stored in a highly structured
2408
      form. The feature tree selected here will be used to generate textual
2409
      representation in natural language.'
2410
    ),
2411
  );
2412

    
2413

    
2414

    
2415
  // ---- DISTRIBUTION LAYOUT ---- //
2416
  $form['taxon_profile']['distribution_layout'] = array(
2417
    '#title' => t('Distribution'),
2418
    '#collapsible' => TRUE,
2419
    '#collapsed' => FALSE,
2420
    '#type' => 'fieldset',
2421
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2422
        Map settings regarding the geometry, layers, etc are found in the '
2423
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2424
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2425
      . l(
2426
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2427
        array('fragment' => 'edit-feature-block-settings')
2428
      )
2429
      . ' More general settings regrading the filtering of Distributions are found at '
2430
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2431
      . '. (These settings here will be merged in future releases into the feature block settings)',
2432

    
2433
  );
2434

    
2435
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2436

    
2437
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2438
    '#type' => 'checkbox',
2439
    '#title' => t('Condensed distribution'),
2440
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2441
    '#description' => 'This option enables the display of a very compact representation
2442
    of the distribution which includes also information on the status.',
2443
  );
2444

    
2445
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2446
    '#type' => 'select',
2447
    '#title' => t('Condensed distribution recipe'),
2448
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2449
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2450
    '#description' => 'Recipe for creating the condensed distribution.',
2451
  );
2452

    
2453
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2454
    '#type' => 'textfield',
2455
    '#title' => t('Condensed distribution info path'),
2456
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2457
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2458
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2459
  );
2460

    
2461

    
2462
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2463
    '#type' => 'radios',
2464
    '#title' => t('Display mode') . ':',
2465
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2466
    '#options' => array(
2467
      'FLAT_ALPHA' => t('Flat list'),
2468
      'TREE' => t('Hierarchically ordered'),
2469
    ),
2470
    '#description' => 'Taxon distribution information is displayed with
2471
    focus on the area of the distribution. The list of areas can either be shown
2472
    as flat list ordered alphabetically or in the hierarchical of the parent
2473
    area and subarea relationship. Fall back areas areas with no Distribution data
2474
    are hidden from the area hierarchy so that their sub areas will move one level up.
2475
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2476
    ' for details on the <em>Marked area filter</em>.',
2477
  );
2478

    
2479
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2480
    '#type' => 'fieldset',
2481
    '#tree' => true,
2482
    '#title' => t('Distribution hierarchy style')
2483
  );
2484

    
2485
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2486
  foreach(array_keys($hierarchy_styles) as $level) {
2487
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2488
      '#type' => 'fieldset',
2489
      '#tree' => true,
2490
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2491
      '#attributes' => array('class' => array('fieldset-float'))
2492
    );
2493
    foreach ($hierarchy_styles[$level] as $key => $value) {
2494
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2495
        '#type' => 'textfield',
2496
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2497
        '#default_value' => $hierarchy_styles[$level][$key],
2498
        '#maxlength' => 4,
2499
        '#size' => 4
2500
      );
2501
    }
2502
  }
2503

    
2504
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2505
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2506
    '#type' => 'checkboxes',
2507
    '#title' => 'Omit area levels',
2508
    '#options' => $level_options,
2509
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2510
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2511
    Areas which belong to the selected area levels will be hidden in the portal.',
2512
  );
2513

    
2514
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2515
    '#type' => 'checkbox',
2516
    '#title' => t('Show TextData elements on top of the map'),
2517
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2518
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2519
      elements on top of the map. Otherwise all <code>TextData</code>
2520
      distribution elements will be listed below the other area elements.
2521
      This option is useful if you need to have descriptive texts for each
2522
      distribution map.'),
2523
  );
2524

    
2525
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2526
      '#type' => 'textarea',
2527
      '#title' => t('Custom status colors'),
2528
      '#element_validate' => array('form_element_validate_json'),
2529
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2530
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2531
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2532
          reference list of the idInVocabulary values of absence and presence terms:
2533
<pre>
2534
Presence Term
2535
p	present
2536
pd	present: doubtfully present
2537
n	native
2538
nq	native: presence questionable
2539
nd	native: doubtfully native
2540
c	cultivated
2541
i	introduced
2542
iq	introduced: presence questionable
2543
id	introduced: doubtfully introduced (perhaps cultivated only)
2544
ip	introduced: uncertain degree of naturalisation
2545
ia	introduced: adventitious (casual)
2546
in	introduced: naturalized
2547
ic	introduced: cultivated
2548
e	endemic for the relevant area
2549
na	naturalised
2550
iv	invasive
2551

    
2552
AbsenceTerm
2553
a	absent
2554
f	reported in error
2555
nf	native: reported in error
2556
if	introduced: reported in error
2557
cf	cultivated: reported in error
2558
ne	native: formerly native
2559
ie	introduced: formerly introduced
2560

    
2561
</pre>'),
2562
  );
2563

    
2564

    
2565
  /* ====== SYNONYMY ====== */
2566
  $form['taxon_synonymy'] = array(
2567
    '#type' => 'fieldset',
2568
    '#title' => t('Taxon synonymy (tab)'),
2569
    '#collapsible' => TRUE,
2570
    '#collapsed' => TRUE,
2571
    '#description' => t('This section covers the settings related to the taxon
2572
      <strong>synonymy</strong> tab.'),
2573
  );
2574

    
2575
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2576
    '#type' => 'checkbox',
2577
    '#title' => t('Accepted taxon on top of the synonymy'),
2578
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT),
2579
    '#description' => t('If checked, the first homotypic taxon is a repetition
2580
      of the accepted taxon most likely with the full nomenclatural reference, 
2581
      depending on the ' . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout') . '.'),
2582
  );
2583

    
2584
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE] = array(
2585
    '#type' => 'checkbox',
2586
    '#title' => t('Secundum referenence as separate line above the accepted taxon.'),
2587
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE, 0),
2588
    '#description' => t('You may want to remove the <code>"secReferencePart": true,</code> entry from <code>"accepted_taxon.taxon_page_synonymy"{</code> the in the '
2589
      . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout')
2590
      . ' (Only applicable when the "Show accepted taxon on top of the synonymy" option above is enabled.)'),
2591
    '#disabled' =>  !variable_get(CDM_DATAPORTAL_NOMREF_IN_TITLE, CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT)
2592
  );
2593

    
2594
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL] = array(
2595
    '#type' => 'textfield',
2596
    '#description' => 'Label for the secundum referenence.',
2597
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT),
2598
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', 0)
2599
    );
2600

    
2601
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2602
    '#type' => 'checkbox',
2603
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2604
      coming from a synonym link.'),
2605
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2606
    '#description' => t('Check this if after doing a search and clicking on a
2607
      synonym you want to see the "accept of" text for the accepted synonym.'),
2608
  );
2609

    
2610
  $form['taxon_synonymy']['taxon_relations'] = array(
2611
    '#type' => 'fieldset',
2612
    '#title' => t('Taxon relationships'),
2613
    '#collapsible' => FALSE,
2614
    '#collapsed' => FALSE
2615
  );
2616

    
2617
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2618
    '#type' => 'checkbox',
2619
    '#title' => t('Show taxon relations ships of accepted taxon'),
2620
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2621
    '#description' => t('If this option is enabled the synonymy will show the
2622
      below selected taxon relationships of accepted taxa.'),
2623
  );
2624

    
2625
  $taxon_relationship_type_options = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2626
  $taxon_relationship_type_defaults = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
2627
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2628
    '#type' => 'checkboxes',
2629
    '#title' => t('Taxon relationship types') . ':',
2630
    '#description' => 'Only taxon relationships of the selected type will be displayed',
2631
    '#options' => $taxon_relationship_type_options,
2632
    '#default_value' => $taxon_relationship_type_defaults,
2633
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2634
  );
2635

    
2636
  $form['taxon_synonymy']['name_relations'] = array(
2637
    '#type' => 'fieldset',
2638
    '#title' => t('Name relationships'),
2639
    '#collapsible' => FALSE,
2640
    '#collapsed' => FALSE
2641
  );
2642

    
2643
  $name_relationship_type_options = cdm_vocabulary_as_option(
2644
      UUID_NAME_RELATIONSHIP_TYPE,
2645
      '_cdm_relationship_type_term_label_callback',
2646
      false,
2647
      array('uuid' => '/' .UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM . '|'
2648
        . UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM . '|'
2649
        . UUID_NAMERELATIONSHIPTYPE_CONSERVED_AGAINST . '|'
2650
        . UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR . '|'
2651
        . UUID_NAMERELATIONSHIPTYPE_MISSPELLING . '|'
2652
        . UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT . '/' )
2653
  );
2654
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_INLINE_TYPES] = array(
2655
    '#type' => 'checkboxes',
2656
    '#title' => t('Name relationship types') . ':',
2657
    '#description' => 'This setting only affects specific types of name relations which are displayed appended to scientific name. 
2658
    A full listing of all name relationships for a scientific name is provided by the taxon ' . l('name page', 'admin/config/cdm_dataportal/settings/layout/name-page') . '.',
2659
    '#options' => $name_relationship_type_options,
2660
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT)),
2661
  );
2662

    
2663
  // ====== SPECIMENS ====== //
2664
  $form['taxon_specimens'] = array(
2665
    '#type' => 'fieldset',
2666
    '#title' => t('Taxon specimens (tab)'),
2667
    '#collapsible' => TRUE,
2668
    '#collapsed' => TRUE,
2669
    '#description' => t('This section covers the settings related to the taxon
2670
      <strong>specimens</strong> tab.'),
2671
  );
2672

    
2673
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2674

    
2675
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2676
    '#type' => 'checkbox',
2677
    '#title' => t('Show specimen derivatives in a compressed table'),
2678
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2679
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2680
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2681
  );
2682

    
2683
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2684
      '#type' => 'textfield',
2685
      '#title' => t('Number of records per page') . ':',
2686
      '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2687
  );
2688

    
2689
    $form['taxon_specimens']['cdm_dataportal_specimen_derivate_tree'] = array(
2690
        '#type' => 'checkbox',
2691
        '#title' => t('Show specimen derivatives in a tree view'),
2692
        '#default_value' => variable_get('cdm_dataportal_specimen_derivate_tree', CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE),
2693
        '#description' => t('If checked, the specimen will be listed in a tree view.'),
2694
    );
2695

    
2696

    
2697
    $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2698
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2699
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2700
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2701
  }
2702
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2703
    '#type' => 'radios',
2704
    '#title' => t('Specimen description feature tree') . ':',
2705
    '#default_value' => $profile_feature_tree_uuid,
2706
    '#options' =>  $featureTrees['options'],
2707
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2708
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2709
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2710
    ),
2711
  );
2712

    
2713
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2714
  $form_title = t('Specimen media');
2715
  $form_description = t('Specimens may have media which is displayed at the
2716
     Specimen tab/section as a gallery. It is possible to configure the
2717
     thumbnails gallery here, however for configuring how a single media should
2718
     be displayed please go to !url.</p>',
2719
     array(
2720
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2721
     ));
2722
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2723

    
2724
  // --- MEDIA GALLERY ---- //
2725
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2726
  $form_title = 'Media gallery (tab)';
2727
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2728
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2729
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2730
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2731
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2732
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2733
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2734

    
2735
  // Comment @WA: D7 form api does not support reset buttons,
2736
  // so to mimic the D5 reset button we add one like this.
2737
  $form['actions']['reset'] = array(
2738
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2739
    '#weight' => 1000,
2740
  );
2741
  return system_settings_form($form);
2742
}
2743

    
2744
/**
2745
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2746
 *
2747
 * @param $map_id
2748
 * @param $form
2749
 * @return mixed
2750
 */
2751
function _cdm_map_visibility_setting($map_id)
2752
{
2753
  return array(
2754
    '#type' => 'select',
2755
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2756
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2757
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2758
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2759
        The map also can forced to show up <b>always</b> or <b>never</b>."
2760
  );
2761
}
2762

    
2763
/**
2764
 * @return array
2765
 *   The form structure.
2766
 */
2767
function cdm_settings_layout_search() {
2768

    
2769
  $form = array();
2770

    
2771
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2772

    
2773
  $form['search_settings'] = array(
2774
    '#type' => 'fieldset',
2775
    '#title' => t('Taxa Search'),
2776
    '#collapsible' => FALSE,
2777
    '#collapsed' => FALSE,
2778
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2779
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2780
         where they can write the text to be searched. You can find Drupal block configuration
2781
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2782
  );
2783

    
2784
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2785
      '#type' => 'checkbox',
2786
      '#title' => t('Ignore the chosen classification in simple search'),
2787
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2788
      '#description' => t('The simple search, which can be executed via the search block,
2789
          will by default search on the classification selected in the classification browser
2790
          selector. Set the tick if you want your portal to search on all classifications.'),
2791
  );
2792

    
2793
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2794
    '#type' => 'checkbox',
2795
    '#title' => t('Run simple search with free-text search backend.'),
2796
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2797
    '#description' => t('The simple search uses by default another search
2798
      backend as the advances search. By checking this option the simple search can be
2799
      configured to also use the free-text search backend.'),
2800
  );
2801

    
2802
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2803
    '#type' => 'checkbox',
2804
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2805
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2806
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2807
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2808
  );
2809

    
2810
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2811
    '#type' => 'textfield',
2812
    '#title' => t('Results per page') . ':',
2813
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2814
    '#description' => t('Number of results to display per page.'),
2815
  );
2816

    
2817
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2818
    '#type' => 'checkbox',
2819
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2820
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2821
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2822
  );
2823

    
2824
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2825
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2826
      '#type' => 'checkboxes',
2827
      '#title' => 'Search mode',
2828
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2829
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2830
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2831
          defaults set here.',
2832
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2833
      '#default_value' => $search_mode_default
2834
      );
2835

    
2836
  $form['search_settings'][CDM_SEARCH_AREA_FILTER_PRESET] = array(
2837
    '#type' => 'textarea',
2838
    '#title' => t('area_filter_preset') . ':',
2839
    '#default_value' => variable_get(CDM_SEARCH_AREA_FILTER_PRESET, ''), // '05b0dd06-30f8-477d-bf4c-30d9def56320' =>  Caucasia (Ab + Ar + Gg + Rf(CS)) (Cc)
2840

    
2841
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2842
  );
2843

    
2844
    $form['blast_search_settings'] = array(
2845
        '#type' => 'fieldset',
2846
        '#title' => t('Blast Search'),
2847
        '#collapsible' => TRUE,
2848
        '#collapsed' => TRUE,
2849
        '#description' => t('<p>To perform blast searchs
2850
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2851
         where they can write the text to be searched. You can find Drupal block configuration
2852
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p>
2853
         <p>To perform a blast search a blast database for the cdm instance is needed.</p> '),
2854
    );
2855

    
2856
    $form['blast_search_settings'][CDM_SEARCH_BLAST_ENABLED] = array(
2857
        '#type' => 'checkbox',
2858
        '#title' => t('Activate Blast search') . ':',
2859
        '#default_value' => variable_get(CDM_SEARCH_BLAST_ENABLED, 0), // '05b0dd06-30f8-477d-bf4c-30d9def56320' =>  Caucasia (Ab + Ar + Gg + Rf(CS)) (Cc)
2860

    
2861
        '#description' => t('Activate the blast search for this portal, this works only with an existing blast database!'),
2862
    );
2863
    $form['blast_search_settings'][CDM_SEARCH_BLAST_SERVICE_URI] = array(
2864
        '#type' => 'textfield',
2865
        '#title' => t('Webservice URL for blast search') . ':',
2866
        '#default_value' => variable_get(CDM_SEARCH_BLAST_SERVICE_URI, 'http://130.133.70.28:9001/api/sequence'),
2867

    
2868
        '#description' => t('Enter the webservice URL for blast search'),
2869
    );
2870

    
2871
  // --- SEARCH TAXA GALLERY ---- //
2872
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2873
  $collapsed = FALSE;
2874
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2875
  $form_title = 'Taxa Search thumbnails';
2876
  $form_description = 'Search results may show thumbnails. ';
2877
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2878

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

    
2888

    
2889
/**
2890
 * @return array
2891
 *   The form structure.
2892
 */
2893
function cdm_settings_layout_name_page()
2894
{
2895

    
2896
  $form = array();
2897

    
2898

    
2899
  $form['name_relations'] = array(
2900
    '#type' => 'fieldset',
2901
    '#title' => t('Name relationship listings'),
2902
    '#collapsible' => FALSE,
2903
    '#collapsed' => FALSE
2904
  );
2905

    
2906
  $name_relationship_type_options = cdm_vocabulary_as_option(
2907
    UUID_NAME_RELATIONSHIP_TYPE,
2908
    '_cdm_relationship_type_term_label_callback',
2909
    false
2910
  );
2911
  $form['name_relations'][CDM_NAME_RELATIONSHIP_LIST_TYPES] = array(
2912
    '#type' => 'checkboxes',
2913
    '#title' => t('Name relationship types') . ':',
2914
    '#description' => 'This setting only affects specific types of name relations which are displayed as list. Another representations 
2915
    is the inline style used in the synonymy which may show a different (reduced) set of name relations. 
2916
    The according settings can be adjusted in the ' . l('taxon page settings section synonmy', 'admin/config/cdm_dataportal/settings/layout/taxon') . '.',
2917
    '#options' => $name_relationship_type_options,
2918
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_LIST_TYPES, cdm_vocabulary_as_defaults(UUID_NAME_RELATIONSHIP_TYPE)),
2919
  );
2920

    
2921
  $form[CDM_NAME_PAGE_SECTION_TAXA] = array (
2922
    '#type' => 'checkbox',
2923
    '#title' => 'Show the associated taxa section',
2924
    '#default_value' => variable_get(CDM_NAME_PAGE_SECTION_TAXA, CDM_NAME_PAGE_SECTION_TAXA_DEFAULT)
2925

    
2926
  );
2927

    
2928
  return system_settings_form($form);
2929
}
2930

    
2931
/**
2932
 * @return array
2933
 *   The form structure.
2934
 */
2935
function cdm_settings_layout_media() {
2936

    
2937
  $form = array();
2938

    
2939
  $form['media_settings'] = array(
2940
    '#type' => 'fieldset',
2941
    '#title' => t('Media settings'),
2942
    '#collapsible' => FALSE,
2943
    '#collapsed' => FALSE,
2944
    '#description' => 'This section covers layout settings for media pages.'
2945
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2946
  );
2947

    
2948
  $form['media_settings'][CDM_MEDIA_GALLERY_VIEWER] = array(
2949
    '#type' => 'select',
2950
    '#title' => t('Image viewer') . ':',
2951
    '#default_value' => variable_get(CDM_MEDIA_GALLERY_VIEWER, CDM_MEDIA_GALLERY_VIEWER_DEFAULT),
2952
    '#options' => array(
2953
      CDM_MEDIA_GALLERY_VIEWER_DEFAULT => t('Universalviewer'),
2954
      'fsi' => t('FSI viewer (requires FSI server!)'),
2955
      'default' => t('Simple viewer'),
2956
    ),
2957
    '#description' => 'The <b>Universalviewer</b> is a feature rich image gallery and viewer which provides support
2958
            for mobile devices and thus is highly recommended over the other options.<br/>
2959
            <b>Simple viewer</b> combines a HTML gallery with a simple image viewer and only provides basic functionality 
2960
            and does not work well on mobile devices.<br />
2961
            <b>FSI Viewer</b> can only be used in conjunction with images served by an FSI server.'
2962
  );
2963

    
2964
  // --- STANDARD_IMAGE_VIEWER ---- //
2965
  if(variable_get(CDM_MEDIA_GALLERY_VIEWER, CDM_MEDIA_GALLERY_VIEWER_DEFAULT) == CDM_MEDIA_GALLERY_VIEWER_SIMPLE) {
2966
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2967
      '#type' => 'fieldset',
2968
      '#tree' => true,
2969
      '#title' => t('Standard image viewer settings'),
2970
      '#collapsible' => FALSE,
2971
      '#collapsed' => FALSE,
2972
      );
2973

    
2974
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2975
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2976
      '#type' => 'checkbox',
2977
      '#title' => 'Show media representations',
2978
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2979
    );
2980

    
2981
  }
2982
  if(variable_get(CDM_MEDIA_GALLERY_VIEWER, 'default') == CDM_MEDIA_GALLERY_VIEWER_DEFAULT) {
2983
    $form['media_settings'][CDM_ADDITIONAL_MEDIA_COPYRIGHT] = [
2984
      '#type' => 'textarea',
2985
      '#title' => 'Additional media copyright statement',
2986
      '#default_value' => variable_get(CDM_ADDITIONAL_MEDIA_COPYRIGHT, NULL),
2987
      '#description' => 'This statement will be shown below the <b>Universal imgage viewer only</b>'
2988
    ];
2989
  }
2990

    
2991
  // @WA: D7 form api does not support reset buttons,
2992
  // so to mimic the D5 reset button we add one like this.
2993
  $form['actions']['reset'] = array(
2994
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2995
    '#weight' => 1000,
2996
  );
2997
  return system_settings_form($form);
2998
}
2999

    
3000
/**
3001
 * GEOSERVICE and Map settings.
3002
 *
3003
 *  @return array
3004
 *   The form structure.
3005
 */
3006
function cdm_settings_geo($form, &$form_state) {
3007

    
3008
  $current_geoserver_settings = get_edit_map_service_settings();
3009
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
3010

    
3011

    
3012
  $form = array();
3013

    
3014
  $dummy_distribution_query = NULL;
3015
  if($map_distribution['map_type'] != 1){
3016
    // we need to apply a dummy query since the map service requires for image maps
3017
    // at least as and ad to be defined
3018
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
3019
  }
3020

    
3021
  $form['map_preview'] = array(
3022
      '#type' => 'fieldset',
3023
      '#tree' => FALSE,
3024
      '#title' => t('Map preview'),
3025
      '#collapsible' => FALSE,
3026
      '#description' => 'The preview of the map'
3027
       . ($dummy_distribution_query != null ?
3028
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
3029
           '.<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.')
3030
  );
3031
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, NULL, $dummy_distribution_query, NULL, [
3032
    'move' => "this.cdmOpenlayersMap.printInfo",
3033
    '#execute' => "this.cdmOpenlayersMap.printInfo"
3034
  ], TRUE // resizable
3035
  );
3036

    
3037
  /*
3038
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
3039
  );
3040
  */
3041

    
3042
  /*
3043
   * GEO SERVER
3044
   */
3045
  $form['edit_map_server'] = array(
3046
    '#type' => 'fieldset',
3047
    '#tree' => true,
3048
    '#title' => t('EDIT map service'),
3049
    '#collapsible' => TRUE,
3050
    '#collapsed' => TRUE,
3051
    '#description' => t('Configuration and selection of your geo server.
3052
      The Geo Server is responsible for generating the maps.'),
3053
  );
3054

    
3055
  $form['edit_map_server']['base_uri'] = array(
3056
    '#type' => 'select',
3057
    '#title' => t('EDIT map service') . ':',
3058
    '#default_value' => $current_geoserver_settings['base_uri'],
3059
    '#options' => unserialize(EDIT_MAPSERVER_URI),
3060
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
3061
  );
3062
  $form['edit_map_server']['version'] = array(
3063
      '#type' => 'select',
3064
      '#title' => t('Version') . ':',
3065
      '#default_value' => $current_geoserver_settings['version'],
3066
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
3067
      '#description' => t('The version of the EDIT map services'),
3068
  );
3069

    
3070
  /*
3071
   * MAP SETTINGS
3072
   */
3073

    
3074
  $form[CDM_MAP_DISTRIBUTION] = array(
3075
    '#type' => 'fieldset',
3076
    '#tree' => TRUE,
3077
    '#title' => t('Maps settings'),
3078
    '#collapsible' => TRUE,
3079
    '#collapsed' => TRUE,
3080
    '#description' => t('General configuration for all map types.'),
3081
  );
3082

    
3083
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
3084
    '#type' => 'radios',
3085
    '#title' => 'Map types',
3086
    '#options' => array(
3087
      1 => "OpenLayers dynamic map viewer",
3088
      0 => "Plain image",
3089
    ),
3090
    '#default_value' => $map_distribution['map_type'],
3091
    '#description' => 'Two different map types are available :
3092
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
3093
      which allows zooming and panning. If enabled you can configure the default layer
3094
      (background of your maps) below.</li>
3095
      <li><em>Plain image</em>: The map will be static non interactive
3096
      image.</li></ul>',
3097
  );
3098
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
3099

    
3100
  /*
3101
   * settings for the distribution map are used also for specimens map!!!!
3102
   */
3103

    
3104
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
3105
      '#type' => 'textfield',
3106
      '#title' => 'Aspect ratio',
3107
      '#default_value' => $map_distribution['aspect_ratio'],
3108
      '#maxlength' => 4,
3109
      '#size' => 4,
3110
      '#element_validate' => array('element_validate_number'),
3111
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
3112
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
3113
      width by the height:</br>
3114
      <pre>aspect ratio = w / h</pre>
3115
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
3116
      for a square map use <strong>1</strong>.',
3117
  );
3118

    
3119
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
3120
    '#type' => 'textfield',
3121
    '#title' => 'Bounding box',
3122
    '#default_value' => $map_distribution['bbox'],
3123
    '#description' =>
3124
      'The bounding box (left, bottom, right, top) defines the area to be initially displayed in maps. The bbox must be given in coordinates of the projection of the chosen layer. 
3125
      For the whole world use Use <code>-180,-90,180,90</code>" for EPSG:4326 layers, for Web Mercator maps Open Street Map or 
3126
      Google maps the maximum bounds of the world are <code>-27395030.933594,-13697515.466797,27395030.933594,13697515.466797</code>.
3127
      Leave <strong>empty</strong> to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
3128
      <strong>TIP:</strong> You can use the map preview above to choose the <span class="map-extent-bbox"><strong class="layer-value">map extent bbox</strong></span> from the details information.
3129
      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
3130
      below the map from where you can copy the bbox string.</p>',
3131
  );
3132

    
3133
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
3134
    '#type' => 'select',
3135
    '#title' => 'Max zoom level',
3136
    '#default_value' => $map_distribution['maxZoom'],
3137
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
3138
  );
3139

    
3140
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
3141
    '#type' => 'checkbox',
3142
    '#title' => 'Display area labels',
3143
    '#default_value' => $map_distribution['show_labels'],
3144
    '#description' => t('The map will show name labels of the areas'),
3145
  );
3146

    
3147
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
3148
    '#type' => 'textfield',
3149
    '#title' => 'Map caption',
3150
    '#default_value' => $map_distribution['caption'],
3151
    '#description' => t('The caption will be shown below the map.'),
3152
  );
3153

    
3154
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
3155
    '#type' => 'textfield',
3156
    '#title' => 'Distribution layer opacity',
3157
    '#default_value' => $map_distribution['distribution_opacity'],
3158
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
3159
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
3160
  );
3161

    
3162
  // --- Plain Image Settings --- //
3163
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
3164
    '#type' => 'fieldset',
3165
    '#title' => 'Plain image map settings',
3166
    '#tree' => TRUE,
3167
    '#collapsible' => TRUE,
3168
    '#collapsed' => $open_layers_is_enabled,
3169
    '#description' => 'The settings in this section are still expertimental
3170
      and can only be used with the EDIT map service version 1.1 or above.',
3171
  );
3172
  $edit_mapserver_version = get_edit_map_service_version_number();
3173
  if ($edit_mapserver_version < 1.1) {
3174
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
3175
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
3176
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
3177
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
3178
  }
3179

    
3180
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
3181
    '#type' => 'textfield',
3182
    '#title' => 'Width',
3183
    '#default_value' => $map_distribution['image_map']['width'],
3184
    '#maxlength' => 4,
3185
    '#size' => 4,
3186
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
3187
  );
3188

    
3189
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
3190
    '#type' => 'textfield',
3191
    '#title' => 'Background layer',
3192
    '#default_value' => $map_distribution['image_map']['base_layer'],
3193
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
3194
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
3195
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
3196
    )),
3197
  );
3198

    
3199
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3200
    '#type' => 'textfield',
3201
    '#title' => 'Background color',
3202
    '#default_value' => $map_distribution['image_map']['bg_color'],
3203
  );
3204

    
3205
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3206
    '#type' => 'textfield',
3207
    '#title' => 'Background layer style',
3208
     // Only line color by now.
3209
    '#default_value' => $map_distribution['image_map']['layer_style'],
3210
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3211
  );
3212

    
3213
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3214
      '#type' => 'textfield',
3215
      '#title' => 'Projection',
3216
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3217
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3218
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3219
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3220
  );
3221

    
3222

    
3223
  // --- OpenLayers Settings --- //
3224
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3225
    '#type' => 'fieldset',
3226
    '#title' => 'OpenLayers settings',
3227
    '#tree' => TRUE,
3228
    '#collapsible' => TRUE,
3229
    '#collapsed' => !$open_layers_is_enabled,
3230
    '#description' => '',
3231
  );
3232

    
3233

    
3234
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3235
      '#type' => 'checkbox',
3236
      '#title' => 'Display outside max extent',
3237
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3238
      '#description' => t('Allows the map to display parts of the layers which are outside
3239
         the max extent if the aspect ratio of the map and of the baselayer
3240
         are not equal.'),
3241
  );
3242

    
3243

    
3244
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3245
      '#type' => 'checkbox',
3246
      '#title' => 'Show Layer Switcher',
3247
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3248
      '#description' => 'The Layer Switcher control displays a table of contents
3249
      for the map.  This allows the user interface to switch between
3250
      base layers and to show or hide overlays.  By default the switcher is
3251
      shown minimized on the right edge of the map, the user may expand it
3252
      by clicking on the handle.',
3253
  );
3254

    
3255
  if (!$open_layers_is_enabled) {
3256
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3257
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3258
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3259
  }
3260

    
3261
  // The default layer must always be enabled
3262
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3263
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3264

    
3265
  $baselayer_options = array(
3266
    /*
3267
   NOTICE: must correspond to the layers defined in
3268
   js/openlayers_,ap.js#getLayersByName()
3269
   */
3270
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3271
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3272
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3273
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3274
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3275
    // all others EPSG:900913
3276
    'mapnik' => 'OpenStreetMap (mapnik)',
3277
    'stamen_terrain' => 'Stamen Terrain',
3278
    'open_topomap' => 'OpenTopoMap',
3279
    // map quest is no longer free. it is required to sign up for a test plan.
3280
    // 'mapquest_open' => "MapQuest",
3281
    // 'mapquest_sat' => "MapQuest Sattelite",
3282
    'groadmap' => 'Google Roadmap',
3283
    'gsatellite' => 'Google Satellite',
3284
    'ghybrid' => 'Google Hybrid',
3285
    'gterrain' => 'Google Terrain',
3286
//     'veroad' => 'Virtual Earth Roads',
3287
//     'veaer' => 'Virtual Earth Aerial',
3288
//     'vehyb' => 'Virtual Earth Hybrid',
3289
    // 'yahoo' => 'Yahoo Street',
3290
    // 'yahoosat' => 'Yahoo Satellite',
3291
    // 'yahoohyb' => 'Yahoo Hybrid',
3292
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3293
  );
3294

    
3295
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3296
    '#type' => 'checkboxes_preferred',
3297
    '#title' => 'Base Layers',
3298
    '#options' => $baselayer_options,
3299
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3300
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3301
  );
3302

    
3303
  $google_maps_api_key = null;
3304
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3305
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3306
  }
3307
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3308
    '#type' => 'textfield',
3309
    '#title' => 'Google Maps API Key',
3310
    '#default_value' => $google_maps_api_key,
3311
    '#description' => 'In order to use any of the Google map layers you need to provide 
3312
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3313
  );
3314

    
3315
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3316
    $map_distribution['openlayers']['custom_wms_base_layer'],
3317
    'Custom WMS base layer',
3318
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3319
    true // add projection settings
3320
    );
3321

    
3322
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3323
    $map_distribution['openlayers']['wms_overlay_layer'],
3324
    'WMS overlay layer',
3325
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3326
                You can actually combine multiple layers for this overlay. 
3327
                For details please refer to the wms query parameter <code>Layers</code> .'
3328
  );
3329

    
3330
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3331
    '#type' => 'checkbox',
3332
    '#title' => 'Enable overlay layer',
3333
    '#weight' => -100,
3334
    '#default_value' => isset($map_distribution['openlayers']['wms_overlay_layer']['is_enabled']) && $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3335
  );
3336

    
3337
  /*
3338
   * Map Legend
3339
   */
3340
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3341
    '#type' => 'fieldset',
3342
    '#title' => 'Map legend',
3343
    '#tree' => TRUE,
3344
    '#collapsible' => TRUE,
3345
    '#collapsed' => TRUE,
3346
    '#description' => 'Configure the maps legend.',
3347
  );
3348

    
3349
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3350
    '#type' => 'checkbox',
3351
    '#title' => 'Display a map legend',
3352
    '#default_value' => $map_distribution['legend']['show'],
3353
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3354
  );
3355

    
3356
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3357
    '#type' => 'textfield',
3358
    '#title' => 'Legend opacity',
3359
    '#default_value' => $map_distribution['legend']['opacity'],
3360
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3361
                         to 0.0 will be not much visible.',
3362
  );
3363

    
3364
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3365
    '#type' => 'textfield',
3366
    '#title' => 'Font size',
3367
    '#default_value' => $map_distribution['legend']['font_size'],
3368
    '#description' => 'Font size in pixels.',
3369
  );
3370

    
3371
  $fontStyles = array(
3372
    0 => "plane",
3373
    1 => "italic",
3374
  );
3375
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3376
    '#type' => 'select',
3377
    '#title' => 'Available font styles',
3378
    '#default_value' => $map_distribution['legend']['font_style'],
3379
    '#options' => $fontStyles,
3380
    '#description' => 'Select a font style for the map legend.',
3381
  );
3382

    
3383
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3384
    '#type' => 'textfield',
3385
    '#title' => 'Icon width',
3386
    '#default_value' => $map_distribution['legend']['icon_width'],
3387
    '#description' => 'Legend icon width in pixels.',
3388
  );
3389
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3390
    '#type' => 'textfield',
3391
    '#title' => 'Icon height',
3392
    '#default_value' => $map_distribution['legend']['icon_height'],
3393
    '#description' => 'Legend icon height in pixels.',
3394
  );
3395

    
3396
  // @WA: D7 form api does not support reset buttons,
3397
  // so to mimic the D5 reset button we add one like this.
3398
  $form['actions']['reset'] = array(
3399
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3400
    '#weight' => 1000,
3401
  );
3402

    
3403
  return system_settings_form($form);
3404
}
3405

    
3406
/**
3407
 * @param $default_settings
3408
 * @param $title
3409
 * @param $description
3410
 * @param bool $add_projection_settings
3411
 * @return array
3412
 */
3413
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3414
{
3415
  $form_elements = array(
3416
    '#type' => 'fieldset',
3417
    '#title' => $title,
3418
    '#tree' => TRUE,
3419
    '#collapsible' => FALSE,
3420
    '#collapsed' => FALSE,
3421
    '#description' => $description,
3422
  );
3423

    
3424
  $form_elements['name'] = array(
3425
    '#type' => 'textfield',
3426
    '#title' => 'Layer name',
3427
    '#default_value' => $default_settings['name'],
3428
    '#description' => 'A arbitrary name for the layer.',
3429
  );
3430
  $form_elements['url'] = array(
3431
    '#type' => 'textfield',
3432
    '#title' => 'WMS url',
3433
    '#default_value' => $default_settings['url'],
3434
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3435
  );
3436
  $form_elements['untiled'] = array(
3437
    '#type' => 'checkbox',
3438
    '#title' => 'Untiled',
3439
    '#default_value' => $default_settings['untiled'],
3440
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3441
  );
3442
  $form_elements['params'] = array(
3443
    '#type' => 'textarea',
3444
    '#title' => 'WMS parameters',
3445
    '#element_validate' => array('form_element_validate_json'),
3446
    '#default_value' => $default_settings['params'],
3447
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3448
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3449
      . '), entered in valid JSON. For example:
3450
<pre> {
3451
  "Layers": "topp:em_tiny_jan2003",
3452
  "Format": "image/png",
3453
  "BGCOLOR": "0xe0faff"
3454
}
3455
</pre>
3456
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3457
  );
3458

    
3459
  if($add_projection_settings){
3460

    
3461
    $form_elements['projection'] = array(
3462
      '#type' => 'textfield',
3463
      '#title' => 'Projection',
3464
      '#default_value' => $default_settings['projection'],
3465
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
3466
    );
3467
    $form_elements['proj4js_def'] = array(
3468
      '#type' => 'textfield',
3469
      '#maxlength' => 256,
3470
      '#title' => 'proj4js definition',
3471
      '#default_value' => $default_settings['proj4js_def'],
3472
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
3473
              The definitions for
3474
              EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
3475
              EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
3476
              are already predefined and must NOT be added here again.  If your dont know the defintion of your desired projection,
3477
              go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
3478
              choose to display the proj4js definition string.
3479
              <h5>Quick Reference on the common proj4js definition parameters:</h5>
3480
              <pre>
3481
  +a         Semimajor radius of the ellipsoid axis
3482
  +alpha     ? Used with Oblique Mercator and possibly a few others
3483
  +axis      Axis orientation (new in 4.8.0)
3484
  +b         Semiminor radius of the ellipsoid axis
3485
  +datum     Datum name (see `proj -ld`)
3486
  +ellps     Ellipsoid name (see `proj -le`)
3487
  +k         Scaling factor (old name)
3488
  +k_0       Scaling factor (new name)
3489
  +lat_0     Latitude of origin
3490
  +lat_1     Latitude of first standard parallel
3491
  +lat_2     Latitude of second standard parallel
3492
  +lat_ts    Latitude of true scale
3493
  +lon_0     Central meridian
3494
  +lonc      ? Longitude used with Oblique Mercator and possibly a few others
3495
  +lon_wrap  Center longitude to use for wrapping (see below)
3496
  +nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
3497
  +no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
3498
  +over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
3499
  +pm        Alternate prime meridian (typically a city name, see below)
3500
  +proj      Projection name (see `proj -l`)
3501
  +south     Denotes southern hemisphere UTM zone
3502
  +to_meter  Multiplier to convert map units to 1.0m
3503
  +towgs84   3 or 7 term datum transform parameters (see below)
3504
  +units     meters, US survey feet, etc.
3505
  +vto_meter vertical conversion to meters.
3506
  +vunits    vertical units.
3507
  +x_0       False easting
3508
  +y_0       False northing
3509
  +zone      UTM zone
3510
              </pre>
3511
            For the full reference please refer to <a href="http://proj4.org/parameters.html">http://proj4.org/parameters.html</a>.'
3512
    );
3513
    $form_elements['max_extent'] = array(
3514
      '#type' => 'textfield',
3515
      '#title' => 'Maximum extent',
3516
      '#default_value' => $default_settings['max_extent'],
3517
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
3518
    );
3519
    $form_elements['units'] = array(
3520
      '#type' => 'textfield',
3521
      '#title' => 'Units',
3522
      '#default_value' => $default_settings['units'],
3523
      '#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.'
3524
    );
3525

    
3526
  }
3527
  return $form_elements;
3528
}
3529

    
3530

    
3531
/**
3532
 * @return array
3533
 *   The form structure.
3534
 */
3535
function cdm_settings_cache() {
3536

    
3537
  $form = array();
3538

    
3539
  $form['cache_settings'] = array(
3540
    '#type' => 'fieldset',
3541
    '#title' => t('Cache Settings'),
3542
    '#collapsible' => FALSE,
3543
    '#collapsed' => FALSE,
3544
    '#description' => t('<p>When caching is enabled all single taxon sites are
3545
      stored in an internal drupal cache doing the portal response of taxa pages
3546
      faster. This is possible because the sites are loaded from the cache and
3547
      are not created from scratch.</p>'),
3548
  );
3549

    
3550
  $form['cache_settings']['cdm_webservice_cache'] = array(
3551
    '#type' => 'checkbox',
3552
    '#title' => t('<strong>Enable caching</strong>'),
3553
    '#options' => cdm_help_general_cache(),
3554
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3555
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3556
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3557
       application the changes will be not visible till the cache is erased.
3558
       Therefore developers should deactived this feature when they are working
3559
       on the CDM Dataportal Module.</p>'),
3560
  );
3561

    
3562
  $form['cache_settings']['cdm_run_cache'] = array(
3563
    '#markup' => cdm_view_cache_site(),
3564
  );
3565

    
3566
  // @WA: D7 form api does not support reset buttons,
3567
  // so to mimic the D5 reset button we add one like this.
3568
  $form['actions']['reset'] = array(
3569
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3570
    '#weight' => 1000,
3571
  );
3572
  return system_settings_form($form);
3573
}
3574

    
3575
/**
3576
 * Walk and cache all taxon pages.
3577
 */
3578
function cdm_view_cache_site() {
3579

    
3580
  $out = '';
3581

    
3582
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3583

    
3584
  $request_params = array();
3585
  $request_params['class'] = "Taxon";
3586

    
3587
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3588
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3589
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3590

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

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

    
3600
  // Comment @WA: A form within a form is not valid html and not needed here.
3601
  // Also, it would be recommended just to include this part of the form in the
3602
  // rest of the form array in cdm_settings_cache().
3603
  // $out .= '<form id="cache_site">';
3604
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3605
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3606
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3607
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3608
  // $out .= '</form>';
3609
  $out .= '</div>';
3610
  /*
3611
  foreach($taxonPager->records as $taxon){
3612
    cdm_dataportal_taxon_view($uuid);
3613
  }
3614
  */
3615
  return $out;
3616
}
3617

    
3618

    
3619
function cdm_settings_layout_taxon_submit($form, &$form_state){
3620
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3621
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3622
    if(is_object($file)){
3623
      $file->status = FILE_STATUS_PERMANENT;
3624
      file_save($file);
3625
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3626
    }
3627
  }
3628
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3629
  $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]);
3630
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3631
  if($tab_lables_modified || $tabs_enabled_modified){
3632
    // we first need to set the variable to persist the changes setting
3633
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3634
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3635
    menu_rebuild();
3636
  }
3637
}
3638

    
3639
function cdm_settings_layout_search_submit($form, &$form_state){
3640
  // the visibility of media thumbnails also affects the ui of the search results
3641
  // so reset the according session variable
3642
  //    1. in order to give the user immediate
3643
  //       feedback on potential setting changes
3644
  //    2. let refresh the default if it has changed
3645
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3646
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3647
  }
3648
}
3649

    
3650
/**
3651
 * Form validation handler for cdm_settings_general
3652
 *
3653
 * @param $form
3654
 * @param $form_state
3655
 */
3656
function cdm_settings_general_validate($form, &$form_state) {
3657

    
3658
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3659
    $form_state['values']['cdm_webservice_url'] .= '/';
3660
  }
3661

    
3662
}
3663

    
3664
/**
3665
 * Form submit handler for settings general.
3666
 *
3667
 * tasks performed:
3668
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3669
 *
3670
 * @param $form
3671
 * @param $form_state
3672
 */
3673
function cdm_settings_general_submit($form, &$form_state){
3674
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3675
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3676
  unset($_SESSION['cdm_login']);
3677
}
3678

    
3679
/**
3680
 * Form validation handler for cdm_settings_cache
3681
 */
3682
function cdm_settings_cache_validate($form, &$form_state) {
3683
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3684
    cache_clear_all(NULL, 'cache_cdm_ws');
3685
    // Better clear secref_cache since I can not be sure if the cache has not
3686
    // be used during this response.
3687
    cdm_api_secref_cache_clear();
3688
  }
3689

    
3690
}
3691

    
3692
/**
3693
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3694
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3695
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3696
 *  - version: the version, e.g.: v1.1
3697
 *
3698
 * @return array
3699
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3700
 */
3701
function get_edit_map_service_settings() {
3702

    
3703
  $settings = variable_get('edit_map_server', array(
3704
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3705
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3706
      )
3707
  );
3708

    
3709
  return $settings;
3710
}
3711

    
3712
/**
3713
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3714
 *
3715
 * @return string
3716
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3717
 */
3718
function get_edit_map_service_full_uri() {
3719
  $settings = get_edit_map_service_settings();
3720
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3721
}
3722

    
3723

    
3724
/**
3725
 * Returns the version number of the currently selected edit mapserver as a float
3726
 *
3727
 * @return float
3728
 *   The version number of the currently selected edit mapserver as a float.
3729
 *   Returns 0 on error.
3730
 */
3731
function get_edit_map_service_version_number() {
3732

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

    
3735
  $settings = get_edit_map_service_settings();
3736
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3737
  if (isset($matches[1])) {
3738
    // Convert string to float.
3739
    $version = 1 + $matches[1][0] - 1;
3740
    return $version;
3741
  }
3742
  else {
3743
    // Report error.
3744
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3745
        array(
3746
          '!version' => $settings['version'],
3747
          'warning')
3748
        )
3749
      );
3750
    return 0;
3751
  }
3752
}
3753

    
3754
/**
3755
 * Returns the array of selected items in a options array
3756
 *
3757
 * @param array $options
3758
 *   An options array as generated by a form element like checkoxes, select ...,
3759
 */
3760
function get_selection($options) {
3761
  $selection = array();
3762
  foreach ($options as $key=>$val) {
3763
    if (!empty($val)) {
3764
      $selection[] = $val;
3765
    }
3766
  }
3767
  return $selection;
3768
}
3769

    
3770

    
3771
/**
3772
 * Implements hook_element_info().
3773
 *
3774
 * Allows modules to declare their own Form API element types and specify their default values.
3775
 *
3776
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3777
 */
3778
function cdm_dataportal_element_info() {
3779
  $type['checkboxes_preferred'] = array(
3780
    '#input' => TRUE,
3781
    '#process' => array('checkboxes_preferred_expand'),
3782
    '#after_build' => array('checkboxes_preferred_after_build'),
3783
    '#theme' => array('checkboxes_preferred'),
3784
    // '#theme_wrapper' => array('form_element'),
3785
  );
3786
  return $type;
3787
}
3788

    
3789
/**
3790
 * #process callback function for the custom form element type 'checkbox_preferred'
3791
 *
3792
 *
3793
 */
3794
function checkboxes_preferred_expand($element, &$form_state, $form) {
3795

    
3796
  // First of all create checkboxes for each of the elements
3797
  $element = form_process_checkboxes($element);
3798

    
3799
  // compose the element name
3800
  $parents = array();
3801
  array_deep_copy($element['#parents'], $parents);
3802
  $parents[count($parents) -1 ] .= '_preferred';
3803
  $element_name = $parents[0];
3804
  for ($i=1; $i < count($parents); $i++){
3805
    $element_name .= '[' . $parents[$i] . ']';
3806
  }
3807

    
3808
  $children = element_children($element);
3809

    
3810
  $element['table_start'] = array(
3811
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3812
    '#weight' => -1,
3813
  );
3814

    
3815
  // prepare first part each of the table rows which contains the row label
3816
  $weight = 0;
3817
  foreach ($children as $key) {
3818
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3819
    $element[$key]['#weight'] = $weight;
3820
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3821
    $element[$key]['#suffix'] = '</td>';
3822
    unset($element[$key]['#title']);
3823
    $weight += 2;
3824
  }
3825
  $weight = 0;
3826

    
3827
  // add a radio button to each of the checkboxes, the
3828
  // check boxes have already been created at the beginning
3829
  // of this function
3830
  if (count($element['#options']) > 0) {
3831
    foreach ($element['#options'] as $key => $choice) {
3832
      if (!isset($element[$key . '_preferred'])) {
3833
        $element[$key . '_preferred'] = array(
3834
          '#type' => 'radio',
3835
          '#name' => $element_name,
3836
          '#return_value' => check_plain($key),
3837
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3838
          '#attributes' => $element['#attributes'],
3839
          '#parents' => $element['#parents'],
3840
          // '#spawned' => TRUE,
3841
          '#weight' => $weight + 1,
3842
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3843
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3844
        );
3845
      }
3846
      $weight += 2;
3847
    }
3848
  }
3849

    
3850
  // end the table
3851
  $element['table_end'] = array(
3852
    '#markup' => '</table>',
3853
    '#weight' => $weight++,
3854
  );
3855

    
3856
  return $element;
3857
}
3858

    
3859
/**
3860
 * Theme function for the custom form field 'checkboxes_preferred'.
3861
 */
3862
function theme_checkboxes_preferred($variables) {
3863
  $element = $variables['element'];
3864
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3865
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3866
  $out .= drupal_render_children($element);
3867
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3868
  $out .= '</div>';
3869
  return $out;
3870
}
3871

    
3872
/**
3873
 * Callback for checkboxes preferred for widget which will
3874
 * be called after the form or element is built. The call
3875
 * back is configured in the form element by setting it as
3876
 * #after_build parameter.
3877
 *
3878
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3879
 *
3880
 * @param $element
3881
 *   Nested array of form elements that comprise the form.
3882
 * @param $form_state
3883
 *   A keyed array containing the current state of the form.
3884
 *   This includes the current persistent storage data for the form.
3885
 *   Additional information, like the sanitized $_POST data,
3886
 *   is also accumulated here in $form_state['input']
3887
 *
3888
 * @return the modified form array
3889
 */
3890
function checkboxes_preferred_after_build($element, &$form_state) {
3891

    
3892
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3893

    
3894
  if ($_POST && count($_POST) > 0) {
3895
    // TODO use  $form_state['input'] instead of POST !!!
3896
    // First pass of form processing.
3897
    $parents = array();
3898
    array_deep_copy($element['#parents'], $parents);
3899
    $parents[count($parents) - 1] .= '_preferred';
3900
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3901
    $element['#value']['PREFERRED'] = $preferred_layer;
3902
//     $form_state[$parent_id] = $element['#value'];
3903
//     $form_state['values']['baselayers'] = $element['#value'];
3904
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3905
    $form_state_element_values = $element['#value'];
3906
  }
3907
  else {
3908
    // Second pass of form processing.
3909
    $preferred_layer = $element['#value']['PREFERRED'];
3910
  }
3911

    
3912
  // Also set the chosen value (not sure if this is good Drupal style ....).
3913
  foreach ($children = element_children($element) as $key) {
3914
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3915
      $element[$key]['#value'] = $preferred_layer;
3916
    }
3917
  }
3918
  // The default layer must always be enabled.
3919
  $element[$preferred_layer]['#value'] = $preferred_layer;
3920

    
3921
  return $element;
3922
}
3923

    
3924
function radios_prepare_options_suffix(&$elements){
3925

    
3926
  $childrenKeys = element_children($elements);
3927
  foreach($childrenKeys as $key){
3928
    if(!is_array($elements[$key]['#theme_wrappers'])){
3929
      $elements[$key]['#theme_wrappers'] = array();
3930
    }
3931
    if(isset($elements['#options_suffixes'][$key])){
3932
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3933
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3934
    }
3935
  }
3936
  return $elements;
3937

    
3938
}
3939

    
3940
/**
3941
 * TODO
3942
 * @param unknown $variables
3943
 */
3944
function theme_radio_options_suffix($variables) {
3945
  $element = $variables['element'];
3946
  if(isset($element['#options_suffix'])) {
3947
    $element['#children'] .= $element['#options_suffix'];
3948
  }
3949
  return $element['#children'];
3950
}
3951

    
3952

    
3953
/**
3954
 * Element validate callback for text field and arrays containing json.
3955
 *
3956
 * @param $element
3957
 *   The form element to validate
3958
 * @param $form_state
3959
 *   A keyed array containing the current state of the form.
3960
 * @param $form
3961
 *   Nested array of form elements that comprise the form.
3962
 */
3963
function form_element_validate_json($element, &$form_state, $form) {
3964
   if (!empty($element['#value'])) {
3965
     json_decode($element['#value']);
3966
     if(json_last_error() != JSON_ERROR_NONE){
3967
       form_error($element,
3968
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3969
         . l('JSONLint', 'http://jsonlint.com/')
3970
       );
3971
     }
3972
   }
3973
}
3974

    
3975
/**
3976
 * Form submission handler for textareas and textfields containing JSON.
3977
 *
3978
 * The contained JSON will be converted into an php array
3979
 * or object and will be stored in the variables as such.
3980
 *
3981
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3982
 *
3983
 * @param $form
3984
 *   Nested array of form elements that comprise the form.
3985
 * @param $form_state
3986
 *   A keyed array containing the current state of the form.
3987
 *
3988
 */
3989
function submit_json_as_php_array($form, &$form_state) {
3990
  if (is_array($form['#json_elements'])) {
3991
    foreach ($form['#json_elements'] as $element){
3992
      if (trim($form_state['values'][$element])) {
3993
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3994
      } else {
3995
        $form_state['values'][$element] = NULL;
3996
      }
3997
    }
3998
  }
3999
}
(18-18/18)