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

    
21
const CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES = 'cdm_taxonpage_taxon_node_show_status';
22
define('TAXONTREE_RANKLIMIT', 'cdm_taxontree_ranklimit');
23
define('TAXONTREE_RANKLIMIT_DEFAULT', 0);
24
  define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
25
  define('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
26

    
27
  define('CDM_SUB_TREE_FILTER_UUID', 'cdm_sub_tree_filter_uuid');
28

    
29
  define('NO_SORT', -1);
30
  define('SORT_HIERARCHICAL', 9);
31

    
32
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
33

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

    
50
  define('CDM_SEARCH_BLAST_SERVICE_URI', 'http://bgbm-import:9001/api/sequence');
51
  define('CDM_SEARCH_BLAST_ENABLED', 0);
52
  define('CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK', 'cdm_registration_presistent_identifier_as_link');
53

    
54
  /* annotationTypeKeys */
55
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
56
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
57
    $annotationTypeKeys = array_flip($annotationTypeKeys);
58

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

    
66
  const ANNOTATION_TYPES_VISIBLE = 'annotations_types_as_footnotes';
67
  define('ANNOTATION_TYPES_VISIBLE_DEFAULT', serialize($annotationTypeKeys));
68

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

    
78
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
79
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
80
    'enabled' => 0,
81
    'key_format' => 'ALPHA'
82
  )));
83

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

    
96

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

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

    
142

    
143
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
144

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

    
154
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
155
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
156
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
157
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
158
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
159

    
160
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
161
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
162
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
163
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
164

    
165
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
166
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
167

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

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

    
200

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

    
214
$taxon_tab_options = get_taxon_tabs_list();
215
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
216

    
217
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
218

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

    
229
}
230

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

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

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

    
408
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
409

    
410
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
411
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
412
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
413

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

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

    
437
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
438
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
439
  'media_representation_details_enabled' => 0
440
)));
441

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

    
450
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES', 'cdm_name_relationship_types');
451
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT', serialize(
452
    array(
453
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
454
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
455
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
456
    )
457
  )
458
);
459

    
460
define('CDM_NAME_RELATIONSHIP_LIST_TYPES', 'cdm_name_relationship_list_types');
461

    
462

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

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

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

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

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

    
542
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
543
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
544
    array(
545
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
546
        'includeOccurrences' => 0,
547
        'includeTaxonNameDescriptions' => 0
548
     )
549
  ));
550

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

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

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

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

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

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

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

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

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

    
747
  // ---- DEFAULTS settings
748

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

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

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

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

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

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

    
925
  $default_theme = variable_get('theme_default', NULL);
926

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

    
951
  // ---- END of DEFAULTS
952

    
953
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
954

    
955
  $feature_block_setting = null;
956

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

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

    
977
  return $feature_block_setting;
978
}
979

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

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

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

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

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

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

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

    
1104
}
1105

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1250
  $form['sub_tree_filter'] = array(
1251
    '#type' => 'fieldset',
1252
    '#title' => t('Subtree filter'),
1253
    '#collapsible' => FALSE,
1254
    '#collapsed' => TRUE,
1255
    '#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.'),
1256
  );
1257

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1433
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1434
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1435

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

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

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

    
1467

    
1468

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

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

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

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

    
1515
  $form['#submit'][] = 'cdm_settings_general_submit';
1516

    
1517
  return system_settings_form($form);
1518
}
1519

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

    
1530

    
1531
/**
1532
 * LAYOUT settings
1533
 *
1534
 * @return array
1535
 *   The form structure.
1536
 */
1537
function cdm_settings_layout() {
1538

    
1539
  $form = array();
1540

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

    
1547
  // ---- footnotes --- //
1548
  $form['footnotes'] = array(
1549
    '#type' => 'fieldset',
1550
    '#title' => t('Footnotes'),
1551
    '#collapsible' => FALSE,
1552
    '#collapsed' => FALSE,
1553
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1554
      media or distribution areas may have annotations or footnotes. When the
1555
      footnotes are enabled they will be visible (if they exist).'),
1556
  );
1557

    
1558
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1559
    '#type' => 'checkbox',
1560
    '#title' => t('Do not show footnotes'),
1561
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1562
    '#description' => t('Check this if you do not want to show any footnotes'),
1563
  );
1564

    
1565
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1566
    '#type' => 'checkbox',
1567
    '#title' => t('Do not show annotation footnotes'),
1568
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1569
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1570
  );
1571

    
1572
  $form['annotations'] = array(
1573
    '#type' => 'fieldset',
1574
    '#title' => t('Annotations'),
1575
    '#collapsible' => FALSE,
1576
    '#collapsed' => FALSE,
1577
    '#description' => t('This sections allows configuring global settings regarding annotations and thus will affect annotations dispayed as footnote and others.'),
1578
  );
1579

    
1580
  $annotation_type_options = cdm_terms_by_type_as_option('AnnotationType');
1581
  // Additional option for the NULL case.
1582
  $annotation_type_options['NULL_VALUE'] = t('untyped');
1583
  $annotations_types_visible = variable_get(ANNOTATION_TYPES_VISIBLE, unserialize(EXTENSION_TYPES_VISIBLE_DEFAULT));
1584
  $form['annotations'][ANNOTATION_TYPES_VISIBLE] = array(
1585
    '#type' => 'checkboxes',
1586
    '#title' => t('Visbility of annotation types'),
1587
    '#description' => t("Only annotations of the selected type will be displayed. You may want to turn 'technical annotations' off."),
1588
    '#options' => $annotation_type_options,
1589
    '#default_value' => $annotations_types_visible
1590
  );
1591

    
1592
  $form['extensions'] = array(
1593
    '#type' => 'fieldset',
1594
    '#title' => t('Extensions'),
1595
    '#collapsible' => FALSE,
1596
    '#collapsed' => FALSE,
1597
    '#description' => t('This sections allows configuring global settings regarding the data type extensions.'),
1598
  );
1599

    
1600
  $extension_type_options = cdm_terms_by_type_as_option('ExtensionType');
1601
  $extension_types_visible = variable_get(EXTENSION_TYPES_VISIBLE, unserialize(EXTENSION_TYPES_VISIBLE_DEFAULT));
1602
  $form['extensions'][EXTENSION_TYPES_VISIBLE] = array(
1603
    '#type' => 'checkboxes',
1604
    '#title' => t('Visbility of extension types'),
1605
    '#description' => t("Only extensions of the selected type will be displayed."),
1606
    '#options' => $extension_type_options,
1607
    '#default_value' => $extension_types_visible
1608
  );
1609

    
1610

    
1611
  // ---- original source --- //
1612
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1613
      '#type' => 'fieldset',
1614
      '#tree' => TRUE,
1615
      '#title' => t('Source Citations'),
1616
      '#collapsible' => FALSE,
1617
      '#collapsed' => FALSE,
1618
  );
1619

    
1620
  $bibliography_settings = get_bibliography_settings(true);
1621

    
1622
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1623
      '#type' => 'checkbox',
1624
      '#title' => t('Original Source in bibliography'),
1625
      '#default_value' => $bibliography_settings['enabled'],
1626
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1627
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1628
       into the bibliography also depends on the settings in the ' .
1629
        l("Taxon profile feature block settings", "admin/config/cdm_dataportal/settings/layout/taxon") .
1630
        '. 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.'),
1631
  );
1632

    
1633
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1634
    '#type' => 'select',
1635
    '#title' => t('The format of the key numerals'),
1636
    '#default_value' => $bibliography_settings['key_format'],
1637
    '#options' => array('latin' => 'Latin',
1638
      'ROMAN' => 'Roman (upper case)',
1639
      'roman' => 'Roman (lower case)',
1640
      'ALPHA'=> 'Alphabet (upper case)',
1641
      'alpha' => 'Alphabet (lower case)')
1642
  );
1643

    
1644
  // --- Advanced Search --- //
1645
  $form['asearch'] = array(
1646
      '#type' => 'fieldset',
1647
      '#title' => t('Advanced search'),
1648
      '#collapsible' => FALSE,
1649
      '#collapsed' => FALSE,
1650
  );
1651
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1652
      '#type' => 'checkbox',
1653
      '#title' => t('Show advanced search link'),
1654
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1655
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1656
  );
1657

    
1658
  // --- Name page autoredirect feature --- //
1659
  $form['name_page'] = array(
1660
    '#type' => 'fieldset',
1661
    '#title' => t('Name page'),
1662
    '#collapsible' => FALSE,
1663
    '#collapsed' => FALSE,
1664
  );
1665
  $form['name_page'][CDM_NAME_PAGE_AUTOREDIRECT] = array(
1666
    '#type' => 'checkbox',
1667
    '#title' => 'Always redirect to taxon',
1668
    '#default_value' => variable_get(CDM_NAME_PAGE_AUTOREDIRECT, 0),
1669
    '#description' => t('By checking this option you can globally enable the redirection behavior of the name page. 
1670
    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. 
1671
    This option allows to enable this behavior also for contexts in which the redirection normally is not active.'),
1672
  );
1673

    
1674
  // --- Registrations --- //
1675
  $form['registrations'] = array(
1676
    '#type' => 'fieldset',
1677
    '#title' => t('Registrations'),
1678
    '#collapsible' => FALSE,
1679
    '#collapsed' => FALSE,
1680
  );
1681
  $form['registrations']['cdm_registration_presistent_identifier_as_link'] = array(
1682
    '#type' => 'checkbox',
1683
    '#title' => t('Use the persistent http identifier as link'),
1684
    '#default_value' => variable_get('cdm_registration_presistent_identifier_as_link', 0),
1685
    '#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.'),
1686
  );
1687

    
1688
  // ---- Taxon Name Rendering --- //
1689
  $form['taxon_name'] = array(
1690
      '#type' => 'fieldset',
1691
      '#title' => t('Taxon name display'),
1692
      '#collapsible' => TRUE,
1693
      '#collapsed' => TRUE,
1694
      '#description' => t('The display of taxon names is configured by two parts.
1695
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1696
          The name parts are defined in the <stong>part definitions</strong>'),
1697
  );
1698

    
1699
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1700
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1701
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1702
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1703

    
1704
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1705
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1706
    $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.)';
1707
  } else if($is_custom_part_definition){
1708
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1709
  } else  {
1710
    $which_version_message = '(These are the default part definition.)';
1711
  }
1712

    
1713
  $diff_viewer_markup = '';
1714
  if($is_custom_part_definition){
1715
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1716
  }
1717

    
1718
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1719
    . $which_version_message
1720
    . '</div>'
1721
    . $diff_viewer_markup;
1722

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

    
1812
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1813
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1814
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1815
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1816
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1817

    
1818
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1819
    $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.)';
1820
  } else if($is_custom_render_template){
1821
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1822
  } else {
1823
    $which_version_message = '(These are the default render templates.)';
1824
  }
1825

    
1826
  $diff_viewer_markup = '';
1827
  if($is_custom_render_template){
1828
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1829
  }
1830

    
1831
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1832
    . $which_version_message
1833
    . '</div>'
1834
    . $diff_viewer_markup;
1835

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

    
1876
  // @WA: D7 form api does not support reset buttons,
1877
  // so to mimic the D5 reset button we add one like this.
1878
  $form['actions']['reset'] = array(
1879
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1880
    '#weight' => 1000,
1881
  );
1882

    
1883
  $form['#submit'] = array('submit_json_as_php_array');
1884
  // #json_elements especially defined for submit_json_as_php_array()
1885
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1886
  return system_settings_form($form);
1887
}
1888

    
1889

    
1890
/**
1891
 * @param $form_name
1892
 * @param $form_title
1893
 * @param $collapsed
1894
 * @param string $form_description
1895
 *   The description for the fieldset of the gallery setting.
1896
 * @return mixed
1897
 */
1898
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1899
  $form[$form_name] = array(
1900
    '#type' => 'fieldset',
1901
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1902
    '#collapsible' => TRUE,
1903
    '#collapsed' => $collapsed,
1904
    '#tree' => TRUE,
1905
    '#description' => $form_description,
1906
  );
1907

    
1908
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1909
  $gallery_settings = variable_get($form_name, $default_values);
1910
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1911
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1912
    /*
1913
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1914
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1915
    '#type' => 'textfield',
1916
    '#title' => t('Search Page Size'),
1917
    '#default_value' => $test,
1918
    '#description' => t('Number of Names to display per page in search results.')
1919
    );
1920
    */
1921
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1922
      '#type' => 'checkbox',
1923
      '#title' => t('Show media thumbnails for accepted taxa'),
1924
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1925
    );
1926

    
1927
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1928
      '#type' => 'checkbox',
1929
      '#title' => t('Show media thumbnails for synonyms'),
1930
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1931
      '#description' => '',
1932
    );
1933
  }
1934

    
1935
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1936
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1937
    '#type' => 'checkbox',
1938
    '#title' => t('Show captions under thumbnails'),
1939
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1940
    '#description' => '',
1941
  );
1942

    
1943
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1944
    '#type' => 'textfield',
1945
    '#title' => t('Thumbnail size (max of width or height)') . ':',
1946
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1947
    '#description' => t('The maximum extend in either dimension, width or height, in pixels for the thumbnail images in the gallery.'),
1948
  );
1949

    
1950
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1951
    '#type' => 'textfield',
1952
    '#title' => t('Number of columns') . ':',
1953
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1954
    '#description' => t('Group the thumbnails in columns: select how many
1955
      columns the gallery should display.'),
1956
  );
1957

    
1958
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1959
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1960
      '#type' => 'textfield',
1961
      '#title' => t('Maximum number of rows') . ':',
1962
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1963
      '#description' => t('You can group the thumbnails in rows, select in how
1964
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1965
        If you want an unlimited number of rows please set to 0.'),
1966
    );
1967
  }
1968

    
1969
  return $form;
1970
}
1971

    
1972
/**
1973
 * @return array
1974
 *   The form structure.
1975
 */
1976
function cdm_settings_layout_taxon() {
1977
  $collapsed = FALSE;
1978
  $form = array();
1979

    
1980
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1981

    
1982
  // --------- TABBED TAXON ------- //
1983
  $form['taxon_node'] = array(
1984
    '#type' => 'fieldset',
1985
    '#title' => t('Taxon node'),
1986
    '#collapsible' => TRUE,
1987
    '#collapsed' => TRUE,
1988
    '#description' => 'Taxa are organized in a classification tree by taxon nodes. Display of taxon node related information like states can be manged here.'
1989
  );
1990
  $form['taxon_node'][CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES] = array(
1991
    '#type' => 'checkbox',
1992
    '#title' => t('Show taxon node states'),
1993
    '#default_value' => variable_get(CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES, 1),
1994
    '#description' => t('Show the taxon node states excluded, unplaced and placement doubtful.'),
1995
  );
1996

    
1997
  // --------- TABBED TAXON ------- //
1998
  $form['taxon_tabs'] = array(
1999
    '#type' => 'fieldset',
2000
    '#title' => t('Taxon tabs'),
2001
    '#collapsible' => TRUE,
2002
    '#collapsed' => TRUE,
2003
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
2004
  );
2005

    
2006
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
2007
    '#type' => 'checkbox',
2008
    '#title' => t('Tabbed taxon page'),
2009
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
2010
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
2011
  );
2012

    
2013
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
2014
    '#type' => 'checkbox',
2015
    '#title' => t('Synonymy as tab'),
2016
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
2017
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
2018
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
2019
  );
2020

    
2021
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
2022
    '#type' => 'checkboxes',
2023
    '#title' => t('Section/Tab visibility') . ':',
2024
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
2025
    '#options' => get_taxon_options_list()
2026
  );
2027

    
2028
  // WEIGHT
2029
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
2030
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
2031
    '#title'  => 'Section/Tab order',
2032
    '#type' => 'fieldset',
2033
    '#collapsible' => false,
2034
    '#tree' => true,
2035
    '#description' => 'The weight value defines the order of the section/tab.'
2036
  );
2037
  // Weights range from -delta to +delta, so delta should be at least half
2038
  // of the amount of tabs present.
2039
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
2040
  foreach (get_taxon_tabs_list() as $label) {
2041
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
2042
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
2043
        '#title' => $label,
2044
        '#type'  => 'weight',
2045
        '#default_value' => $taxon_tabs_weights[$key],
2046
        '#delta' => $tab_weight_delta
2047
    );
2048
  }
2049

    
2050
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
2051
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
2052
    '#title'  => 'Section/Tab label override',
2053
    '#type' => 'fieldset',
2054
    '#collapsible' => false,
2055
    '#tree' => true,
2056
    '#description' => 'Setting a label for a section/tab will override the default label. 
2057
      Please enter the label text in the default language of the portal.'
2058
  );
2059
  foreach (get_taxon_tabs_list() as $label) {
2060
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
2061
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
2062
      '#title' => $label,
2063
      '#type'  => 'textfield',
2064
      '#default_value' => $taxon_tabs_labels[$key]
2065
    );
2066
  }
2067

    
2068
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
2069
    '#type' => 'select',
2070
    '#title' => t('Default tab to display') . ':',
2071
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
2072
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
2073
    '#description' => t('<p>Select the default tab to display when visiting a
2074
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
2075
      <strong>Note:</strong> After performing a search and clicking in any
2076
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
2077
      taxon and not the above selected tab.'),
2078
  );
2079

    
2080
  /* ======  TAXON_PROFILE ====== */
2081
  $form['taxon_profile'] = array(
2082
    '#type' => 'fieldset',
2083
    '#title' => t('Taxon profile (tab)'),
2084
    '#description' => t('<p>This section covers the settings related to the taxon
2085
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
2086
    '#collapsible' => TRUE,
2087
    '#collapsed' => TRUE,
2088
  );
2089

    
2090
  // ---- PROFILE PICTURE ----//
2091

    
2092
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
2093
    '#type' => 'fieldset',
2094
    '#tree' => TRUE,
2095
    '#title' => t('Taxon profile picture'),
2096
    '#collapsible' => TRUE,
2097
    '#collapsed' => FALSE,
2098
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
2099
  );
2100

    
2101
  //FIXME migrate variables:
2102
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
2103
  // FIXME
2104
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
2105

    
2106
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
2107

    
2108
  /*
2109
   * 'show' => 1,
2110
   * 'maxextend' => 184,
2111
   * 'media_uri_query' => ''
2112
   * 'custom_placeholder_image_on' => 1,
2113
   * 'custom_placeholder_image_fid' => ''
2114
   */
2115
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
2116
    '#type' => 'checkbox',
2117
    '#title' => t('Enable profile picture'),
2118
    '#description' => t('Show the profile picture.'),
2119
    '#default_value' => $taxon_profile_image_settings['show'],
2120
  );
2121

    
2122
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
2123
      '#type' => 'textfield',
2124
      '#tree' => TRUE,
2125
      '#title' => t('Profile picture maximum extend'),
2126
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
2127
      '#field_suffix' => 'px',
2128
      '#maxlength' => 4,
2129
      '#size' => 4,
2130
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
2131
  );
2132

    
2133
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
2134
      '#type' => 'textfield',
2135
      '#tree' => TRUE,
2136
      '#title' => t('Additional URI query parameter'),
2137
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
2138
      '#maxlength' => 1024,
2139
      '#size' => 60,
2140
      '#description' => t('Additional query parameters to be used when requesting for the  
2141
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
2142
            The query parameters will be appended to the uri of the media representation part
2143
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
2144
  );
2145

    
2146
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2147
    '#type' => 'checkbox',
2148
    '#title' => t('Show the placeholder image'),
2149
    '#description' => t("A placeholder image will be shown if no taxon profile picture is available."),
2150
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2151
  );
2152

    
2153
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2154
      '#type' => 'checkbox',
2155
      '#title' => t('Use a custom placeholder image'),
2156
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2157
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2158
  );
2159

    
2160
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2161
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2162
        '#type' => 'managed_file',
2163
        '#title' => t('Custom placeholder image file'),
2164
        '#progress_indicator' => 'bar',
2165
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2166
    //       '#name' => 'custom_placeholder_image',
2167
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2168
    );
2169

    
2170
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2171
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2172
      $url = file_create_url($profile_image_file->uri);
2173
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2174
                '#type' => 'item',
2175
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2176
      );
2177
    }
2178
  } else {
2179
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2180
      '#type' => 'hidden',
2181
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2182
    );
2183
  }
2184

    
2185
  $options = cdm_vocabulary_as_option(UUID_RANK, null, true);
2186
  array_unshift($options, '-- DISABLED --');
2187
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2188
    '#type' => 'select',
2189
    '#title' => t('Hide profile picture for higher ranks') . ':',
2190
    '#default_value' => variable_get('image_hide_rank', '0'),
2191
    '#options' => $options,
2192
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2193
  );
2194

    
2195
  // -- MEDIA THUMBNAILS -- //
2196
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2197
  $form_title = 'Taxon Profile Images';
2198
  $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>';
2199
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2200

    
2201
  // ---- FEATURE TREE BLOCKS ---- //
2202
  $form['taxon_profile']['feature_blocks'] = array(
2203
    '#type' => 'fieldset',
2204
    '#title' => t('Feature Blocks'),
2205
    '#collapsible' => TRUE,
2206
    '#collapsed' => FALSE,
2207
    '#description' => t("This section covers settings related to the taxon's
2208
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2209
      features such as description, distribution, common names"),
2210
  );
2211
  $featureTrees = cdm_get_featureTrees_as_options(TRUE, TRUE);
2212
  $profile_feature_tree = get_profile_feature_tree();
2213
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2214
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2215
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2216
  }
2217
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2218
    '#type' => 'radios',
2219
    '#title' => t('Taxon profile feature tree') . ':',
2220
    '#default_value' => $profile_feature_tree_uuid,
2221
    '#options' =>  $featureTrees['options'],
2222
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2223
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2224
    '#description' => t('The Feature Tree selected defines the type and order 
2225
    of the according feature blocks visible in the taxon profile page. A feature block 
2226
    only is shown if any data for it is present. The block weight is shown after the feature label in brackets'
2227
    ),
2228
  );
2229

    
2230
  $pseudo_feature_weights = get_array_variable_merged(CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS, CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT);
2231
  $form['taxon_profile']['feature_blocks'][CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS] = array(
2232
    '#title'  => 'Pseudo feature block weight',
2233
    '#type' => 'fieldset',
2234
    '#collapsible' => false,
2235
    '#tree' => true,
2236
    '#description' => 'Weights for the pseudo feature blocks. The weight value defines the 
2237
    position in the list of blocks. The weight of normal feature is defined by the position 
2238
    of the according feature. Please see the specific feature details above to find the feature weight.'
2239
  );
2240
  foreach ([PSEUDO_FEATURE_NUMBER_OF_TAXA, PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS, PSEUDO_FEATURE_BIBLIOGRAPHY] as $ps_feature) {
2241
    $form['taxon_profile']['feature_blocks'][CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS][$ps_feature] = array(
2242
      '#title' => $ps_feature,
2243
      '#type'  => 'textfield',
2244
      '#element_validate' => array('element_validate_number'),
2245
      '#size' => 4,
2246
      '#default_value' => $pseudo_feature_weights[$ps_feature]
2247
    );
2248
  }
2249

    
2250

    
2251
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2252
  $profile_feature_tree = get_profile_feature_tree();
2253

    
2254
  if (isset($profile_feature_tree->root->childNodes)) {
2255

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

    
2298

    
2299
    $feature_list_layout_settings_disabled = FALSE;
2300

    
2301
    // creating helper object to retrieve the default settings
2302
    $featureNode = new stdClass();
2303
    $featureNode->term = new stdClass();
2304
    $featureNode->term->uuid="DEFAULT";
2305
    $featureNode->term->representation_L10n = "Default";
2306
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2307

    
2308
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2309

    
2310
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2311

    
2312
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2313
        $subform_id = $featureNode->term->uuid;
2314
        $feature_block_setting = get_feature_block_settings($featureNode->term->uuid);
2315

    
2316
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2317

    
2318
        $form_feature_block_layout[$subform_id] = array(
2319
          '#type' => 'fieldset',
2320
          '#tree' => TRUE,
2321
          '#title' => $featureNode->term->representation_L10n,
2322
          '#collapsible' => FALSE,
2323
          '#collapsed' => FALSE,
2324
        );
2325
        if($featureNode->term->uuid == "DEFAULT"){
2326
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2327
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2328
          references</em> and <em>names in source</em> is only possible in the defaults';
2329
        }
2330

    
2331
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2332
          '#type' => 'select',
2333
          '#title' => 'List type',
2334
          '#default_value' => $feature_block_setting['as_list'],
2335
          '#options' => array(
2336
            'div' => 'not as list',
2337
            'ul' => 'bullet list',
2338
            'ol' => 'numbered list',
2339
            'dl' => 'definition list'
2340
          ),
2341
        );
2342

    
2343
        if($featureNode->term->uuid == "DEFAULT"){
2344
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2345
            '#type' => 'checkbox',
2346
            '#title' => t('Link to reference'),
2347
            '#default_value' => $feature_block_setting['link_to_reference'],
2348
          );
2349

    
2350
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2351
            '#type' => 'checkbox',
2352
            '#title' => 'Link to name used in source',
2353
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2354
          );
2355
        }
2356

    
2357
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2358
          '#type' => 'checkbox',
2359
          '#title' => 'Sources as content',
2360
          '#default_value' => $feature_block_setting['sources_as_content'],
2361
        );
2362

    
2363
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2364
          '#type' => 'checkbox',
2365
          '#title' => 'Put sources also as content to bibliography',
2366
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2367
        );
2368

    
2369
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2370
          '#type' => 'select',
2371
          '#title' => t('Sort elements'),
2372
          '#default_value' => $feature_block_setting['sort_elements'],
2373
          '#options' => array(
2374
            NO_SORT => 'No sorting',
2375
            SORT_ASC => 'Ascending',
2376
            SORT_DESC => 'Descending',
2377
            SORT_HIERARCHICAL => 'Hierarchical'
2378
          ),
2379
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2380
          <dl>
2381
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2382
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2383
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2384
          <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>
2385
          </dl>',
2386
        );
2387

    
2388
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2389
          '#type' => 'select',
2390
          '#title' => t('Element tag'),
2391
          '#options' => array(
2392
            'span' => 'span',
2393
            'div' => 'div',
2394
            'p' => 'p'
2395
          ),
2396
          '#default_value' => $feature_block_setting['element_tag'],
2397
        );
2398
        $form_feature_block_layout[$subform_id]['glue'] = array(
2399
          '#type' => 'textfield',
2400
          '#title' => t('Element glue'),
2401
          '#default_value' => $feature_block_setting['glue'],
2402
          '#size' => 10
2403
      );
2404

    
2405
      }
2406
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2407
    }
2408
  }
2409

    
2410
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2411
  $form['taxon_profile']['structured_description_featuretree'] = array(
2412
    '#type' => 'fieldset',
2413
    '#title' => t('Structured Description Feature Tree'),
2414
    '#collapsible' => TRUE,
2415
    '#collapsed' => FALSE,
2416
  );
2417
  $featureTrees = cdm_get_featureTrees_as_options();
2418
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2419
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2420
    $profile_feature_tree_uuid = NULL;
2421
  }
2422
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2423
    '#type' => 'radios',
2424
    '#title' => t('Natural language representation of structured descriptions') . ':',
2425
    '#default_value' => $profile_feature_tree_uuid,
2426
    '#options' => $featureTrees['options'],
2427
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2428
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2429
    '#description' => t('Taxon descriptions can be stored in a highly structured
2430
      form. The feature tree selected here will be used to generate textual
2431
      representation in natural language.'
2432
    ),
2433
  );
2434

    
2435

    
2436

    
2437
  // ---- DISTRIBUTION LAYOUT ---- //
2438
  $form['taxon_profile']['distribution_layout'] = array(
2439
    '#title' => t('Distribution'),
2440
    '#collapsible' => TRUE,
2441
    '#collapsed' => FALSE,
2442
    '#type' => 'fieldset',
2443
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2444
        Map settings regarding the geometry, layers, etc are found in the '
2445
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2446
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2447
      . l(
2448
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2449
        array('fragment' => 'edit-feature-block-settings')
2450
      )
2451
      . ' More general settings regrading the filtering of Distributions are found at '
2452
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2453
      . '. (These settings here will be merged in future releases into the feature block settings)',
2454

    
2455
  );
2456

    
2457
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2458

    
2459
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2460
    '#type' => 'checkbox',
2461
    '#title' => t('Condensed distribution'),
2462
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2463
    '#description' => 'This option enables the display of a very compact representation
2464
    of the distribution which includes also information on the status.',
2465
  );
2466

    
2467
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2468
    '#type' => 'select',
2469
    '#title' => t('Condensed distribution recipe'),
2470
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2471
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2472
    '#description' => 'Recipe for creating the condensed distribution.',
2473
  );
2474

    
2475
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2476
    '#type' => 'textfield',
2477
    '#title' => t('Condensed distribution info path'),
2478
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2479
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2480
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2481
  );
2482

    
2483

    
2484
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2485
    '#type' => 'radios',
2486
    '#title' => t('Display mode') . ':',
2487
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2488
    '#options' => array(
2489
      'FLAT_ALPHA' => t('Flat list'),
2490
      'TREE' => t('Hierarchically ordered'),
2491
    ),
2492
    '#description' => 'Taxon distribution information is displayed with
2493
    focus on the area of the distribution. The list of areas can either be shown
2494
    as flat list ordered alphabetically or in the hierarchical of the parent
2495
    area and subarea relationship. Fall back areas areas with no Distribution data
2496
    are hidden from the area hierarchy so that their sub areas will move one level up.
2497
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2498
    ' for details on the <em>Marked area filter</em>.',
2499
  );
2500

    
2501
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2502
    '#type' => 'fieldset',
2503
    '#tree' => true,
2504
    '#title' => t('Distribution hierarchy style')
2505
  );
2506

    
2507
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2508
  foreach(array_keys($hierarchy_styles) as $level) {
2509
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2510
      '#type' => 'fieldset',
2511
      '#tree' => true,
2512
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2513
      '#attributes' => array('class' => array('fieldset-float'))
2514
    );
2515
    foreach ($hierarchy_styles[$level] as $key => $value) {
2516
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2517
        '#type' => 'textfield',
2518
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2519
        '#default_value' => $hierarchy_styles[$level][$key],
2520
        '#maxlength' => 4,
2521
        '#size' => 4
2522
      );
2523
    }
2524
  }
2525

    
2526
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2527
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2528
    '#type' => 'checkboxes',
2529
    '#title' => 'Omit area levels',
2530
    '#options' => $level_options,
2531
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2532
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2533
    Areas which belong to the selected area levels will be hidden in the portal.',
2534
  );
2535

    
2536
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2537
    '#type' => 'checkbox',
2538
    '#title' => t('Show TextData elements on top of the map'),
2539
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2540
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2541
      elements on top of the map. Otherwise all <code>TextData</code>
2542
      distribution elements will be listed below the other area elements.
2543
      This option is useful if you need to have descriptive texts for each
2544
      distribution map.'),
2545
  );
2546

    
2547
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2548
      '#type' => 'textarea',
2549
      '#title' => t('Custom status colors'),
2550
      '#element_validate' => array('form_element_validate_json'),
2551
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2552
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2553
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2554
          reference list of the idInVocabulary values of absence and presence terms:
2555
<pre>
2556
Presence Term
2557
p	present
2558
pd	present: doubtfully present
2559
n	native
2560
nq	native: presence questionable
2561
nd	native: doubtfully native
2562
c	cultivated
2563
i	introduced
2564
iq	introduced: presence questionable
2565
id	introduced: doubtfully introduced (perhaps cultivated only)
2566
ip	introduced: uncertain degree of naturalisation
2567
ia	introduced: adventitious (casual)
2568
in	introduced: naturalized
2569
ic	introduced: cultivated
2570
e	endemic for the relevant area
2571
na	naturalised
2572
iv	invasive
2573

    
2574
AbsenceTerm
2575
a	absent
2576
f	reported in error
2577
nf	native: reported in error
2578
if	introduced: reported in error
2579
cf	cultivated: reported in error
2580
ne	native: formerly native
2581
ie	introduced: formerly introduced
2582

    
2583
</pre>'),
2584
  );
2585

    
2586

    
2587
  /* ====== SYNONYMY ====== */
2588
  $form['taxon_synonymy'] = array(
2589
    '#type' => 'fieldset',
2590
    '#title' => t('Taxon synonymy (tab)'),
2591
    '#collapsible' => TRUE,
2592
    '#collapsed' => TRUE,
2593
    '#description' => t('This section covers the settings related to the taxon
2594
      <strong>synonymy</strong> tab.'),
2595
  );
2596

    
2597
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2598
    '#type' => 'checkbox',
2599
    '#title' => t('Accepted taxon on top of the synonymy'),
2600
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT),
2601
    '#description' => t('If checked, the first homotypic taxon is a repetition
2602
      of the accepted taxon most likely with the full nomenclatural reference, 
2603
      depending on the ' . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout') . '.'),
2604
  );
2605

    
2606
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE] = array(
2607
    '#type' => 'checkbox',
2608
    '#title' => t('Secundum referenence as separate line above the accepted taxon.'),
2609
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE, 0),
2610
    '#description' => t('You may want to remove the <code>"secReferencePart": true,</code> entry from <code>"accepted_taxon.taxon_page_synonymy"{</code> the in the '
2611
      . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout')
2612
      . ' (Only applicable when the "Show accepted taxon on top of the synonymy" option above is enabled.)'),
2613
    '#disabled' =>  !variable_get(CDM_DATAPORTAL_NOMREF_IN_TITLE, CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT)
2614
  );
2615

    
2616
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL] = array(
2617
    '#type' => 'textfield',
2618
    '#description' => 'Label for the secundum referenence.',
2619
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT),
2620
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', 0)
2621
    );
2622

    
2623
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2624
    '#type' => 'checkbox',
2625
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2626
      coming from a synonym link.'),
2627
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2628
    '#description' => t('Check this if after doing a search and clicking on a
2629
      synonym you want to see the "accept of" text for the accepted synonym.'),
2630
  );
2631

    
2632
  $form['taxon_synonymy']['taxon_relations'] = array(
2633
    '#type' => 'fieldset',
2634
    '#title' => t('Taxon relationships'),
2635
    '#collapsible' => FALSE,
2636
    '#collapsed' => FALSE
2637
  );
2638

    
2639
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2640
    '#type' => 'checkbox',
2641
    '#title' => t('Show taxon relations ships of accepted taxon'),
2642
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2643
    '#description' => t('If this option is enabled the synonymy will show the
2644
      below selected taxon relationships of accepted taxa.'),
2645
  );
2646

    
2647
  $taxon_relationship_type_options = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2648
  $taxon_relationship_type_defaults = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
2649
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2650
    '#type' => 'checkboxes',
2651
    '#title' => t('Taxon relationship types') . ':',
2652
    '#description' => 'Only taxon relationships of the selected type will be displayed',
2653
    '#options' => $taxon_relationship_type_options,
2654
    '#default_value' => $taxon_relationship_type_defaults,
2655
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2656
  );
2657

    
2658
  $form['taxon_synonymy']['name_relations'] = array(
2659
    '#type' => 'fieldset',
2660
    '#title' => t('Name relationships'),
2661
    '#collapsible' => FALSE,
2662
    '#collapsed' => FALSE
2663
  );
2664

    
2665
  $name_relationship_type_options = cdm_vocabulary_as_option(
2666
      UUID_NAME_RELATIONSHIP_TYPE,
2667
      '_cdm_relationship_type_term_label_callback',
2668
      false,
2669
      array('uuid' => '/' .UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM . '|'
2670
        . UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM . '|'
2671
        . UUID_NAMERELATIONSHIPTYPE_CONSERVED_AGAINST . '|'
2672
        . UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR . '|'
2673
        . UUID_NAMERELATIONSHIPTYPE_MISSPELLING . '|'
2674
        . UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT . '/' )
2675
  );
2676
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_INLINE_TYPES] = array(
2677
    '#type' => 'checkboxes',
2678
    '#title' => t('Name relationship types') . ':',
2679
    '#description' => 'This setting only affects specific types of name relations which are displayed appended to scientific name. 
2680
    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') . '.',
2681
    '#options' => $name_relationship_type_options,
2682
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT)),
2683
  );
2684

    
2685
  // ====== SPECIMENS ====== //
2686
  $form['taxon_specimens'] = array(
2687
    '#type' => 'fieldset',
2688
    '#title' => t('Taxon specimens (tab)'),
2689
    '#collapsible' => TRUE,
2690
    '#collapsed' => TRUE,
2691
    '#description' => t('This section covers the settings related to the taxon
2692
      <strong>specimens</strong> tab.'),
2693
  );
2694

    
2695
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2696

    
2697
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2698
    '#type' => 'checkbox',
2699
    '#title' => t('Show specimen derivatives in a compressed table'),
2700
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2701
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2702
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2703
  );
2704

    
2705
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2706
      '#type' => 'textfield',
2707
      '#title' => t('Number of records per page') . ':',
2708
      '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2709
  );
2710

    
2711
    $form['taxon_specimens']['cdm_dataportal_specimen_derivate_tree'] = array(
2712
        '#type' => 'checkbox',
2713
        '#title' => t('Show specimen derivatives in a tree view'),
2714
        '#default_value' => variable_get('cdm_dataportal_specimen_derivate_tree', CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE),
2715
        '#description' => t('If checked, the specimen will be listed in a tree view.'),
2716
    );
2717

    
2718

    
2719
    $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2720
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2721
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2722
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2723
  }
2724
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2725
    '#type' => 'radios',
2726
    '#title' => t('Specimen description feature tree') . ':',
2727
    '#default_value' => $profile_feature_tree_uuid,
2728
    '#options' =>  $featureTrees['options'],
2729
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2730
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2731
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2732
    ),
2733
  );
2734

    
2735
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2736
  $form_title = t('Specimen media');
2737
  $form_description = t('Specimens may have media which is displayed at the
2738
     Specimen tab/section as a gallery. It is possible to configure the
2739
     thumbnails gallery here, however for configuring how a single media should
2740
     be displayed please go to !url.</p>',
2741
     array(
2742
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2743
     ));
2744
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2745

    
2746
  // --- MEDIA GALLERY ---- //
2747
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2748
  $form_title = 'Media gallery (tab)';
2749
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2750
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2751
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2752
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2753
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2754
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2755
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2756

    
2757
  // Comment @WA: D7 form api does not support reset buttons,
2758
  // so to mimic the D5 reset button we add one like this.
2759
  $form['actions']['reset'] = array(
2760
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2761
    '#weight' => 1000,
2762
  );
2763
  return system_settings_form($form);
2764
}
2765

    
2766
/**
2767
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2768
 *
2769
 * @param $map_id
2770
 * @param $form
2771
 * @return mixed
2772
 */
2773
function _cdm_map_visibility_setting($map_id)
2774
{
2775
  return array(
2776
    '#type' => 'select',
2777
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2778
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2779
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2780
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2781
        The map also can forced to show up <b>always</b> or <b>never</b>."
2782
  );
2783
}
2784

    
2785
/**
2786
 * @return array
2787
 *   The form structure.
2788
 */
2789
function cdm_settings_layout_search() {
2790

    
2791
  $form = array();
2792

    
2793
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2794

    
2795
  $form['search_settings'] = array(
2796
    '#type' => 'fieldset',
2797
    '#title' => t('Taxa Search'),
2798
    '#collapsible' => FALSE,
2799
    '#collapsed' => FALSE,
2800
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2801
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2802
         where they can write the text to be searched. You can find Drupal block configuration
2803
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2804
  );
2805

    
2806
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2807
      '#type' => 'checkbox',
2808
      '#title' => t('Ignore the chosen classification in simple search'),
2809
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2810
      '#description' => t('The simple search, which can be executed via the search block,
2811
          will by default search on the classification selected in the classification browser
2812
          selector. Set the tick if you want your portal to search on all classifications.'),
2813
  );
2814

    
2815
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2816
    '#type' => 'checkbox',
2817
    '#title' => t('Run simple search with free-text search backend.'),
2818
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2819
    '#description' => t('The simple search uses by default another search
2820
      backend as the advances search. By checking this option the simple search can be
2821
      configured to also use the free-text search backend.'),
2822
  );
2823

    
2824
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2825
    '#type' => 'checkbox',
2826
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2827
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2828
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2829
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2830
  );
2831

    
2832
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2833
    '#type' => 'textfield',
2834
    '#title' => t('Results per page') . ':',
2835
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2836
    '#description' => t('Number of results to display per page.'),
2837
  );
2838

    
2839
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2840
    '#type' => 'checkbox',
2841
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2842
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2843
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2844
  );
2845

    
2846
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2847
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2848
      '#type' => 'checkboxes',
2849
      '#title' => 'Search mode',
2850
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2851
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2852
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2853
          defaults set here.',
2854
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2855
      '#default_value' => $search_mode_default
2856
      );
2857

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

    
2863
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2864
  );
2865

    
2866
    $form['blast_search_settings'] = array(
2867
        '#type' => 'fieldset',
2868
        '#title' => t('Blast Search'),
2869
        '#collapsible' => TRUE,
2870
        '#collapsed' => TRUE,
2871
        '#description' => t('<p>To perform blast searchs
2872
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2873
         where they can write the text to be searched. You can find Drupal block configuration
2874
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p>
2875
         <p>To perform a blast search a blast database for the cdm instance is needed.</p> '),
2876
    );
2877

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

    
2883
        '#description' => t('Activate the blast search for this portal, this works only with an existing blast database!'),
2884
    );
2885
    $form['blast_search_settings'][CDM_SEARCH_BLAST_SERVICE_URI] = array(
2886
        '#type' => 'textfield',
2887
        '#title' => t('Webservice URL for blast search') . ':',
2888
        '#default_value' => variable_get(CDM_SEARCH_BLAST_SERVICE_URI, 'http://130.133.70.28:9001/api/sequence'),
2889

    
2890
        '#description' => t('Enter the webservice URL for blast search'),
2891
    );
2892

    
2893
  // --- SEARCH TAXA GALLERY ---- //
2894
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2895
  $collapsed = FALSE;
2896
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2897
  $form_title = 'Taxa Search thumbnails';
2898
  $form_description = 'Search results may show thumbnails. ';
2899
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2900

    
2901
  // Comment @WA: D7 form api does not support reset buttons,
2902
  // so to mimic the D5 reset button we add one like this.
2903
  $form['actions']['reset'] = array(
2904
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2905
    '#weight' => 1000,
2906
  );
2907
  return system_settings_form($form);
2908
}
2909

    
2910

    
2911
/**
2912
 * @return array
2913
 *   The form structure.
2914
 */
2915
function cdm_settings_layout_name_page()
2916
{
2917

    
2918
  $form = array();
2919

    
2920

    
2921
  $form['name_relations'] = array(
2922
    '#type' => 'fieldset',
2923
    '#title' => t('Name relationship listings'),
2924
    '#collapsible' => FALSE,
2925
    '#collapsed' => FALSE
2926
  );
2927

    
2928
  $name_relationship_type_options = cdm_vocabulary_as_option(
2929
    UUID_NAME_RELATIONSHIP_TYPE,
2930
    '_cdm_relationship_type_term_label_callback',
2931
    false
2932
  );
2933
  $form['name_relations'][CDM_NAME_RELATIONSHIP_LIST_TYPES] = array(
2934
    '#type' => 'checkboxes',
2935
    '#title' => t('Name relationship types') . ':',
2936
    '#description' => 'This setting only affects specific types of name relations which are displayed as list. Another representations 
2937
    is the inline style used in the synonymy which may show a different (reduced) set of name relations. 
2938
    The according settings can be adjusted in the ' . l('taxon page settings section synonmy', 'admin/config/cdm_dataportal/settings/layout/taxon') . '.',
2939
    '#options' => $name_relationship_type_options,
2940
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_LIST_TYPES, cdm_vocabulary_as_defaults(UUID_NAME_RELATIONSHIP_TYPE)),
2941
  );
2942

    
2943
  $form[CDM_NAME_PAGE_SECTION_TAXA] = array (
2944
    '#type' => 'checkbox',
2945
    '#title' => 'Show the associated taxa section',
2946
    '#default_value' => variable_get(CDM_NAME_PAGE_SECTION_TAXA, CDM_NAME_PAGE_SECTION_TAXA_DEFAULT)
2947

    
2948
  );
2949

    
2950
  return system_settings_form($form);
2951
}
2952

    
2953
/**
2954
 * @return array
2955
 *   The form structure.
2956
 */
2957
function cdm_settings_layout_media() {
2958

    
2959
  $form = array();
2960

    
2961
  $form['media_settings'] = array(
2962
    '#type' => 'fieldset',
2963
    '#title' => t('Media settings'),
2964
    '#collapsible' => FALSE,
2965
    '#collapsed' => FALSE,
2966
    '#description' => 'This section covers layout settings for media pages.'
2967
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2968
  );
2969

    
2970
  $form['media_settings'][CDM_MEDIA_GALLERY_VIEWER] = array(
2971
    '#type' => 'select',
2972
    '#title' => t('Image viewer') . ':',
2973
    '#default_value' => variable_get(CDM_MEDIA_GALLERY_VIEWER, CDM_MEDIA_GALLERY_VIEWER_DEFAULT),
2974
    '#options' => array(
2975
      CDM_MEDIA_GALLERY_VIEWER_DEFAULT => t('Universalviewer (new default)'),
2976
      'fsi' => t('FSI viewer (requires FSI server!)'),
2977
      'default' => t('Standard image viewer (deprecated)'),
2978
    ),
2979
  );
2980

    
2981
  // --- STANDARD_IMAGE_VIEWER ---- //
2982
  if(variable_get(CDM_MEDIA_GALLERY_VIEWER, 'default') == 'default') {
2983
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2984
      '#type' => 'fieldset',
2985
      '#tree' => true,
2986
      '#title' => t('Standard image viewer settings'),
2987
      '#collapsible' => FALSE,
2988
      '#collapsed' => FALSE,
2989
      );
2990

    
2991
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2992
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2993
      '#type' => 'checkbox',
2994
      '#title' => 'Show media representations',
2995
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2996

    
2997
    );
2998
  }
2999

    
3000

    
3001
  // @WA: D7 form api does not support reset buttons,
3002
  // so to mimic the D5 reset button we add one like this.
3003
  $form['actions']['reset'] = array(
3004
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3005
    '#weight' => 1000,
3006
  );
3007
  return system_settings_form($form);
3008
}
3009

    
3010
/**
3011
 * GEOSERVICE and Map settings.
3012
 *
3013
 *  @return array
3014
 *   The form structure.
3015
 */
3016
function cdm_settings_geo($form, &$form_state) {
3017

    
3018
  $current_geoserver_settings = get_edit_map_service_settings();
3019
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
3020

    
3021

    
3022
  $form = array();
3023

    
3024
  $dummy_distribution_query = NULL;
3025
  if($map_distribution['map_type'] != 1){
3026
    // we need to apply a dummy query since the map service requires for image maps
3027
    // at least as and ad to be defined
3028
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
3029
  }
3030

    
3031
  $form['map_preview'] = array(
3032
      '#type' => 'fieldset',
3033
      '#tree' => FALSE,
3034
      '#title' => t('Map preview'),
3035
      '#collapsible' => FALSE,
3036
      '#description' => 'The preview of the map'
3037
       . ($dummy_distribution_query != null ?
3038
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
3039
           '.<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.')
3040
  );
3041
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, NULL, $dummy_distribution_query, NULL, [
3042
    'move' => "this.cdmOpenlayersMap.printInfo",
3043
    '#execute' => "this.cdmOpenlayersMap.printInfo"
3044
  ], TRUE // resizable
3045
  );
3046

    
3047
  /*
3048
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
3049
  );
3050
  */
3051

    
3052
  /*
3053
   * GEO SERVER
3054
   */
3055
  $form['edit_map_server'] = array(
3056
    '#type' => 'fieldset',
3057
    '#tree' => true,
3058
    '#title' => t('EDIT map service'),
3059
    '#collapsible' => TRUE,
3060
    '#collapsed' => TRUE,
3061
    '#description' => t('Configuration and selection of your geo server.
3062
      The Geo Server is responsible for generating the maps.'),
3063
  );
3064

    
3065
  $form['edit_map_server']['base_uri'] = array(
3066
    '#type' => 'select',
3067
    '#title' => t('EDIT map service') . ':',
3068
    '#default_value' => $current_geoserver_settings['base_uri'],
3069
    '#options' => unserialize(EDIT_MAPSERVER_URI),
3070
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
3071
  );
3072
  $form['edit_map_server']['version'] = array(
3073
      '#type' => 'select',
3074
      '#title' => t('Version') . ':',
3075
      '#default_value' => $current_geoserver_settings['version'],
3076
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
3077
      '#description' => t('The version of the EDIT map services'),
3078
  );
3079

    
3080
  /*
3081
   * MAP SETTINGS
3082
   */
3083

    
3084
  $form[CDM_MAP_DISTRIBUTION] = array(
3085
    '#type' => 'fieldset',
3086
    '#tree' => TRUE,
3087
    '#title' => t('Maps settings'),
3088
    '#collapsible' => TRUE,
3089
    '#collapsed' => TRUE,
3090
    '#description' => t('General configuration for all map types.'),
3091
  );
3092

    
3093
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
3094
    '#type' => 'radios',
3095
    '#title' => 'Map types',
3096
    '#options' => array(
3097
      1 => "OpenLayers dynamic map viewer",
3098
      0 => "Plain image",
3099
    ),
3100
    '#default_value' => $map_distribution['map_type'],
3101
    '#description' => 'Two different map types are available :
3102
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
3103
      which allows zooming and panning. If enabled you can configure the default layer
3104
      (background of your maps) below.</li>
3105
      <li><em>Plain image</em>: The map will be static non interactive
3106
      image.</li></ul>',
3107
  );
3108
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
3109

    
3110
  /*
3111
   * settings for the distribution map are used also for specimens map!!!!
3112
   */
3113

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

    
3129
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
3130
    '#type' => 'textfield',
3131
    '#title' => 'Bounding box',
3132
    '#default_value' => $map_distribution['bbox'],
3133
    '#description' =>
3134
      '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. 
3135
      For the whole world use Use <code>-180,-90,180,90</code>" for EPSG:4326 layers, for Web Mercator maps Open Street Map or 
3136
      Google maps the maximum bounds of the world are <code>-27395030.933594,-13697515.466797,27395030.933594,13697515.466797</code>.
3137
      Leave <strong>empty</strong> to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
3138
      <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.
3139
      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
3140
      below the map from where you can copy the bbox string.</p>',
3141
  );
3142

    
3143
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
3144
    '#type' => 'select',
3145
    '#title' => 'Max zoom level',
3146
    '#default_value' => $map_distribution['maxZoom'],
3147
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
3148
  );
3149

    
3150
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
3151
    '#type' => 'checkbox',
3152
    '#title' => 'Display area labels',
3153
    '#default_value' => $map_distribution['show_labels'],
3154
    '#description' => t('The map will show name labels of the areas'),
3155
  );
3156

    
3157
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
3158
    '#type' => 'textfield',
3159
    '#title' => 'Map caption',
3160
    '#default_value' => $map_distribution['caption'],
3161
    '#description' => t('The caption will be shown below the map.'),
3162
  );
3163

    
3164
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
3165
    '#type' => 'textfield',
3166
    '#title' => 'Distribution layer opacity',
3167
    '#default_value' => $map_distribution['distribution_opacity'],
3168
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
3169
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
3170
  );
3171

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

    
3190
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
3191
    '#type' => 'textfield',
3192
    '#title' => 'Width',
3193
    '#default_value' => $map_distribution['image_map']['width'],
3194
    '#maxlength' => 4,
3195
    '#size' => 4,
3196
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
3197
  );
3198

    
3199
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
3200
    '#type' => 'textfield',
3201
    '#title' => 'Background layer',
3202
    '#default_value' => $map_distribution['image_map']['base_layer'],
3203
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
3204
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
3205
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
3206
    )),
3207
  );
3208

    
3209
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3210
    '#type' => 'textfield',
3211
    '#title' => 'Background color',
3212
    '#default_value' => $map_distribution['image_map']['bg_color'],
3213
  );
3214

    
3215
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3216
    '#type' => 'textfield',
3217
    '#title' => 'Background layer style',
3218
     // Only line color by now.
3219
    '#default_value' => $map_distribution['image_map']['layer_style'],
3220
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3221
  );
3222

    
3223
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3224
      '#type' => 'textfield',
3225
      '#title' => 'Projection',
3226
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3227
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3228
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3229
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3230
  );
3231

    
3232

    
3233
  // --- OpenLayers Settings --- //
3234
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3235
    '#type' => 'fieldset',
3236
    '#title' => 'OpenLayers settings',
3237
    '#tree' => TRUE,
3238
    '#collapsible' => TRUE,
3239
    '#collapsed' => !$open_layers_is_enabled,
3240
    '#description' => '',
3241
  );
3242

    
3243

    
3244
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3245
      '#type' => 'checkbox',
3246
      '#title' => 'Display outside max extent',
3247
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3248
      '#description' => t('Allows the map to display parts of the layers which are outside
3249
         the max extent if the aspect ratio of the map and of the baselayer
3250
         are not equal.'),
3251
  );
3252

    
3253

    
3254
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3255
      '#type' => 'checkbox',
3256
      '#title' => 'Show Layer Switcher',
3257
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3258
      '#description' => 'The Layer Switcher control displays a table of contents
3259
      for the map.  This allows the user interface to switch between
3260
      base layers and to show or hide overlays.  By default the switcher is
3261
      shown minimized on the right edge of the map, the user may expand it
3262
      by clicking on the handle.',
3263
  );
3264

    
3265
  if (!$open_layers_is_enabled) {
3266
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3267
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3268
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3269
  }
3270

    
3271
  // The default layer must always be enabled
3272
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3273
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3274

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

    
3305
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3306
    '#type' => 'checkboxes_preferred',
3307
    '#title' => 'Base Layers',
3308
    '#options' => $baselayer_options,
3309
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3310
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3311
  );
3312

    
3313
  $google_maps_api_key = null;
3314
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3315
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3316
  }
3317
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3318
    '#type' => 'textfield',
3319
    '#title' => 'Google Maps API Key',
3320
    '#default_value' => $google_maps_api_key,
3321
    '#description' => 'In order to use any of the Google map layers you need to provide 
3322
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3323
  );
3324

    
3325
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3326
    $map_distribution['openlayers']['custom_wms_base_layer'],
3327
    'Custom WMS base layer',
3328
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3329
    true // add projection settings
3330
    );
3331

    
3332
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3333
    $map_distribution['openlayers']['wms_overlay_layer'],
3334
    'WMS overlay layer',
3335
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3336
                You can actually combine multiple layers for this overlay. 
3337
                For details please refer to the wms query parameter <code>Layers</code> .'
3338
  );
3339

    
3340
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3341
    '#type' => 'checkbox',
3342
    '#title' => 'Enable overlay layer',
3343
    '#weight' => -100,
3344
    '#default_value' => isset($map_distribution['openlayers']['wms_overlay_layer']['is_enabled']) && $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3345
  );
3346

    
3347
  /*
3348
   * Map Legend
3349
   */
3350
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3351
    '#type' => 'fieldset',
3352
    '#title' => 'Map legend',
3353
    '#tree' => TRUE,
3354
    '#collapsible' => TRUE,
3355
    '#collapsed' => TRUE,
3356
    '#description' => 'Configure the maps legend.',
3357
  );
3358

    
3359
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3360
    '#type' => 'checkbox',
3361
    '#title' => 'Display a map legend',
3362
    '#default_value' => $map_distribution['legend']['show'],
3363
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3364
  );
3365

    
3366
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3367
    '#type' => 'textfield',
3368
    '#title' => 'Legend opacity',
3369
    '#default_value' => $map_distribution['legend']['opacity'],
3370
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3371
                         to 0.0 will be not much visible.',
3372
  );
3373

    
3374
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3375
    '#type' => 'textfield',
3376
    '#title' => 'Font size',
3377
    '#default_value' => $map_distribution['legend']['font_size'],
3378
    '#description' => 'Font size in pixels.',
3379
  );
3380

    
3381
  $fontStyles = array(
3382
    0 => "plane",
3383
    1 => "italic",
3384
  );
3385
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3386
    '#type' => 'select',
3387
    '#title' => 'Available font styles',
3388
    '#default_value' => $map_distribution['legend']['font_style'],
3389
    '#options' => $fontStyles,
3390
    '#description' => 'Select a font style for the map legend.',
3391
  );
3392

    
3393
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3394
    '#type' => 'textfield',
3395
    '#title' => 'Icon width',
3396
    '#default_value' => $map_distribution['legend']['icon_width'],
3397
    '#description' => 'Legend icon width in pixels.',
3398
  );
3399
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3400
    '#type' => 'textfield',
3401
    '#title' => 'Icon height',
3402
    '#default_value' => $map_distribution['legend']['icon_height'],
3403
    '#description' => 'Legend icon height in pixels.',
3404
  );
3405

    
3406
  // @WA: D7 form api does not support reset buttons,
3407
  // so to mimic the D5 reset button we add one like this.
3408
  $form['actions']['reset'] = array(
3409
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3410
    '#weight' => 1000,
3411
  );
3412

    
3413
  return system_settings_form($form);
3414
}
3415

    
3416
/**
3417
 * @param $default_settings
3418
 * @param $title
3419
 * @param $description
3420
 * @param bool $add_projection_settings
3421
 * @return array
3422
 */
3423
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3424
{
3425
  $form_elements = array(
3426
    '#type' => 'fieldset',
3427
    '#title' => $title,
3428
    '#tree' => TRUE,
3429
    '#collapsible' => FALSE,
3430
    '#collapsed' => FALSE,
3431
    '#description' => $description,
3432
  );
3433

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

    
3469
  if($add_projection_settings){
3470

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

    
3536
  }
3537
  return $form_elements;
3538
}
3539

    
3540

    
3541
/**
3542
 * @return array
3543
 *   The form structure.
3544
 */
3545
function cdm_settings_cache() {
3546

    
3547
  $form = array();
3548

    
3549
  $form['cache_settings'] = array(
3550
    '#type' => 'fieldset',
3551
    '#title' => t('Cache Settings'),
3552
    '#collapsible' => FALSE,
3553
    '#collapsed' => FALSE,
3554
    '#description' => t('<p>When caching is enabled all single taxon sites are
3555
      stored in an internal drupal cache doing the portal response of taxa pages
3556
      faster. This is possible because the sites are loaded from the cache and
3557
      are not created from scratch.</p>'),
3558
  );
3559

    
3560
  $form['cache_settings']['cdm_webservice_cache'] = array(
3561
    '#type' => 'checkbox',
3562
    '#title' => t('<strong>Enable caching</strong>'),
3563
    '#options' => cdm_help_general_cache(),
3564
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3565
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3566
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3567
       application the changes will be not visible till the cache is erased.
3568
       Therefore developers should deactived this feature when they are working
3569
       on the CDM Dataportal Module.</p>'),
3570
  );
3571

    
3572
  $form['cache_settings']['cdm_run_cache'] = array(
3573
    '#markup' => cdm_view_cache_site(),
3574
  );
3575

    
3576
  // @WA: D7 form api does not support reset buttons,
3577
  // so to mimic the D5 reset button we add one like this.
3578
  $form['actions']['reset'] = array(
3579
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3580
    '#weight' => 1000,
3581
  );
3582
  return system_settings_form($form);
3583
}
3584

    
3585
/**
3586
 * Walk and cache all taxon pages.
3587
 */
3588
function cdm_view_cache_site() {
3589

    
3590
  $out = '';
3591

    
3592
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3593

    
3594
  $request_params = array();
3595
  $request_params['class'] = "Taxon";
3596

    
3597
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3598
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3599
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3600

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

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

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

    
3628

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

    
3649
function cdm_settings_layout_search_submit($form, &$form_state){
3650
  // the visibility of media thumbnails also affects the ui of the search results
3651
  // so reset the according session variable
3652
  //    1. in order to give the user immediate
3653
  //       feedback on potential setting changes
3654
  //    2. let refresh the default if it has changed
3655
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3656
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3657
  }
3658
}
3659

    
3660
/**
3661
 * Form validation handler for cdm_settings_general
3662
 *
3663
 * @param $form
3664
 * @param $form_state
3665
 */
3666
function cdm_settings_general_validate($form, &$form_state) {
3667

    
3668
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3669
    $form_state['values']['cdm_webservice_url'] .= '/';
3670
  }
3671

    
3672
}
3673

    
3674
/**
3675
 * Form submit handler for settings general.
3676
 *
3677
 * tasks performed:
3678
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3679
 *
3680
 * @param $form
3681
 * @param $form_state
3682
 */
3683
function cdm_settings_general_submit($form, &$form_state){
3684
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3685
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3686
  unset($_SESSION['cdm_login']);
3687
}
3688

    
3689
/**
3690
 * Form validation handler for cdm_settings_cache
3691
 */
3692
function cdm_settings_cache_validate($form, &$form_state) {
3693
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3694
    cache_clear_all(NULL, 'cache_cdm_ws');
3695
    // Better clear secref_cache since I can not be sure if the cache has not
3696
    // be used during this response.
3697
    cdm_api_secref_cache_clear();
3698
  }
3699

    
3700
}
3701

    
3702
/**
3703
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3704
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3705
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3706
 *  - version: the version, e.g.: v1.1
3707
 *
3708
 * @return array
3709
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3710
 */
3711
function get_edit_map_service_settings() {
3712

    
3713
  $settings = variable_get('edit_map_server', array(
3714
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3715
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3716
      )
3717
  );
3718

    
3719
  return $settings;
3720
}
3721

    
3722
/**
3723
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3724
 *
3725
 * @return string
3726
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3727
 */
3728
function get_edit_map_service_full_uri() {
3729
  $settings = get_edit_map_service_settings();
3730
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3731
}
3732

    
3733

    
3734
/**
3735
 * Returns the version number of the currently selected edit mapserver as a float
3736
 *
3737
 * @return float
3738
 *   The version number of the currently selected edit mapserver as a float.
3739
 *   Returns 0 on error.
3740
 */
3741
function get_edit_map_service_version_number() {
3742

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

    
3745
  $settings = get_edit_map_service_settings();
3746
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3747
  if (isset($matches[1])) {
3748
    // Convert string to float.
3749
    $version = 1 + $matches[1][0] - 1;
3750
    return $version;
3751
  }
3752
  else {
3753
    // Report error.
3754
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3755
        array(
3756
          '!version' => $settings['version'],
3757
          'warning')
3758
        )
3759
      );
3760
    return 0;
3761
  }
3762
}
3763

    
3764
/**
3765
 * Returns the array of selected items in a options array
3766
 *
3767
 * @param array $options
3768
 *   An options array as generated by a form element like checkoxes, select ...,
3769
 */
3770
function get_selection($options) {
3771
  $selection = array();
3772
  foreach ($options as $key=>$val) {
3773
    if (!empty($val)) {
3774
      $selection[] = $val;
3775
    }
3776
  }
3777
  return $selection;
3778
}
3779

    
3780

    
3781
/**
3782
 * Implements hook_element_info().
3783
 *
3784
 * Allows modules to declare their own Form API element types and specify their default values.
3785
 *
3786
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3787
 */
3788
function cdm_dataportal_element_info() {
3789
  $type['checkboxes_preferred'] = array(
3790
    '#input' => TRUE,
3791
    '#process' => array('checkboxes_preferred_expand'),
3792
    '#after_build' => array('checkboxes_preferred_after_build'),
3793
    '#theme' => array('checkboxes_preferred'),
3794
    // '#theme_wrapper' => array('form_element'),
3795
  );
3796
  return $type;
3797
}
3798

    
3799
/**
3800
 * #process callback function for the custom form element type 'checkbox_preferred'
3801
 *
3802
 *
3803
 */
3804
function checkboxes_preferred_expand($element, &$form_state, $form) {
3805

    
3806
  // First of all create checkboxes for each of the elements
3807
  $element = form_process_checkboxes($element);
3808

    
3809
  // compose the element name
3810
  $parents = array();
3811
  array_deep_copy($element['#parents'], $parents);
3812
  $parents[count($parents) -1 ] .= '_preferred';
3813
  $element_name = $parents[0];
3814
  for ($i=1; $i < count($parents); $i++){
3815
    $element_name .= '[' . $parents[$i] . ']';
3816
  }
3817

    
3818
  $children = element_children($element);
3819

    
3820
  $element['table_start'] = array(
3821
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3822
    '#weight' => -1,
3823
  );
3824

    
3825
  // prepare first part each of the table rows which contains the row label
3826
  $weight = 0;
3827
  foreach ($children as $key) {
3828
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3829
    $element[$key]['#weight'] = $weight;
3830
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3831
    $element[$key]['#suffix'] = '</td>';
3832
    unset($element[$key]['#title']);
3833
    $weight += 2;
3834
  }
3835
  $weight = 0;
3836

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

    
3860
  // end the table
3861
  $element['table_end'] = array(
3862
    '#markup' => '</table>',
3863
    '#weight' => $weight++,
3864
  );
3865

    
3866
  return $element;
3867
}
3868

    
3869
/**
3870
 * Theme function for the custom form field 'checkboxes_preferred'.
3871
 */
3872
function theme_checkboxes_preferred($variables) {
3873
  $element = $variables['element'];
3874
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3875
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3876
  $out .= drupal_render_children($element);
3877
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3878
  $out .= '</div>';
3879
  return $out;
3880
}
3881

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

    
3902
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3903

    
3904
  if ($_POST && count($_POST) > 0) {
3905
    // TODO use  $form_state['input'] instead of POST !!!
3906
    // First pass of form processing.
3907
    $parents = array();
3908
    array_deep_copy($element['#parents'], $parents);
3909
    $parents[count($parents) - 1] .= '_preferred';
3910
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3911
    $element['#value']['PREFERRED'] = $preferred_layer;
3912
//     $form_state[$parent_id] = $element['#value'];
3913
//     $form_state['values']['baselayers'] = $element['#value'];
3914
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3915
    $form_state_element_values = $element['#value'];
3916
  }
3917
  else {
3918
    // Second pass of form processing.
3919
    $preferred_layer = $element['#value']['PREFERRED'];
3920
  }
3921

    
3922
  // Also set the chosen value (not sure if this is good Drupal style ....).
3923
  foreach ($children = element_children($element) as $key) {
3924
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3925
      $element[$key]['#value'] = $preferred_layer;
3926
    }
3927
  }
3928
  // The default layer must always be enabled.
3929
  $element[$preferred_layer]['#value'] = $preferred_layer;
3930

    
3931
  return $element;
3932
}
3933

    
3934
function radios_prepare_options_suffix(&$elements){
3935

    
3936
  $childrenKeys = element_children($elements);
3937
  foreach($childrenKeys as $key){
3938
    if(!is_array($elements[$key]['#theme_wrappers'])){
3939
      $elements[$key]['#theme_wrappers'] = array();
3940
    }
3941
    if(isset($elements['#options_suffixes'][$key])){
3942
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3943
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3944
    }
3945
  }
3946
  return $elements;
3947

    
3948
}
3949

    
3950
/**
3951
 * TODO
3952
 * @param unknown $variables
3953
 */
3954
function theme_radio_options_suffix($variables) {
3955
  $element = $variables['element'];
3956
  if(isset($element['#options_suffix'])) {
3957
    $element['#children'] .= $element['#options_suffix'];
3958
  }
3959
  return $element['#children'];
3960
}
3961

    
3962

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

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