Project

General

Profile

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

    
7

    
8
  // TODO Genus UUID.
9

    
10
  define('TAXONTREE_RANKLIMIT', 'cdm_taxontree_ranklimit');
11
  define('TAXONTREE_RANKLIMIT_DEFAULT', 0);
12
  define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
13
  define('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
14

    
15
  define('NO_SORT', -1);
16
  define('SORT_HIERARCHICAL', 9);
17

    
18
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
19

    
20
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
21
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
22

    
23
  define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
24
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
25
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE', 50);
26
  define('CDM_DATAPORTAL_TAXON_AUTO_SUGGEST', 0);
27
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 1);
28
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
29
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
30
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
31
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
32

    
33
  /* annotationTypeKeys */
34
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
35
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
36
    $annotationTypeKeys = array_flip($annotationTypeKeys);
37

    
38
    // Technical annotation are off by default.
39
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
40
    $annotationTypeKeys = array_flip($annotationTypeKeys);
41
    // Additional value for the NULL case.
42
    $annotationTypeKeys[] = 'NULL_VALUE';
43
  }
44
  define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
45

    
46
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
47
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
48
    'enabled' => 0,
49
    'key_format' => 'ALPHA'
50
  )));
51

    
52
  /* taxonRelationshipTypes */
53
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
54

    
55

    
56

    
57
    /* ---- MAP SETTING CONSTANTS ---- */
58
  /**
59
   * @var array of URIs eg. http://edit.africamuseum.be"
60
   *   An options array
61
   */
62
  define('EDIT_MAPSERVER_URI', serialize(
63
      array(
64
        'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)',
65
        'http://edit.br.fgov.be'=>'Secondary (http://edit.br.fgov.be)',
66
      )
67
    )
68
  );
69
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
70
  /**
71
   * @var array of versions eg. "v1.2"
72
   *   An options array
73
   */
74
  define('EDIT_MAPSERVER_VERSION', serialize(
75
      array(
76
//        'v1' => 'v1' ,           // no longer recommended
77
//        'v1.1' => 'v1.1',        // no longer recommended
78
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
79
        'v1.2' => 'v1.2',
80
        'v1.3_dev' => 'v1.3_dev (not recommended)',
81
        'v1.4_dev' => 'v1.4_dev (experimental features)'
82
      )
83
    )
84
  );
85
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
86
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
87

    
88
    // --- Taxon profile settings --- /
89
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
90
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
91
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
92
      array(
93
          'show' => 0,
94
          'maxextend' => 184,
95
          'media_uri_query' => '',
96
          'custom_placeholder_enabled' => 1,
97
          'custom_placeholder_image_on' => 0,
98
          'custom_placeholder_image_fid' => ''
99
      )
100
    )
101
  );
102

    
103

    
104
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
105

    
106
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
107
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
108
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
109
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
110
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
111

    
112
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
113
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
114
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
115
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
116

    
117
/**
118
 * Returns the array of implemented taxon page tabs.
119
 * The array has fixed integer keys which must not be changed.
120
 */
121
function get_taxon_tabs_list() {
122
  return array(
123
    0 => 'General',
124
    1 => 'Synonymy',
125
    2 => 'Images',
126
    3 => 'Specimens',
127
    4 => 'Keys',
128
    5 => 'Experts',
129
  );
130
}
131

    
132
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
133
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
134
  array(
135
    'general' => '-3',
136
    'synonymy' => '-2',
137
    'images' => '0',
138
    'specimens' => '1',
139
    'keys' => '3',
140
    'experts' => '5',
141
    )
142
));
143

    
144

    
145
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
146
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
147
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
148
  array(
149
    'general' => null,
150
    'synonymy' => null,
151
    'images' => null,
152
    'specimens' => null,
153
    'keys' => null,
154
    'experts' => null,
155
  )
156
));
157

    
158
$taxon_tab_options = get_taxon_tabs_list();
159
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
160

    
161
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
162

    
163
/**
164
 * @todo document this function.
165
 */
166
function get_taxon_options_list() {
167
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
168
  foreach ($taxon_tab_options as $key => $value) {
169
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
170
  }
171
  return $taxon_tab_options;
172

    
173
}
174

    
175
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
176
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
177
  array(
178
      'ZoologicalName' => array(
179
        'namePart' => array('name' => TRUE),
180
        'nameAuthorPart' => array('name' => TRUE),
181
        'referencePart' => array('authors' => TRUE),
182
        'microreferencePart' => array('microreference' => TRUE),
183
        'secReferencePart' => array('secReference' => TRUE,),
184
        'statusPart' => array('status' => TRUE),
185
        'descriptionPart' => array('description' => TRUE),
186
      ),
187
      'BotanicalName'=> array(
188
        'namePart' => array('name' => TRUE),
189
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
190
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
191
        'secReferencePart' => array('secReference' => TRUE,),
192
        'referenceYearPart' => array('reference.year' => TRUE),
193
        'statusPart' => array('status' => TRUE),
194
        'descriptionPart' => array('description' => TRUE),
195
      ),
196
     '#DEFAULT' => array(
197
        'namePart' => array(
198
            'name' => TRUE
199
        ),
200
        'nameAuthorPart' => array(
201
            'name' => TRUE,
202
            'authors' => TRUE
203
        ),
204
       'referencePart' => array(
205
         'reference' => TRUE
206
        ),
207
       'secReferencePart' => array(
208
         'secReference' => TRUE,
209
       ),
210
       'microreferencePart' => array(
211
          'microreference' => TRUE,
212
        ),
213
       'statusPart' => array(
214
          'status' => TRUE,
215
        ),
216
       'descriptionPart' => array(
217
          'description' => TRUE,
218
        ),
219
      )
220
    )
221
  )
222
);
223
  define('CDM_PART_DEFINITIONS_DEFAULT_PRE_380', serialize(
224
    array(
225
      'ZoologicalName' => array(
226
        'namePart' => array('name' => TRUE),
227
        'nameAuthorPart' => array('name' => TRUE),
228
        'referencePart' => array('authors' => TRUE),
229
        'microreferencePart' => array('microreference' => TRUE),
230
        'statusPart' => array('status' => TRUE),
231
        'descriptionPart' => array('description' => TRUE),
232
      ),
233
      'BotanicalName'=> array(
234
        'namePart' => array('name' => TRUE),
235
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
236
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
237
        'referenceYearPart' => array('reference.year' => TRUE),
238
        'statusPart' => array('status' => TRUE),
239
        'descriptionPart' => array('description' => TRUE),
240
      ),
241
      '#DEFAULT' => array(
242
        'namePart' => array(
243
          'name' => TRUE
244
        ),
245
        'nameAuthorPart' => array(
246
          'name' => TRUE,
247
          'authors' => TRUE
248
        ),
249
        'referencePart' => array(
250
          'reference' => TRUE
251
        ),
252
        'microreferencePart' => array(
253
          'microreference' => TRUE,
254
        ),
255
        'statusPart' => array(
256
          'status' => TRUE,
257
        ),
258
        'descriptionPart' => array(
259
          'description' => TRUE,
260
        ),
261
      )
262
    )
263
  )
264
  );
265

    
266
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
267
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
268
  array (
269
    'taxon_page_title,polytomousKey'=> array(
270
        'namePart' => array('#uri' => TRUE),
271
      ),
272
    'not_in_current_classification' => array(
273
     'nameAuthorPart' => TRUE,
274
     'referencePart' => TRUE,
275
     'statusPart' => TRUE,
276
     'secReferencePart' => TRUE,
277
    ),
278
    'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy'=> array(
279
      'nameAuthorPart' => array('#uri' => TRUE),
280
      'referencePart' => TRUE,
281
      'statusPart' => TRUE,
282
      'descriptionPart' => TRUE,
283
    ),
284
    'related_taxon.other_taxon_relationship.taxon_relationships.taxon_page_synonymy'=> array(
285
      'nameAuthorPart' => array('#uri' => TRUE),
286
      'referencePart' => TRUE,
287
      'statusPart' => TRUE,
288
      'secReferencePart' => TRUE,
289
      'descriptionPart' => TRUE,
290
    ),
291
    'related_taxon.misapplied_name_for.taxon_relationships.taxon_page_synonymy' => array(
292
      'nameAuthorPart' => array('#uri' => TRUE),
293
      'referencePart' => TRUE,
294
      'statusPart' => TRUE,
295
      /* no sec ref in this case, misapplied names are
296
       * de-duplicated and the sec ref is shown as footnote */
297
      'descriptionPart' => TRUE,
298
    ),
299
    'homonym'=> array(
300
        'nameAuthorPart' => array('#uri' => TRUE),
301
        'referenceYearPart' => TRUE,
302
        'statusPart' => TRUE,
303
    ),
304
    'acceptedFor,typedesignations,list_of_taxa' => array(
305
        'nameAuthorPart' => array('#uri' => TRUE),
306
        'referencePart' => TRUE,
307
      ),
308
    '#DEFAULT' => array(
309
        'nameAuthorPart' => array('#uri' => TRUE),
310
        'referencePart' => TRUE,
311
     )
312
  )
313
));
314
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
315
  array (
316
    'taxon_page_title,polytomousKey'=> array(
317
      'namePart' => array('#uri' => TRUE),
318
    ),
319
    'taxon_page_synonymy,related_taxon'=> array(
320
      'nameAuthorPart' => array('#uri' => TRUE),
321
      'referencePart' => TRUE,
322
      'statusPart' => TRUE,
323
      'descriptionPart' => TRUE,
324
    ),
325
    'homonym'=> array(
326
      'nameAuthorPart' => array('#uri' => TRUE),
327
      'referenceYearPart' => TRUE,
328
    ),
329
    'acceptedFor,typedesignations,list_of_taxa' => array(
330
      'nameAuthorPart' => array('#uri' => TRUE),
331
      'referencePart' => TRUE,
332
    ),
333
    '#DEFAULT' => array(
334
      'nameAuthorPart' => array('#uri' => TRUE),
335
      'referencePart' => TRUE,
336
    )
337
  )
338
));
339

    
340
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
341
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
342
    // to unset a default enntry set the value to 0
343
    array(
344
      'doTaxa'=>'doTaxa',
345
      'doSynonyms' => 'doSynonyms',
346
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
347
      'doMisappliedNames' => 'doMisappliedNames'
348
    )
349
  )
350
);
351

    
352
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
353

    
354
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
355
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
356

    
357
/* Gallery variables. */
358
$gallery_settings = array(
359
    "cdm_dataportal_show_taxon_thumbnails" => 1,
360
    "cdm_dataportal_show_synonym_thumbnails" => 0,
361
    "cdm_dataportal_show_thumbnail_captions" => 1,
362
    "cdm_dataportal_media_maxextend" => 120,
363
    "cdm_dataportal_media_cols" => 3,
364
    "cdm_dataportal_media_maxRows" => 1,
365
);
366

    
367
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
368
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
369
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
370
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
371
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
372
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
373
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
374
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
375
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
376
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
377
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
378
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
379

    
380
/**
381
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
382
 * the snonymy.
383
 *
384
 * @var string
385
 */
386
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
387

    
388
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
389
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
390
    array(
391
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
392
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
393
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
394
    )
395
  )
396
);
397

    
398
/**
399
 * The drupal variable for the configuration of the information aggregation along
400
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
401
 *    - direct: the uuids of the taxon relationship types to take into account in invers
402
 *      direction.
403
 *    - invers: the uuids of the taxon relationship types to take into account in direct
404
 *      direction.
405
 *
406
 * @var String
407
 */
408
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
409
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
410
    array(
411
        'direct'=>array(),
412
        'invers'=>array()
413
     )
414
   ));
415
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
416
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
417
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
418

    
419
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
420
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
421
      array(
422
      'filter_rules' => array(
423
        'statusOrderPreference' => 0,
424
        'subAreaPreference' => 0,
425
      ),
426
      'hiddenAreaMarkerType' => array()
427
     )
428
));
429

    
430
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
431
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
432
  "level_0" => array(
433
    'label_suffix' => ':',
434
    'status_glue' => '',
435
    'item_glue' => ' ',
436
    'item_group_prefix' => '',
437
    'item_group_postfix' => ''
438
  ),
439
  "level_1" => array(
440
    'label_suffix' => '',
441
    'status_glue' => '‒ ', // '&#8210; '
442
    'item_glue' => '; ',
443
    'item_group_prefix' => ', ',
444
    'item_group_postfix' => ''
445
  ),
446
  "level_2" => array(
447
    'label_suffix' => '',
448
    'status_glue' => '‒ ', // '&#8210; '
449
    'item_glue' => ', ',
450
    'item_group_prefix' => ' (',
451
    'item_group_postfix' => ')'
452
  )
453
)));
454

    
455
/**
456
 * Constant for the drupal variable key distribution_map_visibility
457
 *
458
 * possible values:
459
 *  - never
460
 *  - automatic
461
 *  - always
462
 */
463
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
464
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
465

    
466
/**
467
 * Constant for the drupal variable key specimen_map_visibility
468
 *
469
 * possible values:
470
 *  - never
471
 *  - automatic
472
 *  - always
473
 */
474
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
475
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
476

    
477
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
478
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
479
    array(
480
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
481
        'includeOccurrences' => 0,
482
        'includeTaxonNameDescriptions' => 0
483
     )
484
  ));
485

    
486
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
487
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
488
  // needs to be merged with user setting by drupal_array_merge_deep()
489
  // 'width' => 512, // optimum size for OSM layers is 512
490
  // 'height' => 512 / 2, // optimum size for OSM layers 256
491
  'aspect_ratio' => 2,
492
  'bbox' => '', // empty to allow automatic zooming to extend
493
  'show_labels' => FALSE,
494
  'caption' => '',
495
  'distribution_opacity' => '0.5',
496
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
497
  'image_map' => array(
498
    'base_layer' => '', // none, formerly this was cyprusdivs
499
    'bg_color' => '1874CD',
500
    'layer_style' => 'ffffff,606060,,',
501
  ),
502
  'openlayers' => array(
503
    'base_layers' =>  array(
504
      // A layer MUST NOT BE SET in the defaults,
505
      // otherwise it can not be overidden by the user settings:
506
      // 'mapproxy_vmap0' => 'mapproxy_vmap0',
507
      // it is sufficient to define the preferred layer,
508
      // since it will automatically be enabled:
509
      'PREFERRED' => 'mapproxy_vmap0'),
510
    'custom_wms_base_layer' => array(
511
      'name' => NULL,
512
      'url' => NULL,
513
      'params' =>  NULL,
514
      'projection' => NULL,
515
      'proj4js_def' => NULL,
516
      'max_extent' => NULL,
517
      'units' => NULL
518
    ),
519
    'show_layer_switcher' => TRUE,
520
    'display_outside_max_extent' => FALSE,
521
    'google_maps_api_key' => NULL,
522
  ),
523
  'legend' => array(
524
    'show' => TRUE,
525
    'opacity' => '0.5',
526
    'font_size' => 10,
527
    'font_style' => FALSE,
528
    'icon_width' => 35,
529
    'icon_height' => 15
530
  )
531
)));
532

    
533
/**
534
 * Merges the named array variable with the array of defaults.
535
 *
536
 * IMPORTANT: The array keys must be strings. When the keys are integers
537
 * the merging will not take place for these entities. Number keyed entities
538
 * are just appended to the result array.
539
 *
540
 * @param string $variable_name
541
 *     The variable name
542
 * @param string | array $default
543
 *     The array containing the default values either as array or serialized as string.
544
 *     Unserialization is cared for if necessary
545
 * @return array
546
 *     The merged array as returned by drupal_array_merge_deep()
547
 *
548
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
549
 * TODO force $default being an array
550
 */
551
function get_array_variable_merged($variable_name, $default){
552

    
553
    // unserialize if nessecary
554
    if(!is_array($default)){
555
      $default = unserialize($default);
556
    }
557
    $variable = variable_get($variable_name, array());
558
    $result = drupal_array_merge_deep($default, $variable);
559
    return $result;
560
}
561

    
562
/**
563
 * @todo document this function.
564
 */
565
function getGallerySettings($gallery_config_form_name) {
566
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
567
}
568

    
569
/**
570
 * Returns the string representation of the default tab.
571
 *
572
 * @param bool $returnTabIndex
573
 *   Defaults to FALSE, if set true this function will return the index number
574
 *   of the default tab. (used to supply default values to form elements).
575
 */
576
function get_default_taxon_tab($returnTabIndex = FALSE) {
577

    
578
  global $user;
579
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
580
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
581
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
582
  // Get the user value if the used has chosen to overwrite the system settings.
583
  $user_tab_on = variable_get($user_tab_active, FALSE);
584
  if ($user_tab_on) {
585
    $user_value = variable_get($user_tab, 0);
586
    $index_value = $user_value;
587
    // Get the system value.
588
  }
589
  else {
590
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
591
    $index_value = $system_value;
592
  }
593

    
594
  // Return the index value or the string representation.
595
  if ($returnTabIndex) {
596
    return $index_value;
597
  }
598
  else {
599
    return ($values[$index_value]);
600
  }
601
}
602

    
603

    
604
  /**
605
   * Provides the feature block settings for a specific feature which matches the $feature_uuid parameter.
606
   *
607
   * In case specifically configured settings array, like these which are stored in the drupal variables, is missing
608
   * one or more fields these fields are taken from the default. That is the specific settings are always merges
609
   * with the default.
610
   *
611
   * Note: These settings only apply to feature blocks which do not have a special rendering
612
   * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
613
   * 'special' element of the settings
614
   *
615
   * @param $feature_uuid
616
   *   The uuid string representation of the feature to return the settings for
617
   *
618
   * @return array
619
   *  an associative array of settings, with the following fields:
620
   *    - as_list: string
621
   *        this setting will be used in compose_feature_block_wrap_elements() as $enclosing_tag
622
   *        possible values are:
623
   *          div: not as list,
624
   *          ul: as bullet list,
625
   *          ol: as numbered list,
626
   *          dl: as definition list
627
   *        The tag used for the inner element, thus depends on the value of this field. The
628
   *        inner tag name can be retrieved by the function cdm_feature_block_element_tag_name()
629
   *    - link_to_reference: boolean,
630
   *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
631
   *    - link_to_name_used_in_source": boolean
632
   *        whether to show name is source information as link which will point to the according name page
633
   *    - sources_as_content (boolean)
634
   *        TRUE (int: 1):
635
   *          1. If element is of the CDM type TextData and the text is not empty the source references will be
636
   *             appended in brackets like "text (source references)". If the original source has name in source
637
   *             information it will be appended to the citation string,
638
   *             like : "(citation, as name in source; citation, as name in source)"
639
   *          2. if the text of the TextData is empty, the original source citations are the only content
640
   *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
641
   *             prepended to the citation string like: "name in source: citation"
642
   *        FALSE (int: 0):
643
   *          Original sources are put into the bibliography(=references) pseudo feature block. If the original source
644
   *          citations are the only content, the resulting feature block content would only consist of footnotes.
645
   *          In this case the display of the respective feature block is suppressed.
646
   *          TODO if the bibliography is not enabled the sources will be treated as footnotes like annotations,
647
   *               in future however they will in this case be shown in a separate references section for each
648
   *               feature block.
649
   *    - sources_as_content_to_bibliography  (boolean)
650
   *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
651
   *        in the bibliography.
652
   *    - sort_elements
653
   *        whether and how to sort the elements
654
   *        possible values are the constants SORT_ASC, SORT_DESC, NULL,
655
   *        some feature types (Distribution) also support: SORT_HIERARCHICAL (
656
   *        TODO option to exclude levels, put in special?,
657
   *        TODO make use of this setting in compose_feature_block_wrap_elements())
658
   *    - element_tag
659
   *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
660
   *        possible values are span | div. the proper inner tag name can be retrieved by the function
661
   *        cdm_feature_block_element_tag_name()
662
   *    - special: array()
663
   *        an array with further settings, this field can be used for special
664
   *        settings for specialized rendering like for distributions
665
   *  }
666
   *
667
   */
668
  function get_feature_block_settings($feature_uuid = 'DEFAULT') {
669
    // the default must conform to the default parameter values of
670
    // compose_feature_block_wrap_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
671
    // compose_description_element_text_data() : asListElement = NULL
672

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

    
675
    // ---- DEFAULTS settings
676

    
677
    // only needed as final option, when the settings are not having a default
678
    $default = array(
679
      'DEFAULT' => array(
680
        'as_list' => 'div',
681
        'link_to_reference' => 0,
682
        'link_to_name_used_in_source' => 1,
683
        'sources_as_content' => 0,
684
        'sources_as_content_to_bibliography' => 0,
685
        'sort_elements' => NO_SORT,
686
        'glue' => '',
687
        'element_tag' => NULL
688
      )
689
    );
690

    
691
    // will be used as preset in the settings
692
    $other_themes_default = array(
693
      'DEFAULT' => array(
694
        'as_list' => 'div',
695
        'link_to_reference' => 0,
696
        'link_to_name_used_in_source' => 1,
697
        'sources_as_content' => 0,
698
        'sources_as_content_to_bibliography' => 0,
699
        'sort_elements' => NO_SORT,
700
        'glue' => '',
701
        'element_tag' => NULL
702
      ),
703
      UUID_CITATION => array(
704
        'as_list' => 'div',
705
        'link_to_reference' => 0,
706
        'link_to_name_used_in_source' => 0,
707
        'sources_as_content' => 1,
708
        'sources_as_content_to_bibliography' => 0,
709
        'sort_elements' => SORT_ASC,
710
        'glue' => '',
711
        'element_tag' => 'div'
712
      ),
713
      UUID_DISTRIBUTION => array(
714
        'as_list' => 'div', // currently ignored
715
        'link_to_reference' => 0,
716
        'link_to_name_used_in_source' => 0,
717
        'sources_as_content' => 0,
718
        'sources_as_content_to_bibliography' => 0,
719
        'sort_elements' => NO_SORT, // will cause ...
720
        'glue' => '',
721
        'element_tag' => 'div',
722
        'special' => array()
723
      ),
724
      UUID_COMMON_NAME => array(
725
        'as_list' => 'div',
726
        'link_to_reference' => 0,
727
        'link_to_name_used_in_source' => 1,
728
        'sources_as_content' => 0,
729
        'sources_as_content_to_bibliography' => 0,
730
        'sort_elements' => NO_SORT,
731
        'glue' => '',
732
        'element_tag' => 'span'
733
      ),
734
    );
735

    
736
    // ---- Special DEFAULTS for existing portals
737
    // TODO:
738
    // this can be removed once the feature block
739
    // settings have been deployed for the first time to these portals
740

    
741
    $cichorieae_default = array(
742
      'DEFAULT' => array(
743
        'as_list' => 'div',
744
        'link_to_reference' => 1,
745
        'link_to_name_used_in_source' => 1,
746
        'sources_as_content' => 1,
747
        'sources_as_content_to_bibliography' => 0,
748
        'sort_elements' => NO_SORT,
749
        'glue' => '',
750
        'element_tag' => 'div'
751
      ),
752
      UUID_CITATION => array(
753
        'as_list' => 'div',
754
        'link_to_reference' => 0,
755
        'link_to_name_used_in_source' => 0,
756
        'sources_as_content' => 1,
757
        'sources_as_content_to_bibliography' => 0,
758
        'sort_elements' => SORT_ASC,
759
        'glue' => '',
760
        'element_tag' => 'div'
761
      ),
762
      UUID_CHROMOSOMES_NUMBERS => array(
763
        'as_list' => 'ul',
764
        'link_to_reference' => 1,
765
        'link_to_name_used_in_source' => 1,
766
        'sources_as_content' => 1,
767
        'sources_as_content_to_bibliography' => 0,
768
        'sort_elements' => NO_SORT,
769
        'glue' => '',
770
        'element_tag' => 'div'
771
      ),
772
      UUID_CHROMOSOMES => array(
773
        'as_list' => 'ul',
774
        'link_to_reference' => 0,
775
        'link_to_name_used_in_source' => 1,
776
        'sources_as_content' => 1,
777
        'sources_as_content_to_bibliography' => 0,
778
        'sort_elements' => NO_SORT,
779
        'glue' => '',
780
        'element_tag' => 'div'
781
      ),
782
      UUID_COMMON_NAME => array(
783
        'as_list' => 'div',
784
        'link_to_reference' => 0,
785
        'link_to_name_used_in_source' => 1,
786
        'sources_as_content' => 0,
787
        'sources_as_content_to_bibliography' => 0,
788
        'sort_elements' => NO_SORT,
789
        'glue' => '',
790
        'element_tag' => 'span'
791
      ),
792
    );
793

    
794
    $palmweb_default = array(
795
      'DEFAULT' => array(
796
        'as_list' => 'ul',
797
        'link_to_reference' => 1,
798
        'link_to_name_used_in_source' => 1,
799
        'sources_as_content' => 1,
800
        'sources_as_content_to_bibliography' => 1,
801
        'sort_elements' => NO_SORT,
802
        'glue' => '',
803
        'element_tag' => NULL
804
      ),
805
      UUID_CITATION => array(
806
        'as_list' => 'ul',
807
        'link_to_reference' => 1,
808
        'link_to_name_used_in_source' => 1,
809
        'sources_as_content' => 0,
810
        'sources_as_content_to_bibliography' => 1,
811
        'sort_elements' => SORT_ASC,
812
        'glue' => '',
813
        'element_tag' => 'div'
814
      ),
815
      UUID_DISTRIBUTION => array(
816
        'as_list' => 'div', // currently ignored
817
        'link_to_reference' => 1,
818
        'link_to_name_used_in_source' => 1,
819
        'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
820
        'sources_as_content_to_bibliography' => 1,
821
        'sort_elements' => NO_SORT, // will cause ...
822
        'glue' => '',
823
        'element_tag' => 'div',
824
        'special' => array()
825
      ),
826
    );
827

    
828
    $cyprus_default = $cichorieae_default;
829
    $cyprus_default[UUID_DISTRIBUTION] = array(
830
      'as_list' => 'div', // currently ignored
831
      'link_to_reference' => 0,
832
      'link_to_name_used_in_source' => 0,
833
      'sources_as_content' => 0,
834
      'sources_as_content_to_bibliography' => 0,
835
      'sort_elements' => NO_SORT, // will cause ...
836
      'glue' => '',
837
      'element_tag' => 'div',
838
      'special' => array()
839
    );
840

    
841
    $default_theme = variable_get('theme_default', NULL);
842

    
843
    switch ($default_theme) {
844
      case 'garland_cichorieae':
845
        $settings_for_theme = $cichorieae_default;
846
        break;
847
      case 'cyprus':
848
        // cyprus: no longer used in production,
849
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
850
        $settings_for_theme = $cyprus_default;
851
        break;
852
      case 'flore_afrique_centrale':
853
      case 'flora_malesiana':
854
      case 'flore_gabon':
855
        $settings_for_theme = $cichorieae_default;
856
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
857
        break;
858
      case 'palmweb_2':
859
        $settings_for_theme = $palmweb_default;
860
        break;
861
      default:
862
        $settings_for_theme = $other_themes_default;
863
    }
864
    // ---- END of DEFAULTS
865

    
866
    $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
867

    
868
    $feature_block_setting = null;
869

    
870
    if (isset($saved_settings[$feature_uuid])) {
871
      $feature_block_setting = $saved_settings[$feature_uuid];
872
    }
873
    else if (isset($settings_for_theme[$feature_uuid])) {
874
      $feature_block_setting = $settings_for_theme[$feature_uuid];
875
    }
876
    else if (isset($settings_for_theme['DEFAULT'])) {
877
      $feature_block_setting = $settings_for_theme['DEFAULT'];
878
    }
879

    
880
    // now merge the default and specific settings
881
    $settings_to_merge = array($default['DEFAULT']);
882
    if(is_array($saved_settings)){
883
      $settings_to_merge[] = $saved_settings['DEFAULT'];
884
    }
885
    if(isset($feature_block_setting)){
886
      $settings_to_merge[] = $feature_block_setting;
887
    }
888
    $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
889

    
890
    return $feature_block_setting;
891
}
892
  /**
893
 * returns the current setting for the original source bibliography
894
 *
895
 * Caches internally
896
 *
897
 * @return array
898
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
899
 *   - 'enabled': 1|0
900
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
901
 */
902
function get_bibliography_settings($clear_cache = false){
903
  static $bibliography_settings = null;
904
  if(!$bibliography_settings || $clear_cache){
905
    $bibliography_settings = get_array_variable_merged(
906
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
907
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
908
    );
909
  }
910
  return $bibliography_settings;
911
}
912

    
913
/**
914
 * @todo Please document this function.
915
 * @see http://drupal.org/node/1354
916
 */
917
function cdm_dataportal_menu_admin(&$items) {
918
  // Display section on admin/config page.
919
  $items['admin/config/cdm_dataportal'] = array(
920
    'title' => 'CDM Dataportal',
921
    'description' => 'Settings for the CDM DataPortal.',
922
    'position' => 'right',
923
    'weight' => 10,
924
    'page callback' => 'system_admin_menu_block_page',
925
    'access arguments' => array('administer cdm_dataportal'),
926
    'file' => 'system.admin.inc',
927
    'file path' => drupal_get_path('module', 'system'),
928
  );
929
  $items['admin/config/cdm_dataportal/settings'] = array(
930
    'title' => 'Settings',
931
    'description' => 'Settings for the CDM DataPortal.',
932
    'weight' => 0,
933
    'page callback' => 'drupal_get_form',
934
    'page arguments' => array('cdm_settings_general'),
935
    'access arguments' => array('administer cdm_dataportal'),
936
    'type' => MENU_NORMAL_ITEM,
937
  );
938
  $items['admin/config/cdm_dataportal/settings/general'] = array(
939
    'title' => 'General',
940
    'description' => 'General',
941
    'weight' => 0,
942
    'page callback' => 'drupal_get_form',
943
    'page arguments' => array('cdm_settings_general'),
944
    'access arguments' => array('administer cdm_dataportal'),
945
    'type' => MENU_DEFAULT_LOCAL_TASK,
946
  );
947

    
948
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
949
    'title' => 'Cache',
950
    'description' => 'Cache',
951
    'access arguments' => array('administer cdm_dataportal'),
952
    'page callback' => 'drupal_get_form',
953
    'page arguments' => array('cdm_settings_cache'),
954
    'weight' => 10,
955
    'type' => MENU_LOCAL_TASK,
956
  );
957

    
958
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
959
    'title' => 'Geo & Map',
960
    'description' => 'Geo & Map',
961
    'access arguments' => array('administer cdm_dataportal'),
962
    'page callback' => 'drupal_get_form',
963
    'page arguments' => array('cdm_settings_geo'),
964
    'weight' => 1,
965
    'type' => MENU_LOCAL_TASK,
966
  );
967

    
968
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
969
    'title' => 'Layout',
970
    'description' => 'Configure and adjust the layout of your DataPortal ',
971
    'access arguments' => array('administer cdm_dataportal'),
972
    'page callback' => 'drupal_get_form',
973
    'page arguments' => array('cdm_settings_layout'),
974
    'weight' => 2,
975
    'type' => MENU_LOCAL_TASK,
976
  );
977

    
978
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
979
    'title' => 'Taxon',
980
    'description' => 'Configure and adjust the layout of your DataPortal ',
981
    'access arguments' => array('administer cdm_dataportal'),
982
    'page callback' => 'drupal_get_form',
983
    'page arguments' => array('cdm_settings_layout_taxon'),
984
    'weight' => 1,
985
    'type' => MENU_LOCAL_TASK,
986
  );
987
  /*
988
  $items[] = array(
989
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
990
  'title' => t('Synonymy'),
991
  'description' => t('Configure and adjust the layout of your DataPortal '),
992
  'access' => user_access('administer cdm_dataportal'),
993
  'callback' => 'drupal_get_form',
994
  'callback arguments' => array('cdm_settings_layout_synonymy'),
995
  'weight' => 1,
996
  'type' => MENU_LOCAL_TASK,
997
  );
998

    
999
  $items[] = array(
1000
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
1001
  'title' => t('Specimens'),
1002
  'description' => t('Configure and adjust the layout of your DataPortal '),
1003
  'access' => user_access('administer cdm_dataportal'),
1004
  'callback' => 'drupal_get_form',
1005
  'callback arguments' => array('cdm_settings_layout_specimens'),
1006
  'weight' => 1,
1007
  'type' => MENU_LOCAL_TASK,
1008
  );
1009
  */
1010
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1011
    'title' => 'Search',
1012
    'description' => 'Configure and adjust the layout of your DataPortal ',
1013
    'access arguments' => array('administer cdm_dataportal'),
1014
    'page callback' => 'drupal_get_form',
1015
    'page arguments' => array('cdm_settings_layout_search'),
1016
    'weight' => 2,
1017
    'type' => MENU_LOCAL_TASK,
1018
  );
1019

    
1020
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1021
    'title' => 'Media',
1022
    'description' => 'Configure and adjust the layout of your DataPortal ',
1023
    'access arguments' => array('administer cdm_dataportal'),
1024
    'page callback' => 'drupal_get_form',
1025
    'page arguments' => array('cdm_settings_layout_media'),
1026
    'weight' => 3,
1027
    'type' => MENU_LOCAL_TASK,
1028
  );
1029

    
1030
}
1031

    
1032
/**
1033
 * @todo document this function.
1034
 */
1035
function cdm_help_general_cache() {
1036
  $form = array();
1037
  $form['cache_help'] = array(
1038
    '#type' => 'fieldset',
1039
    '#title' => t('Help'),
1040
    '#collapsible' => TRUE,
1041
    '#collapsed' => TRUE,
1042
  );
1043
  $form['cache_help']['test'] = array('#value' => t('probando'));
1044
  return drupal_render($form);
1045
  $res = array();
1046
  $res['default'] = drupal_render($help);
1047
  return $res;
1048
}
1049

    
1050
/**
1051
 * Configures the settings form for the CDM-API module.
1052
 *
1053
 * @return array
1054
 *   Drupal settings form.
1055
 */
1056
function cdm_settings_general() {
1057

    
1058
  $form['cdm_webservice'] = array(
1059
    '#type' => 'fieldset',
1060
    '#title' => t('CDM Server'),
1061
    '#collapsible' => FALSE,
1062
    '#collapsed' => FALSE,
1063
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1064
        CDM data base to the web via RESTful web services and thus is the source of the data
1065
        to be displayed by a CDM DataPotal.'),
1066
  );
1067

    
1068
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1069
    '#type' => 'textfield',
1070
    '#title' => t('CDM web service URL') . ':',
1071
    '#description' => t('This is the URL to the CDM-Server exposing your data
1072
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1073
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1074
  );
1075

    
1076
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1077
    '#type' => 'markup',
1078
    '#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')
1079
      . ' visible only for administrators',
1080
  );
1081

    
1082
  $form['cdm_webservice']['freetext_index'] = array(
1083
    '#type' => 'fieldset',
1084
    '#title' => t('Freetext index'),
1085
    '#collapsible' => FALSE,
1086
    '#collapsed' => FALSE,
1087
  );
1088

    
1089
  // Check the cdmserver port number and display a waring if it is not port 80
1090
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1091
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1092
    $form['cdm_webservice']['freetext_index']['message'] = array(
1093
      '#markup' => "<div class=\"description\">"
1094
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1095
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1096
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1097
          array('!port' => $portNumberMatch[1][0])
1098
        )
1099
      . "</div>",
1100
    );
1101
  };
1102

    
1103
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1104
  $trigger_link_options = array(
1105
    'attributes' => array(
1106
      'class' => 'index-trigger',
1107
    ),
1108
  );
1109
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1110
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1111
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1112
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1113
      ))
1114
    . '<div id="index-progress"></div></div>',
1115
  );
1116
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1117

    
1118
    $form['cdm_webservice']['freetext_index']['cdm_dataportal_taxon_auto_suggest'] = array(
1119
        '#type' => 'checkbox',
1120
        '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
1121
        '#default_value' => variable_get('cdm_dataportal_taxon_auto_suggest', CDM_DATAPORTAL_TAXON_AUTO_SUGGEST),
1122
        '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
1123
        This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
1124
    );
1125

    
1126
  $form['cdm_webservice']['proxy'] = array(
1127
    '#type' => 'fieldset',
1128
    '#title' => t('Proxy'),
1129
    '#collapsible' => TRUE,
1130
    '#collapsed' => TRUE,
1131
  );
1132

    
1133
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1134
    '#type' => 'textfield',
1135
    '#title' => t('Proxy URL') . ':',
1136
    '#description' => t('If this proxy url is set the cdm api tries
1137
    to connect the web service over the given proxy server.
1138
    Otherwise proxy usage is deactivated.'),
1139
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1140
  );
1141

    
1142
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1143
    '#type' => 'textfield',
1144
    '#title' => t('Proxy port') . ':',
1145
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1146
  );
1147

    
1148
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1149
    '#type' => 'textfield',
1150
    '#title' => t('Login') . ':',
1151
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1152
  );
1153

    
1154
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1155
    '#type' => 'textfield',
1156
    '#title' => t('Password') . ':',
1157
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1158
  );
1159

    
1160
  // TODO: settings are still incomplete, compare with
1161
  // trunk/dataportal/inc/config_default.php.inc.
1162
  $form['taxon_tree'] = array(
1163
    '#type' => 'fieldset',
1164
    '#title' => t('Taxon Tree'),
1165
    '#collapsible' => FALSE,
1166
    '#collapsed' => TRUE,
1167
    '#description' => t('<p>When you explore your collection, you can navigate
1168
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1169
      able to navigate through your collection the
1170
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1171
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1172
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1173
      </a></p>'),
1174
  );
1175

    
1176
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1177
    '#type' => 'select',
1178
    '#title' => t('Available classifications') . ':',
1179
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1180
    '#options' => cdm_get_taxontrees_as_options(),
1181
    '#description' => t('Select the default taxa classification for your
1182
      <em>taxon tree</em>, the other classifications will be also available but
1183
      with a manual user change.'),
1184
  );
1185

    
1186
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1187
    '#type' => 'select',
1188
    '#title' => t('Rank of highest displayed taxon') . ':',
1189
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1190
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1191
    '#options' => cdm_rankVocabulary_as_option(),
1192
    '#description' => t('This is the rank of the highest displayed taxon in the
1193
      <em>taxon tree</em>. You can select here which rank should be at the top
1194
      level of the tree structure.'),
1195
  );
1196

    
1197
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1198
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1199
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1200
      '#type' => 'checkboxes',
1201
      '#title' => t('Included Classifications') . ':',
1202
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1203
      '#options' => cdm_get_taxontrees_as_options(),
1204
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1205
  );
1206

    
1207
  $form['distribution'] = array(
1208
      '#type' => 'fieldset',
1209
      '#title' => t('Distributions'),
1210
      '#collapsible' => FALSE,
1211
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1212
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1213
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1214
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1215
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1216
          '<p>
1217
          </p>',
1218
  );
1219

    
1220
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1221
      '#type' => 'fieldset',
1222
      '#title' => 'Distribution filter',
1223
      '#collapsible' => FALSE,
1224
      '#collapsed' => FALSE,
1225
      '#tree' => TRUE,
1226
      '#description' => 'The Distribution filter offers the following options
1227
      <ul>
1228
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1229
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1230
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1231
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1232
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1233
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1234
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1235
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1236
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1237
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1238
      </ul>'
1239
  );
1240

    
1241
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1242
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1243
      '#type' => 'checkboxes',
1244
      '#title' => 'Filter rules',
1245
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1246
      '#options' => array(
1247
          'statusOrderPreference' => 'Status order preference rule',
1248
          'subAreaPreference' => 'Sub area preference rule'
1249
      ),
1250
  );
1251

    
1252
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1253
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1254
      '#type' => 'checkboxes',
1255
      '#title' => 'Hide marked area filter',
1256
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1257
      '#options' => $marker_type_options,
1258
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1259
  );
1260

    
1261
  $form['aggregation'] = array(
1262
      '#type' => 'fieldset',
1263
      '#title' => t('Aggregation of data'),
1264
      '#collapsible' => FALSE,
1265
      '#description' => 'This section covers the different aspects of aggregating information.
1266
          <p>
1267
          </p>',
1268
  );
1269

    
1270
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1271
      '#type' => 'checkboxes',
1272
      '#title' => 'Taxon media filter',
1273
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1274
      '#options' => array(
1275
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1276
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1277
          'includeOccurrences' => 'Media related to specimens and occurrences',
1278
      ),
1279
      '#description' => 'This filter configures which images should be taken into account.',
1280
  );
1281

    
1282
  $form['aggregation']['notice'] = array(
1283
      '#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
1284
          want to make use of the caching capabilities of the dataportal.',
1285
  );
1286

    
1287
  $form['aggregation']['media_aggregation'] = array(
1288
      '#type' => 'fieldset',
1289
      '#title' => t('Media aggregation'),
1290
      '#collapsible' => FALSE,
1291
      '#collapsed' => TRUE,
1292
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1293

    
1294
  );
1295
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1296
      '#type' => 'select',
1297
      '#title' => t('Aggregation of taxon pictures') . ':',
1298
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1299
      '#options' => array(
1300
          0 => "Show only pictures of the current taxon",
1301
          1 => "Include pictures of taxonomic children",
1302
      ),
1303
      '#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."),
1304
  );
1305

    
1306
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1307
      '#type' => 'fieldset',
1308
      '#attributes' => array('class' => array('clearfix')),
1309
      '#title' => t('Aggregation via taxon relationsships'),
1310
      '#collapsible' => TRUE,
1311
      '#collapsed' => TRUE,
1312
      '#tree' => TRUE,
1313
      '#description' => t('Information on taxa will be aggregated along the below chosen
1314
          taxon relation ships. This will affect images and occurrences (specimens).
1315
          Taxon relation ships are directed and point form one taxon to another. The taxon
1316
          relationships to be taken into accunt can therefore configured for the direct direction
1317
          and for the inverse.'),
1318
  );
1319

    
1320
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1321
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1322

    
1323
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1324
      '#type' => 'checkboxes',
1325
      '#title' => t('Direct'),
1326
      '#options' => $taxonRelationshipTypeOptions,
1327
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1328
  );
1329
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1330
      '#type' => 'checkboxes',
1331
      '#title' => t('Invers'),
1332
      '#options' => $taxonRelationshipTypeOptions,
1333
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1334
  );
1335

    
1336
  $form['drupal_integration'] = array(
1337
    '#type' => 'fieldset',
1338
    '#attributes' => array('class'=> array('clearfix')),
1339
    '#title' => t('Drupal integration'),
1340
    '#collapsible' => FALSE,
1341
    '#collapsed' => FALSE,
1342
    '#tree' => FALSE
1343
  );
1344

    
1345
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1346
    '#type' => 'checkbox',
1347
    '#title' => 'Create drupal nodes',
1348
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1349
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1350
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1351
    cdm pages it is required that drupal nodes are created and stored in the database.'
1352
  );
1353

    
1354

    
1355

    
1356
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1357
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1358
    <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>',
1359
  );
1360
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1361
    '#type' => 'submit',
1362
    '#value' => t('Drop all cdm nodes'),
1363
    '#submit' => array('drop_all_cdm_nodes_submit')
1364
  );
1365

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

    
1370
    // ----------------------
1371
  $form['cdm_js_devel_mode'] = array(
1372
      '#type' => 'checkbox',
1373
      '#title' => 'Java-script developer mode',
1374
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1375
      '#description' => 'In production envirionments the java script libraries
1376
      the cdm_dataportal is making use of are compressed and optimized. This
1377
      is good for performance but a caveat if you need to debug java-script. When the
1378
      java-script developer mode is enabled the uncompressed and commented developer
1379
      versions of java-script libraries will be used where possible.
1380
      <br/><strong>Do not use this option in production!</strong>'
1381
  );
1382
  // ----------------------
1383
  $form['cdm_debug_mode'] = array(
1384
      '#type' => 'checkbox',
1385
      '#title' => 'CDM page debug mode',
1386
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1387
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1388
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1389
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1390
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1391
      The log is written by the drupal devel module function <code>dd()</code>.
1392
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1393
  );
1394

    
1395
  // Comment @WA: D7 form api does not support reset buttons,
1396
  // so to mimic the D5 reset button we add one like this.
1397
  $form['actions']['reset'] = array(
1398
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1399
    '#weight' => 1000,
1400
  );
1401

    
1402
  $form['#submit'][] = 'cdm_settings_general_submit';
1403

    
1404
  return system_settings_form($form);
1405
}
1406

    
1407
/**
1408
 * Submit callback; drops all cdm nodes.
1409
 *
1410
 * @ingroup forms
1411
 */
1412
function drop_all_cdm_nodes_submit($form, &$form_state) {
1413
  cdm_delete_all_cdm_nodes();
1414
  drupal_set_message(t('All cdm nodes dropped.'));
1415
}
1416

    
1417

    
1418
/**
1419
 * LAYOUT settings
1420
 * @return
1421
 *   todo
1422
 */
1423
function cdm_settings_layout() {
1424

    
1425
  $form = array();
1426

    
1427
  $form['about'] = array(
1428
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1429
      layout. If you want to configure the specific sites layout visit the
1430
      respective configuration site for taxon, search or media.') . '</p>',
1431
  );
1432

    
1433
  // ---- footnotes --- //
1434
  $form['footnotes'] = array(
1435
    '#type' => 'fieldset',
1436
    '#title' => t('Footnotes'),
1437
    '#collapsible' => FALSE,
1438
    '#collapsed' => FALSE,
1439
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1440
      media or distribution areas may have annotations or footnotes. When the
1441
      footnotes are enabled they will be visible (if they exist).'),
1442
  );
1443

    
1444
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1445
    '#type' => 'checkbox',
1446
    '#title' => t('Do not show footnotes'),
1447
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1448
    '#description' => t('Check this if you do not want to show any footnotes'),
1449
  );
1450

    
1451
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1452
    '#type' => 'checkbox',
1453
    '#title' => t('Do not show annotation footnotes'),
1454
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1455
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1456
  );
1457

    
1458
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1459
  // Additional option for the NULL case.
1460
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1461
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1462
    '#type' => 'checkboxes',
1463
    '#title' => t('Annotation types as footnotes'),
1464
    '#description' => t("Only annotations of the selected type will be displayed
1465
       as footnotes. You may want to turn 'technical annotations' off."),
1466
    '#options' => $annotationTypeOptions,
1467
  );
1468
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1469
  if (!empty($annotationsTypesAsFootnotes)) {
1470
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1471
  }
1472

    
1473
  // ---- original source --- //
1474
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1475
      '#type' => 'fieldset',
1476
      '#tree' => TRUE,
1477
      '#title' => t('Source Citations'),
1478
      '#collapsible' => FALSE,
1479
      '#collapsed' => FALSE,
1480
  );
1481

    
1482
  $bibliography_settings = get_bibliography_settings(true);
1483

    
1484
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1485
      '#type' => 'checkbox',
1486
      '#title' => t('Original Source in bibliography'),
1487
      '#default_value' => $bibliography_settings['enabled'],
1488
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1489
       annotations in each feature block.'),
1490
  );
1491

    
1492
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1493
    '#type' => 'select',
1494
    '#title' => t('The format of the key numerals'),
1495
    '#default_value' => $bibliography_settings['key_format'],
1496
    '#options' => array('latin' => 'Latin',
1497
      'ROMAN' => 'Roman (upper case)',
1498
      'roman' => 'Roman (lower case)',
1499
      'ALPHA'=> 'Alphabet (upper case)',
1500
      'alpha' => 'Alphabet (lower case)')
1501
  );
1502

    
1503
  // --- Advanced Search --- //
1504
  $form['asearch'] = array(
1505
      '#type' => 'fieldset',
1506
      '#title' => t('Advanced search'),
1507
      '#collapsible' => FALSE,
1508
      '#collapsed' => FALSE,
1509
  );
1510
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1511
      '#type' => 'checkbox',
1512
      '#title' => t('Show advanced search link'),
1513
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1514
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1515
  );
1516

    
1517
  // ---- Taxon Name Rendering --- //
1518
  $form['taxon_name'] = array(
1519
      '#type' => 'fieldset',
1520
      '#title' => t('Taxon name display'),
1521
      '#collapsible' => TRUE,
1522
      '#collapsed' => TRUE,
1523
      '#description' => t('The display of taxon names is configured by two parts.
1524
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1525
          The name parts are defined in the <stong>part definitions</strong>'),
1526
  );
1527

    
1528
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1529
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1530
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1531
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1532

    
1533
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1534
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1535
    $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.)';
1536
  } else if($is_custom_part_definition){
1537
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1538
  } else  {
1539
    $which_version_message = '(These are the default part definition.)';
1540
  }
1541

    
1542
  $diff_viewer_markup = '';
1543
  if($is_custom_part_definition){
1544
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1545
  }
1546

    
1547
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1548
    . $which_version_message
1549
    . '</div>'
1550
    . $diff_viewer_markup;
1551

    
1552
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1553
      '#type' => 'textarea',
1554
      '#title' => t('Part definitions'),
1555
      '#element_validate' => array('form_element_validate_json'),
1556
      '#default_value' =>  $current_part_definition_json,
1557
      '#description' => '
1558
          <p>' . $which_version_message . '</p>
1559
          <p>
1560
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1561
          </p>
1562
          <p>
1563
           A full taxon name plus additional information can consist of the following elements:
1564
          <ul>
1565
             <li>name: the taxon name inclugin rank nbut without author</li>
1566
             <li>authors:  The authors of a reference, also used in taxon names</li>
1567
             <li>reference: the nomenclatural reference,</li>
1568
             <li>microreference:  Volume, page number etc.</li>
1569
             <li>status:  The nomenclatural status of a name</li>
1570
             <li>description: name descriptions like protologues etc ...</li>
1571
          </ul>
1572
          </p>
1573
          <p>
1574
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1575
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1576
           The following parts can be formed and are recognized by the system:
1577
          <ul>
1578
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1579
            <li>authorshipPart: the author (for example: "L.")</li>
1580
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1581
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1582
               be combined when a link to the taxon is rendered.</li>
1583
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1584
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1585
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1586
            <li>statusPart: the nomenclatorical status</li>
1587
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1588
          </ul>
1589
          </p>
1590
          <p>
1591
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1592
           specific parts part definitions:
1593
          <ul>
1594
            <li>BotanicalName</li>
1595
            <li>ZoologicalName</li>
1596
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1597
          </ul>
1598
           An example:
1599
          <pre>
1600
           {
1601
            "ZoologicalName": {
1602
              "namePart": {
1603
                "name": true
1604
              },
1605
              "referencePart": {
1606
                "authors": true
1607
              },
1608
              "microreferencePart": {
1609
                "microreference": true
1610
              },
1611
              "statusPart": {
1612
                "status": true
1613
              },
1614
              "descriptionPart": {
1615
                "description": true
1616
              }
1617
            },
1618
            "BotanicalName": {
1619
              "namePart": {
1620
                "name": true,
1621
                "authors": true
1622
              },
1623
              "referencePart": {
1624
                "reference": true,
1625
                "microreference": true
1626
              },
1627
              "secReferencePart": {
1628
                "secReference": true
1629
              },
1630
              "statusPart": {
1631
                "status": true
1632
              },
1633
              "descriptionPart": {
1634
                "description": true
1635
              }
1636
            }
1637
          }
1638
           </pre>',
1639
  );
1640

    
1641
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1642
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1643
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1644
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1645
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1646

    
1647
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1648
    $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.)';
1649
  } else if($is_custom_render_template){
1650
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1651
  } else {
1652
    $which_version_message = '(These are the default render templates.)';
1653
  }
1654

    
1655
  $diff_viewer_markup = '';
1656
  if($is_custom_render_template){
1657
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1658
  }
1659

    
1660
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1661
    . $which_version_message
1662
    . '</div>'
1663
    . $diff_viewer_markup;
1664

    
1665
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1666
      '#type' => 'textarea',
1667
      '#title' => t('Name render templates'),
1668
      '#element_validate' => array('form_element_validate_json'),
1669
      '#default_value' =>  $current_render_templates_json,
1670
      '#description' => '
1671
          <p>' . $which_version_message . '</p>
1672
          <p>
1673
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1674
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1675
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1676
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1677
          The following render Path keys are currently recognized:
1678
          <ul>
1679
            <li>list_of_taxa</li>
1680
            <li>acceptedFor</li>
1681
            <li>homonym</li>
1682
            <li>taxon_page_synonymy</li>
1683
            <li>typedesignations</li>
1684
            <li>taxon_page_title</li>
1685
            <li>polytomousKey</li>
1686
            <li>na: name + authorship</li>
1687
            <li>nar:name + authorship + reference</li>
1688
            <li>#DEFAULT</li>
1689
          </ul>
1690
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1691
          array element should be a comma separated list of render paths, without any whitespace!.
1692
          </p>
1693
          <p>
1694
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1695
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1696
          <p>
1697
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1698
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1699
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1700
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1701
          links if the paramters $nameLink or $refenceLink are given to the name render function
1702
          (this is hard coded and cannot be configured here).',
1703
  );
1704

    
1705
  // @WA: D7 form api does not support reset buttons,
1706
  // so to mimic the D5 reset button we add one like this.
1707
  $form['actions']['reset'] = array(
1708
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1709
    '#weight' => 1000,
1710
  );
1711

    
1712
  $form['#submit'] = array('submit_json_as_php_array');
1713
  // #json_elements especially defined for submit_json_as_php_array()
1714
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1715
  return system_settings_form($form);
1716
}
1717

    
1718

    
1719

    
1720
  /**
1721
 * @todo Please document this function.
1722
 * @see http://drupal.org/node/1354
1723
 */
1724
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1725
  $form[$form_name] = array(
1726
    '#type' => 'fieldset',
1727
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1728
    '#collapsible' => TRUE,
1729
    '#collapsed' => $collapsed,
1730
    '#tree' => TRUE,
1731
    '#description' => t('@$form-description', array('@$form-description' => $form_description)),
1732
  );
1733

    
1734
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1735
  $gallery_settings = variable_get($form_name, $default_values);
1736
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1737
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1738
    /*
1739
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1740
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1741
    '#type' => 'textfield',
1742
    '#title' => t('Search Page Size'),
1743
    '#default_value' => $test,
1744
    '#description' => t('Number of Names to display per page in search results.')
1745
    );
1746
    */
1747
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1748
      '#type' => 'checkbox',
1749
      '#title' => t('Show media thumbnails for accepted taxa'),
1750
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1751
    );
1752

    
1753
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1754
      '#type' => 'checkbox',
1755
      '#title' => t('Show media thumbnails for synonyms'),
1756
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1757
      '#description' => '',
1758
    );
1759
  }
1760

    
1761
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1762
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1763
    '#type' => 'checkbox',
1764
    '#title' => t('Show captions under thumbnails'),
1765
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1766
    '#description' => '',
1767
  );
1768

    
1769
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1770
    '#type' => 'textfield',
1771
    '#title' => t('Thumbnail size') . ':',
1772
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1773
    '#description' => t('Select the size of each individual thumbnail.'),
1774
  );
1775

    
1776
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1777
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1778
      '#type' => 'textfield',
1779
      '#title' => t('Number of columns') . ':',
1780
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1781
      '#description' => t('Group the thumbnails in columns: select how many
1782
        columns the gallery should display.'),
1783
    );
1784
  }
1785

    
1786
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1787
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1788
      '#type' => 'textfield',
1789
      '#title' => t('Maximum number of rows') . ':',
1790
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1791
      '#description' => t('You can group the thumbnails in rows, select in how
1792
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1793
        If you want an unlimited number of rows please set to 0.'),
1794
    );
1795
  }
1796

    
1797
  return $form;
1798
}
1799

    
1800
/**
1801
 * @todo document this function.
1802
 */
1803
function cdm_settings_layout_taxon() {
1804
  $collapsed = FALSE;
1805
  $form = array();
1806

    
1807
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1808

    
1809
  // --------- TABBED TAXON ------- //
1810
  $form['taxon_tabs'] = array(
1811
    '#type' => 'fieldset',
1812
    '#title' => t('Taxon tabs'),
1813
    '#collapsible' => TRUE,
1814
    '#collapsed' => TRUE,
1815
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1816
      be splitted in four diferent tabs; General, Synonymy, Images and
1817
      Specimens. If the taxon has no information for any of the tabs/sections
1818
      such tab will be not displayed.'),
1819
  );
1820

    
1821
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1822
    '#type' => 'checkbox',
1823
    '#title' => t('Tabbed taxon page'),
1824
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1825
    '#description' => t('<p>If selected split the taxon page into individual
1826
      tabs for description, images, synonymy and specimens. If not the taxon
1827
      data is rendered as a long single page without tabs.</p>'),
1828
  );
1829

    
1830
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1831
    '#type' => 'checkboxes',
1832
    '#title' => t('Tabs visibility options') . ':',
1833
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1834
    '#options' => get_taxon_options_list(),
1835
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1836
  );
1837

    
1838
  // WEIGHT
1839
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1840
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1841
    '#title'  => 'Tabs order',
1842
    '#type' => 'fieldset',
1843
    '#collapsible' => false,
1844
    '#tree' => true,
1845
    '#description' => 'The weight value defines the order of the tabs or of the respective content block on the 
1846
        taxon page when it is the tabless mode.'
1847
  );
1848
  // Weights range from -delta to +delta, so delta should be at least half
1849
  // of the amount of tabs present.
1850
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1851
  foreach (get_taxon_tabs_list() as $label) {
1852
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1853
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1854
        '#title' => $label,
1855
        '#type'  => 'weight',
1856
        '#default_value' => $taxon_tabs_weights[$key],
1857
        '#delta' => $tab_weight_delta
1858
    );
1859
  }
1860

    
1861
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1862
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1863
    '#title'  => 'Tab label override',
1864
    '#type' => 'fieldset',
1865
    '#collapsible' => false,
1866
    '#tree' => true,
1867
    '#description' => 'Setting a label for a tab will override the default label. 
1868
      Please enter the label text in the default language of the portal.'
1869
  );
1870
  foreach (get_taxon_tabs_list() as $label) {
1871
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1872
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1873
      '#title' => $label,
1874
      '#type'  => 'textfield',
1875
      '#default_value' => $taxon_tabs_labels[$key]
1876
    );
1877
  }
1878

    
1879
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1880
    '#type' => 'select',
1881
    '#title' => t('Default tab to display') . ':',
1882
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1883
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1884
    '#description' => t('<p>Select the default tab to display when visiting a
1885
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1886
      <strong>Note:</strong> After performing a search and clicking in any
1887
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1888
      taxon and not the above selected tab.'),
1889
  );
1890

    
1891
  /* ======  TAXON_PROFILE ====== */
1892
  $form['taxon_profile'] = array(
1893
    '#type' => 'fieldset',
1894
    '#title' => t('Taxon profile (tab)'),
1895
    '#description' => t('<p>This section covers the settings related to the taxon
1896
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1897
    '#collapsible' => TRUE,
1898
    '#collapsed' => TRUE,
1899
  );
1900

    
1901
  // ---- PROFILE PICTURE ----//
1902

    
1903
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1904
    '#type' => 'fieldset',
1905
    '#tree' => TRUE,
1906
    '#title' => t('Taxon profile picture'),
1907
    '#collapsible' => TRUE,
1908
    '#collapsed' => FALSE,
1909
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1910
  );
1911

    
1912
  //FIXME migrate variables:
1913
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1914
  // FIXME
1915
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1916

    
1917
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1918

    
1919
  /*
1920
   * 'show' => 1,
1921
   * 'maxextend' => 184,
1922
   * 'media_uri_query' => ''
1923
   * 'custom_placeholder_image_on' => 1,
1924
   * 'custom_placeholder_image_fid' => ''
1925
   */
1926
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1927
    '#type' => 'checkbox',
1928
    '#title' => t('Enable profile picture'),
1929
    '#description' => t('Show the profile picture.'),
1930
    '#default_value' => $taxon_profile_image_settings['show'],
1931
  );
1932

    
1933
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1934
      '#type' => 'textfield',
1935
      '#tree' => TRUE,
1936
      '#title' => t('Profile picture maximum extend'),
1937
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1938
      '#field_suffix' => 'px',
1939
      '#maxlength' => 4,
1940
      '#size' => 4,
1941
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
1942
  );
1943

    
1944
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1945
      '#type' => 'textfield',
1946
      '#tree' => TRUE,
1947
      '#title' => t('Additional URI query parameter'),
1948
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1949
      '#maxlength' => 1024,
1950
      '#size' => 60,
1951
      '#description' => t('Additional query parameters to be used when requesting for the  
1952
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
1953
            The query parameters will be appended to the uri of the media representation part
1954
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1955
  );
1956

    
1957
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1958
    '#type' => 'checkbox',
1959
    '#title' => t('Show the placeholder image'),
1960
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
1961
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1962
  );
1963

    
1964
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1965
      '#type' => 'checkbox',
1966
      '#title' => t('Use a custom placeholder image'),
1967
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1968
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1969
  );
1970

    
1971
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1972
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1973
        '#type' => 'managed_file',
1974
        '#title' => t('Custom placeholder image file'),
1975
        '#progress_indicator' => 'bar',
1976
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1977
    //       '#name' => 'custom_placeholder_image',
1978
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1979
    );
1980

    
1981
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1982
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1983
      $url = file_create_url($profile_image_file->uri);
1984
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1985
                '#type' => 'item',
1986
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1987
      );
1988
    }
1989
  } else {
1990
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1991
      '#type' => 'hidden',
1992
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1993
    );
1994
  }
1995

    
1996
  $options = cdm_rankVocabulary_as_option();
1997
  array_unshift($options, '-- DISABLED --');
1998
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1999
    '#type' => 'select',
2000
    '#title' => t('Hide profile picture for higher ranks') . ':',
2001
    '#default_value' => variable_get('image_hide_rank', '0'),
2002
    '#options' => $options,
2003
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2004
  );
2005

    
2006
  // -- MEDIA THUMBNAILS -- //
2007
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2008
  $form_title = 'Taxon Profile Images';
2009
  $form_description = '<p>The different section in the taxon  profile can have images associated with them. These images are displayed in a gallery of thumbnails wich can be configuered here:</p>';
2010
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2011

    
2012
  // ---- FEATURE TREE BLOCKS ---- //
2013
  $form['taxon_profile']['feature_blocks'] = array(
2014
    '#type' => 'fieldset',
2015
    '#title' => t('Feature Blocks'),
2016
    '#collapsible' => TRUE,
2017
    '#collapsed' => FALSE,
2018
    '#description' => t("This section covers settings related to the taxon's
2019
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2020
      features such as description, distribution, common names"),
2021
  );
2022
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2023
  $profile_feature_tree = get_profile_feature_tree();
2024
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2025
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2026
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2027
  }
2028
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2029
    '#type' => 'radios',
2030
    '#title' => t('Taxon profile feature tree') . ':',
2031
    '#default_value' => $profile_feature_tree_uuid,
2032
    '#options' =>  $featureTrees['options'],
2033
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2034
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2035
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
2036
      profile page.'
2037
    ),
2038
  );
2039

    
2040
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2041
  $profile_feature_tree = get_profile_feature_tree();
2042

    
2043
  if (isset($profile_feature_tree->root->childNodes)) {
2044

    
2045
    $form_feature_block_layout = array(
2046
      '#type' => 'fieldset',
2047
      '#tree' => true,
2048
      '#title' => t('Taxon profile feature block settings'),
2049
      '#collapsible' => TRUE,
2050
      '#collapsed' => FALSE,
2051
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2052
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
2053
      The subforms have the following settings in common:<br />
2054
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2055
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2056
      <h6>Link to name used in source:</h6><div>Whether to show name is source information as link which will point to the according name page</div>
2057
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2058
            <ol>
2059
            <li>If element is of the CDM type TextData and the text is not empty the source references will be
2060
                appended in brackets like "text (source references)". If the original source has name in source
2061
                information it will be appended to the citation string,
2062
                like : "(citation, as name in source; citation, as name in source)"</li>
2063
             <li>if the text of the TextData is empty, the original source citations are the only content
2064
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2065
                prepended to the citation string like: "name in source: citation"</li>
2066
            </ol>
2067
            <strong>If disabled:</strong><br />
2068
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2069
             citations are the only content, the resulting feature block content would only consist of footnotes.
2070
             In this case the display of the respective feature block is suppressed.</div>
2071
      </dl>
2072
      <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
2073
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2074
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2075
        . '</em></div>
2076
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2077
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2078
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2079
      <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>
2080
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2081
           cdm_feature_block_element_tag_name()</div>',
2082
    );
2083

    
2084

    
2085
    $feature_list_layout_settings_disabled = FALSE;
2086

    
2087
    // creating helper object to retrieve the default settings
2088
    $featureNode = new stdClass();
2089
    $featureNode->feature = new stdClass();
2090
    $featureNode->feature->uuid="DEFAULT";
2091
    $featureNode->feature->representation_L10n = "Default";
2092
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2093

    
2094
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2095

    
2096
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2097

    
2098
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2099
        $subform_id = $featureNode->feature->uuid;
2100
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2101

    
2102
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2103

    
2104
        $form_feature_block_layout[$subform_id] = array(
2105
          '#type' => 'fieldset',
2106
          '#tree' => TRUE,
2107
          '#title' => $featureNode->feature->representation_L10n,
2108
          '#collapsible' => FALSE,
2109
          '#collapsed' => FALSE,
2110
        );
2111
        if($featureNode->feature->uuid == "DEFAULT"){
2112
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2113
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2114
          references</em> and <em>names in source</em> is only possible in the defaults';
2115
        }
2116

    
2117
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2118
          '#type' => 'select',
2119
          '#title' => 'List type',
2120
          '#default_value' => $feature_block_setting['as_list'],
2121
          '#options' => array(
2122
            'div' => 'not as list',
2123
            'ul' => 'bullet list',
2124
            'ol' => 'numbered list',
2125
            'dl' => 'definition list'
2126
          ),
2127
        );
2128

    
2129
        if($featureNode->feature->uuid == "DEFAULT"){
2130
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2131
            '#type' => 'checkbox',
2132
            '#title' => t('Link to reference'),
2133
            '#default_value' => $feature_block_setting['link_to_reference'],
2134
          );
2135

    
2136
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2137
            '#type' => 'checkbox',
2138
            '#title' => 'Link to name used in source',
2139
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2140
          );
2141
        }
2142

    
2143
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2144
          '#type' => 'checkbox',
2145
          '#title' => 'Sources as content',
2146
          '#default_value' => $feature_block_setting['sources_as_content'],
2147
        );
2148

    
2149
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2150
          '#type' => 'checkbox',
2151
          '#title' => 'Put sources also as content to bibliography',
2152
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2153
        );
2154

    
2155
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2156
          '#type' => 'select',
2157
          '#title' => t('Sort elements'),
2158
          '#default_value' => $feature_block_setting['sort_elements'],
2159
          '#options' => array(
2160
            NO_SORT => 'No sorting',
2161
            SORT_ASC => 'Ascending',
2162
            SORT_DESC => 'Descending',
2163
            SORT_HIERARCHICAL => 'Hierarchical'
2164
          ),
2165
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2166
          <dl>
2167
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2168
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2169
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2170
          <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>
2171
          </dl>',
2172
        );
2173

    
2174
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2175
          '#type' => 'select',
2176
          '#title' => t('Element tag'),
2177
          '#options' => array(
2178
            'span' => 'span',
2179
            'div' => 'div'
2180
          ),
2181
          '#default_value' => $feature_block_setting['element_tag'],
2182
        );
2183
      }
2184
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2185
    }
2186
  }
2187

    
2188
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2189
  $form['taxon_profile']['structured_description_featuretree'] = array(
2190
    '#type' => 'fieldset',
2191
    '#title' => t('Structured Description Feature Tree'),
2192
    '#collapsible' => TRUE,
2193
    '#collapsed' => FALSE,
2194
  );
2195
  $featureTrees = cdm_get_featureTrees_as_options();
2196
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2197
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2198
    $profile_feature_tree_uuid = NULL;
2199
  }
2200
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2201
    '#type' => 'radios',
2202
    '#title' => t('Natural language representation of structured descriptions') . ':',
2203
    '#default_value' => $profile_feature_tree_uuid,
2204
    '#options' => $featureTrees['options'],
2205
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2206
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2207
    '#description' => t('Taxon descriptions can be stored in a highly structured
2208
      form. The feature tree selected here will be used to generate textual
2209
      representation in natural language.'
2210
    ),
2211
  );
2212

    
2213

    
2214

    
2215
  // ---- DISTRIBUTION LAYOUT ---- //
2216
  $form['taxon_profile']['distribution_layout'] = array(
2217
    '#title' => t('Distribution'),
2218
    '#collapsible' => TRUE,
2219
    '#collapsed' => FALSE,
2220
    '#type' => 'fieldset',
2221
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2222
        Map settings regarding the geometry, layers, etc are found in the '
2223
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2224
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2225
      . l(
2226
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2227
        array('fragment' => 'edit-feature-block-settings')
2228
      )
2229
      . ' More general settings regrading the filtering of Distributions are found at '
2230
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2231
      . '. (These settings here will be merged in future releases into the feature block settings)',
2232

    
2233
  );
2234

    
2235
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2236

    
2237
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2238
    '#type' => 'checkbox',
2239
    '#title' => t('Condensed distribution'),
2240
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2241
    '#description' => 'This option enables the display of a very compact representation
2242
    of the distribution which includes also information on the status.',
2243
  );
2244

    
2245
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2246
    '#type' => 'select',
2247
    '#title' => t('Condensed distribution recipe'),
2248
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2249
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2250
    '#description' => 'Recipe for creating the condensed distribution.',
2251
  );
2252

    
2253
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2254
    '#type' => 'textfield',
2255
    '#title' => t('Condensed distribution info path'),
2256
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2257
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2258
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2259
  );
2260

    
2261

    
2262
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2263
    '#type' => 'radios',
2264
    '#title' => t('Display mode') . ':',
2265
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2266
    '#options' => array(
2267
      'FLAT_ALPHA' => t('Flat list'),
2268
      'TREE' => t('Hierarchically ordered'),
2269
    ),
2270
    '#description' => 'Taxon distribution information is displayed with
2271
    focus on the area of the distribution. The list of areas can either be shown
2272
    as flat list ordered alphabetically or in the hierarchical of the parent
2273
    area and subarea relationship. Fall back areas areas with no Distribution data
2274
    are hidden from the area hierarchy so that their sub areas will move one level up.
2275
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2276
    ' for details on the <em>Marked area filter</em>.',
2277
  );
2278

    
2279
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2280
    '#type' => 'fieldset',
2281
    '#tree' => true,
2282
    '#title' => t('Distribution hierarchy style')
2283
  );
2284

    
2285
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2286
  foreach(array_keys($hierarchy_styles) as $level) {
2287
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2288
      '#type' => 'fieldset',
2289
      '#tree' => true,
2290
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2291
      '#attributes' => array('class' => array('fieldset-float'))
2292
    );
2293
    foreach ($hierarchy_styles[$level] as $key => $value) {
2294
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2295
        '#type' => 'textfield',
2296
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2297
        '#default_value' => $hierarchy_styles[$level][$key],
2298
        '#maxlength' => 4,
2299
        '#size' => 4
2300
      );
2301
    }
2302
  }
2303

    
2304
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2305
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2306
    '#type' => 'checkboxes',
2307
    '#title' => 'Omit area levels',
2308
    '#options' => $level_options,
2309
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2310
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2311
    Areas which belong to the selected area levels will be hidden in the portal.',
2312
  );
2313

    
2314
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2315
    '#type' => 'checkbox',
2316
    '#title' => t('Show TextData elements on top of the map'),
2317
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2318
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2319
      elements on top of the map. Otherwise all <code>TextData</code>
2320
      distribution elements will be listed below the other area elements.
2321
      This option is useful if you need to have descriptive texts for each
2322
      distribution map.'),
2323
  );
2324

    
2325
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2326
      '#type' => 'textarea',
2327
      '#title' => t('Custom status colors'),
2328
      '#element_validate' => array('form_element_validate_json'),
2329
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2330
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2331
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2332
          reference list of the idInVocabulary values of absence and presence terms:
2333
<pre>
2334
Presence Term
2335
p	present
2336
pd	present: doubtfully present
2337
n	native
2338
nq	native: presence questionable
2339
nd	native: doubtfully native
2340
c	cultivated
2341
i	introduced
2342
iq	introduced: presence questionable
2343
id	introduced: doubtfully introduced (perhaps cultivated only)
2344
ip	introduced: uncertain degree of naturalisation
2345
ia	introduced: adventitious (casual)
2346
in	introduced: naturalized
2347
ic	introduced: cultivated
2348
e	endemic for the relevant area
2349
na	naturalised
2350
iv	invasive
2351

    
2352
AbsenceTerm
2353
a	absent
2354
f	reported in error
2355
nf	native: reported in error
2356
if	introduced: reported in error
2357
cf	cultivated: reported in error
2358
ne	native: formerly native
2359
ie	introduced: formerly introduced
2360

    
2361
</pre>'),
2362
  );
2363

    
2364

    
2365
  /* ====== SYNONYMY ====== */
2366
  $form['taxon_synonymy'] = array(
2367
    '#type' => 'fieldset',
2368
    '#title' => t('Taxon synonymy (tab)'),
2369
    '#collapsible' => TRUE,
2370
    '#collapsed' => TRUE,
2371
    '#description' => t('This section covers the settings related to the taxon
2372
      <strong>synonymy</strong> tab.'),
2373
  );
2374

    
2375
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2376
    '#type' => 'checkbox',
2377
    '#title' => t('Show accepted taxon on top of the synonymy'),
2378
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2379
    '#description' => t('If checked, the first homotypic taxon is a repetition
2380
      of the accepted taxon most likely with the full nomenclatural reference
2381
      (depending on the currently chosen theme).'),
2382
  );
2383

    
2384
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2385
    '#type' => 'checkbox',
2386
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2387
      coming from a synonym link.'),
2388
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2389
    '#description' => t('Check this if after doing a search and clicking on a
2390
      synonym you want to see the "accept of" text for the accepted synonym.'),
2391
  );
2392

    
2393
  /* === currently unused ===
2394
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2395
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2396
    '#type' => 'checkboxes',
2397
    '#title' => t('Display name relationships') . ':',
2398
    '#default_value' => variable_get('name_relationships_to_show', 0),
2399
    '#options' => $nameRelationshipTypeOptions,
2400
    '#description' => t('Select the name relationships you want to show for the
2401
      accepted taxa.'),
2402
  );
2403
 */
2404

    
2405
  $form['taxon_synonymy']['taxon_relations'] = array(
2406
    '#type' => 'fieldset',
2407
    '#title' => t('Taxon relationships'),
2408
    '#collapsible' => FALSE,
2409
    '#collapsed' => FALSE
2410
  );
2411

    
2412
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2413
    '#type' => 'checkbox',
2414
    '#title' => t('Show taxon relations ships of accepted taxon'),
2415
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2416
    '#description' => t('If this option is enabled the synonymy will show the
2417
      below selected taxon relationships of accepted taxa.'),
2418
  );
2419

    
2420
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2421
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2422
    '#type' => 'checkboxes',
2423
    '#title' => t('Taxon relationship types') . ':',
2424
    '#description' => t('Only taxon relationships of the selected type will be
2425
      displayed'),
2426
    '#options' => $taxonRelationshipTypeOptions,
2427
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2428
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2429
  );
2430

    
2431
  $form['taxon_synonymy']['name_relations'] = array(
2432
    '#type' => 'fieldset',
2433
    '#title' => t('Name relationships'),
2434
    '#collapsible' => FALSE,
2435
    '#collapsed' => FALSE
2436
  );
2437

    
2438
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2439
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2440
    '#type' => 'checkboxes',
2441
    '#title' => t('Name relationship types') . ':',
2442
    '#description' => t('Only name relationships of the selected type will be
2443
      displayed'),
2444
    '#options' => $taxonRelationshipTypeOptions,
2445
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2446
  );
2447

    
2448
  // ====== SPECIMENS ====== //
2449
  $form['taxon_specimens'] = array(
2450
    '#type' => 'fieldset',
2451
    '#title' => t('Taxon specimens (tab)'),
2452
    '#collapsible' => TRUE,
2453
    '#collapsed' => TRUE,
2454
    '#description' => t('This section covers the settings related to the taxon
2455
      <strong>specimens</strong> tab.'),
2456
  );
2457

    
2458
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2459

    
2460
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2461
    '#type' => 'checkbox',
2462
    '#title' => t('Show specimen derivatives in a compressed table'),
2463
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2464
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2465
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2466
  );
2467

    
2468
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2469
        '#type' => 'textfield',
2470
        '#title' => t('Number of records per page') . ':',
2471
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2472
    );
2473

    
2474
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2475
    '#type' => 'checkbox',
2476
    '#title' => t('Show "Associated with" in specimen table.'),
2477
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2478
  );
2479

    
2480
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2481
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2482
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2483
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2484
  }
2485
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2486
    '#type' => 'radios',
2487
    '#title' => t('Specimen description feature tree') . ':',
2488
    '#default_value' => $profile_feature_tree_uuid,
2489
    '#options' =>  $featureTrees['options'],
2490
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2491
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2492
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2493
    ),
2494
  );
2495

    
2496
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2497
  $form_title = t('Specimen media');
2498
  $form_description = t('Specimens may have media which is displayed at the
2499
     Specimen tab/section as a gallery. It is possible to configure the
2500
     thumbnails gallery here, however for configuring how a single media should
2501
     be displayed please go to !url.</p>',
2502
     array(
2503
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2504
     ));
2505
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2506

    
2507
  // --- MEDIA GALLERY ---- //
2508
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2509
  $form_title = 'Media gallery (tab)';
2510
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2511
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2512
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2513
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2514
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2515
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2516
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2517

    
2518
  // Comment @WA: D7 form api does not support reset buttons,
2519
  // so to mimic the D5 reset button we add one like this.
2520
  $form['actions']['reset'] = array(
2521
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2522
    '#weight' => 1000,
2523
  );
2524
  return system_settings_form($form);
2525
}
2526

    
2527
/**
2528
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2529
 *
2530
 * @param $map_id
2531
 * @param $form
2532
 * @return mixed
2533
 */
2534
function _cdm_map_visibility_setting($map_id)
2535
{
2536
  return array(
2537
    '#type' => 'select',
2538
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2539
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2540
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2541
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2542
        The map also can forced to show up <b>always</b> or <b>never</b>."
2543
  );
2544
}
2545

    
2546
/**
2547
 * @todo document this function.
2548
 */
2549
function cdm_settings_layout_search() {
2550

    
2551
  $form = array();
2552

    
2553
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2554

    
2555
  $form['search_settings'] = array(
2556
    '#type' => 'fieldset',
2557
    '#title' => t('Taxa Search'),
2558
    '#collapsible' => FALSE,
2559
    '#collapsed' => FALSE,
2560
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2561
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2562
         where they can write the text to be searched. You can find Drupal block configuration
2563
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2564
  );
2565

    
2566
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2567
      '#type' => 'checkbox',
2568
      '#title' => t('Ignore the chosen classification in simple search'),
2569
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2570
      '#description' => t('The simple search, which can be executed via the search block,
2571
          will by default search on the classification selected in the classification browser
2572
          selector. Set the tick if you want your portal to search on all classifications.'),
2573
  );
2574

    
2575
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2576
    '#type' => 'checkbox',
2577
    '#title' => t('Run simple search with free-text search backend.'),
2578
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2579
    '#description' => t('The simple search uses by default another search
2580
      backend as the advances search. By checking this option the simple search can be
2581
      configured to also use the free-text search backend.'),
2582
  );
2583

    
2584
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2585
    '#type' => 'textfield',
2586
    '#title' => t('Results per page') . ':',
2587
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2588
    '#description' => t('Number of results to display per page.'),
2589
  );
2590

    
2591
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2592
    '#type' => 'checkbox',
2593
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2594
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2595
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2596
  );
2597

    
2598
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2599
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2600
      '#type' => 'checkboxes',
2601
      '#title' => 'Search mode',
2602
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2603
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2604
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2605
          defaults set here.',
2606
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2607
      '#default_value' => $search_mode_default
2608
      );
2609

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

    
2615
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2616
  );
2617

    
2618
  // --- SEARCH TAXA GALLERY ---- //
2619
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2620
  $collapsed = FALSE;
2621
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2622
  $form_title = 'Taxa Search thumbnails';
2623
  $form_description = 'Search results may show thumbnails. ';
2624
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2625

    
2626
  // Comment @WA: D7 form api does not support reset buttons,
2627
  // so to mimic the D5 reset button we add one like this.
2628
  $form['actions']['reset'] = array(
2629
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2630
    '#weight' => 1000,
2631
  );
2632
  return system_settings_form($form);
2633
}
2634

    
2635
/**
2636
 * @todo document this function.
2637
 */
2638
function cdm_settings_layout_media() {
2639

    
2640
  $form = array();
2641

    
2642
  $form['media_settings'] = array(
2643
    '#type' => 'fieldset',
2644
    '#title' => t('Media settings'),
2645
    '#collapsible' => FALSE,
2646
    '#collapsed' => FALSE,
2647
    '#description' => 'This section covers layout settings for media pages.'
2648
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2649
  );
2650

    
2651
  $form['media_settings']['image_gallery_viewer'] = array(
2652
    '#type' => 'select',
2653
    '#title' => t('Image viewer') . ':',
2654
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2655
    '#options' => array(
2656
      'default' => t('Standard image viewer'),
2657
      'fsi' => t('FSI viewer (requires FSI server!)'),
2658
    ),
2659
  );
2660

    
2661
  // --- MEDIA GALLERY ---- //
2662
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2663
  $form_title = 'Standard viewer';
2664
  $form_description = '<p>Configure the standard image viewer.</p><p><strong>Note:</strong> the image viewer should selected otherwise settings are not taking into account.</p>';
2665
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2666
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2667

    
2668
  // @WA: D7 form api does not support reset buttons,
2669
  // so to mimic the D5 reset button we add one like this.
2670
  $form['actions']['reset'] = array(
2671
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2672
    '#weight' => 1000,
2673
  );
2674
  return system_settings_form($form);
2675
}
2676

    
2677
/**
2678
 * GEOSERVICE and Map settings.
2679
 */
2680
function cdm_settings_geo($form, &$form_state) {
2681

    
2682
  $current_geoserver_settings = get_edit_map_service_settings();
2683
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2684

    
2685

    
2686
  $form = array();
2687

    
2688
  $dummy_distribution_query = NULL;
2689
  if($map_distribution['map_type'] != 1){
2690
    // we need to apply a dummy query since the map service requires for image maps
2691
    // at least as and ad to be defined
2692
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2693
  }
2694

    
2695
  $form['map_preview'] = array(
2696
      '#type' => 'fieldset',
2697
      '#tree' => FALSE,
2698
      '#title' => t('Map preview'),
2699
      '#collapsible' => FALSE,
2700
      '#description' => 'The preview of the map'
2701
       . ($dummy_distribution_query != null ?
2702
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2703
           '.<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.')
2704
  );
2705
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2706
    'move' => "this.cdmOpenlayersMap.printInfo",
2707
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2708
  ), true // resizable
2709
  );
2710

    
2711
  /*
2712
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2713
  );
2714
  */
2715

    
2716
  /*
2717
   * GEO SERVER
2718
   */
2719
  $form['edit_map_server'] = array(
2720
    '#type' => 'fieldset',
2721
    '#tree' => true,
2722
    '#title' => t('EDIT map service'),
2723
    '#collapsible' => TRUE,
2724
    '#collapsed' => TRUE,
2725
    '#description' => t('Configuration and selection of your geo server.
2726
      The Geo Server is responsible for generating the maps.'),
2727
  );
2728

    
2729
  $form['edit_map_server']['base_uri'] = array(
2730
    '#type' => 'select',
2731
    '#title' => t('EDIT map service') . ':',
2732
    '#default_value' => $current_geoserver_settings['base_uri'],
2733
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2734
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2735
  );
2736
  $form['edit_map_server']['version'] = array(
2737
      '#type' => 'select',
2738
      '#title' => t('Version') . ':',
2739
      '#default_value' => $current_geoserver_settings['version'],
2740
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2741
      '#description' => t('The version of the EDIT map services'),
2742
  );
2743

    
2744
  /*
2745
   * MAP SETTINGS
2746
   */
2747

    
2748
  $form[CDM_MAP_DISTRIBUTION] = array(
2749
    '#type' => 'fieldset',
2750
    '#tree' => TRUE,
2751
    '#title' => t('Maps settings'),
2752
    '#collapsible' => TRUE,
2753
    '#collapsed' => TRUE,
2754
    '#description' => t('General configuration for all map types.'),
2755
  );
2756

    
2757
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2758
    '#type' => 'radios',
2759
    '#title' => 'Map types',
2760
    '#options' => array(
2761
      1 => "OpenLayers dynamic map viewer",
2762
      0 => "Plain image",
2763
    ),
2764
    '#default_value' => $map_distribution['map_type'],
2765
    '#description' => 'Two different map types are available :
2766
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2767
      which allows zooming and panning. If enabled you can configure the default layer
2768
      (background of your maps) below.</li>
2769
      <li><em>Plain image</em>: The map will be static non interactive
2770
      image.</li></ul>',
2771
  );
2772
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2773

    
2774
  /*
2775
   * settings for the distribution map are used also for specimens map!!!!
2776
   */
2777

    
2778
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2779
      '#type' => 'textfield',
2780
      '#title' => 'Aspect ratio',
2781
      '#default_value' => $map_distribution['aspect_ratio'],
2782
      '#maxlength' => 4,
2783
      '#size' => 4,
2784
      '#element_validate' => array('element_validate_number'),
2785
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2786
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2787
      width by the height:</br>
2788
      <pre>aspect ratio = w / h</pre>
2789
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2790
      for a square map use <strong>1</strong>.',
2791
  );
2792

    
2793
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2794
    '#type' => 'textfield',
2795
    '#title' => 'Bounding box',
2796
    '#default_value' => $map_distribution['bbox'],
2797
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2798
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2799
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2800
      <strong>TIP:</strong> You can use the map preview above to choose the <span class="map-extent-bbox"><strong>map extent bbox</strong> in <strong class="degree-value"">degree</strong></span> from the map.
2801
      (Maybe you need to change the map base layer to OpeLayers.)
2802
      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
2803
      below the map from where you can copy the bbox string.</p>'),
2804
  );
2805

    
2806
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2807
    '#type' => 'checkbox',
2808
    '#title' => 'Display area labels',
2809
    '#default_value' => $map_distribution['show_labels'],
2810
    '#description' => t('The map will show name labels of the areas'),
2811
  );
2812

    
2813
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2814
    '#type' => 'textfield',
2815
    '#title' => 'Map caption',
2816
    '#default_value' => $map_distribution['caption'],
2817
    '#description' => t('The caption will be shown below the map.'),
2818
  );
2819

    
2820
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2821
    '#type' => 'textfield',
2822
    '#title' => 'Distribution layer opacity',
2823
    '#default_value' => $map_distribution['distribution_opacity'],
2824
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2825
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2826
  );
2827

    
2828
  // --- Plain Image Settings --- //
2829
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2830
    '#type' => 'fieldset',
2831
    '#title' => 'Plain image map settings',
2832
    '#tree' => TRUE,
2833
    '#collapsible' => TRUE,
2834
    '#collapsed' => $open_layers_is_enabled,
2835
    '#description' => 'The settings in this section are still expertimental
2836
      and can only be used with the EDIT map service version 1.1 or above.',
2837
  );
2838
  $edit_mapserver_version = get_edit_map_service_version_number();
2839
  if ($edit_mapserver_version < 1.1) {
2840
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2841
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2842
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2843
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2844
  }
2845

    
2846
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2847
    '#type' => 'textfield',
2848
    '#title' => 'Width',
2849
    '#default_value' => $map_distribution['image_map']['width'],
2850
    '#maxlength' => 4,
2851
    '#size' => 4,
2852
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2853
  );
2854

    
2855
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2856
    '#type' => 'textfield',
2857
    '#title' => 'Background layer',
2858
    '#default_value' => $map_distribution['image_map']['base_layer'],
2859
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2860
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2861
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2862
    )),
2863
  );
2864

    
2865
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2866
    '#type' => 'textfield',
2867
    '#title' => 'Background color',
2868
    '#default_value' => $map_distribution['image_map']['bg_color'],
2869
  );
2870

    
2871
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2872
    '#type' => 'textfield',
2873
    '#title' => 'Background layer style',
2874
     // Only line color by now.
2875
    '#default_value' => $map_distribution['image_map']['layer_style'],
2876
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2877
  );
2878

    
2879
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2880
      '#type' => 'textfield',
2881
      '#title' => 'Projection',
2882
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2883
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2884
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2885
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2886
  );
2887

    
2888

    
2889
  // --- OpenLayers Settings --- //
2890
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2891
    '#type' => 'fieldset',
2892
    '#title' => 'OpenLayers settings',
2893
    '#tree' => TRUE,
2894
    '#collapsible' => TRUE,
2895
    '#collapsed' => !$open_layers_is_enabled,
2896
    '#description' => '',
2897
  );
2898

    
2899

    
2900
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2901
      '#type' => 'checkbox',
2902
      '#title' => 'Display outside max extent',
2903
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2904
      '#description' => t('Allows the map to display parts of the layers which are outside
2905
         the max extent if the aspect ratio of the map and of the baselayer
2906
         are not equal.'),
2907
  );
2908

    
2909

    
2910
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2911
      '#type' => 'checkbox',
2912
      '#title' => 'Show Layer Switcher',
2913
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2914
      '#description' => 'The Layer Switcher control displays a table of contents
2915
      for the map.  This allows the user interface to switch between
2916
      base layers and to show or hide overlays.  By default the switcher is
2917
      shown minimized on the right edge of the map, the user may expand it
2918
      by clicking on the handle.',
2919
  );
2920

    
2921
  if (!$open_layers_is_enabled) {
2922
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2923
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2924
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2925
  }
2926

    
2927
  // The default layer must always be enabled
2928
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2929
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2930

    
2931
  $baselayer_options = array(
2932
    /*
2933
   NOTICE: must correspond to the layers defined in
2934
   js/openlayers_,ap.js#getLayersByName()
2935
   */
2936
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
2937
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
2938
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
2939
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
2940
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2941
    // all others EPSG:900913
2942
    'mapnik' => 'OpenStreetMap',
2943
    'mapquest_open' => "MapQuest",
2944
    'mapquest_sat' => "MapQuest Sattelite",
2945
    'groadmap' => 'Google Roadmap',
2946
    'gsatellite' => 'Google Satellite',
2947
    'ghybrid' => 'Google Hybrid',
2948
    'gterrain' => 'Google Terrain',
2949
//     'veroad' => 'Virtual Earth Roads',
2950
//     'veaer' => 'Virtual Earth Aerial',
2951
//     'vehyb' => 'Virtual Earth Hybrid',
2952
    // 'yahoo' => 'Yahoo Street',
2953
    // 'yahoosat' => 'Yahoo Satellite',
2954
    // 'yahoohyb' => 'Yahoo Hybrid',
2955
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2956
  );
2957

    
2958
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2959
    '#type' => 'checkboxes_preferred',
2960
    '#title' => 'Base Layers',
2961
    '#options' => $baselayer_options,
2962
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2963
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2964
  );
2965

    
2966
  $google_maps_api_key = null;
2967
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
2968
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
2969
  }
2970
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
2971
    '#type' => 'textfield',
2972
    '#title' => 'Google Maps API Key',
2973
    '#default_value' => $google_maps_api_key,
2974
    '#description' => 'In order to use any of the Google map layers you need to provide 
2975
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
2976
  );
2977

    
2978
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2979
      '#type' => 'fieldset',
2980
      '#title' => 'Custom WMS base layer',
2981
      '#tree' => TRUE,
2982
      '#collapsible' => FALSE,
2983
      '#collapsed' => FALSE,
2984
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2985
  );
2986

    
2987
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2988
      '#type' => 'textfield',
2989
      '#title' => 'Layer name',
2990
      // Only line color by now.
2991
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2992
      '#description' => 'A arbitrary name for the layer.',
2993
  );
2994
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2995
      '#type' => 'textfield',
2996
      '#title' => 'WMS url',
2997
      // Only line color by now.
2998
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2999
      '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3000
  );
3001
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
3002
      '#type' => 'textarea',
3003
      '#title' => 'WMS parameters',
3004
      '#element_validate' => array('form_element_validate_json'),
3005
      // Only line color by now.
3006
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
3007
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
3008
<pre> {
3009
  "Layers": "topp:em_tiny_jan2003",
3010
  "Format": "image/png",
3011
  "BGCOLOR": "0xe0faff"
3012
}
3013
</pre>'
3014
  );
3015
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
3016
      '#type' => 'textfield',
3017
      '#title' => 'Projection',
3018
      // Only line color by now.
3019
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
3020
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
3021
  );
3022
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
3023
      '#type' => 'textfield',
3024
      '#maxlength' => 256,
3025
      '#title' => 'proj4js definition',
3026
      // Only line color by now.
3027
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
3028
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
3029
            The definitions for
3030
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
3031
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
3032
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
3033
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
3034
            choose to display the proj4js definition string.
3035
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
3036
            <pre>
3037
+a         Semimajor radius of the ellipsoid axis
3038
+alpha     ? Used with Oblique Mercator and possibly a few others
3039
+axis      Axis orientation (new in 4.8.0)
3040
+b         Semiminor radius of the ellipsoid axis
3041
+datum     Datum name (see `proj -ld`)
3042
+ellps     Ellipsoid name (see `proj -le`)
3043
+k         Scaling factor (old name)
3044
+k_0       Scaling factor (new name)
3045
+lat_0     Latitude of origin
3046
+lat_1     Latitude of first standard parallel
3047
+lat_2     Latitude of second standard parallel
3048
+lat_ts    Latitude of true scale
3049
+lon_0     Central meridian
3050
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
3051
+lon_wrap  Center longitude to use for wrapping (see below)
3052
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
3053
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
3054
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
3055
+pm        Alternate prime meridian (typically a city name, see below)
3056
+proj      Projection name (see `proj -l`)
3057
+south     Denotes southern hemisphere UTM zone
3058
+to_meter  Multiplier to convert map units to 1.0m
3059
+towgs84   3 or 7 term datum transform parameters (see below)
3060
+units     meters, US survey feet, etc.
3061
+vto_meter vertical conversion to meters.
3062
+vunits    vertical units.
3063
+x_0       False easting
3064
+y_0       False northing
3065
+zone      UTM zone
3066
            </pre>
3067
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
3068
  );
3069
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
3070
      '#type' => 'textfield',
3071
      '#title' => 'Maximum extent',
3072
      // Only line color by now.
3073
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
3074
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
3075
  );
3076
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
3077
      '#type' => 'textfield',
3078
      '#title' => 'Units',
3079
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
3080
      '#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.'
3081
  );
3082

    
3083
  /*
3084
   * Map Legend
3085
   */
3086
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3087
    '#type' => 'fieldset',
3088
    '#title' => 'Map legend',
3089
    '#tree' => TRUE,
3090
    '#collapsible' => TRUE,
3091
    '#collapsed' => TRUE,
3092
    '#description' => 'Configure the maps legend.',
3093
  );
3094

    
3095
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3096
    '#type' => 'checkbox',
3097
    '#title' => 'Display a map legend',
3098
    '#default_value' => $map_distribution['legend']['show'],
3099
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3100
  );
3101

    
3102
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3103
    '#type' => 'textfield',
3104
    '#title' => 'Legend opacity',
3105
    '#default_value' => $map_distribution['legend']['opacity'],
3106
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3107
                         to 0.0 will be not much visible.',
3108
  );
3109

    
3110
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3111
    '#type' => 'textfield',
3112
    '#title' => 'Font size',
3113
    '#default_value' => $map_distribution['legend']['font_size'],
3114
    '#description' => 'Font size in pixels.',
3115
  );
3116

    
3117
  $fontStyles = array(
3118
    0 => "plane",
3119
    1 => "italic",
3120
  );
3121
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3122
    '#type' => 'select',
3123
    '#title' => 'Available font styles',
3124
    '#default_value' => $map_distribution['legend']['font_style'],
3125
    '#options' => $fontStyles,
3126
    '#description' => 'Select a font style for the map legend.',
3127
  );
3128

    
3129
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3130
    '#type' => 'textfield',
3131
    '#title' => 'Icon width',
3132
    '#default_value' => $map_distribution['legend']['icon_width'],
3133
    '#description' => 'Legend icon width in pixels.',
3134
  );
3135
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3136
    '#type' => 'textfield',
3137
    '#title' => 'Icon height',
3138
    '#default_value' => $map_distribution['legend']['icon_height'],
3139
    '#description' => 'Legend icon height in pixels.',
3140
  );
3141

    
3142
  // @WA: D7 form api does not support reset buttons,
3143
  // so to mimic the D5 reset button we add one like this.
3144
  $form['actions']['reset'] = array(
3145
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3146
    '#weight' => 1000,
3147
  );
3148

    
3149
  return system_settings_form($form);
3150
}
3151

    
3152

    
3153
/**
3154
 * @todo document this function.
3155
 */
3156
function cdm_settings_cache() {
3157

    
3158
  $form = array();
3159

    
3160
  $form['cache_settings'] = array(
3161
    '#type' => 'fieldset',
3162
    '#title' => t('Cache Settings'),
3163
    '#collapsible' => FALSE,
3164
    '#collapsed' => FALSE,
3165
    '#description' => t('<p>When caching is enabled all single taxon sites are
3166
      stored in an internal drupal cache doing the portal response of taxa pages
3167
      faster. This is possible because the sites are loaded from the cache and
3168
      are not created from scratch.</p>'),
3169
  );
3170

    
3171
  $form['cache_settings']['cdm_webservice_cache'] = array(
3172
    '#type' => 'checkbox',
3173
    '#title' => t('<strong>Enable caching</strong>'),
3174
    '#options' => cdm_help_general_cache(),
3175
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3176
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3177
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3178
       application the changes will be not visible till the cache is erased.
3179
       Therefore developers should deactived this feature when they are working
3180
       on the CDM Dataportal Module.</p>'),
3181
  );
3182

    
3183
  $form['cache_settings']['cdm_run_cache'] = array(
3184
    '#markup' => cdm_view_cache_site(),
3185
  );
3186

    
3187
  // @WA: D7 form api does not support reset buttons,
3188
  // so to mimic the D5 reset button we add one like this.
3189
  $form['actions']['reset'] = array(
3190
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3191
    '#weight' => 1000,
3192
  );
3193
  return system_settings_form($form);
3194
}
3195

    
3196
/**
3197
 * Walk and cache all taxon pages.
3198
 */
3199
function cdm_view_cache_site() {
3200

    
3201
  $out = '';
3202

    
3203
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3204

    
3205
  $request_params = array();
3206
  $request_params['class'] = "Taxon";
3207

    
3208
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3209
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3210
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3211

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

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

    
3221
  // Comment @WA: A form within a form is not valid html and not needed here.
3222
  // Also, it would be recommended just to include this part of the form in the
3223
  // rest of the form array in cdm_settings_cache().
3224
  // $out .= '<form id="cache_site">';
3225
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3226
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3227
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3228
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3229
  // $out .= '</form>';
3230
  $out .= '</div>';
3231
  /*
3232
  foreach($taxonPager->records as $taxon){
3233
    cdm_dataportal_taxon_view($uuid);
3234
  }
3235
  */
3236
  return $out;
3237
}
3238

    
3239

    
3240
function cdm_settings_layout_taxon_submit($form, &$form_state){
3241
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3242
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3243
    if(is_object($file)){
3244
      $file->status = FILE_STATUS_PERMANENT;
3245
      file_save($file);
3246
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3247
    }
3248
  }
3249
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3250
  $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]);
3251
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3252
  if($tab_lables_modified || $tabs_enabled_modified){
3253
    // we first need to set the variable to persist the changes setting
3254
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3255
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3256
    menu_rebuild();
3257
  }
3258
}
3259

    
3260
function cdm_settings_layout_search_submit($form, &$form_state){
3261
  // the visibility of media thumbnails also affects the ui of the search results
3262
  // so reset the according session variable
3263
  //    1. in order to give the user immediate
3264
  //       feedback on potential setting changes
3265
  //    2. let refresh the default if it has changed
3266
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3267
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3268
  }
3269
}
3270

    
3271
/**
3272
 * Form validation handler for cdm_settings_general
3273
 *
3274
 * @param $form
3275
 * @param $form_state
3276
 */
3277
function cdm_settings_general_validate($form, &$form_state) {
3278

    
3279
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3280
    $form_state['values']['cdm_webservice_url'] .= '/';
3281
  }
3282

    
3283
}
3284

    
3285
/**
3286
 * Form submit handler for settings general.
3287
 *
3288
 * tasks performed:
3289
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3290
 *
3291
 * @param $form
3292
 * @param $form_state
3293
 */
3294
function cdm_settings_general_submit($form, &$form_state){
3295
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3296
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3297
}
3298

    
3299
/**
3300
 * Form validation handler for cdm_settings_cache
3301
 */
3302
function cdm_settings_cache_validate($form, &$form_state) {
3303
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3304
    cache_clear_all(NULL, 'cache_cdm_ws');
3305
    // Better clear secref_cache since I can not be sure if the cache has not
3306
    // be used during this response.
3307
    cdm_api_secref_cache_clear();
3308
  }
3309

    
3310
}
3311

    
3312
/**
3313
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3314
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3315
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3316
 *  - version: the version, e.g.: v1.1
3317
 *
3318
 * @return array
3319
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3320
 */
3321
function get_edit_map_service_settings() {
3322

    
3323
  $settings = variable_get('edit_map_server', array(
3324
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3325
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3326
      )
3327
  );
3328

    
3329
  return $settings;
3330
}
3331

    
3332
/**
3333
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3334
 *
3335
 * @return string
3336
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3337
 */
3338
function get_edit_map_service_full_uri() {
3339
  $settings = get_edit_map_service_settings();
3340
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3341
}
3342

    
3343

    
3344
/**
3345
 * Returns the version number of the currently selected edit mapserver as a float
3346
 *
3347
 * @return float
3348
 *   The version number of the currently selected edit mapserver as a float.
3349
 *   Returns 0 on error.
3350
 */
3351
function get_edit_map_service_version_number() {
3352

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

    
3355
  $settings = get_edit_map_service_settings();
3356
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3357
  if (isset($matches[1])) {
3358
    // Convert string to float.
3359
    $version = 1 + $matches[1][0] - 1;
3360
    return $version;
3361
  }
3362
  else {
3363
    // Report error.
3364
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3365
        array(
3366
          '!version' => $settings['version'],
3367
          'warning')
3368
        )
3369
      );
3370
    return 0;
3371
  }
3372
}
3373

    
3374
/**
3375
 * Returns the array of selected items in a options array
3376
 *
3377
 * @param array $options
3378
 *   An options array as generated by a form element like checkoxes, select ...,
3379
 */
3380
function get_selection($options) {
3381
  $selection = array();
3382
  foreach ($options as $key=>$val) {
3383
    if (!empty($val)) {
3384
      $selection[] = $val;
3385
    }
3386
  }
3387
  return $selection;
3388
}
3389

    
3390

    
3391
/**
3392
 * Implements hook_element_info().
3393
 *
3394
 * Allows modules to declare their own Form API element types and specify their default values.
3395
 *
3396
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3397
 */
3398
function cdm_dataportal_element_info() {
3399
  $type['checkboxes_preferred'] = array(
3400
    '#input' => TRUE,
3401
    '#process' => array('checkboxes_preferred_expand'),
3402
    '#after_build' => array('checkboxes_preferred_after_build'),
3403
    '#theme' => array('checkboxes_preferred'),
3404
    // '#theme_wrapper' => array('form_element'),
3405
  );
3406
  return $type;
3407
}
3408

    
3409
/**
3410
 * #process callback function for the custom form element type 'checkbox_preferred'
3411
 *
3412
 *
3413
 */
3414
function checkboxes_preferred_expand($element, &$form_state, $form) {
3415

    
3416
  // First of all create checkboxes for each of the elements
3417
  $element = form_process_checkboxes($element);
3418

    
3419
  // compose the element name
3420
  $parents = array();
3421
  array_deep_copy($element['#parents'], $parents);
3422
  $parents[count($parents) -1 ] .= '_preferred';
3423
  $element_name = $parents[0];
3424
  for ($i=1; $i < count($parents); $i++){
3425
    $element_name .= '[' . $parents[$i] . ']';
3426
  }
3427

    
3428
  $children = element_children($element);
3429

    
3430
  $element['table_start'] = array(
3431
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3432
    '#weight' => -1,
3433
  );
3434

    
3435
  // prepare first part each of the table rows which contains the row label
3436
  $weight = 0;
3437
  foreach ($children as $key) {
3438
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3439
    $element[$key]['#weight'] = $weight;
3440
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3441
    $element[$key]['#suffix'] = '</td>';
3442
    unset($element[$key]['#title']);
3443
    $weight += 2;
3444
  }
3445
  $weight = 0;
3446

    
3447
  // add a radio button to each of the checkboxes, the
3448
  // check boxes have already been created at the beginning
3449
  // of this function
3450
  if (count($element['#options']) > 0) {
3451
    foreach ($element['#options'] as $key => $choice) {
3452
      if (!isset($element[$key . '_preferred'])) {
3453
        $element[$key . '_preferred'] = array(
3454
          '#type' => 'radio',
3455
          '#name' => $element_name,
3456
          '#return_value' => check_plain($key),
3457
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3458
          '#attributes' => $element['#attributes'],
3459
          '#parents' => $element['#parents'],
3460
          // '#spawned' => TRUE,
3461
          '#weight' => $weight + 1,
3462
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3463
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3464
        );
3465
      }
3466
      $weight += 2;
3467
    }
3468
  }
3469

    
3470
  // end the table
3471
  $element['table_end'] = array(
3472
    '#markup' => '</table>',
3473
    '#weight' => $weight++,
3474
  );
3475

    
3476
  return $element;
3477
}
3478

    
3479
/**
3480
 * Theme function for the custom form field 'checkboxes_preferred'.
3481
 */
3482
function theme_checkboxes_preferred($variables) {
3483
  $element = $variables['element'];
3484
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3485
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3486
  $out .= drupal_render_children($element);
3487
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3488
  $out .= '</div>';
3489
  return $out;
3490
}
3491

    
3492
/**
3493
 * Callback for checkboxes preferred for widget which will
3494
 * be called after the form or element is built. The call
3495
 * back is configured in the form element by setting it as
3496
 * #after_build parameter.
3497
 *
3498
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3499
 *
3500
 * @param $element
3501
 *   Nested array of form elements that comprise the form.
3502
 * @param $form_state
3503
 *   A keyed array containing the current state of the form.
3504
 *   This includes the current persistent storage data for the form.
3505
 *   Additional information, like the sanitized $_POST data,
3506
 *   is also accumulated here in $form_state['input']
3507
 *
3508
 * @return the modified form array
3509
 */
3510
function checkboxes_preferred_after_build($element, &$form_state) {
3511

    
3512
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3513

    
3514
  if ($_POST && count($_POST) > 0) {
3515
    // TODO use  $form_state['input'] instead of POST !!!
3516
    // First pass of form processing.
3517
    $parents = array();
3518
    array_deep_copy($element['#parents'], $parents);
3519
    $parents[count($parents) - 1] .= '_preferred';
3520
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3521
    $element['#value']['PREFERRED'] = $preferred_layer;
3522
//     $form_state[$parent_id] = $element['#value'];
3523
//     $form_state['values']['baselayers'] = $element['#value'];
3524
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3525
    $form_state_element_values = $element['#value'];
3526
  }
3527
  else {
3528
    // Second pass of form processing.
3529
    $preferred_layer = $element['#value']['PREFERRED'];
3530
  }
3531

    
3532
  // Also set the chosen value (not sure if this is good Drupal style ....).
3533
  foreach ($children = element_children($element) as $key) {
3534
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3535
      $element[$key]['#value'] = $preferred_layer;
3536
    }
3537
  }
3538
  // The default layer must always be enabled.
3539
  $element[$preferred_layer]['#value'] = $preferred_layer;
3540

    
3541
  return $element;
3542
}
3543

    
3544
function radios_prepare_options_suffix(&$elements){
3545

    
3546
  $childrenKeys = element_children($elements);
3547
  foreach($childrenKeys as $key){
3548
    if(!is_array($elements[$key]['#theme_wrappers'])){
3549
      $elements[$key]['#theme_wrappers'] = array();
3550
    }
3551
    if(isset($elements['#options_suffixes'][$key])){
3552
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3553
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3554
    }
3555
  }
3556
  return $elements;
3557

    
3558
}
3559

    
3560
/**
3561
 * TODO
3562
 * @param unknown $variables
3563
 */
3564
function theme_radio_options_suffix($variables) {
3565
  $element = $variables['element'];
3566
  if(isset($element['#options_suffix'])) {
3567
    $element['#children'] .= $element['#options_suffix'];
3568
  }
3569
  return $element['#children'];
3570
}
3571

    
3572

    
3573
/**
3574
 * Element validate callback for text field and arrays containing json.
3575
 *
3576
 * @param $element
3577
 *   The form element to validate
3578
 * @param $form_state
3579
 *   A keyed array containing the current state of the form.
3580
 * @param $form
3581
 *   Nested array of form elements that comprise the form.
3582
 */
3583
function form_element_validate_json($element, &$form_state, $form) {
3584
   if (!empty($element['#value'])) {
3585
     json_decode($element['#value']);
3586
     if(json_last_error() != JSON_ERROR_NONE){
3587
       form_error($element,
3588
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3589
         . l('JSONLint', 'http://jsonlint.com/')
3590
       );
3591
     }
3592
   }
3593
}
3594

    
3595
/**
3596
 * Form submission handler for textareas and textfields containing JSON.
3597
 *
3598
 * The contained JSON will be converted into an php array
3599
 * or object and will be stored in the variables as such.
3600
 *
3601
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3602
 *
3603
 * @param $form
3604
 *   Nested array of form elements that comprise the form.
3605
 * @param $form_state
3606
 *   A keyed array containing the current state of the form.
3607
 *
3608
 */
3609
function submit_json_as_php_array($form, &$form_state) {
3610
  if (is_array($form['#json_elements'])) {
3611
    foreach ($form['#json_elements'] as $element){
3612
      if (trim($form_state['values'][$element])) {
3613
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3614
      } else {
3615
        $form_state['values'][$element] = NULL;
3616
      }
3617
    }
3618
  }
3619
}
(16-16/16)