Project

General

Profile

Download (148 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

    
1117
  $form['cdm_webservice']['freetext_index']['cdm_login'] = array(
1118
    // this must not be stored, it is only used by the _add_js_cdm_ws_progressbar
1119
    '#type' => 'textfield',
1120
    '#title' => t('Login'),
1121
    '#description' => t('Your cdm user credentials in the following form: <code>user:password</code>')
1122
  );
1123
  drupal_add_js('
1124
        jQuery(document).ready(function() {
1125
             jQuery("#edit-cdm-login").change(function (e) {
1126
                var login = jQuery(e.target).val();
1127
                jQuery("#edit-freetext-index .index-trigger").each(function(index){
1128
                   var url = jQuery(this).attr("href");
1129
                   url = url.replace(/:\/\/[^@]+@|:\/\//, "://" + login + "@");
1130
                   jQuery(this).attr("href", url);
1131
                });
1132
            });
1133
        });
1134
      ',
1135
    array(
1136
      'type' => 'inline',
1137
      'scope' => 'footer'
1138
    )
1139
  );
1140
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1141

    
1142
    $form['cdm_webservice']['freetext_index']['cdm_dataportal_taxon_auto_suggest'] = array(
1143
        '#type' => 'checkbox',
1144
        '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
1145
        '#default_value' => variable_get('cdm_dataportal_taxon_auto_suggest', CDM_DATAPORTAL_TAXON_AUTO_SUGGEST),
1146
        '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
1147
        This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
1148
    );
1149

    
1150
  $form['cdm_webservice']['proxy'] = array(
1151
    '#type' => 'fieldset',
1152
    '#title' => t('Proxy'),
1153
    '#collapsible' => TRUE,
1154
    '#collapsed' => TRUE,
1155
  );
1156

    
1157
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1158
    '#type' => 'textfield',
1159
    '#title' => t('Proxy URL') . ':',
1160
    '#description' => t('If this proxy url is set the cdm api tries
1161
    to connect the web service over the given proxy server.
1162
    Otherwise proxy usage is deactivated.'),
1163
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1164
  );
1165

    
1166
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1167
    '#type' => 'textfield',
1168
    '#title' => t('Proxy port') . ':',
1169
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1170
  );
1171

    
1172
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1173
    '#type' => 'textfield',
1174
    '#title' => t('Login') . ':',
1175
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1176
  );
1177

    
1178
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1179
    '#type' => 'textfield',
1180
    '#title' => t('Password') . ':',
1181
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1182
  );
1183

    
1184
  // TODO: settings are still incomplete, compare with
1185
  // trunk/dataportal/inc/config_default.php.inc.
1186
  $form['taxon_tree'] = array(
1187
    '#type' => 'fieldset',
1188
    '#title' => t('Taxon Tree'),
1189
    '#collapsible' => FALSE,
1190
    '#collapsed' => TRUE,
1191
    '#description' => t('<p>When you explore your collection, you can navigate
1192
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1193
      able to navigate through your collection the
1194
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1195
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1196
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1197
      </a></p>'),
1198
  );
1199

    
1200
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1201
    '#type' => 'select',
1202
    '#title' => t('Available classifications') . ':',
1203
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1204
    '#options' => cdm_get_taxontrees_as_options(),
1205
    '#description' => t('Select the default taxa classification for your
1206
      <em>taxon tree</em>, the other classifications will be also available but
1207
      with a manual user change.'),
1208
  );
1209

    
1210
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1211
    '#type' => 'select',
1212
    '#title' => t('Rank of highest displayed taxon') . ':',
1213
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1214
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1215
    '#options' => cdm_rankVocabulary_as_option(),
1216
    '#description' => t('This is the rank of the highest displayed taxon in the
1217
      <em>taxon tree</em>. You can select here which rank should be at the top
1218
      level of the tree structure.'),
1219
  );
1220

    
1221
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1222
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1223
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1224
      '#type' => 'checkboxes',
1225
      '#title' => t('Included Classifications') . ':',
1226
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1227
      '#options' => cdm_get_taxontrees_as_options(),
1228
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1229
  );
1230

    
1231
  $form['distribution'] = array(
1232
      '#type' => 'fieldset',
1233
      '#title' => t('Distributions'),
1234
      '#collapsible' => FALSE,
1235
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1236
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1237
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1238
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1239
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1240
          '<p>
1241
          </p>',
1242
  );
1243

    
1244
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1245
      '#type' => 'fieldset',
1246
      '#title' => 'Distribution filter',
1247
      '#collapsible' => FALSE,
1248
      '#collapsed' => FALSE,
1249
      '#tree' => TRUE,
1250
      '#description' => 'The Distribution filter offers the following options
1251
      <ul>
1252
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1253
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1254
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1255
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1256
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1257
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1258
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1259
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1260
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1261
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1262
      </ul>'
1263
  );
1264

    
1265
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1266
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1267
      '#type' => 'checkboxes',
1268
      '#title' => 'Filter rules',
1269
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1270
      '#options' => array(
1271
          'statusOrderPreference' => 'Status order preference rule',
1272
          'subAreaPreference' => 'Sub area preference rule'
1273
      ),
1274
  );
1275

    
1276
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1277
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1278
      '#type' => 'checkboxes',
1279
      '#title' => 'Hide marked area filter',
1280
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1281
      '#options' => $marker_type_options,
1282
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1283
  );
1284

    
1285
  $form['aggregation'] = array(
1286
      '#type' => 'fieldset',
1287
      '#title' => t('Aggregation of data'),
1288
      '#collapsible' => FALSE,
1289
      '#description' => 'This section covers the different aspects of aggregating information.
1290
          <p>
1291
          </p>',
1292
  );
1293

    
1294
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1295
      '#type' => 'checkboxes',
1296
      '#title' => 'Taxon media filter',
1297
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1298
      '#options' => array(
1299
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1300
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1301
          'includeOccurrences' => 'Media related to specimens and occurrences',
1302
      ),
1303
      '#description' => 'This filter configures which images should be taken into account.',
1304
  );
1305

    
1306
  $form['aggregation']['notice'] = array(
1307
      '#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
1308
          want to make use of the caching capabilities of the dataportal.',
1309
  );
1310

    
1311
  $form['aggregation']['media_aggregation'] = array(
1312
      '#type' => 'fieldset',
1313
      '#title' => t('Media aggregation'),
1314
      '#collapsible' => FALSE,
1315
      '#collapsed' => TRUE,
1316
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1317

    
1318
  );
1319
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1320
      '#type' => 'select',
1321
      '#title' => t('Aggregation of taxon pictures') . ':',
1322
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1323
      '#options' => array(
1324
          0 => "Show only pictures of the current taxon",
1325
          1 => "Include pictures of taxonomic children",
1326
      ),
1327
      '#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."),
1328
  );
1329

    
1330
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1331
      '#type' => 'fieldset',
1332
      '#attributes' => array('class' => array('clearfix')),
1333
      '#title' => t('Aggregation via taxon relationsships'),
1334
      '#collapsible' => TRUE,
1335
      '#collapsed' => TRUE,
1336
      '#tree' => TRUE,
1337
      '#description' => t('Information on taxa will be aggregated along the below chosen
1338
          taxon relation ships. This will affect images and occurrences (specimens).
1339
          Taxon relation ships are directed and point form one taxon to another. The taxon
1340
          relationships to be taken into accunt can therefore configured for the direct direction
1341
          and for the inverse.'),
1342
  );
1343

    
1344
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1345
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1346

    
1347
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1348
      '#type' => 'checkboxes',
1349
      '#title' => t('Direct'),
1350
      '#options' => $taxonRelationshipTypeOptions,
1351
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1352
  );
1353
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1354
      '#type' => 'checkboxes',
1355
      '#title' => t('Invers'),
1356
      '#options' => $taxonRelationshipTypeOptions,
1357
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1358
  );
1359

    
1360
  $form['drupal_integration'] = array(
1361
    '#type' => 'fieldset',
1362
    '#attributes' => array('class'=> array('clearfix')),
1363
    '#title' => t('Drupal integration'),
1364
    '#collapsible' => FALSE,
1365
    '#collapsed' => FALSE,
1366
    '#tree' => FALSE
1367
  );
1368

    
1369
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1370
    '#type' => 'checkbox',
1371
    '#title' => 'Create drupal nodes',
1372
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1373
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1374
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1375
    cdm pages it is required that drupal nodes are created and stored in the database.'
1376
  );
1377

    
1378

    
1379

    
1380
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1381
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1382
    <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>',
1383
  );
1384
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1385
    '#type' => 'submit',
1386
    '#value' => t('Drop all cdm nodes'),
1387
    '#submit' => array('drop_all_cdm_nodes_submit')
1388
  );
1389

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

    
1394
    // ----------------------
1395
  $form['cdm_js_devel_mode'] = array(
1396
      '#type' => 'checkbox',
1397
      '#title' => 'Java-script developer mode',
1398
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1399
      '#description' => 'In production envirionments the java script libraries
1400
      the cdm_dataportal is making use of are compressed and optimized. This
1401
      is good for performance but a caveat if you need to debug java-script. When the
1402
      java-script developer mode is enabled the uncompressed and commented developer
1403
      versions of java-script libraries will be used where possible.
1404
      <br/><strong>Do not use this option in production!</strong>'
1405
  );
1406
  // ----------------------
1407
  $form['cdm_debug_mode'] = array(
1408
      '#type' => 'checkbox',
1409
      '#title' => 'CDM page debug mode',
1410
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1411
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1412
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1413
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1414
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1415
      The log is written by the drupal devel module function <code>dd()</code>.
1416
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1417
  );
1418

    
1419
  // Comment @WA: D7 form api does not support reset buttons,
1420
  // so to mimic the D5 reset button we add one like this.
1421
  $form['actions']['reset'] = array(
1422
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1423
    '#weight' => 1000,
1424
  );
1425

    
1426
  $form['#submit'][] = 'cdm_settings_general_submit';
1427

    
1428
  return system_settings_form($form);
1429
}
1430

    
1431
/**
1432
 * Submit callback; drops all cdm nodes.
1433
 *
1434
 * @ingroup forms
1435
 */
1436
function drop_all_cdm_nodes_submit($form, &$form_state) {
1437
  cdm_delete_all_cdm_nodes();
1438
  drupal_set_message(t('All cdm nodes dropped.'));
1439
}
1440

    
1441

    
1442
/**
1443
 * LAYOUT settings
1444
 * @return
1445
 *   todo
1446
 */
1447
function cdm_settings_layout() {
1448

    
1449
  $form = array();
1450

    
1451
  $form['about'] = array(
1452
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1453
      layout. If you want to configure the specific sites layout visit the
1454
      respective configuration site for taxon, search or media.') . '</p>',
1455
  );
1456

    
1457
  // ---- footnotes --- //
1458
  $form['footnotes'] = array(
1459
    '#type' => 'fieldset',
1460
    '#title' => t('Footnotes'),
1461
    '#collapsible' => FALSE,
1462
    '#collapsed' => FALSE,
1463
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1464
      media or distribution areas may have annotations or footnotes. When the
1465
      footnotes are enabled they will be visible (if they exist).'),
1466
  );
1467

    
1468
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1469
    '#type' => 'checkbox',
1470
    '#title' => t('Do not show footnotes'),
1471
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1472
    '#description' => t('Check this if you do not want to show any footnotes'),
1473
  );
1474

    
1475
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1476
    '#type' => 'checkbox',
1477
    '#title' => t('Do not show annotation footnotes'),
1478
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1479
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1480
  );
1481

    
1482
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1483
  // Additional option for the NULL case.
1484
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1485
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1486
    '#type' => 'checkboxes',
1487
    '#title' => t('Annotation types as footnotes'),
1488
    '#description' => t("Only annotations of the selected type will be displayed
1489
       as footnotes. You may want to turn 'technical annotations' off."),
1490
    '#options' => $annotationTypeOptions,
1491
  );
1492
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1493
  if (!empty($annotationsTypesAsFootnotes)) {
1494
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1495
  }
1496

    
1497
  // ---- original source --- //
1498
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1499
      '#type' => 'fieldset',
1500
      '#tree' => TRUE,
1501
      '#title' => t('Source Citations'),
1502
      '#collapsible' => FALSE,
1503
      '#collapsed' => FALSE,
1504
  );
1505

    
1506
  $bibliography_settings = get_bibliography_settings(true);
1507

    
1508
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1509
      '#type' => 'checkbox',
1510
      '#title' => t('Original Source in bibliography'),
1511
      '#default_value' => $bibliography_settings['enabled'],
1512
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1513
       annotations in each feature block.'),
1514
  );
1515

    
1516
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1517
    '#type' => 'select',
1518
    '#title' => t('The format of the key numerals'),
1519
    '#default_value' => $bibliography_settings['key_format'],
1520
    '#options' => array('latin' => 'Latin',
1521
      'ROMAN' => 'Roman (upper case)',
1522
      'roman' => 'Roman (lower case)',
1523
      'ALPHA'=> 'Alphabet (upper case)',
1524
      'alpha' => 'Alphabet (lower case)')
1525
  );
1526

    
1527
  // --- Advanced Search --- //
1528
  $form['asearch'] = array(
1529
      '#type' => 'fieldset',
1530
      '#title' => t('Advanced search'),
1531
      '#collapsible' => FALSE,
1532
      '#collapsed' => FALSE,
1533
  );
1534
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1535
      '#type' => 'checkbox',
1536
      '#title' => t('Show advanced search link'),
1537
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1538
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1539
  );
1540

    
1541
  // ---- Taxon Name Rendering --- //
1542
  $form['taxon_name'] = array(
1543
      '#type' => 'fieldset',
1544
      '#title' => t('Taxon name display'),
1545
      '#collapsible' => TRUE,
1546
      '#collapsed' => TRUE,
1547
      '#description' => t('The display of taxon names is configured by two parts.
1548
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1549
          The name parts are defined in the <stong>part definitions</strong>'),
1550
  );
1551

    
1552
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1553
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1554
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1555
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1556

    
1557
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1558
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1559
    $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.)';
1560
  } else if($is_custom_part_definition){
1561
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1562
  } else  {
1563
    $which_version_message = '(These are the default part definition.)';
1564
  }
1565

    
1566
  $diff_viewer_markup = '';
1567
  if($is_custom_part_definition){
1568
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1569
  }
1570

    
1571
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1572
    . $which_version_message
1573
    . '</div>'
1574
    . $diff_viewer_markup;
1575

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

    
1665
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1666
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1667
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1668
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1669
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1670

    
1671
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1672
    $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.)';
1673
  } else if($is_custom_render_template){
1674
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1675
  } else {
1676
    $which_version_message = '(These are the default render templates.)';
1677
  }
1678

    
1679
  $diff_viewer_markup = '';
1680
  if($is_custom_render_template){
1681
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1682
  }
1683

    
1684
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1685
    . $which_version_message
1686
    . '</div>'
1687
    . $diff_viewer_markup;
1688

    
1689
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1690
      '#type' => 'textarea',
1691
      '#title' => t('Name render templates'),
1692
      '#element_validate' => array('form_element_validate_json'),
1693
      '#default_value' =>  $current_render_templates_json,
1694
      '#description' => '
1695
          <p>' . $which_version_message . '</p>
1696
          <p>
1697
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1698
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1699
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1700
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1701
          The following render Path keys are currently recognized:
1702
          <ul>
1703
            <li>list_of_taxa</li>
1704
            <li>acceptedFor</li>
1705
            <li>homonym</li>
1706
            <li>taxon_page_synonymy</li>
1707
            <li>typedesignations</li>
1708
            <li>taxon_page_title</li>
1709
            <li>polytomousKey</li>
1710
            <li>na: name + authorship</li>
1711
            <li>nar:name + authorship + reference</li>
1712
            <li>#DEFAULT</li>
1713
          </ul>
1714
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1715
          array element should be a comma separated list of render paths, without any whitespace!.
1716
          </p>
1717
          <p>
1718
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1719
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1720
          <p>
1721
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1722
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1723
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1724
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1725
          links if the paramters $nameLink or $refenceLink are given to the name render function
1726
          (this is hard coded and cannot be configured here).',
1727
  );
1728

    
1729
  // @WA: D7 form api does not support reset buttons,
1730
  // so to mimic the D5 reset button we add one like this.
1731
  $form['actions']['reset'] = array(
1732
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1733
    '#weight' => 1000,
1734
  );
1735

    
1736
  $form['#submit'] = array('submit_json_as_php_array');
1737
  // #json_elements especially defined for submit_json_as_php_array()
1738
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1739
  return system_settings_form($form);
1740
}
1741

    
1742

    
1743

    
1744
  /**
1745
 * @todo Please document this function.
1746
 * @see http://drupal.org/node/1354
1747
 */
1748
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1749
  $form[$form_name] = array(
1750
    '#type' => 'fieldset',
1751
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1752
    '#collapsible' => TRUE,
1753
    '#collapsed' => $collapsed,
1754
    '#tree' => TRUE,
1755
    '#description' => t('@$form-description', array('@$form-description' => $form_description)),
1756
  );
1757

    
1758
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1759
  $gallery_settings = variable_get($form_name, $default_values);
1760
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1761
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1762
    /*
1763
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1764
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1765
    '#type' => 'textfield',
1766
    '#title' => t('Search Page Size'),
1767
    '#default_value' => $test,
1768
    '#description' => t('Number of Names to display per page in search results.')
1769
    );
1770
    */
1771
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1772
      '#type' => 'checkbox',
1773
      '#title' => t('Show media thumbnails for accepted taxa'),
1774
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1775
    );
1776

    
1777
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1778
      '#type' => 'checkbox',
1779
      '#title' => t('Show media thumbnails for synonyms'),
1780
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1781
      '#description' => '',
1782
    );
1783
  }
1784

    
1785
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1786
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1787
    '#type' => 'checkbox',
1788
    '#title' => t('Show captions under thumbnails'),
1789
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1790
    '#description' => '',
1791
  );
1792

    
1793
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1794
    '#type' => 'textfield',
1795
    '#title' => t('Thumbnail size') . ':',
1796
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1797
    '#description' => t('Select the size of each individual thumbnail.'),
1798
  );
1799

    
1800
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1801
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1802
      '#type' => 'textfield',
1803
      '#title' => t('Number of columns') . ':',
1804
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1805
      '#description' => t('Group the thumbnails in columns: select how many
1806
        columns the gallery should display.'),
1807
    );
1808
  }
1809

    
1810
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1811
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1812
      '#type' => 'textfield',
1813
      '#title' => t('Maximum number of rows') . ':',
1814
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1815
      '#description' => t('You can group the thumbnails in rows, select in how
1816
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1817
        If you want an unlimited number of rows please set to 0.'),
1818
    );
1819
  }
1820

    
1821
  return $form;
1822
}
1823

    
1824
/**
1825
 * @todo document this function.
1826
 */
1827
function cdm_settings_layout_taxon() {
1828
  $collapsed = FALSE;
1829
  $form = array();
1830

    
1831
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1832

    
1833
  // --------- TABBED TAXON ------- //
1834
  $form['taxon_tabs'] = array(
1835
    '#type' => 'fieldset',
1836
    '#title' => t('Taxon tabs'),
1837
    '#collapsible' => TRUE,
1838
    '#collapsed' => TRUE,
1839
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1840
      be splitted in four diferent tabs; General, Synonymy, Images and
1841
      Specimens. If the taxon has no information for any of the tabs/sections
1842
      such tab will be not displayed.'),
1843
  );
1844

    
1845
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1846
    '#type' => 'checkbox',
1847
    '#title' => t('Tabbed taxon page'),
1848
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1849
    '#description' => t('<p>If selected split the taxon page into individual
1850
      tabs for description, images, synonymy and specimens. If not the taxon
1851
      data is rendered as a long single page without tabs.</p>'),
1852
  );
1853

    
1854
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1855
    '#type' => 'checkboxes',
1856
    '#title' => t('Tabs visibility options') . ':',
1857
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1858
    '#options' => get_taxon_options_list(),
1859
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1860
  );
1861

    
1862
  // WEIGHT
1863
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1864
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1865
    '#title'  => 'Tabs order',
1866
    '#type' => 'fieldset',
1867
    '#collapsible' => false,
1868
    '#tree' => true,
1869
    '#description' => 'The weight value defines the order of the tabs or of the respective content block on the 
1870
        taxon page when it is the tabless mode.'
1871
  );
1872
  // Weights range from -delta to +delta, so delta should be at least half
1873
  // of the amount of tabs present.
1874
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1875
  foreach (get_taxon_tabs_list() as $label) {
1876
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1877
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1878
        '#title' => $label,
1879
        '#type'  => 'weight',
1880
        '#default_value' => $taxon_tabs_weights[$key],
1881
        '#delta' => $tab_weight_delta
1882
    );
1883
  }
1884

    
1885
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1886
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1887
    '#title'  => 'Tab label override',
1888
    '#type' => 'fieldset',
1889
    '#collapsible' => false,
1890
    '#tree' => true,
1891
    '#description' => 'Setting a label for a tab will override the default label. 
1892
      Please enter the label text in the default language of the portal.'
1893
  );
1894
  foreach (get_taxon_tabs_list() as $label) {
1895
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1896
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1897
      '#title' => $label,
1898
      '#type'  => 'textfield',
1899
      '#default_value' => $taxon_tabs_labels[$key]
1900
    );
1901
  }
1902

    
1903
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1904
    '#type' => 'select',
1905
    '#title' => t('Default tab to display') . ':',
1906
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1907
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1908
    '#description' => t('<p>Select the default tab to display when visiting a
1909
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1910
      <strong>Note:</strong> After performing a search and clicking in any
1911
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1912
      taxon and not the above selected tab.'),
1913
  );
1914

    
1915
  /* ======  TAXON_PROFILE ====== */
1916
  $form['taxon_profile'] = array(
1917
    '#type' => 'fieldset',
1918
    '#title' => t('Taxon profile (tab)'),
1919
    '#description' => t('<p>This section covers the settings related to the taxon
1920
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1921
    '#collapsible' => TRUE,
1922
    '#collapsed' => TRUE,
1923
  );
1924

    
1925
  // ---- PROFILE PICTURE ----//
1926

    
1927
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1928
    '#type' => 'fieldset',
1929
    '#tree' => TRUE,
1930
    '#title' => t('Taxon profile picture'),
1931
    '#collapsible' => TRUE,
1932
    '#collapsed' => FALSE,
1933
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1934
  );
1935

    
1936
  //FIXME migrate variables:
1937
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1938
  // FIXME
1939
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1940

    
1941
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1942

    
1943
  /*
1944
   * 'show' => 1,
1945
   * 'maxextend' => 184,
1946
   * 'media_uri_query' => ''
1947
   * 'custom_placeholder_image_on' => 1,
1948
   * 'custom_placeholder_image_fid' => ''
1949
   */
1950
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1951
    '#type' => 'checkbox',
1952
    '#title' => t('Enable profile picture'),
1953
    '#description' => t('Show the profile picture.'),
1954
    '#default_value' => $taxon_profile_image_settings['show'],
1955
  );
1956

    
1957
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1958
      '#type' => 'textfield',
1959
      '#tree' => TRUE,
1960
      '#title' => t('Profile picture maximum extend'),
1961
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1962
      '#field_suffix' => 'px',
1963
      '#maxlength' => 4,
1964
      '#size' => 4,
1965
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
1966
  );
1967

    
1968
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1969
      '#type' => 'textfield',
1970
      '#tree' => TRUE,
1971
      '#title' => t('Additional URI query parameter'),
1972
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1973
      '#maxlength' => 1024,
1974
      '#size' => 60,
1975
      '#description' => t('Additional query parameters to be used when requesting for the  
1976
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
1977
            The query parameters will be appended to the uri of the media representation part
1978
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1979
  );
1980

    
1981
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1982
    '#type' => 'checkbox',
1983
    '#title' => t('Show the placeholder image'),
1984
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
1985
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1986
  );
1987

    
1988
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1989
      '#type' => 'checkbox',
1990
      '#title' => t('Use a custom placeholder image'),
1991
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1992
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1993
  );
1994

    
1995
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1996
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1997
        '#type' => 'managed_file',
1998
        '#title' => t('Custom placeholder image file'),
1999
        '#progress_indicator' => 'bar',
2000
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2001
    //       '#name' => 'custom_placeholder_image',
2002
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2003
    );
2004

    
2005
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2006
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2007
      $url = file_create_url($profile_image_file->uri);
2008
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2009
                '#type' => 'item',
2010
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2011
      );
2012
    }
2013
  } else {
2014
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2015
      '#type' => 'hidden',
2016
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2017
    );
2018
  }
2019

    
2020
  $options = cdm_rankVocabulary_as_option();
2021
  array_unshift($options, '-- DISABLED --');
2022
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2023
    '#type' => 'select',
2024
    '#title' => t('Hide profile picture for higher ranks') . ':',
2025
    '#default_value' => variable_get('image_hide_rank', '0'),
2026
    '#options' => $options,
2027
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2028
  );
2029

    
2030
  // -- MEDIA THUMBNAILS -- //
2031
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2032
  $form_title = 'Taxon Profile Images';
2033
  $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>';
2034
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2035

    
2036
  // ---- FEATURE TREE BLOCKS ---- //
2037
  $form['taxon_profile']['feature_blocks'] = array(
2038
    '#type' => 'fieldset',
2039
    '#title' => t('Feature Blocks'),
2040
    '#collapsible' => TRUE,
2041
    '#collapsed' => FALSE,
2042
    '#description' => t("This section covers settings related to the taxon's
2043
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2044
      features such as description, distribution, common names"),
2045
  );
2046
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2047
  $profile_feature_tree = get_profile_feature_tree();
2048
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2049
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2050
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2051
  }
2052
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2053
    '#type' => 'radios',
2054
    '#title' => t('Taxon profile feature tree') . ':',
2055
    '#default_value' => $profile_feature_tree_uuid,
2056
    '#options' =>  $featureTrees['options'],
2057
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2058
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2059
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
2060
      profile page.'
2061
    ),
2062
  );
2063

    
2064
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2065
  $profile_feature_tree = get_profile_feature_tree();
2066

    
2067
  if (isset($profile_feature_tree->root->childNodes)) {
2068

    
2069
    $form_feature_block_layout = array(
2070
      '#type' => 'fieldset',
2071
      '#tree' => true,
2072
      '#title' => t('Taxon profile feature block settings'),
2073
      '#collapsible' => TRUE,
2074
      '#collapsed' => FALSE,
2075
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2076
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
2077
      The subforms have the following settings in common:<br />
2078
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2079
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2080
      <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>
2081
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2082
            <ol>
2083
            <li>If element is of the CDM type TextData and the text is not empty the source references will be
2084
                appended in brackets like "text (source references)". If the original source has name in source
2085
                information it will be appended to the citation string,
2086
                like : "(citation, as name in source; citation, as name in source)"</li>
2087
             <li>if the text of the TextData is empty, the original source citations are the only content
2088
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2089
                prepended to the citation string like: "name in source: citation"</li>
2090
            </ol>
2091
            <strong>If disabled:</strong><br />
2092
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2093
             citations are the only content, the resulting feature block content would only consist of footnotes.
2094
             In this case the display of the respective feature block is suppressed.</div>
2095
      </dl>
2096
      <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
2097
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2098
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2099
        . '</em></div>
2100
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2101
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2102
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2103
      <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>
2104
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2105
           cdm_feature_block_element_tag_name()</div>',
2106
    );
2107

    
2108

    
2109
    $feature_list_layout_settings_disabled = FALSE;
2110

    
2111
    // creating helper object to retrieve the default settings
2112
    $featureNode = new stdClass();
2113
    $featureNode->feature = new stdClass();
2114
    $featureNode->feature->uuid="DEFAULT";
2115
    $featureNode->feature->representation_L10n = "Default";
2116
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2117

    
2118
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2119

    
2120
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2121

    
2122
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2123
        $subform_id = $featureNode->feature->uuid;
2124
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2125

    
2126
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2127

    
2128
        $form_feature_block_layout[$subform_id] = array(
2129
          '#type' => 'fieldset',
2130
          '#tree' => TRUE,
2131
          '#title' => $featureNode->feature->representation_L10n,
2132
          '#collapsible' => FALSE,
2133
          '#collapsed' => FALSE,
2134
        );
2135
        if($featureNode->feature->uuid == "DEFAULT"){
2136
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2137
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2138
          references</em> and <em>names in source</em> is only possible in the defaults';
2139
        }
2140

    
2141
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2142
          '#type' => 'select',
2143
          '#title' => 'List type',
2144
          '#default_value' => $feature_block_setting['as_list'],
2145
          '#options' => array(
2146
            'div' => 'not as list',
2147
            'ul' => 'bullet list',
2148
            'ol' => 'numbered list',
2149
            'dl' => 'definition list'
2150
          ),
2151
        );
2152

    
2153
        if($featureNode->feature->uuid == "DEFAULT"){
2154
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2155
            '#type' => 'checkbox',
2156
            '#title' => t('Link to reference'),
2157
            '#default_value' => $feature_block_setting['link_to_reference'],
2158
          );
2159

    
2160
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2161
            '#type' => 'checkbox',
2162
            '#title' => 'Link to name used in source',
2163
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2164
          );
2165
        }
2166

    
2167
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2168
          '#type' => 'checkbox',
2169
          '#title' => 'Sources as content',
2170
          '#default_value' => $feature_block_setting['sources_as_content'],
2171
        );
2172

    
2173
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2174
          '#type' => 'checkbox',
2175
          '#title' => 'Put sources also as content to bibliography',
2176
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2177
        );
2178

    
2179
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2180
          '#type' => 'select',
2181
          '#title' => t('Sort elements'),
2182
          '#default_value' => $feature_block_setting['sort_elements'],
2183
          '#options' => array(
2184
            NO_SORT => 'No sorting',
2185
            SORT_ASC => 'Ascending',
2186
            SORT_DESC => 'Descending',
2187
            SORT_HIERARCHICAL => 'Hierarchical'
2188
          ),
2189
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2190
          <dl>
2191
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2192
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2193
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2194
          <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>
2195
          </dl>',
2196
        );
2197

    
2198
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2199
          '#type' => 'select',
2200
          '#title' => t('Element tag'),
2201
          '#options' => array(
2202
            'span' => 'span',
2203
            'div' => 'div'
2204
          ),
2205
          '#default_value' => $feature_block_setting['element_tag'],
2206
        );
2207
      }
2208
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2209
    }
2210
  }
2211

    
2212
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2213
  $form['taxon_profile']['structured_description_featuretree'] = array(
2214
    '#type' => 'fieldset',
2215
    '#title' => t('Structured Description Feature Tree'),
2216
    '#collapsible' => TRUE,
2217
    '#collapsed' => FALSE,
2218
  );
2219
  $featureTrees = cdm_get_featureTrees_as_options();
2220
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2221
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2222
    $profile_feature_tree_uuid = NULL;
2223
  }
2224
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2225
    '#type' => 'radios',
2226
    '#title' => t('Natural language representation of structured descriptions') . ':',
2227
    '#default_value' => $profile_feature_tree_uuid,
2228
    '#options' => $featureTrees['options'],
2229
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2230
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2231
    '#description' => t('Taxon descriptions can be stored in a highly structured
2232
      form. The feature tree selected here will be used to generate textual
2233
      representation in natural language.'
2234
    ),
2235
  );
2236

    
2237

    
2238

    
2239
  // ---- DISTRIBUTION LAYOUT ---- //
2240
  $form['taxon_profile']['distribution_layout'] = array(
2241
    '#title' => t('Distribution'),
2242
    '#collapsible' => TRUE,
2243
    '#collapsed' => FALSE,
2244
    '#type' => 'fieldset',
2245
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2246
        Map settings regarding the geometry, layers, etc are found in the '
2247
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2248
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2249
      . l(
2250
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2251
        array('fragment' => 'edit-feature-block-settings')
2252
      )
2253
      . ' More general settings regrading the filtering of Distributions are found at '
2254
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2255
      . '. (These settings here will be merged in future releases into the feature block settings)',
2256

    
2257
  );
2258

    
2259
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2260

    
2261
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2262
    '#type' => 'checkbox',
2263
    '#title' => t('Condensed distribution'),
2264
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2265
    '#description' => 'This option enables the display of a very compact representation
2266
    of the distribution which includes also information on the status.',
2267
  );
2268

    
2269
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2270
    '#type' => 'select',
2271
    '#title' => t('Condensed distribution recipe'),
2272
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2273
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2274
    '#description' => 'Recipe for creating the condensed distribution.',
2275
  );
2276

    
2277
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2278
    '#type' => 'textfield',
2279
    '#title' => t('Condensed distribution info path'),
2280
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2281
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2282
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2283
  );
2284

    
2285

    
2286
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2287
    '#type' => 'radios',
2288
    '#title' => t('Display mode') . ':',
2289
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2290
    '#options' => array(
2291
      'FLAT_ALPHA' => t('Flat list'),
2292
      'TREE' => t('Hierarchically ordered'),
2293
    ),
2294
    '#description' => 'Taxon distribution information is displayed with
2295
    focus on the area of the distribution. The list of areas can either be shown
2296
    as flat list ordered alphabetically or in the hierarchical of the parent
2297
    area and subarea relationship. Fall back areas areas with no Distribution data
2298
    are hidden from the area hierarchy so that their sub areas will move one level up.
2299
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2300
    ' for details on the <em>Marked area filter</em>.',
2301
  );
2302

    
2303
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2304
    '#type' => 'fieldset',
2305
    '#tree' => true,
2306
    '#title' => t('Distribution hierarchy style')
2307
  );
2308

    
2309
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2310
  foreach(array_keys($hierarchy_styles) as $level) {
2311
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2312
      '#type' => 'fieldset',
2313
      '#tree' => true,
2314
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2315
      '#attributes' => array('class' => array('fieldset-float'))
2316
    );
2317
    foreach ($hierarchy_styles[$level] as $key => $value) {
2318
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2319
        '#type' => 'textfield',
2320
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2321
        '#default_value' => $hierarchy_styles[$level][$key],
2322
        '#maxlength' => 4,
2323
        '#size' => 4
2324
      );
2325
    }
2326
  }
2327

    
2328
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2329
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2330
    '#type' => 'checkboxes',
2331
    '#title' => 'Omit area levels',
2332
    '#options' => $level_options,
2333
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2334
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2335
    Areas which belong to the selected area levels will be hidden in the portal.',
2336
  );
2337

    
2338
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2339
    '#type' => 'checkbox',
2340
    '#title' => t('Show TextData elements on top of the map'),
2341
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2342
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2343
      elements on top of the map. Otherwise all <code>TextData</code>
2344
      distribution elements will be listed below the other area elements.
2345
      This option is useful if you need to have descriptive texts for each
2346
      distribution map.'),
2347
  );
2348

    
2349
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2350
      '#type' => 'textarea',
2351
      '#title' => t('Custom status colors'),
2352
      '#element_validate' => array('form_element_validate_json'),
2353
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2354
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2355
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2356
          reference list of the idInVocabulary values of absence and presence terms:
2357
<pre>
2358
Presence Term
2359
p	present
2360
pd	present: doubtfully present
2361
n	native
2362
nq	native: presence questionable
2363
nd	native: doubtfully native
2364
c	cultivated
2365
i	introduced
2366
iq	introduced: presence questionable
2367
id	introduced: doubtfully introduced (perhaps cultivated only)
2368
ip	introduced: uncertain degree of naturalisation
2369
ia	introduced: adventitious (casual)
2370
in	introduced: naturalized
2371
ic	introduced: cultivated
2372
e	endemic for the relevant area
2373
na	naturalised
2374
iv	invasive
2375

    
2376
AbsenceTerm
2377
a	absent
2378
f	reported in error
2379
nf	native: reported in error
2380
if	introduced: reported in error
2381
cf	cultivated: reported in error
2382
ne	native: formerly native
2383
ie	introduced: formerly introduced
2384

    
2385
</pre>'),
2386
  );
2387

    
2388

    
2389
  /* ====== SYNONYMY ====== */
2390
  $form['taxon_synonymy'] = array(
2391
    '#type' => 'fieldset',
2392
    '#title' => t('Taxon synonymy (tab)'),
2393
    '#collapsible' => TRUE,
2394
    '#collapsed' => TRUE,
2395
    '#description' => t('This section covers the settings related to the taxon
2396
      <strong>synonymy</strong> tab.'),
2397
  );
2398

    
2399
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2400
    '#type' => 'checkbox',
2401
    '#title' => t('Show accepted taxon on top of the synonymy'),
2402
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2403
    '#description' => t('If checked, the first homotypic taxon is a repetition
2404
      of the accepted taxon most likely with the full nomenclatural reference
2405
      (depending on the currently chosen theme).'),
2406
  );
2407

    
2408
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2409
    '#type' => 'checkbox',
2410
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2411
      coming from a synonym link.'),
2412
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2413
    '#description' => t('Check this if after doing a search and clicking on a
2414
      synonym you want to see the "accept of" text for the accepted synonym.'),
2415
  );
2416

    
2417
  /* === currently unused ===
2418
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2419
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2420
    '#type' => 'checkboxes',
2421
    '#title' => t('Display name relationships') . ':',
2422
    '#default_value' => variable_get('name_relationships_to_show', 0),
2423
    '#options' => $nameRelationshipTypeOptions,
2424
    '#description' => t('Select the name relationships you want to show for the
2425
      accepted taxa.'),
2426
  );
2427
 */
2428

    
2429
  $form['taxon_synonymy']['taxon_relations'] = array(
2430
    '#type' => 'fieldset',
2431
    '#title' => t('Taxon relationships'),
2432
    '#collapsible' => FALSE,
2433
    '#collapsed' => FALSE
2434
  );
2435

    
2436
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2437
    '#type' => 'checkbox',
2438
    '#title' => t('Show taxon relations ships of accepted taxon'),
2439
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2440
    '#description' => t('If this option is enabled the synonymy will show the
2441
      below selected taxon relationships of accepted taxa.'),
2442
  );
2443

    
2444
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2445
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2446
    '#type' => 'checkboxes',
2447
    '#title' => t('Taxon relationship types') . ':',
2448
    '#description' => t('Only taxon relationships of the selected type will be
2449
      displayed'),
2450
    '#options' => $taxonRelationshipTypeOptions,
2451
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2452
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2453
  );
2454

    
2455
  $form['taxon_synonymy']['name_relations'] = array(
2456
    '#type' => 'fieldset',
2457
    '#title' => t('Name relationships'),
2458
    '#collapsible' => FALSE,
2459
    '#collapsed' => FALSE
2460
  );
2461

    
2462
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2463
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2464
    '#type' => 'checkboxes',
2465
    '#title' => t('Name relationship types') . ':',
2466
    '#description' => t('Only name relationships of the selected type will be
2467
      displayed'),
2468
    '#options' => $taxonRelationshipTypeOptions,
2469
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2470
  );
2471

    
2472
  // ====== SPECIMENS ====== //
2473
  $form['taxon_specimens'] = array(
2474
    '#type' => 'fieldset',
2475
    '#title' => t('Taxon specimens (tab)'),
2476
    '#collapsible' => TRUE,
2477
    '#collapsed' => TRUE,
2478
    '#description' => t('This section covers the settings related to the taxon
2479
      <strong>specimens</strong> tab.'),
2480
  );
2481

    
2482
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2483

    
2484
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2485
    '#type' => 'checkbox',
2486
    '#title' => t('Show specimen derivatives in a compressed table'),
2487
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2488
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2489
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2490
  );
2491

    
2492
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2493
        '#type' => 'textfield',
2494
        '#title' => t('Number of records per page') . ':',
2495
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2496
    );
2497

    
2498
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2499
    '#type' => 'checkbox',
2500
    '#title' => t('Show "Associated with" in specimen table.'),
2501
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2502
  );
2503

    
2504
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2505
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2506
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2507
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2508
  }
2509
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2510
    '#type' => 'radios',
2511
    '#title' => t('Specimen description feature tree') . ':',
2512
    '#default_value' => $profile_feature_tree_uuid,
2513
    '#options' =>  $featureTrees['options'],
2514
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2515
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2516
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2517
    ),
2518
  );
2519

    
2520
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2521
  $form_title = t('Specimen media');
2522
  $form_description = t('Specimens may have media which is displayed at the
2523
     Specimen tab/section as a gallery. It is possible to configure the
2524
     thumbnails gallery here, however for configuring how a single media should
2525
     be displayed please go to !url.</p>',
2526
     array(
2527
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2528
     ));
2529
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2530

    
2531
  // --- MEDIA GALLERY ---- //
2532
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2533
  $form_title = 'Media gallery (tab)';
2534
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2535
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2536
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2537
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2538
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2539
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2540
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2541

    
2542
  // Comment @WA: D7 form api does not support reset buttons,
2543
  // so to mimic the D5 reset button we add one like this.
2544
  $form['actions']['reset'] = array(
2545
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2546
    '#weight' => 1000,
2547
  );
2548
  return system_settings_form($form);
2549
}
2550

    
2551
/**
2552
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2553
 *
2554
 * @param $map_id
2555
 * @param $form
2556
 * @return mixed
2557
 */
2558
function _cdm_map_visibility_setting($map_id)
2559
{
2560
  return array(
2561
    '#type' => 'select',
2562
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2563
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2564
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2565
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2566
        The map also can forced to show up <b>always</b> or <b>never</b>."
2567
  );
2568
}
2569

    
2570
/**
2571
 * @todo document this function.
2572
 */
2573
function cdm_settings_layout_search() {
2574

    
2575
  $form = array();
2576

    
2577
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2578

    
2579
  $form['search_settings'] = array(
2580
    '#type' => 'fieldset',
2581
    '#title' => t('Taxa Search'),
2582
    '#collapsible' => FALSE,
2583
    '#collapsed' => FALSE,
2584
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2585
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2586
         where they can write the text to be searched. You can find Drupal block configuration
2587
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2588
  );
2589

    
2590
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2591
      '#type' => 'checkbox',
2592
      '#title' => t('Ignore the chosen classification in simple search'),
2593
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2594
      '#description' => t('The simple search, which can be executed via the search block,
2595
          will by default search on the classification selected in the classification browser
2596
          selector. Set the tick if you want your portal to search on all classifications.'),
2597
  );
2598

    
2599
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2600
    '#type' => 'checkbox',
2601
    '#title' => t('Run simple search with free-text search backend.'),
2602
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2603
    '#description' => t('The simple search uses by default another search
2604
      backend as the advances search. By checking this option the simple search can be
2605
      configured to also use the free-text search backend.'),
2606
  );
2607

    
2608
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2609
    '#type' => 'textfield',
2610
    '#title' => t('Results per page') . ':',
2611
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2612
    '#description' => t('Number of results to display per page.'),
2613
  );
2614

    
2615
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2616
    '#type' => 'checkbox',
2617
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2618
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2619
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2620
  );
2621

    
2622
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2623
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2624
      '#type' => 'checkboxes',
2625
      '#title' => 'Search mode',
2626
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2627
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2628
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2629
          defaults set here.',
2630
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2631
      '#default_value' => $search_mode_default
2632
      );
2633

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

    
2639
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2640
  );
2641

    
2642
  // --- SEARCH TAXA GALLERY ---- //
2643
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2644
  $collapsed = FALSE;
2645
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2646
  $form_title = 'Taxa Search thumbnails';
2647
  $form_description = 'Search results may show thumbnails. ';
2648
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2649

    
2650
  // Comment @WA: D7 form api does not support reset buttons,
2651
  // so to mimic the D5 reset button we add one like this.
2652
  $form['actions']['reset'] = array(
2653
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2654
    '#weight' => 1000,
2655
  );
2656
  return system_settings_form($form);
2657
}
2658

    
2659
/**
2660
 * @todo document this function.
2661
 */
2662
function cdm_settings_layout_media() {
2663

    
2664
  $form = array();
2665

    
2666
  $form['media_settings'] = array(
2667
    '#type' => 'fieldset',
2668
    '#title' => t('Media settings'),
2669
    '#collapsible' => FALSE,
2670
    '#collapsed' => FALSE,
2671
    '#description' => 'This section covers layout settings for media pages.'
2672
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2673
  );
2674

    
2675
  $form['media_settings']['image_gallery_viewer'] = array(
2676
    '#type' => 'select',
2677
    '#title' => t('Image viewer') . ':',
2678
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2679
    '#options' => array(
2680
      'default' => t('Standard image viewer'),
2681
      'fsi' => t('FSI viewer (requires FSI server!)'),
2682
    ),
2683
  );
2684

    
2685
  // --- MEDIA GALLERY ---- //
2686
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2687
  $form_title = 'Standard viewer';
2688
  $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>';
2689
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2690
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2691

    
2692
  // @WA: D7 form api does not support reset buttons,
2693
  // so to mimic the D5 reset button we add one like this.
2694
  $form['actions']['reset'] = array(
2695
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2696
    '#weight' => 1000,
2697
  );
2698
  return system_settings_form($form);
2699
}
2700

    
2701
/**
2702
 * GEOSERVICE and Map settings.
2703
 */
2704
function cdm_settings_geo($form, &$form_state) {
2705

    
2706
  $current_geoserver_settings = get_edit_map_service_settings();
2707
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2708

    
2709

    
2710
  $form = array();
2711

    
2712
  $dummy_distribution_query = NULL;
2713
  if($map_distribution['map_type'] != 1){
2714
    // we need to apply a dummy query since the map service requires for image maps
2715
    // at least as and ad to be defined
2716
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2717
  }
2718

    
2719
  $form['map_preview'] = array(
2720
      '#type' => 'fieldset',
2721
      '#tree' => FALSE,
2722
      '#title' => t('Map preview'),
2723
      '#collapsible' => FALSE,
2724
      '#description' => 'The preview of the map'
2725
       . ($dummy_distribution_query != null ?
2726
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2727
           '.<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.')
2728
  );
2729
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2730
    'move' => "this.cdmOpenlayersMap.printInfo",
2731
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2732
  ), true // resizable
2733
  );
2734

    
2735
  /*
2736
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2737
  );
2738
  */
2739

    
2740
  /*
2741
   * GEO SERVER
2742
   */
2743
  $form['edit_map_server'] = array(
2744
    '#type' => 'fieldset',
2745
    '#tree' => true,
2746
    '#title' => t('EDIT map service'),
2747
    '#collapsible' => TRUE,
2748
    '#collapsed' => TRUE,
2749
    '#description' => t('Configuration and selection of your geo server.
2750
      The Geo Server is responsible for generating the maps.'),
2751
  );
2752

    
2753
  $form['edit_map_server']['base_uri'] = array(
2754
    '#type' => 'select',
2755
    '#title' => t('EDIT map service') . ':',
2756
    '#default_value' => $current_geoserver_settings['base_uri'],
2757
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2758
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2759
  );
2760
  $form['edit_map_server']['version'] = array(
2761
      '#type' => 'select',
2762
      '#title' => t('Version') . ':',
2763
      '#default_value' => $current_geoserver_settings['version'],
2764
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2765
      '#description' => t('The version of the EDIT map services'),
2766
  );
2767

    
2768
  /*
2769
   * MAP SETTINGS
2770
   */
2771

    
2772
  $form[CDM_MAP_DISTRIBUTION] = array(
2773
    '#type' => 'fieldset',
2774
    '#tree' => TRUE,
2775
    '#title' => t('Maps settings'),
2776
    '#collapsible' => TRUE,
2777
    '#collapsed' => TRUE,
2778
    '#description' => t('General configuration for all map types.'),
2779
  );
2780

    
2781
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2782
    '#type' => 'radios',
2783
    '#title' => 'Map types',
2784
    '#options' => array(
2785
      1 => "OpenLayers dynamic map viewer",
2786
      0 => "Plain image",
2787
    ),
2788
    '#default_value' => $map_distribution['map_type'],
2789
    '#description' => 'Two different map types are available :
2790
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2791
      which allows zooming and panning. If enabled you can configure the default layer
2792
      (background of your maps) below.</li>
2793
      <li><em>Plain image</em>: The map will be static non interactive
2794
      image.</li></ul>',
2795
  );
2796
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2797

    
2798
  /*
2799
   * settings for the distribution map are used also for specimens map!!!!
2800
   */
2801

    
2802
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2803
      '#type' => 'textfield',
2804
      '#title' => 'Aspect ratio',
2805
      '#default_value' => $map_distribution['aspect_ratio'],
2806
      '#maxlength' => 4,
2807
      '#size' => 4,
2808
      '#element_validate' => array('element_validate_number'),
2809
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2810
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2811
      width by the height:</br>
2812
      <pre>aspect ratio = w / h</pre>
2813
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2814
      for a square map use <strong>1</strong>.',
2815
  );
2816

    
2817
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2818
    '#type' => 'textfield',
2819
    '#title' => 'Bounding box',
2820
    '#default_value' => $map_distribution['bbox'],
2821
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2822
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2823
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2824
      <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.
2825
      (Maybe you need to change the map base layer to OpeLayers.)
2826
      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
2827
      below the map from where you can copy the bbox string.</p>'),
2828
  );
2829

    
2830
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2831
    '#type' => 'checkbox',
2832
    '#title' => 'Display area labels',
2833
    '#default_value' => $map_distribution['show_labels'],
2834
    '#description' => t('The map will show name labels of the areas'),
2835
  );
2836

    
2837
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2838
    '#type' => 'textfield',
2839
    '#title' => 'Map caption',
2840
    '#default_value' => $map_distribution['caption'],
2841
    '#description' => t('The caption will be shown below the map.'),
2842
  );
2843

    
2844
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2845
    '#type' => 'textfield',
2846
    '#title' => 'Distribution layer opacity',
2847
    '#default_value' => $map_distribution['distribution_opacity'],
2848
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2849
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2850
  );
2851

    
2852
  // --- Plain Image Settings --- //
2853
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2854
    '#type' => 'fieldset',
2855
    '#title' => 'Plain image map settings',
2856
    '#tree' => TRUE,
2857
    '#collapsible' => TRUE,
2858
    '#collapsed' => $open_layers_is_enabled,
2859
    '#description' => 'The settings in this section are still expertimental
2860
      and can only be used with the EDIT map service version 1.1 or above.',
2861
  );
2862
  $edit_mapserver_version = get_edit_map_service_version_number();
2863
  if ($edit_mapserver_version < 1.1) {
2864
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2865
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2866
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2867
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2868
  }
2869

    
2870
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2871
    '#type' => 'textfield',
2872
    '#title' => 'Width',
2873
    '#default_value' => $map_distribution['image_map']['width'],
2874
    '#maxlength' => 4,
2875
    '#size' => 4,
2876
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2877
  );
2878

    
2879
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2880
    '#type' => 'textfield',
2881
    '#title' => 'Background layer',
2882
    '#default_value' => $map_distribution['image_map']['base_layer'],
2883
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2884
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2885
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2886
    )),
2887
  );
2888

    
2889
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2890
    '#type' => 'textfield',
2891
    '#title' => 'Background color',
2892
    '#default_value' => $map_distribution['image_map']['bg_color'],
2893
  );
2894

    
2895
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2896
    '#type' => 'textfield',
2897
    '#title' => 'Background layer style',
2898
     // Only line color by now.
2899
    '#default_value' => $map_distribution['image_map']['layer_style'],
2900
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2901
  );
2902

    
2903
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2904
      '#type' => 'textfield',
2905
      '#title' => 'Projection',
2906
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2907
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2908
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2909
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2910
  );
2911

    
2912

    
2913
  // --- OpenLayers Settings --- //
2914
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2915
    '#type' => 'fieldset',
2916
    '#title' => 'OpenLayers settings',
2917
    '#tree' => TRUE,
2918
    '#collapsible' => TRUE,
2919
    '#collapsed' => !$open_layers_is_enabled,
2920
    '#description' => '',
2921
  );
2922

    
2923

    
2924
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2925
      '#type' => 'checkbox',
2926
      '#title' => 'Display outside max extent',
2927
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2928
      '#description' => t('Allows the map to display parts of the layers which are outside
2929
         the max extent if the aspect ratio of the map and of the baselayer
2930
         are not equal.'),
2931
  );
2932

    
2933

    
2934
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2935
      '#type' => 'checkbox',
2936
      '#title' => 'Show Layer Switcher',
2937
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2938
      '#description' => 'The Layer Switcher control displays a table of contents
2939
      for the map.  This allows the user interface to switch between
2940
      base layers and to show or hide overlays.  By default the switcher is
2941
      shown minimized on the right edge of the map, the user may expand it
2942
      by clicking on the handle.',
2943
  );
2944

    
2945
  if (!$open_layers_is_enabled) {
2946
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2947
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2948
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2949
  }
2950

    
2951
  // The default layer must always be enabled
2952
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2953
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2954

    
2955
  $baselayer_options = array(
2956
    /*
2957
   NOTICE: must correspond to the layers defined in
2958
   js/openlayers_,ap.js#getLayersByName()
2959
   */
2960
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
2961
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
2962
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
2963
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
2964
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2965
    // all others EPSG:900913
2966
    'mapnik' => 'OpenStreetMap',
2967
    'mapquest_open' => "MapQuest",
2968
    'mapquest_sat' => "MapQuest Sattelite",
2969
    'groadmap' => 'Google Roadmap',
2970
    'gsatellite' => 'Google Satellite',
2971
    'ghybrid' => 'Google Hybrid',
2972
    'gterrain' => 'Google Terrain',
2973
//     'veroad' => 'Virtual Earth Roads',
2974
//     'veaer' => 'Virtual Earth Aerial',
2975
//     'vehyb' => 'Virtual Earth Hybrid',
2976
    // 'yahoo' => 'Yahoo Street',
2977
    // 'yahoosat' => 'Yahoo Satellite',
2978
    // 'yahoohyb' => 'Yahoo Hybrid',
2979
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2980
  );
2981

    
2982
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2983
    '#type' => 'checkboxes_preferred',
2984
    '#title' => 'Base Layers',
2985
    '#options' => $baselayer_options,
2986
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2987
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2988
  );
2989

    
2990
  $google_maps_api_key = null;
2991
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
2992
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
2993
  }
2994
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
2995
    '#type' => 'textfield',
2996
    '#title' => 'Google Maps API Key',
2997
    '#default_value' => $google_maps_api_key,
2998
    '#description' => 'In order to use any of the Google map layers you need to provide 
2999
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3000
  );
3001

    
3002
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
3003
      '#type' => 'fieldset',
3004
      '#title' => 'Custom WMS base layer',
3005
      '#tree' => TRUE,
3006
      '#collapsible' => FALSE,
3007
      '#collapsed' => FALSE,
3008
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
3009
  );
3010

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

    
3107
  /*
3108
   * Map Legend
3109
   */
3110
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3111
    '#type' => 'fieldset',
3112
    '#title' => 'Map legend',
3113
    '#tree' => TRUE,
3114
    '#collapsible' => TRUE,
3115
    '#collapsed' => TRUE,
3116
    '#description' => 'Configure the maps legend.',
3117
  );
3118

    
3119
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3120
    '#type' => 'checkbox',
3121
    '#title' => 'Display a map legend',
3122
    '#default_value' => $map_distribution['legend']['show'],
3123
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3124
  );
3125

    
3126
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3127
    '#type' => 'textfield',
3128
    '#title' => 'Legend opacity',
3129
    '#default_value' => $map_distribution['legend']['opacity'],
3130
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3131
                         to 0.0 will be not much visible.',
3132
  );
3133

    
3134
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3135
    '#type' => 'textfield',
3136
    '#title' => 'Font size',
3137
    '#default_value' => $map_distribution['legend']['font_size'],
3138
    '#description' => 'Font size in pixels.',
3139
  );
3140

    
3141
  $fontStyles = array(
3142
    0 => "plane",
3143
    1 => "italic",
3144
  );
3145
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3146
    '#type' => 'select',
3147
    '#title' => 'Available font styles',
3148
    '#default_value' => $map_distribution['legend']['font_style'],
3149
    '#options' => $fontStyles,
3150
    '#description' => 'Select a font style for the map legend.',
3151
  );
3152

    
3153
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3154
    '#type' => 'textfield',
3155
    '#title' => 'Icon width',
3156
    '#default_value' => $map_distribution['legend']['icon_width'],
3157
    '#description' => 'Legend icon width in pixels.',
3158
  );
3159
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3160
    '#type' => 'textfield',
3161
    '#title' => 'Icon height',
3162
    '#default_value' => $map_distribution['legend']['icon_height'],
3163
    '#description' => 'Legend icon height in pixels.',
3164
  );
3165

    
3166
  // @WA: D7 form api does not support reset buttons,
3167
  // so to mimic the D5 reset button we add one like this.
3168
  $form['actions']['reset'] = array(
3169
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3170
    '#weight' => 1000,
3171
  );
3172

    
3173
  return system_settings_form($form);
3174
}
3175

    
3176

    
3177
/**
3178
 * @todo document this function.
3179
 */
3180
function cdm_settings_cache() {
3181

    
3182
  $form = array();
3183

    
3184
  $form['cache_settings'] = array(
3185
    '#type' => 'fieldset',
3186
    '#title' => t('Cache Settings'),
3187
    '#collapsible' => FALSE,
3188
    '#collapsed' => FALSE,
3189
    '#description' => t('<p>When caching is enabled all single taxon sites are
3190
      stored in an internal drupal cache doing the portal response of taxa pages
3191
      faster. This is possible because the sites are loaded from the cache and
3192
      are not created from scratch.</p>'),
3193
  );
3194

    
3195
  $form['cache_settings']['cdm_webservice_cache'] = array(
3196
    '#type' => 'checkbox',
3197
    '#title' => t('<strong>Enable caching</strong>'),
3198
    '#options' => cdm_help_general_cache(),
3199
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3200
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3201
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3202
       application the changes will be not visible till the cache is erased.
3203
       Therefore developers should deactived this feature when they are working
3204
       on the CDM Dataportal Module.</p>'),
3205
  );
3206

    
3207
  $form['cache_settings']['cdm_run_cache'] = array(
3208
    '#markup' => cdm_view_cache_site(),
3209
  );
3210

    
3211
  // @WA: D7 form api does not support reset buttons,
3212
  // so to mimic the D5 reset button we add one like this.
3213
  $form['actions']['reset'] = array(
3214
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3215
    '#weight' => 1000,
3216
  );
3217
  return system_settings_form($form);
3218
}
3219

    
3220
/**
3221
 * Walk and cache all taxon pages.
3222
 */
3223
function cdm_view_cache_site() {
3224

    
3225
  $out = '';
3226

    
3227
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3228

    
3229
  $request_params = array();
3230
  $request_params['class'] = "Taxon";
3231

    
3232
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3233
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3234
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3235

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

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

    
3245
  // Comment @WA: A form within a form is not valid html and not needed here.
3246
  // Also, it would be recommended just to include this part of the form in the
3247
  // rest of the form array in cdm_settings_cache().
3248
  // $out .= '<form id="cache_site">';
3249
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3250
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3251
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3252
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3253
  // $out .= '</form>';
3254
  $out .= '</div>';
3255
  /*
3256
  foreach($taxonPager->records as $taxon){
3257
    cdm_dataportal_taxon_view($uuid);
3258
  }
3259
  */
3260
  return $out;
3261
}
3262

    
3263

    
3264
function cdm_settings_layout_taxon_submit($form, &$form_state){
3265
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3266
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3267
    if(is_object($file)){
3268
      $file->status = FILE_STATUS_PERMANENT;
3269
      file_save($file);
3270
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3271
    }
3272
  }
3273
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3274
  $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]);
3275
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3276
  if($tab_lables_modified || $tabs_enabled_modified){
3277
    // we first need to set the variable to persist the changes setting
3278
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3279
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3280
    menu_rebuild();
3281
  }
3282
}
3283

    
3284
function cdm_settings_layout_search_submit($form, &$form_state){
3285
  // the visibility of media thumbnails also affects the ui of the search results
3286
  // so reset the according session variable
3287
  //    1. in order to give the user immediate
3288
  //       feedback on potential setting changes
3289
  //    2. let refresh the default if it has changed
3290
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3291
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3292
  }
3293
}
3294

    
3295
/**
3296
 * Form validation handler for cdm_settings_general
3297
 *
3298
 * @param $form
3299
 * @param $form_state
3300
 */
3301
function cdm_settings_general_validate($form, &$form_state) {
3302

    
3303
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3304
    $form_state['values']['cdm_webservice_url'] .= '/';
3305
  }
3306

    
3307
}
3308

    
3309
/**
3310
 * Form submit handler for settings general.
3311
 *
3312
 * tasks performed:
3313
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3314
 *
3315
 * @param $form
3316
 * @param $form_state
3317
 */
3318
function cdm_settings_general_submit($form, &$form_state){
3319
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3320
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3321
  unset($_SESSION['cdm_login']);
3322
}
3323

    
3324
/**
3325
 * Form validation handler for cdm_settings_cache
3326
 */
3327
function cdm_settings_cache_validate($form, &$form_state) {
3328
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3329
    cache_clear_all(NULL, 'cache_cdm_ws');
3330
    // Better clear secref_cache since I can not be sure if the cache has not
3331
    // be used during this response.
3332
    cdm_api_secref_cache_clear();
3333
  }
3334

    
3335
}
3336

    
3337
/**
3338
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3339
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3340
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3341
 *  - version: the version, e.g.: v1.1
3342
 *
3343
 * @return array
3344
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3345
 */
3346
function get_edit_map_service_settings() {
3347

    
3348
  $settings = variable_get('edit_map_server', array(
3349
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3350
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3351
      )
3352
  );
3353

    
3354
  return $settings;
3355
}
3356

    
3357
/**
3358
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3359
 *
3360
 * @return string
3361
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3362
 */
3363
function get_edit_map_service_full_uri() {
3364
  $settings = get_edit_map_service_settings();
3365
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3366
}
3367

    
3368

    
3369
/**
3370
 * Returns the version number of the currently selected edit mapserver as a float
3371
 *
3372
 * @return float
3373
 *   The version number of the currently selected edit mapserver as a float.
3374
 *   Returns 0 on error.
3375
 */
3376
function get_edit_map_service_version_number() {
3377

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

    
3380
  $settings = get_edit_map_service_settings();
3381
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3382
  if (isset($matches[1])) {
3383
    // Convert string to float.
3384
    $version = 1 + $matches[1][0] - 1;
3385
    return $version;
3386
  }
3387
  else {
3388
    // Report error.
3389
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3390
        array(
3391
          '!version' => $settings['version'],
3392
          'warning')
3393
        )
3394
      );
3395
    return 0;
3396
  }
3397
}
3398

    
3399
/**
3400
 * Returns the array of selected items in a options array
3401
 *
3402
 * @param array $options
3403
 *   An options array as generated by a form element like checkoxes, select ...,
3404
 */
3405
function get_selection($options) {
3406
  $selection = array();
3407
  foreach ($options as $key=>$val) {
3408
    if (!empty($val)) {
3409
      $selection[] = $val;
3410
    }
3411
  }
3412
  return $selection;
3413
}
3414

    
3415

    
3416
/**
3417
 * Implements hook_element_info().
3418
 *
3419
 * Allows modules to declare their own Form API element types and specify their default values.
3420
 *
3421
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3422
 */
3423
function cdm_dataportal_element_info() {
3424
  $type['checkboxes_preferred'] = array(
3425
    '#input' => TRUE,
3426
    '#process' => array('checkboxes_preferred_expand'),
3427
    '#after_build' => array('checkboxes_preferred_after_build'),
3428
    '#theme' => array('checkboxes_preferred'),
3429
    // '#theme_wrapper' => array('form_element'),
3430
  );
3431
  return $type;
3432
}
3433

    
3434
/**
3435
 * #process callback function for the custom form element type 'checkbox_preferred'
3436
 *
3437
 *
3438
 */
3439
function checkboxes_preferred_expand($element, &$form_state, $form) {
3440

    
3441
  // First of all create checkboxes for each of the elements
3442
  $element = form_process_checkboxes($element);
3443

    
3444
  // compose the element name
3445
  $parents = array();
3446
  array_deep_copy($element['#parents'], $parents);
3447
  $parents[count($parents) -1 ] .= '_preferred';
3448
  $element_name = $parents[0];
3449
  for ($i=1; $i < count($parents); $i++){
3450
    $element_name .= '[' . $parents[$i] . ']';
3451
  }
3452

    
3453
  $children = element_children($element);
3454

    
3455
  $element['table_start'] = array(
3456
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3457
    '#weight' => -1,
3458
  );
3459

    
3460
  // prepare first part each of the table rows which contains the row label
3461
  $weight = 0;
3462
  foreach ($children as $key) {
3463
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3464
    $element[$key]['#weight'] = $weight;
3465
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3466
    $element[$key]['#suffix'] = '</td>';
3467
    unset($element[$key]['#title']);
3468
    $weight += 2;
3469
  }
3470
  $weight = 0;
3471

    
3472
  // add a radio button to each of the checkboxes, the
3473
  // check boxes have already been created at the beginning
3474
  // of this function
3475
  if (count($element['#options']) > 0) {
3476
    foreach ($element['#options'] as $key => $choice) {
3477
      if (!isset($element[$key . '_preferred'])) {
3478
        $element[$key . '_preferred'] = array(
3479
          '#type' => 'radio',
3480
          '#name' => $element_name,
3481
          '#return_value' => check_plain($key),
3482
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3483
          '#attributes' => $element['#attributes'],
3484
          '#parents' => $element['#parents'],
3485
          // '#spawned' => TRUE,
3486
          '#weight' => $weight + 1,
3487
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3488
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3489
        );
3490
      }
3491
      $weight += 2;
3492
    }
3493
  }
3494

    
3495
  // end the table
3496
  $element['table_end'] = array(
3497
    '#markup' => '</table>',
3498
    '#weight' => $weight++,
3499
  );
3500

    
3501
  return $element;
3502
}
3503

    
3504
/**
3505
 * Theme function for the custom form field 'checkboxes_preferred'.
3506
 */
3507
function theme_checkboxes_preferred($variables) {
3508
  $element = $variables['element'];
3509
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3510
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3511
  $out .= drupal_render_children($element);
3512
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3513
  $out .= '</div>';
3514
  return $out;
3515
}
3516

    
3517
/**
3518
 * Callback for checkboxes preferred for widget which will
3519
 * be called after the form or element is built. The call
3520
 * back is configured in the form element by setting it as
3521
 * #after_build parameter.
3522
 *
3523
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3524
 *
3525
 * @param $element
3526
 *   Nested array of form elements that comprise the form.
3527
 * @param $form_state
3528
 *   A keyed array containing the current state of the form.
3529
 *   This includes the current persistent storage data for the form.
3530
 *   Additional information, like the sanitized $_POST data,
3531
 *   is also accumulated here in $form_state['input']
3532
 *
3533
 * @return the modified form array
3534
 */
3535
function checkboxes_preferred_after_build($element, &$form_state) {
3536

    
3537
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3538

    
3539
  if ($_POST && count($_POST) > 0) {
3540
    // TODO use  $form_state['input'] instead of POST !!!
3541
    // First pass of form processing.
3542
    $parents = array();
3543
    array_deep_copy($element['#parents'], $parents);
3544
    $parents[count($parents) - 1] .= '_preferred';
3545
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3546
    $element['#value']['PREFERRED'] = $preferred_layer;
3547
//     $form_state[$parent_id] = $element['#value'];
3548
//     $form_state['values']['baselayers'] = $element['#value'];
3549
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3550
    $form_state_element_values = $element['#value'];
3551
  }
3552
  else {
3553
    // Second pass of form processing.
3554
    $preferred_layer = $element['#value']['PREFERRED'];
3555
  }
3556

    
3557
  // Also set the chosen value (not sure if this is good Drupal style ....).
3558
  foreach ($children = element_children($element) as $key) {
3559
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3560
      $element[$key]['#value'] = $preferred_layer;
3561
    }
3562
  }
3563
  // The default layer must always be enabled.
3564
  $element[$preferred_layer]['#value'] = $preferred_layer;
3565

    
3566
  return $element;
3567
}
3568

    
3569
function radios_prepare_options_suffix(&$elements){
3570

    
3571
  $childrenKeys = element_children($elements);
3572
  foreach($childrenKeys as $key){
3573
    if(!is_array($elements[$key]['#theme_wrappers'])){
3574
      $elements[$key]['#theme_wrappers'] = array();
3575
    }
3576
    if(isset($elements['#options_suffixes'][$key])){
3577
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3578
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3579
    }
3580
  }
3581
  return $elements;
3582

    
3583
}
3584

    
3585
/**
3586
 * TODO
3587
 * @param unknown $variables
3588
 */
3589
function theme_radio_options_suffix($variables) {
3590
  $element = $variables['element'];
3591
  if(isset($element['#options_suffix'])) {
3592
    $element['#children'] .= $element['#options_suffix'];
3593
  }
3594
  return $element['#children'];
3595
}
3596

    
3597

    
3598
/**
3599
 * Element validate callback for text field and arrays containing json.
3600
 *
3601
 * @param $element
3602
 *   The form element to validate
3603
 * @param $form_state
3604
 *   A keyed array containing the current state of the form.
3605
 * @param $form
3606
 *   Nested array of form elements that comprise the form.
3607
 */
3608
function form_element_validate_json($element, &$form_state, $form) {
3609
   if (!empty($element['#value'])) {
3610
     json_decode($element['#value']);
3611
     if(json_last_error() != JSON_ERROR_NONE){
3612
       form_error($element,
3613
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3614
         . l('JSONLint', 'http://jsonlint.com/')
3615
       );
3616
     }
3617
   }
3618
}
3619

    
3620
/**
3621
 * Form submission handler for textareas and textfields containing JSON.
3622
 *
3623
 * The contained JSON will be converted into an php array
3624
 * or object and will be stored in the variables as such.
3625
 *
3626
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3627
 *
3628
 * @param $form
3629
 *   Nested array of form elements that comprise the form.
3630
 * @param $form_state
3631
 *   A keyed array containing the current state of the form.
3632
 *
3633
 */
3634
function submit_json_as_php_array($form, &$form_state) {
3635
  if (is_array($form['#json_elements'])) {
3636
    foreach ($form['#json_elements'] as $element){
3637
      if (trim($form_state['values'][$element])) {
3638
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3639
      } else {
3640
        $form_state['values'][$element] = NULL;
3641
      }
3642
    }
3643
  }
3644
}
(16-16/16)