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
  const CDM_SEARCH_RESULT_PAGE_SIZE_DEFAULT = 25;
36
  const CDM_SEARCH_RESULT_PAGE_SIZE = 'cdm_dataportal_search_items_on_page';
37

    
38
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
39
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
40
 const CDM_DATAPORTAL_NOMREF_IN_TITLE = 'cdm_dataportal_nomref_in_title';
41
 const CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT =  1;
42
 const CDM_SPECIMEN_LIST_VIEW_MODE = 'cdm_specimen_list_view_mode';
43
 const CDM_SPECIMEN_LIST_VIEW_MODE_DEFAULT = 'derivate_table';
44
 const CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TABLE = 'derivate_table';
45
 const CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE = 'derivate_tree';
46
 const CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_PATH = 'derivate_path';
47
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
48
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE', 'cdm_synonymy_accepted_taxon_sec_separate');
49
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL', 'cdm_synonymy_accepted_taxon_sec_separate_label');
50
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT', 'Source');
51
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
52
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
53
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
54

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

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

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

    
71
  const ANNOTATION_TYPES_VISIBLE = 'annotations_types_as_footnotes';
72
  define('ANNOTATION_TYPES_VISIBLE_DEFAULT', serialize($annotationTypeKeys));
73

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

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

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

    
101

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

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

    
148

    
149
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
150

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

    
160
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
161
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
162
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
163
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
164
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
165

    
166
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
167
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
168
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
169
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
170

    
171
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
172
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
173

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

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

    
206

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

    
220
$taxon_tab_options = get_taxon_tabs_list();
221
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
222

    
223
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
224

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

    
235
}
236

    
237
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
238
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
239
    array(
240
      'ZoologicalName' => array(
241
        'namePart' => array('name' => TRUE),
242
        'nameAuthorPart' => array('name' => TRUE),
243
        'referencePart' => array('authors' => TRUE),
244
        'microreferencePart' => array('microreference' => TRUE),
245
        'secReferencePart' => array('secReference' => TRUE,),
246
        'statusPart' => array('status' => TRUE),
247
        'descriptionPart' => array('description' => TRUE),
248
      ),
249
      'BotanicalName'=> array(
250
        'namePart' => array('name' => TRUE),
251
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
252
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
253
        'secReferencePart' => array('secReference' => TRUE,),
254
        'referenceYearPart' => array('reference.year' => TRUE),
255
        'statusPart' => array('status' => TRUE),
256
        'descriptionPart' => array('description' => TRUE),
257
      ),
258
     '#DEFAULT' => array(
259
        'namePart' => array(
260
            'name' => TRUE
261
        ),
262
        'nameAuthorPart' => array(
263
            'name' => TRUE,
264
            'authors' => TRUE
265
        ),
266
       'referencePart' => array(
267
         'reference' => TRUE
268
        ),
269
       'secReferencePart' => array(
270
         'secReference' => TRUE,
271
       ),
272
       'microreferencePart' => array(
273
          'microreference' => TRUE,
274
        ),
275
       'statusPart' => array(
276
          'status' => TRUE,
277
        ),
278
       'descriptionPart' => array(
279
          'description' => TRUE,
280
        ),
281
      )
282
    )
283
  )
284
);
285
define('CDM_PART_DEFINITIONS_DEFAULT_PRE_380', serialize(
286
    array(
287
      'ZoologicalName' => array(
288
        'namePart' => array('name' => TRUE),
289
        'nameAuthorPart' => array('name' => TRUE),
290
        'referencePart' => array('authors' => TRUE),
291
        'microreferencePart' => array('microreference' => TRUE),
292
        'statusPart' => array('status' => TRUE),
293
        'descriptionPart' => array('description' => TRUE),
294
      ),
295
      'BotanicalName'=> array(
296
        'namePart' => array('name' => TRUE),
297
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
298
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
299
        'referenceYearPart' => array('reference.year' => TRUE),
300
        'statusPart' => array('status' => TRUE),
301
        'descriptionPart' => array('description' => TRUE),
302
      ),
303
      '#DEFAULT' => array(
304
        'namePart' => array(
305
          'name' => TRUE
306
        ),
307
        'nameAuthorPart' => array(
308
          'name' => TRUE,
309
          'authors' => TRUE
310
        ),
311
        'referencePart' => array(
312
          'reference' => TRUE
313
        ),
314
        'microreferencePart' => array(
315
          'microreference' => TRUE,
316
        ),
317
        'statusPart' => array(
318
          'status' => TRUE,
319
        ),
320
        'descriptionPart' => array(
321
          'description' => TRUE,
322
        ),
323
      )
324
    )
325
  )
326
  );
327

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

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

    
414
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
415

    
416
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
417
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
418
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
419

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

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

    
443
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
444
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
445
  'media_representation_details_enabled' => 0
446
)));
447

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

    
456
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES', 'cdm_name_relationship_types');
457
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT', serialize(
458
    array(
459
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
460
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
461
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
462
    )
463
  )
464
);
465

    
466
define('CDM_NAME_RELATIONSHIP_LIST_TYPES', 'cdm_name_relationship_list_types');
467

    
468

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

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

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

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

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

    
548
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
549
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
550
    array(
551
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
552
        'includeOccurrences' => 0,
553
        'includeTaxonNameDescriptions' => 0
554
     )
555
  ));
556

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

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

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

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

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

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

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

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

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

    
753
  // ---- DEFAULTS settings
754

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

    
781
  // will be used as preset in the settings
782
  $other_themes_default = array(
783
    'DEFAULT' => array(
784
      'as_list' => 'div',
785
      'link_to_reference' => 0,
786
      'link_to_name_used_in_source' => 1,
787
      'sources_as_content' => 0,
788
      'sources_as_content_to_bibliography' => 0,
789
      'sort_elements' => NO_SORT,
790
      'glue' => '',
791
      'element_tag' => NULL
792
    ),
793
    UUID_CITATION => array(
794
      'as_list' => 'div',
795
      'link_to_reference' => 0,
796
      'link_to_name_used_in_source' => 0,
797
      'sources_as_content' => 1,
798
      'sources_as_content_to_bibliography' => 0,
799
      'sort_elements' => SORT_ASC,
800
      'glue' => '',
801
      'element_tag' => 'div'
802
    ),
803
    UUID_DISTRIBUTION => array(
804
      'as_list' => 'div', // currently ignored
805
      'link_to_reference' => 0,
806
      'link_to_name_used_in_source' => 0,
807
      'sources_as_content' => 0,
808
      'sources_as_content_to_bibliography' => 0,
809
      'sort_elements' => NO_SORT, // will cause ...
810
      'glue' => '',
811
      'element_tag' => 'div',
812
      'special' => array()
813
    ),
814
    UUID_COMMON_NAME => array(
815
      'as_list' => 'div',
816
      'link_to_reference' => 0,
817
      'link_to_name_used_in_source' => 1,
818
      'sources_as_content' => 0,
819
      'sources_as_content_to_bibliography' => 0,
820
      'sort_elements' => NO_SORT,
821
      'glue' => '',
822
      'element_tag' => 'span'
823
    ),
824
  );
825

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

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

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

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

    
931
  $default_theme = variable_get('theme_default', NULL);
932

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

    
957
  // ---- END of DEFAULTS
958

    
959
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
960

    
961
  $feature_block_setting = null;
962

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

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

    
983
  return $feature_block_setting;
984
}
985

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

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

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

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

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

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

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

    
1110
}
1111

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1256
  $form['sub_tree_filter'] = array(
1257
    '#type' => 'fieldset',
1258
    '#title' => t('Subtree filter'),
1259
    '#collapsible' => FALSE,
1260
    '#collapsed' => TRUE,
1261
    '#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.'),
1262
  );
1263

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1439
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1440
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1441

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

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

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

    
1473

    
1474

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

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

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

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

    
1521
  $form['#submit'][] = 'cdm_settings_general_submit';
1522

    
1523
  return system_settings_form($form);
1524
}
1525

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

    
1536

    
1537
/**
1538
 * LAYOUT settings
1539
 *
1540
 * @return array
1541
 *   The form structure.
1542
 */
1543
function cdm_settings_layout() {
1544

    
1545
  $form = array();
1546

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

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

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

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

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

    
1591

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

    
1601
  $bibliography_settings = get_bibliography_settings(true);
1602

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

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

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

    
1639
  // --- Name page autoredirect feature --- //
1640
  $form['name_page'] = array(
1641
    '#type' => 'fieldset',
1642
    '#title' => t('Name page'),
1643
    '#collapsible' => FALSE,
1644
    '#collapsed' => FALSE,
1645
  );
1646
  $form['name_page'][CDM_NAME_PAGE_AUTOREDIRECT] = array(
1647
    '#type' => 'checkbox',
1648
    '#title' => 'Always redirect to taxon',
1649
    '#default_value' => variable_get(CDM_NAME_PAGE_AUTOREDIRECT, 0),
1650
    '#description' => t('By checking this option you can globally enable the redirection behavior of the name page. 
1651
    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. 
1652
    This option allows to enable this behavior also for contexts in which the redirection normally is not active.'),
1653
  );
1654

    
1655
  // --- Registrations --- //
1656
  $form['registrations'] = array(
1657
    '#type' => 'fieldset',
1658
    '#title' => t('Registrations'),
1659
    '#collapsible' => FALSE,
1660
    '#collapsed' => FALSE,
1661
  );
1662
  $form['registrations']['cdm_registration_presistent_identifier_as_link'] = array(
1663
    '#type' => 'checkbox',
1664
    '#title' => t('Use the persistent http identifier as link'),
1665
    '#default_value' => variable_get('cdm_registration_presistent_identifier_as_link', 0),
1666
    '#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.'),
1667
  );
1668

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

    
1680
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1681
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1682
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1683
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1684

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

    
1694
  $diff_viewer_markup = '';
1695
  if($is_custom_part_definition){
1696
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1697
  }
1698

    
1699
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1700
    . $which_version_message
1701
    . '</div>'
1702
    . $diff_viewer_markup;
1703

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

    
1793
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1794
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1795
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1796
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1797
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1798

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

    
1807
  $diff_viewer_markup = '';
1808
  if($is_custom_render_template){
1809
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1810
  }
1811

    
1812
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1813
    . $which_version_message
1814
    . '</div>'
1815
    . $diff_viewer_markup;
1816

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

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

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

    
1870

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

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

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

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

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

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

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

    
1949
  return $form;
1950
}
1951

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

    
1960
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1961

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

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

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

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

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

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

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

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

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

    
2070
  // ---- PROFILE PICTURE ----//
2071

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

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

    
2086
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
2087

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

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

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

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

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

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

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

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

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

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

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

    
2230

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

    
2234
  if (isset($profile_feature_tree->root->childNodes)) {
2235

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

    
2278

    
2279
    $feature_list_layout_settings_disabled = FALSE;
2280

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

    
2288
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2289

    
2290
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2291

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

    
2296
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2297

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

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

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

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

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

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

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

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

    
2385
      }
2386
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2387
    }
2388
  }
2389

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

    
2415

    
2416

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

    
2435
  );
2436

    
2437
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2438

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

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

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

    
2463

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

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

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

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

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

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

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

    
2563
</pre>'),
2564
  );
2565

    
2566

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

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

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

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

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

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

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

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

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

    
2645
  $name_relationship_type_options = cdm_vocabulary_as_option(
2646
      UUID_NAME_RELATIONSHIP_TYPE,
2647
      '_cdm_relationship_type_term_label_callback',
2648
      false,
2649
      array('uuid' => '/' .UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM . '|'
2650
        . UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM . '|'
2651
        . UUID_NAMERELATIONSHIPTYPE_CONSERVED_AGAINST . '|'
2652
        . UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR . '|'
2653
        . UUID_NAMERELATIONSHIPTYPE_MISSPELLING . '|'
2654
        . UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT . '/' )
2655
  );
2656
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_INLINE_TYPES] = array(
2657
    '#type' => 'checkboxes',
2658
    '#title' => t('Name relationship types') . ':',
2659
    '#description' => 'This setting only affects specific types of name relations which are displayed appended to scientific name. 
2660
    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') . '.',
2661
    '#options' => $name_relationship_type_options,
2662
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT)),
2663
  );
2664

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

    
2675
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2676

    
2677

    
2678
  $form['taxon_specimens'][CDM_SPECIMEN_LIST_VIEW_MODE] = array(
2679
      '#type' => 'radios',
2680
      '#title' => t('View mode for lists of specimens or occurrences.'),
2681
      '#default_value' => variable_get(CDM_SPECIMEN_LIST_VIEW_MODE, CDM_SPECIMEN_LIST_VIEW_MODE_DEFAULT),
2682
      '#options' => [
2683
        CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TABLE => 'Compressed derivate table',
2684
        CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE => 'Derivate tree',
2685
        CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_PATH => 'Derivate path'
2686
      ],
2687
      '#description' => 'Available view modes for listing specimens and occurrences are:
2688
        <ul>
2689
         <li>' . CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TABLE . ': As compressed table where every row represents
2690
    a collection. Rows can be expanded to get an overview of the specimens and their derivatives.</li>
2691
         <li>' . CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE . ': As tree of all derivations stemming from the field unit</li>
2692
         <li>' . CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_PATH . ': As the path of derivatives from the specimen to the field unit</li>
2693
       </ul>'
2694
  );
2695

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

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

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

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

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

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

    
2768
  $form = array();
2769

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2887

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

    
2895
  $form = array();
2896

    
2897

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

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

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

    
2925
  );
2926

    
2927
  return system_settings_form($form);
2928
}
2929

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

    
2936
  $form = array();
2937

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

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

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

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

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

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

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

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

    
3010

    
3011
  $form = array();
3012

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

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

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

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

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

    
3069
  /*
3070
   * MAP SETTINGS
3071
   */
3072

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

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

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

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

    
3118
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
3119
    '#type' => 'textfield',
3120
    '#title' => 'Bounding box',
3121
    '#default_value' => $map_distribution['bbox'],
3122
    '#description' =>
3123
      '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. 
3124
      For the whole world use Use <code>-180,-90,180,90</code>" for EPSG:4326 layers, for Web Mercator maps Open Street Map or 
3125
      Google maps the maximum bounds of the world are <code>-27395030.933594,-13697515.466797,27395030.933594,13697515.466797</code>.
3126
      Leave <strong>empty</strong> to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
3127
      <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.
3128
      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
3129
      below the map from where you can copy the bbox string.</p>',
3130
  );
3131

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

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

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

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

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

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

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

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

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

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

    
3221

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

    
3232

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

    
3242

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3402
  return system_settings_form($form);
3403
}
3404

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

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

    
3458
  if($add_projection_settings){
3459

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

    
3525
  }
3526
  return $form_elements;
3527
}
3528

    
3529

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

    
3536
  $form = array();
3537

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

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

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

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

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

    
3579
  $out = '';
3580

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

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

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

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

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

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

    
3617

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

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

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

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

    
3661
}
3662

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

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

    
3689
}
3690

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

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

    
3708
  return $settings;
3709
}
3710

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

    
3722

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

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

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

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

    
3769

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

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

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

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

    
3807
  $children = element_children($element);
3808

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

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

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

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

    
3855
  return $element;
3856
}
3857

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

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

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

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

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

    
3920
  return $element;
3921
}
3922

    
3923
function radios_prepare_options_suffix(&$elements){
3924

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

    
3937
}
3938

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

    
3951

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

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