Project

General

Profile

Download (149 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
      // settings for pseudo feature bibliography
690
      // only hard coded here
691
      'BIBLIOGRAPHY' => array(
692
        'as_list' => 'div',
693
        'link_to_reference' => 0,
694
        'link_to_name_used_in_source' => 1,
695
        'sources_as_content' => 0,
696
        'sources_as_content_to_bibliography' => 0,
697
        'sort_elements' => NO_SORT,
698
        'glue' => '',
699
        'element_tag' => NULL
700
      )
701
    );
702

    
703
    // will be used as preset in the settings
704
    $other_themes_default = array(
705
      'DEFAULT' => array(
706
        'as_list' => 'div',
707
        'link_to_reference' => 0,
708
        'link_to_name_used_in_source' => 1,
709
        'sources_as_content' => 0,
710
        'sources_as_content_to_bibliography' => 0,
711
        'sort_elements' => NO_SORT,
712
        'glue' => '',
713
        'element_tag' => NULL
714
      ),
715
      UUID_CITATION => array(
716
        'as_list' => 'div',
717
        'link_to_reference' => 0,
718
        'link_to_name_used_in_source' => 0,
719
        'sources_as_content' => 1,
720
        'sources_as_content_to_bibliography' => 0,
721
        'sort_elements' => SORT_ASC,
722
        'glue' => '',
723
        'element_tag' => 'div'
724
      ),
725
      UUID_DISTRIBUTION => array(
726
        'as_list' => 'div', // currently ignored
727
        'link_to_reference' => 0,
728
        'link_to_name_used_in_source' => 0,
729
        'sources_as_content' => 0,
730
        'sources_as_content_to_bibliography' => 0,
731
        'sort_elements' => NO_SORT, // will cause ...
732
        'glue' => '',
733
        'element_tag' => 'div',
734
        'special' => array()
735
      ),
736
      UUID_COMMON_NAME => array(
737
        'as_list' => 'div',
738
        'link_to_reference' => 0,
739
        'link_to_name_used_in_source' => 1,
740
        'sources_as_content' => 0,
741
        'sources_as_content_to_bibliography' => 0,
742
        'sort_elements' => NO_SORT,
743
        'glue' => '',
744
        'element_tag' => 'span'
745
      ),
746
    );
747

    
748
    // ---- Special DEFAULTS for existing portals
749
    // TODO:
750
    // this can be removed once the feature block
751
    // settings have been deployed for the first time to these portals
752

    
753
    $cichorieae_default = array(
754
      'DEFAULT' => array(
755
        'as_list' => 'div',
756
        'link_to_reference' => 1,
757
        'link_to_name_used_in_source' => 1,
758
        'sources_as_content' => 1,
759
        'sources_as_content_to_bibliography' => 0,
760
        'sort_elements' => NO_SORT,
761
        'glue' => '',
762
        'element_tag' => 'div'
763
      ),
764
      UUID_CITATION => array(
765
        'as_list' => 'div',
766
        'link_to_reference' => 0,
767
        'link_to_name_used_in_source' => 0,
768
        'sources_as_content' => 1,
769
        'sources_as_content_to_bibliography' => 0,
770
        'sort_elements' => SORT_ASC,
771
        'glue' => '',
772
        'element_tag' => 'div'
773
      ),
774
      UUID_CHROMOSOMES_NUMBERS => array(
775
        'as_list' => 'ul',
776
        'link_to_reference' => 1,
777
        'link_to_name_used_in_source' => 1,
778
        'sources_as_content' => 1,
779
        'sources_as_content_to_bibliography' => 0,
780
        'sort_elements' => NO_SORT,
781
        'glue' => '',
782
        'element_tag' => 'div'
783
      ),
784
      UUID_CHROMOSOMES => array(
785
        'as_list' => 'ul',
786
        'link_to_reference' => 0,
787
        'link_to_name_used_in_source' => 1,
788
        'sources_as_content' => 1,
789
        'sources_as_content_to_bibliography' => 0,
790
        'sort_elements' => NO_SORT,
791
        'glue' => '',
792
        'element_tag' => 'div'
793
      ),
794
      UUID_COMMON_NAME => array(
795
        'as_list' => 'div',
796
        'link_to_reference' => 0,
797
        'link_to_name_used_in_source' => 1,
798
        'sources_as_content' => 0,
799
        'sources_as_content_to_bibliography' => 0,
800
        'sort_elements' => NO_SORT,
801
        'glue' => '',
802
        'element_tag' => 'span'
803
      ),
804
    );
805

    
806
    $palmweb_default = array(
807
      'DEFAULT' => array(
808
        'as_list' => 'ul',
809
        'link_to_reference' => 1,
810
        'link_to_name_used_in_source' => 1,
811
        'sources_as_content' => 1,
812
        'sources_as_content_to_bibliography' => 1,
813
        'sort_elements' => NO_SORT,
814
        'glue' => '',
815
        'element_tag' => NULL
816
      ),
817
      UUID_CITATION => array(
818
        'as_list' => 'ul',
819
        'link_to_reference' => 1,
820
        'link_to_name_used_in_source' => 1,
821
        'sources_as_content' => 0,
822
        'sources_as_content_to_bibliography' => 1,
823
        'sort_elements' => SORT_ASC,
824
        'glue' => '',
825
        'element_tag' => 'div'
826
      ),
827
      UUID_DISTRIBUTION => array(
828
        'as_list' => 'div', // currently ignored
829
        'link_to_reference' => 1,
830
        'link_to_name_used_in_source' => 1,
831
        'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
832
        'sources_as_content_to_bibliography' => 1,
833
        'sort_elements' => NO_SORT, // will cause ...
834
        'glue' => ', ',
835
        'element_tag' => 'span',
836
        'special' => array()
837
      ),
838
    );
839

    
840
    $cyprus_default = $cichorieae_default;
841
    $cyprus_default[UUID_DISTRIBUTION] = array(
842
      'as_list' => 'div', // currently ignored
843
      'link_to_reference' => 0,
844
      'link_to_name_used_in_source' => 0,
845
      'sources_as_content' => 0,
846
      'sources_as_content_to_bibliography' => 0,
847
      'sort_elements' => NO_SORT, // will cause ...
848
      'glue' => ' ',
849
      'element_tag' => 'div',
850
      'special' => array()
851
    );
852

    
853
    $default_theme = variable_get('theme_default', NULL);
854

    
855
    switch ($default_theme) {
856
      case 'garland_cichorieae':
857
        $settings_for_theme = $cichorieae_default;
858
        break;
859
      case 'cyprus':
860
        // cyprus: no longer used in production,
861
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
862
        $settings_for_theme = $cyprus_default;
863
        break;
864
      case 'flore_afrique_centrale':
865
      case 'flora_malesiana':
866
      case 'flore_gabon':
867
        $settings_for_theme = $cichorieae_default;
868
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
869
        break;
870
      case 'palmweb_2':
871
        $settings_for_theme = $palmweb_default;
872
        break;
873
      default:
874
        $settings_for_theme = $other_themes_default;
875
    }
876
    // add pseudo feature settings
877
    $settings_for_theme['BIBLIOGRAPHY'] = $default['BIBLIOGRAPHY'];
878

    
879
    // ---- END of DEFAULTS
880

    
881
    $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
882

    
883
    $feature_block_setting = null;
884

    
885
    if (isset($saved_settings[$feature_uuid])) {
886
      $feature_block_setting = $saved_settings[$feature_uuid];
887
    }
888
    else if (isset($settings_for_theme[$feature_uuid])) {
889
      $feature_block_setting = $settings_for_theme[$feature_uuid];
890
    }
891
    else if (isset($settings_for_theme['DEFAULT'])) {
892
      $feature_block_setting = $settings_for_theme['DEFAULT'];
893
    }
894

    
895
    // now merge the default and specific settings
896
    $settings_to_merge = array($default['DEFAULT']);
897
    if(is_array($saved_settings)){
898
      $settings_to_merge[] = $saved_settings['DEFAULT'];
899
    }
900
    if(isset($feature_block_setting)){
901
      $settings_to_merge[] = $feature_block_setting;
902
    }
903
    $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
904

    
905
    return $feature_block_setting;
906
}
907

    
908
/**
909
 * returns the current setting for the original source bibliography
910
 *
911
 * Caches internally
912
 *
913
 * @return array
914
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
915
 *   - 'enabled': 1|0
916
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
917
 */
918
function get_bibliography_settings($clear_cache = false){
919
  static $bibliography_settings = null;
920
  if(!$bibliography_settings || $clear_cache){
921
    $bibliography_settings = get_array_variable_merged(
922
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
923
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
924
    );
925
  }
926
  return $bibliography_settings;
927
}
928

    
929
/**
930
 * @todo Please document this function.
931
 * @see http://drupal.org/node/1354
932
 */
933
function cdm_dataportal_menu_admin(&$items) {
934
  // Display section on admin/config page.
935
  $items['admin/config/cdm_dataportal'] = array(
936
    'title' => 'CDM Dataportal',
937
    'description' => 'Settings for the CDM DataPortal.',
938
    'position' => 'right',
939
    'weight' => 10,
940
    'page callback' => 'system_admin_menu_block_page',
941
    'access arguments' => array('administer cdm_dataportal'),
942
    'file' => 'system.admin.inc',
943
    'file path' => drupal_get_path('module', 'system'),
944
  );
945
  $items['admin/config/cdm_dataportal/settings'] = array(
946
    'title' => 'Settings',
947
    'description' => 'Settings for the CDM DataPortal.',
948
    'weight' => 0,
949
    'page callback' => 'drupal_get_form',
950
    'page arguments' => array('cdm_settings_general'),
951
    'access arguments' => array('administer cdm_dataportal'),
952
    'type' => MENU_NORMAL_ITEM,
953
  );
954
  $items['admin/config/cdm_dataportal/settings/general'] = array(
955
    'title' => 'General',
956
    'description' => 'General',
957
    'weight' => 0,
958
    'page callback' => 'drupal_get_form',
959
    'page arguments' => array('cdm_settings_general'),
960
    'access arguments' => array('administer cdm_dataportal'),
961
    'type' => MENU_DEFAULT_LOCAL_TASK,
962
  );
963

    
964
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
965
    'title' => 'Cache',
966
    'description' => 'Cache',
967
    'access arguments' => array('administer cdm_dataportal'),
968
    'page callback' => 'drupal_get_form',
969
    'page arguments' => array('cdm_settings_cache'),
970
    'weight' => 10,
971
    'type' => MENU_LOCAL_TASK,
972
  );
973

    
974
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
975
    'title' => 'Geo & Map',
976
    'description' => 'Geo & Map',
977
    'access arguments' => array('administer cdm_dataportal'),
978
    'page callback' => 'drupal_get_form',
979
    'page arguments' => array('cdm_settings_geo'),
980
    'weight' => 1,
981
    'type' => MENU_LOCAL_TASK,
982
  );
983

    
984
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
985
    'title' => 'Layout',
986
    'description' => 'Configure and adjust the layout of your DataPortal ',
987
    'access arguments' => array('administer cdm_dataportal'),
988
    'page callback' => 'drupal_get_form',
989
    'page arguments' => array('cdm_settings_layout'),
990
    'weight' => 2,
991
    'type' => MENU_LOCAL_TASK,
992
  );
993

    
994
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
995
    'title' => 'Taxon',
996
    'description' => 'Configure and adjust the layout of your DataPortal ',
997
    'access arguments' => array('administer cdm_dataportal'),
998
    'page callback' => 'drupal_get_form',
999
    'page arguments' => array('cdm_settings_layout_taxon'),
1000
    'weight' => 1,
1001
    'type' => MENU_LOCAL_TASK,
1002
  );
1003
  /*
1004
  $items[] = array(
1005
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
1006
  'title' => t('Synonymy'),
1007
  'description' => t('Configure and adjust the layout of your DataPortal '),
1008
  'access' => user_access('administer cdm_dataportal'),
1009
  'callback' => 'drupal_get_form',
1010
  'callback arguments' => array('cdm_settings_layout_synonymy'),
1011
  'weight' => 1,
1012
  'type' => MENU_LOCAL_TASK,
1013
  );
1014

    
1015
  $items[] = array(
1016
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
1017
  'title' => t('Specimens'),
1018
  'description' => t('Configure and adjust the layout of your DataPortal '),
1019
  'access' => user_access('administer cdm_dataportal'),
1020
  'callback' => 'drupal_get_form',
1021
  'callback arguments' => array('cdm_settings_layout_specimens'),
1022
  'weight' => 1,
1023
  'type' => MENU_LOCAL_TASK,
1024
  );
1025
  */
1026
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1027
    'title' => 'Search',
1028
    'description' => 'Configure and adjust the layout of your DataPortal ',
1029
    'access arguments' => array('administer cdm_dataportal'),
1030
    'page callback' => 'drupal_get_form',
1031
    'page arguments' => array('cdm_settings_layout_search'),
1032
    'weight' => 2,
1033
    'type' => MENU_LOCAL_TASK,
1034
  );
1035

    
1036
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1037
    'title' => 'Media',
1038
    'description' => 'Configure and adjust the layout of your DataPortal ',
1039
    'access arguments' => array('administer cdm_dataportal'),
1040
    'page callback' => 'drupal_get_form',
1041
    'page arguments' => array('cdm_settings_layout_media'),
1042
    'weight' => 3,
1043
    'type' => MENU_LOCAL_TASK,
1044
  );
1045

    
1046
}
1047

    
1048
/**
1049
 * @todo document this function.
1050
 */
1051
function cdm_help_general_cache() {
1052
  $form = array();
1053
  $form['cache_help'] = array(
1054
    '#type' => 'fieldset',
1055
    '#title' => t('Help'),
1056
    '#collapsible' => TRUE,
1057
    '#collapsed' => TRUE,
1058
  );
1059
  $form['cache_help']['test'] = array('#value' => t('probando'));
1060
  return drupal_render($form);
1061
  $res = array();
1062
  $res['default'] = drupal_render($help);
1063
  return $res;
1064
}
1065

    
1066
/**
1067
 * Configures the settings form for the CDM-API module.
1068
 *
1069
 * @return array
1070
 *   Drupal settings form.
1071
 */
1072
function cdm_settings_general() {
1073

    
1074
  $form['cdm_webservice'] = array(
1075
    '#type' => 'fieldset',
1076
    '#title' => t('CDM Server'),
1077
    '#collapsible' => FALSE,
1078
    '#collapsed' => FALSE,
1079
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1080
        CDM data base to the web via RESTful web services and thus is the source of the data
1081
        to be displayed by a CDM DataPotal.'),
1082
  );
1083

    
1084
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1085
    '#type' => 'textfield',
1086
    '#title' => t('CDM web service URL') . ':',
1087
    '#description' => t('This is the URL to the CDM-Server exposing your data
1088
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1089
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1090
  );
1091

    
1092
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1093
    '#type' => 'markup',
1094
    '#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')
1095
      . ' visible only for administrators',
1096
  );
1097

    
1098
  $form['cdm_webservice']['freetext_index'] = array(
1099
    '#type' => 'fieldset',
1100
    '#title' => t('Freetext index'),
1101
    '#collapsible' => FALSE,
1102
    '#collapsed' => FALSE,
1103
  );
1104

    
1105
  // Check the cdmserver port number and display a waring if it is not port 80
1106
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1107
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1108
    $form['cdm_webservice']['freetext_index']['message'] = array(
1109
      '#markup' => "<div class=\"description\">"
1110
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1111
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1112
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1113
          array('!port' => $portNumberMatch[1][0])
1114
        )
1115
      . "</div>",
1116
    );
1117
  };
1118

    
1119
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1120
  $trigger_link_options = array(
1121
    'attributes' => array(
1122
      'class' => 'index-trigger'
1123
    ),
1124
  );
1125
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1126
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1127
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1128
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1129
      ))
1130
    . '<div id="index-progress"></div></div>',
1131
  );
1132

    
1133
  $form['cdm_webservice']['freetext_index']['cdm_login'] = array(
1134
    // this must not be stored, it is only used by the _add_js_cdm_ws_progressbar
1135
    '#type' => 'textfield',
1136
    '#title' => t('Login'),
1137
    '#description' => t('Your cdm user credentials in the following form: <code>user:password</code>')
1138
  );
1139
  drupal_add_js('
1140
        jQuery(document).ready(function() {
1141
             jQuery("#edit-cdm-login").change(function (e) {
1142
                var login = jQuery(e.target).val();
1143
                jQuery("#edit-freetext-index .index-trigger").each(function(index){
1144
                   var url = jQuery(this).attr("href");
1145
                   url = url.replace(/:\/\/[^@]+@|:\/\//, "://" + login + "@");
1146
                   jQuery(this).attr("href", url);
1147
                });
1148
            });
1149
        });
1150
      ',
1151
    array(
1152
      'type' => 'inline',
1153
      'scope' => 'footer'
1154
    )
1155
  );
1156
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1157

    
1158
    $form['cdm_webservice']['freetext_index']['cdm_dataportal_taxon_auto_suggest'] = array(
1159
        '#type' => 'checkbox',
1160
        '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
1161
        '#default_value' => variable_get('cdm_dataportal_taxon_auto_suggest', CDM_DATAPORTAL_TAXON_AUTO_SUGGEST),
1162
        '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
1163
        This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
1164
    );
1165

    
1166
  $form['cdm_webservice']['proxy'] = array(
1167
    '#type' => 'fieldset',
1168
    '#title' => t('Proxy'),
1169
    '#collapsible' => TRUE,
1170
    '#collapsed' => TRUE,
1171
  );
1172

    
1173
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1174
    '#type' => 'textfield',
1175
    '#title' => t('Proxy URL') . ':',
1176
    '#description' => t('If this proxy url is set the cdm api tries
1177
    to connect the web service over the given proxy server.
1178
    Otherwise proxy usage is deactivated.'),
1179
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1180
  );
1181

    
1182
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1183
    '#type' => 'textfield',
1184
    '#title' => t('Proxy port') . ':',
1185
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1186
  );
1187

    
1188
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1189
    '#type' => 'textfield',
1190
    '#title' => t('Login') . ':',
1191
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1192
  );
1193

    
1194
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1195
    '#type' => 'textfield',
1196
    '#title' => t('Password') . ':',
1197
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1198
  );
1199

    
1200
  // TODO: settings are still incomplete, compare with
1201
  // trunk/dataportal/inc/config_default.php.inc.
1202
  $form['taxon_tree'] = array(
1203
    '#type' => 'fieldset',
1204
    '#title' => t('Taxon Tree'),
1205
    '#collapsible' => FALSE,
1206
    '#collapsed' => TRUE,
1207
    '#description' => t('<p>When you explore your collection, you can navigate
1208
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1209
      able to navigate through your collection the
1210
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1211
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1212
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1213
      </a></p>'),
1214
  );
1215

    
1216
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1217
    '#type' => 'select',
1218
    '#title' => t('Available classifications') . ':',
1219
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1220
    '#options' => cdm_get_taxontrees_as_options(),
1221
    '#description' => t('Select the default taxa classification for your
1222
      <em>taxon tree</em>, the other classifications will be also available but
1223
      with a manual user change.'),
1224
  );
1225

    
1226
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1227
    '#type' => 'select',
1228
    '#title' => t('Rank of highest displayed taxon') . ':',
1229
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1230
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1231
    '#options' => cdm_rankVocabulary_as_option(),
1232
    '#description' => t('This is the rank of the highest displayed taxon in the
1233
      <em>taxon tree</em>. You can select here which rank should be at the top
1234
      level of the tree structure.'),
1235
  );
1236

    
1237
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1238
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1239
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1240
      '#type' => 'checkboxes',
1241
      '#title' => t('Included Classifications') . ':',
1242
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1243
      '#options' => cdm_get_taxontrees_as_options(),
1244
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1245
  );
1246

    
1247
  $form['distribution'] = array(
1248
      '#type' => 'fieldset',
1249
      '#title' => t('Distributions'),
1250
      '#collapsible' => FALSE,
1251
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1252
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1253
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1254
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1255
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1256
          '<p>
1257
          </p>',
1258
  );
1259

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

    
1281
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1282
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1283
      '#type' => 'checkboxes',
1284
      '#title' => 'Filter rules',
1285
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1286
      '#options' => array(
1287
          'statusOrderPreference' => 'Status order preference rule',
1288
          'subAreaPreference' => 'Sub area preference rule'
1289
      ),
1290
  );
1291

    
1292
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1293
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1294
      '#type' => 'checkboxes',
1295
      '#title' => 'Hide marked area filter',
1296
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1297
      '#options' => $marker_type_options,
1298
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1299
  );
1300

    
1301
  $form['aggregation'] = array(
1302
      '#type' => 'fieldset',
1303
      '#title' => t('Aggregation of data'),
1304
      '#collapsible' => FALSE,
1305
      '#description' => 'This section covers the different aspects of aggregating information.
1306
          <p>
1307
          </p>',
1308
  );
1309

    
1310
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1311
      '#type' => 'checkboxes',
1312
      '#title' => 'Taxon media filter',
1313
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1314
      '#options' => array(
1315
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1316
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1317
          'includeOccurrences' => 'Media related to specimens and occurrences',
1318
      ),
1319
      '#description' => 'This filter configures which images should be taken into account.',
1320
  );
1321

    
1322
  $form['aggregation']['notice'] = array(
1323
      '#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
1324
          want to make use of the caching capabilities of the dataportal.',
1325
  );
1326

    
1327
  $form['aggregation']['media_aggregation'] = array(
1328
      '#type' => 'fieldset',
1329
      '#title' => t('Media aggregation'),
1330
      '#collapsible' => FALSE,
1331
      '#collapsed' => TRUE,
1332
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1333

    
1334
  );
1335
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1336
      '#type' => 'select',
1337
      '#title' => t('Aggregation of taxon pictures') . ':',
1338
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1339
      '#options' => array(
1340
          0 => "Show only pictures of the current taxon",
1341
          1 => "Include pictures of taxonomic children",
1342
      ),
1343
      '#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."),
1344
  );
1345

    
1346
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1347
      '#type' => 'fieldset',
1348
      '#attributes' => array('class' => array('clearfix')),
1349
      '#title' => t('Aggregation via taxon relationsships'),
1350
      '#collapsible' => TRUE,
1351
      '#collapsed' => TRUE,
1352
      '#tree' => TRUE,
1353
      '#description' => t('Information on taxa will be aggregated along the below chosen
1354
          taxon relation ships. This will affect images and occurrences (specimens).
1355
          Taxon relation ships are directed and point form one taxon to another. The taxon
1356
          relationships to be taken into accunt can therefore configured for the direct direction
1357
          and for the inverse.'),
1358
  );
1359

    
1360
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1361
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1362

    
1363
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1364
      '#type' => 'checkboxes',
1365
      '#title' => t('Direct'),
1366
      '#options' => $taxonRelationshipTypeOptions,
1367
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1368
  );
1369
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1370
      '#type' => 'checkboxes',
1371
      '#title' => t('Invers'),
1372
      '#options' => $taxonRelationshipTypeOptions,
1373
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1374
  );
1375

    
1376
  $form['drupal_integration'] = array(
1377
    '#type' => 'fieldset',
1378
    '#attributes' => array('class'=> array('clearfix')),
1379
    '#title' => t('Drupal integration'),
1380
    '#collapsible' => FALSE,
1381
    '#collapsed' => FALSE,
1382
    '#tree' => FALSE
1383
  );
1384

    
1385
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1386
    '#type' => 'checkbox',
1387
    '#title' => 'Create drupal nodes',
1388
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1389
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1390
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1391
    cdm pages it is required that drupal nodes are created and stored in the database.'
1392
  );
1393

    
1394

    
1395

    
1396
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1397
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1398
    <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>',
1399
  );
1400
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1401
    '#type' => 'submit',
1402
    '#value' => t('Drop all cdm nodes'),
1403
    '#submit' => array('drop_all_cdm_nodes_submit')
1404
  );
1405

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

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

    
1435
  // Comment @WA: D7 form api does not support reset buttons,
1436
  // so to mimic the D5 reset button we add one like this.
1437
  $form['actions']['reset'] = array(
1438
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1439
    '#weight' => 1000,
1440
  );
1441

    
1442
  $form['#submit'][] = 'cdm_settings_general_submit';
1443

    
1444
  return system_settings_form($form);
1445
}
1446

    
1447
/**
1448
 * Submit callback; drops all cdm nodes.
1449
 *
1450
 * @ingroup forms
1451
 */
1452
function drop_all_cdm_nodes_submit($form, &$form_state) {
1453
  cdm_delete_all_cdm_nodes();
1454
  drupal_set_message(t('All cdm nodes dropped.'));
1455
}
1456

    
1457

    
1458
/**
1459
 * LAYOUT settings
1460
 * @return
1461
 *   todo
1462
 */
1463
function cdm_settings_layout() {
1464

    
1465
  $form = array();
1466

    
1467
  $form['about'] = array(
1468
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1469
      layout. If you want to configure the specific sites layout visit the
1470
      respective configuration site for taxon, search or media.') . '</p>',
1471
  );
1472

    
1473
  // ---- footnotes --- //
1474
  $form['footnotes'] = array(
1475
    '#type' => 'fieldset',
1476
    '#title' => t('Footnotes'),
1477
    '#collapsible' => FALSE,
1478
    '#collapsed' => FALSE,
1479
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1480
      media or distribution areas may have annotations or footnotes. When the
1481
      footnotes are enabled they will be visible (if they exist).'),
1482
  );
1483

    
1484
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1485
    '#type' => 'checkbox',
1486
    '#title' => t('Do not show footnotes'),
1487
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1488
    '#description' => t('Check this if you do not want to show any footnotes'),
1489
  );
1490

    
1491
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1492
    '#type' => 'checkbox',
1493
    '#title' => t('Do not show annotation footnotes'),
1494
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1495
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1496
  );
1497

    
1498
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1499
  // Additional option for the NULL case.
1500
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1501
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1502
    '#type' => 'checkboxes',
1503
    '#title' => t('Annotation types as footnotes'),
1504
    '#description' => t("Only annotations of the selected type will be displayed
1505
       as footnotes. You may want to turn 'technical annotations' off."),
1506
    '#options' => $annotationTypeOptions,
1507
  );
1508
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1509
  if (!empty($annotationsTypesAsFootnotes)) {
1510
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1511
  }
1512

    
1513
  // ---- original source --- //
1514
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1515
      '#type' => 'fieldset',
1516
      '#tree' => TRUE,
1517
      '#title' => t('Source Citations'),
1518
      '#collapsible' => FALSE,
1519
      '#collapsed' => FALSE,
1520
  );
1521

    
1522
  $bibliography_settings = get_bibliography_settings(true);
1523

    
1524
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1525
      '#type' => 'checkbox',
1526
      '#title' => t('Original Source in bibliography'),
1527
      '#default_value' => $bibliography_settings['enabled'],
1528
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1529
       annotations in each feature block.'),
1530
  );
1531

    
1532
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1533
    '#type' => 'select',
1534
    '#title' => t('The format of the key numerals'),
1535
    '#default_value' => $bibliography_settings['key_format'],
1536
    '#options' => array('latin' => 'Latin',
1537
      'ROMAN' => 'Roman (upper case)',
1538
      'roman' => 'Roman (lower case)',
1539
      'ALPHA'=> 'Alphabet (upper case)',
1540
      'alpha' => 'Alphabet (lower case)')
1541
  );
1542

    
1543
  // --- Advanced Search --- //
1544
  $form['asearch'] = array(
1545
      '#type' => 'fieldset',
1546
      '#title' => t('Advanced search'),
1547
      '#collapsible' => FALSE,
1548
      '#collapsed' => FALSE,
1549
  );
1550
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1551
      '#type' => 'checkbox',
1552
      '#title' => t('Show advanced search link'),
1553
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1554
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1555
  );
1556

    
1557
  // ---- Taxon Name Rendering --- //
1558
  $form['taxon_name'] = array(
1559
      '#type' => 'fieldset',
1560
      '#title' => t('Taxon name display'),
1561
      '#collapsible' => TRUE,
1562
      '#collapsed' => TRUE,
1563
      '#description' => t('The display of taxon names is configured by two parts.
1564
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1565
          The name parts are defined in the <stong>part definitions</strong>'),
1566
  );
1567

    
1568
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1569
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1570
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1571
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1572

    
1573
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1574
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1575
    $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.)';
1576
  } else if($is_custom_part_definition){
1577
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1578
  } else  {
1579
    $which_version_message = '(These are the default part definition.)';
1580
  }
1581

    
1582
  $diff_viewer_markup = '';
1583
  if($is_custom_part_definition){
1584
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1585
  }
1586

    
1587
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1588
    . $which_version_message
1589
    . '</div>'
1590
    . $diff_viewer_markup;
1591

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

    
1681
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1682
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1683
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1684
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1685
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1686

    
1687
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1688
    $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.)';
1689
  } else if($is_custom_render_template){
1690
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1691
  } else {
1692
    $which_version_message = '(These are the default render templates.)';
1693
  }
1694

    
1695
  $diff_viewer_markup = '';
1696
  if($is_custom_render_template){
1697
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1698
  }
1699

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

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

    
1745
  // @WA: D7 form api does not support reset buttons,
1746
  // so to mimic the D5 reset button we add one like this.
1747
  $form['actions']['reset'] = array(
1748
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1749
    '#weight' => 1000,
1750
  );
1751

    
1752
  $form['#submit'] = array('submit_json_as_php_array');
1753
  // #json_elements especially defined for submit_json_as_php_array()
1754
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1755
  return system_settings_form($form);
1756
}
1757

    
1758

    
1759

    
1760
  /**
1761
 * @todo Please document this function.
1762
 * @see http://drupal.org/node/1354
1763
 */
1764
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1765
  $form[$form_name] = array(
1766
    '#type' => 'fieldset',
1767
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1768
    '#collapsible' => TRUE,
1769
    '#collapsed' => $collapsed,
1770
    '#tree' => TRUE,
1771
    '#description' => t('@$form-description', array('@$form-description' => $form_description)),
1772
  );
1773

    
1774
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1775
  $gallery_settings = variable_get($form_name, $default_values);
1776
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1777
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1778
    /*
1779
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1780
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1781
    '#type' => 'textfield',
1782
    '#title' => t('Search Page Size'),
1783
    '#default_value' => $test,
1784
    '#description' => t('Number of Names to display per page in search results.')
1785
    );
1786
    */
1787
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1788
      '#type' => 'checkbox',
1789
      '#title' => t('Show media thumbnails for accepted taxa'),
1790
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1791
    );
1792

    
1793
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1794
      '#type' => 'checkbox',
1795
      '#title' => t('Show media thumbnails for synonyms'),
1796
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1797
      '#description' => '',
1798
    );
1799
  }
1800

    
1801
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1802
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1803
    '#type' => 'checkbox',
1804
    '#title' => t('Show captions under thumbnails'),
1805
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1806
    '#description' => '',
1807
  );
1808

    
1809
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1810
    '#type' => 'textfield',
1811
    '#title' => t('Thumbnail size') . ':',
1812
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1813
    '#description' => t('Select the size of each individual thumbnail.'),
1814
  );
1815

    
1816
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1817
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1818
      '#type' => 'textfield',
1819
      '#title' => t('Number of columns') . ':',
1820
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1821
      '#description' => t('Group the thumbnails in columns: select how many
1822
        columns the gallery should display.'),
1823
    );
1824
  }
1825

    
1826
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1827
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1828
      '#type' => 'textfield',
1829
      '#title' => t('Maximum number of rows') . ':',
1830
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1831
      '#description' => t('You can group the thumbnails in rows, select in how
1832
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1833
        If you want an unlimited number of rows please set to 0.'),
1834
    );
1835
  }
1836

    
1837
  return $form;
1838
}
1839

    
1840
/**
1841
 * @todo document this function.
1842
 */
1843
function cdm_settings_layout_taxon() {
1844
  $collapsed = FALSE;
1845
  $form = array();
1846

    
1847
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1848

    
1849
  // --------- TABBED TAXON ------- //
1850
  $form['taxon_tabs'] = array(
1851
    '#type' => 'fieldset',
1852
    '#title' => t('Taxon tabs'),
1853
    '#collapsible' => TRUE,
1854
    '#collapsed' => TRUE,
1855
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1856
      be splitted in four diferent tabs; General, Synonymy, Images and
1857
      Specimens. If the taxon has no information for any of the tabs/sections
1858
      such tab will be not displayed.'),
1859
  );
1860

    
1861
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1862
    '#type' => 'checkbox',
1863
    '#title' => t('Tabbed taxon page'),
1864
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1865
    '#description' => t('<p>If selected split the taxon page into individual
1866
      tabs for description, images, synonymy and specimens. If not the taxon
1867
      data is rendered as a long single page without tabs.</p>'),
1868
  );
1869

    
1870
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1871
    '#type' => 'checkboxes',
1872
    '#title' => t('Tabs visibility options') . ':',
1873
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1874
    '#options' => get_taxon_options_list(),
1875
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1876
  );
1877

    
1878
  // WEIGHT
1879
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1880
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1881
    '#title'  => 'Tabs order',
1882
    '#type' => 'fieldset',
1883
    '#collapsible' => false,
1884
    '#tree' => true,
1885
    '#description' => 'The weight value defines the order of the tabs or of the respective content block on the 
1886
        taxon page when it is the tabless mode.'
1887
  );
1888
  // Weights range from -delta to +delta, so delta should be at least half
1889
  // of the amount of tabs present.
1890
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1891
  foreach (get_taxon_tabs_list() as $label) {
1892
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1893
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1894
        '#title' => $label,
1895
        '#type'  => 'weight',
1896
        '#default_value' => $taxon_tabs_weights[$key],
1897
        '#delta' => $tab_weight_delta
1898
    );
1899
  }
1900

    
1901
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1902
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1903
    '#title'  => 'Tab label override',
1904
    '#type' => 'fieldset',
1905
    '#collapsible' => false,
1906
    '#tree' => true,
1907
    '#description' => 'Setting a label for a tab will override the default label. 
1908
      Please enter the label text in the default language of the portal.'
1909
  );
1910
  foreach (get_taxon_tabs_list() as $label) {
1911
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1912
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1913
      '#title' => $label,
1914
      '#type'  => 'textfield',
1915
      '#default_value' => $taxon_tabs_labels[$key]
1916
    );
1917
  }
1918

    
1919
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1920
    '#type' => 'select',
1921
    '#title' => t('Default tab to display') . ':',
1922
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1923
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1924
    '#description' => t('<p>Select the default tab to display when visiting a
1925
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1926
      <strong>Note:</strong> After performing a search and clicking in any
1927
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1928
      taxon and not the above selected tab.'),
1929
  );
1930

    
1931
  /* ======  TAXON_PROFILE ====== */
1932
  $form['taxon_profile'] = array(
1933
    '#type' => 'fieldset',
1934
    '#title' => t('Taxon profile (tab)'),
1935
    '#description' => t('<p>This section covers the settings related to the taxon
1936
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1937
    '#collapsible' => TRUE,
1938
    '#collapsed' => TRUE,
1939
  );
1940

    
1941
  // ---- PROFILE PICTURE ----//
1942

    
1943
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1944
    '#type' => 'fieldset',
1945
    '#tree' => TRUE,
1946
    '#title' => t('Taxon profile picture'),
1947
    '#collapsible' => TRUE,
1948
    '#collapsed' => FALSE,
1949
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1950
  );
1951

    
1952
  //FIXME migrate variables:
1953
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1954
  // FIXME
1955
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1956

    
1957
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1958

    
1959
  /*
1960
   * 'show' => 1,
1961
   * 'maxextend' => 184,
1962
   * 'media_uri_query' => ''
1963
   * 'custom_placeholder_image_on' => 1,
1964
   * 'custom_placeholder_image_fid' => ''
1965
   */
1966
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1967
    '#type' => 'checkbox',
1968
    '#title' => t('Enable profile picture'),
1969
    '#description' => t('Show the profile picture.'),
1970
    '#default_value' => $taxon_profile_image_settings['show'],
1971
  );
1972

    
1973
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1974
      '#type' => 'textfield',
1975
      '#tree' => TRUE,
1976
      '#title' => t('Profile picture maximum extend'),
1977
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1978
      '#field_suffix' => 'px',
1979
      '#maxlength' => 4,
1980
      '#size' => 4,
1981
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
1982
  );
1983

    
1984
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1985
      '#type' => 'textfield',
1986
      '#tree' => TRUE,
1987
      '#title' => t('Additional URI query parameter'),
1988
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1989
      '#maxlength' => 1024,
1990
      '#size' => 60,
1991
      '#description' => t('Additional query parameters to be used when requesting for the  
1992
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
1993
            The query parameters will be appended to the uri of the media representation part
1994
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1995
  );
1996

    
1997
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1998
    '#type' => 'checkbox',
1999
    '#title' => t('Show the placeholder image'),
2000
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
2001
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2002
  );
2003

    
2004
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2005
      '#type' => 'checkbox',
2006
      '#title' => t('Use a custom placeholder image'),
2007
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2008
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2009
  );
2010

    
2011
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2012
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2013
        '#type' => 'managed_file',
2014
        '#title' => t('Custom placeholder image file'),
2015
        '#progress_indicator' => 'bar',
2016
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2017
    //       '#name' => 'custom_placeholder_image',
2018
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2019
    );
2020

    
2021
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2022
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2023
      $url = file_create_url($profile_image_file->uri);
2024
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2025
                '#type' => 'item',
2026
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2027
      );
2028
    }
2029
  } else {
2030
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2031
      '#type' => 'hidden',
2032
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2033
    );
2034
  }
2035

    
2036
  $options = cdm_rankVocabulary_as_option();
2037
  array_unshift($options, '-- DISABLED --');
2038
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2039
    '#type' => 'select',
2040
    '#title' => t('Hide profile picture for higher ranks') . ':',
2041
    '#default_value' => variable_get('image_hide_rank', '0'),
2042
    '#options' => $options,
2043
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2044
  );
2045

    
2046
  // -- MEDIA THUMBNAILS -- //
2047
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2048
  $form_title = 'Taxon Profile Images';
2049
  $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>';
2050
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2051

    
2052
  // ---- FEATURE TREE BLOCKS ---- //
2053
  $form['taxon_profile']['feature_blocks'] = array(
2054
    '#type' => 'fieldset',
2055
    '#title' => t('Feature Blocks'),
2056
    '#collapsible' => TRUE,
2057
    '#collapsed' => FALSE,
2058
    '#description' => t("This section covers settings related to the taxon's
2059
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2060
      features such as description, distribution, common names"),
2061
  );
2062
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2063
  $profile_feature_tree = get_profile_feature_tree();
2064
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2065
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2066
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2067
  }
2068
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2069
    '#type' => 'radios',
2070
    '#title' => t('Taxon profile feature tree') . ':',
2071
    '#default_value' => $profile_feature_tree_uuid,
2072
    '#options' =>  $featureTrees['options'],
2073
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2074
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2075
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
2076
      profile page.'
2077
    ),
2078
  );
2079

    
2080
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2081
  $profile_feature_tree = get_profile_feature_tree();
2082

    
2083
  if (isset($profile_feature_tree->root->childNodes)) {
2084

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

    
2124

    
2125
    $feature_list_layout_settings_disabled = FALSE;
2126

    
2127
    // creating helper object to retrieve the default settings
2128
    $featureNode = new stdClass();
2129
    $featureNode->feature = new stdClass();
2130
    $featureNode->feature->uuid="DEFAULT";
2131
    $featureNode->feature->representation_L10n = "Default";
2132
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2133

    
2134
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2135

    
2136
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2137

    
2138
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2139
        $subform_id = $featureNode->feature->uuid;
2140
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2141

    
2142
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2143

    
2144
        $form_feature_block_layout[$subform_id] = array(
2145
          '#type' => 'fieldset',
2146
          '#tree' => TRUE,
2147
          '#title' => $featureNode->feature->representation_L10n,
2148
          '#collapsible' => FALSE,
2149
          '#collapsed' => FALSE,
2150
        );
2151
        if($featureNode->feature->uuid == "DEFAULT"){
2152
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2153
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2154
          references</em> and <em>names in source</em> is only possible in the defaults';
2155
        }
2156

    
2157
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2158
          '#type' => 'select',
2159
          '#title' => 'List type',
2160
          '#default_value' => $feature_block_setting['as_list'],
2161
          '#options' => array(
2162
            'div' => 'not as list',
2163
            'ul' => 'bullet list',
2164
            'ol' => 'numbered list',
2165
            'dl' => 'definition list'
2166
          ),
2167
        );
2168

    
2169
        if($featureNode->feature->uuid == "DEFAULT"){
2170
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2171
            '#type' => 'checkbox',
2172
            '#title' => t('Link to reference'),
2173
            '#default_value' => $feature_block_setting['link_to_reference'],
2174
          );
2175

    
2176
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2177
            '#type' => 'checkbox',
2178
            '#title' => 'Link to name used in source',
2179
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2180
          );
2181
        }
2182

    
2183
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2184
          '#type' => 'checkbox',
2185
          '#title' => 'Sources as content',
2186
          '#default_value' => $feature_block_setting['sources_as_content'],
2187
        );
2188

    
2189
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2190
          '#type' => 'checkbox',
2191
          '#title' => 'Put sources also as content to bibliography',
2192
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2193
        );
2194

    
2195
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2196
          '#type' => 'select',
2197
          '#title' => t('Sort elements'),
2198
          '#default_value' => $feature_block_setting['sort_elements'],
2199
          '#options' => array(
2200
            NO_SORT => 'No sorting',
2201
            SORT_ASC => 'Ascending',
2202
            SORT_DESC => 'Descending',
2203
            SORT_HIERARCHICAL => 'Hierarchical'
2204
          ),
2205
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2206
          <dl>
2207
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2208
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2209
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2210
          <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>
2211
          </dl>',
2212
        );
2213

    
2214
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2215
          '#type' => 'select',
2216
          '#title' => t('Element tag'),
2217
          '#options' => array(
2218
            'span' => 'span',
2219
            'div' => 'div',
2220
            'p' => 'p'
2221
          ),
2222
          '#default_value' => $feature_block_setting['element_tag'],
2223
        );
2224
      }
2225
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2226
    }
2227
  }
2228

    
2229
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2230
  $form['taxon_profile']['structured_description_featuretree'] = array(
2231
    '#type' => 'fieldset',
2232
    '#title' => t('Structured Description Feature Tree'),
2233
    '#collapsible' => TRUE,
2234
    '#collapsed' => FALSE,
2235
  );
2236
  $featureTrees = cdm_get_featureTrees_as_options();
2237
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2238
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2239
    $profile_feature_tree_uuid = NULL;
2240
  }
2241
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2242
    '#type' => 'radios',
2243
    '#title' => t('Natural language representation of structured descriptions') . ':',
2244
    '#default_value' => $profile_feature_tree_uuid,
2245
    '#options' => $featureTrees['options'],
2246
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2247
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2248
    '#description' => t('Taxon descriptions can be stored in a highly structured
2249
      form. The feature tree selected here will be used to generate textual
2250
      representation in natural language.'
2251
    ),
2252
  );
2253

    
2254

    
2255

    
2256
  // ---- DISTRIBUTION LAYOUT ---- //
2257
  $form['taxon_profile']['distribution_layout'] = array(
2258
    '#title' => t('Distribution'),
2259
    '#collapsible' => TRUE,
2260
    '#collapsed' => FALSE,
2261
    '#type' => 'fieldset',
2262
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2263
        Map settings regarding the geometry, layers, etc are found in the '
2264
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2265
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2266
      . l(
2267
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2268
        array('fragment' => 'edit-feature-block-settings')
2269
      )
2270
      . ' More general settings regrading the filtering of Distributions are found at '
2271
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2272
      . '. (These settings here will be merged in future releases into the feature block settings)',
2273

    
2274
  );
2275

    
2276
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2277

    
2278
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2279
    '#type' => 'checkbox',
2280
    '#title' => t('Condensed distribution'),
2281
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2282
    '#description' => 'This option enables the display of a very compact representation
2283
    of the distribution which includes also information on the status.',
2284
  );
2285

    
2286
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2287
    '#type' => 'select',
2288
    '#title' => t('Condensed distribution recipe'),
2289
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2290
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2291
    '#description' => 'Recipe for creating the condensed distribution.',
2292
  );
2293

    
2294
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2295
    '#type' => 'textfield',
2296
    '#title' => t('Condensed distribution info path'),
2297
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2298
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2299
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2300
  );
2301

    
2302

    
2303
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2304
    '#type' => 'radios',
2305
    '#title' => t('Display mode') . ':',
2306
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2307
    '#options' => array(
2308
      'FLAT_ALPHA' => t('Flat list'),
2309
      'TREE' => t('Hierarchically ordered'),
2310
    ),
2311
    '#description' => 'Taxon distribution information is displayed with
2312
    focus on the area of the distribution. The list of areas can either be shown
2313
    as flat list ordered alphabetically or in the hierarchical of the parent
2314
    area and subarea relationship. Fall back areas areas with no Distribution data
2315
    are hidden from the area hierarchy so that their sub areas will move one level up.
2316
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2317
    ' for details on the <em>Marked area filter</em>.',
2318
  );
2319

    
2320
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2321
    '#type' => 'fieldset',
2322
    '#tree' => true,
2323
    '#title' => t('Distribution hierarchy style')
2324
  );
2325

    
2326
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2327
  foreach(array_keys($hierarchy_styles) as $level) {
2328
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2329
      '#type' => 'fieldset',
2330
      '#tree' => true,
2331
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2332
      '#attributes' => array('class' => array('fieldset-float'))
2333
    );
2334
    foreach ($hierarchy_styles[$level] as $key => $value) {
2335
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2336
        '#type' => 'textfield',
2337
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2338
        '#default_value' => $hierarchy_styles[$level][$key],
2339
        '#maxlength' => 4,
2340
        '#size' => 4
2341
      );
2342
    }
2343
  }
2344

    
2345
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2346
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2347
    '#type' => 'checkboxes',
2348
    '#title' => 'Omit area levels',
2349
    '#options' => $level_options,
2350
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2351
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2352
    Areas which belong to the selected area levels will be hidden in the portal.',
2353
  );
2354

    
2355
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2356
    '#type' => 'checkbox',
2357
    '#title' => t('Show TextData elements on top of the map'),
2358
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2359
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2360
      elements on top of the map. Otherwise all <code>TextData</code>
2361
      distribution elements will be listed below the other area elements.
2362
      This option is useful if you need to have descriptive texts for each
2363
      distribution map.'),
2364
  );
2365

    
2366
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2367
      '#type' => 'textarea',
2368
      '#title' => t('Custom status colors'),
2369
      '#element_validate' => array('form_element_validate_json'),
2370
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2371
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2372
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2373
          reference list of the idInVocabulary values of absence and presence terms:
2374
<pre>
2375
Presence Term
2376
p	present
2377
pd	present: doubtfully present
2378
n	native
2379
nq	native: presence questionable
2380
nd	native: doubtfully native
2381
c	cultivated
2382
i	introduced
2383
iq	introduced: presence questionable
2384
id	introduced: doubtfully introduced (perhaps cultivated only)
2385
ip	introduced: uncertain degree of naturalisation
2386
ia	introduced: adventitious (casual)
2387
in	introduced: naturalized
2388
ic	introduced: cultivated
2389
e	endemic for the relevant area
2390
na	naturalised
2391
iv	invasive
2392

    
2393
AbsenceTerm
2394
a	absent
2395
f	reported in error
2396
nf	native: reported in error
2397
if	introduced: reported in error
2398
cf	cultivated: reported in error
2399
ne	native: formerly native
2400
ie	introduced: formerly introduced
2401

    
2402
</pre>'),
2403
  );
2404

    
2405

    
2406
  /* ====== SYNONYMY ====== */
2407
  $form['taxon_synonymy'] = array(
2408
    '#type' => 'fieldset',
2409
    '#title' => t('Taxon synonymy (tab)'),
2410
    '#collapsible' => TRUE,
2411
    '#collapsed' => TRUE,
2412
    '#description' => t('This section covers the settings related to the taxon
2413
      <strong>synonymy</strong> tab.'),
2414
  );
2415

    
2416
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2417
    '#type' => 'checkbox',
2418
    '#title' => t('Show accepted taxon on top of the synonymy'),
2419
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2420
    '#description' => t('If checked, the first homotypic taxon is a repetition
2421
      of the accepted taxon most likely with the full nomenclatural reference
2422
      (depending on the currently chosen theme).'),
2423
  );
2424

    
2425
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2426
    '#type' => 'checkbox',
2427
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2428
      coming from a synonym link.'),
2429
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2430
    '#description' => t('Check this if after doing a search and clicking on a
2431
      synonym you want to see the "accept of" text for the accepted synonym.'),
2432
  );
2433

    
2434
  /* === currently unused ===
2435
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2436
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2437
    '#type' => 'checkboxes',
2438
    '#title' => t('Display name relationships') . ':',
2439
    '#default_value' => variable_get('name_relationships_to_show', 0),
2440
    '#options' => $nameRelationshipTypeOptions,
2441
    '#description' => t('Select the name relationships you want to show for the
2442
      accepted taxa.'),
2443
  );
2444
 */
2445

    
2446
  $form['taxon_synonymy']['taxon_relations'] = array(
2447
    '#type' => 'fieldset',
2448
    '#title' => t('Taxon relationships'),
2449
    '#collapsible' => FALSE,
2450
    '#collapsed' => FALSE
2451
  );
2452

    
2453
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2454
    '#type' => 'checkbox',
2455
    '#title' => t('Show taxon relations ships of accepted taxon'),
2456
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2457
    '#description' => t('If this option is enabled the synonymy will show the
2458
      below selected taxon relationships of accepted taxa.'),
2459
  );
2460

    
2461
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2462
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2463
    '#type' => 'checkboxes',
2464
    '#title' => t('Taxon relationship types') . ':',
2465
    '#description' => t('Only taxon relationships of the selected type will be
2466
      displayed'),
2467
    '#options' => $taxonRelationshipTypeOptions,
2468
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2469
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2470
  );
2471

    
2472
  $form['taxon_synonymy']['name_relations'] = array(
2473
    '#type' => 'fieldset',
2474
    '#title' => t('Name relationships'),
2475
    '#collapsible' => FALSE,
2476
    '#collapsed' => FALSE
2477
  );
2478

    
2479
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2480
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2481
    '#type' => 'checkboxes',
2482
    '#title' => t('Name relationship types') . ':',
2483
    '#description' => t('Only name relationships of the selected type will be
2484
      displayed'),
2485
    '#options' => $taxonRelationshipTypeOptions,
2486
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2487
  );
2488

    
2489
  // ====== SPECIMENS ====== //
2490
  $form['taxon_specimens'] = array(
2491
    '#type' => 'fieldset',
2492
    '#title' => t('Taxon specimens (tab)'),
2493
    '#collapsible' => TRUE,
2494
    '#collapsed' => TRUE,
2495
    '#description' => t('This section covers the settings related to the taxon
2496
      <strong>specimens</strong> tab.'),
2497
  );
2498

    
2499
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2500

    
2501
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2502
    '#type' => 'checkbox',
2503
    '#title' => t('Show specimen derivatives in a compressed table'),
2504
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2505
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2506
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2507
  );
2508

    
2509
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2510
        '#type' => 'textfield',
2511
        '#title' => t('Number of records per page') . ':',
2512
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2513
    );
2514

    
2515
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2516
    '#type' => 'checkbox',
2517
    '#title' => t('Show "Associated with" in specimen table.'),
2518
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2519
  );
2520

    
2521
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2522
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2523
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2524
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2525
  }
2526
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2527
    '#type' => 'radios',
2528
    '#title' => t('Specimen description feature tree') . ':',
2529
    '#default_value' => $profile_feature_tree_uuid,
2530
    '#options' =>  $featureTrees['options'],
2531
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2532
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2533
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2534
    ),
2535
  );
2536

    
2537
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2538
  $form_title = t('Specimen media');
2539
  $form_description = t('Specimens may have media which is displayed at the
2540
     Specimen tab/section as a gallery. It is possible to configure the
2541
     thumbnails gallery here, however for configuring how a single media should
2542
     be displayed please go to !url.</p>',
2543
     array(
2544
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2545
     ));
2546
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2547

    
2548
  // --- MEDIA GALLERY ---- //
2549
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2550
  $form_title = 'Media gallery (tab)';
2551
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2552
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2553
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2554
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2555
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2556
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2557
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2558

    
2559
  // Comment @WA: D7 form api does not support reset buttons,
2560
  // so to mimic the D5 reset button we add one like this.
2561
  $form['actions']['reset'] = array(
2562
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2563
    '#weight' => 1000,
2564
  );
2565
  return system_settings_form($form);
2566
}
2567

    
2568
/**
2569
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2570
 *
2571
 * @param $map_id
2572
 * @param $form
2573
 * @return mixed
2574
 */
2575
function _cdm_map_visibility_setting($map_id)
2576
{
2577
  return array(
2578
    '#type' => 'select',
2579
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2580
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2581
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2582
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2583
        The map also can forced to show up <b>always</b> or <b>never</b>."
2584
  );
2585
}
2586

    
2587
/**
2588
 * @todo document this function.
2589
 */
2590
function cdm_settings_layout_search() {
2591

    
2592
  $form = array();
2593

    
2594
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2595

    
2596
  $form['search_settings'] = array(
2597
    '#type' => 'fieldset',
2598
    '#title' => t('Taxa Search'),
2599
    '#collapsible' => FALSE,
2600
    '#collapsed' => FALSE,
2601
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2602
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2603
         where they can write the text to be searched. You can find Drupal block configuration
2604
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2605
  );
2606

    
2607
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2608
      '#type' => 'checkbox',
2609
      '#title' => t('Ignore the chosen classification in simple search'),
2610
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2611
      '#description' => t('The simple search, which can be executed via the search block,
2612
          will by default search on the classification selected in the classification browser
2613
          selector. Set the tick if you want your portal to search on all classifications.'),
2614
  );
2615

    
2616
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2617
    '#type' => 'checkbox',
2618
    '#title' => t('Run simple search with free-text search backend.'),
2619
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2620
    '#description' => t('The simple search uses by default another search
2621
      backend as the advances search. By checking this option the simple search can be
2622
      configured to also use the free-text search backend.'),
2623
  );
2624

    
2625
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2626
    '#type' => 'textfield',
2627
    '#title' => t('Results per page') . ':',
2628
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2629
    '#description' => t('Number of results to display per page.'),
2630
  );
2631

    
2632
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2633
    '#type' => 'checkbox',
2634
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2635
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2636
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2637
  );
2638

    
2639
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2640
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2641
      '#type' => 'checkboxes',
2642
      '#title' => 'Search mode',
2643
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2644
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2645
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2646
          defaults set here.',
2647
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2648
      '#default_value' => $search_mode_default
2649
      );
2650

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

    
2656
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2657
  );
2658

    
2659
  // --- SEARCH TAXA GALLERY ---- //
2660
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2661
  $collapsed = FALSE;
2662
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2663
  $form_title = 'Taxa Search thumbnails';
2664
  $form_description = 'Search results may show thumbnails. ';
2665
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2666

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

    
2676
/**
2677
 * @todo document this function.
2678
 */
2679
function cdm_settings_layout_media() {
2680

    
2681
  $form = array();
2682

    
2683
  $form['media_settings'] = array(
2684
    '#type' => 'fieldset',
2685
    '#title' => t('Media settings'),
2686
    '#collapsible' => FALSE,
2687
    '#collapsed' => FALSE,
2688
    '#description' => 'This section covers layout settings for media pages.'
2689
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2690
  );
2691

    
2692
  $form['media_settings']['image_gallery_viewer'] = array(
2693
    '#type' => 'select',
2694
    '#title' => t('Image viewer') . ':',
2695
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2696
    '#options' => array(
2697
      'default' => t('Standard image viewer'),
2698
      'fsi' => t('FSI viewer (requires FSI server!)'),
2699
    ),
2700
  );
2701

    
2702
  // --- MEDIA GALLERY ---- //
2703
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2704
  $form_title = 'Standard viewer';
2705
  $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>';
2706
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2707
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2708

    
2709
  // @WA: D7 form api does not support reset buttons,
2710
  // so to mimic the D5 reset button we add one like this.
2711
  $form['actions']['reset'] = array(
2712
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2713
    '#weight' => 1000,
2714
  );
2715
  return system_settings_form($form);
2716
}
2717

    
2718
/**
2719
 * GEOSERVICE and Map settings.
2720
 */
2721
function cdm_settings_geo($form, &$form_state) {
2722

    
2723
  $current_geoserver_settings = get_edit_map_service_settings();
2724
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2725

    
2726

    
2727
  $form = array();
2728

    
2729
  $dummy_distribution_query = NULL;
2730
  if($map_distribution['map_type'] != 1){
2731
    // we need to apply a dummy query since the map service requires for image maps
2732
    // at least as and ad to be defined
2733
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2734
  }
2735

    
2736
  $form['map_preview'] = array(
2737
      '#type' => 'fieldset',
2738
      '#tree' => FALSE,
2739
      '#title' => t('Map preview'),
2740
      '#collapsible' => FALSE,
2741
      '#description' => 'The preview of the map'
2742
       . ($dummy_distribution_query != null ?
2743
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2744
           '.<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.')
2745
  );
2746
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2747
    'move' => "this.cdmOpenlayersMap.printInfo",
2748
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2749
  ), true // resizable
2750
  );
2751

    
2752
  /*
2753
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2754
  );
2755
  */
2756

    
2757
  /*
2758
   * GEO SERVER
2759
   */
2760
  $form['edit_map_server'] = array(
2761
    '#type' => 'fieldset',
2762
    '#tree' => true,
2763
    '#title' => t('EDIT map service'),
2764
    '#collapsible' => TRUE,
2765
    '#collapsed' => TRUE,
2766
    '#description' => t('Configuration and selection of your geo server.
2767
      The Geo Server is responsible for generating the maps.'),
2768
  );
2769

    
2770
  $form['edit_map_server']['base_uri'] = array(
2771
    '#type' => 'select',
2772
    '#title' => t('EDIT map service') . ':',
2773
    '#default_value' => $current_geoserver_settings['base_uri'],
2774
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2775
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2776
  );
2777
  $form['edit_map_server']['version'] = array(
2778
      '#type' => 'select',
2779
      '#title' => t('Version') . ':',
2780
      '#default_value' => $current_geoserver_settings['version'],
2781
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2782
      '#description' => t('The version of the EDIT map services'),
2783
  );
2784

    
2785
  /*
2786
   * MAP SETTINGS
2787
   */
2788

    
2789
  $form[CDM_MAP_DISTRIBUTION] = array(
2790
    '#type' => 'fieldset',
2791
    '#tree' => TRUE,
2792
    '#title' => t('Maps settings'),
2793
    '#collapsible' => TRUE,
2794
    '#collapsed' => TRUE,
2795
    '#description' => t('General configuration for all map types.'),
2796
  );
2797

    
2798
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2799
    '#type' => 'radios',
2800
    '#title' => 'Map types',
2801
    '#options' => array(
2802
      1 => "OpenLayers dynamic map viewer",
2803
      0 => "Plain image",
2804
    ),
2805
    '#default_value' => $map_distribution['map_type'],
2806
    '#description' => 'Two different map types are available :
2807
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2808
      which allows zooming and panning. If enabled you can configure the default layer
2809
      (background of your maps) below.</li>
2810
      <li><em>Plain image</em>: The map will be static non interactive
2811
      image.</li></ul>',
2812
  );
2813
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2814

    
2815
  /*
2816
   * settings for the distribution map are used also for specimens map!!!!
2817
   */
2818

    
2819
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2820
      '#type' => 'textfield',
2821
      '#title' => 'Aspect ratio',
2822
      '#default_value' => $map_distribution['aspect_ratio'],
2823
      '#maxlength' => 4,
2824
      '#size' => 4,
2825
      '#element_validate' => array('element_validate_number'),
2826
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2827
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2828
      width by the height:</br>
2829
      <pre>aspect ratio = w / h</pre>
2830
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2831
      for a square map use <strong>1</strong>.',
2832
  );
2833

    
2834
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2835
    '#type' => 'textfield',
2836
    '#title' => 'Bounding box',
2837
    '#default_value' => $map_distribution['bbox'],
2838
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2839
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2840
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2841
      <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.
2842
      (Maybe you need to change the map base layer to OpeLayers.)
2843
      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
2844
      below the map from where you can copy the bbox string.</p>'),
2845
  );
2846

    
2847
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2848
    '#type' => 'checkbox',
2849
    '#title' => 'Display area labels',
2850
    '#default_value' => $map_distribution['show_labels'],
2851
    '#description' => t('The map will show name labels of the areas'),
2852
  );
2853

    
2854
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2855
    '#type' => 'textfield',
2856
    '#title' => 'Map caption',
2857
    '#default_value' => $map_distribution['caption'],
2858
    '#description' => t('The caption will be shown below the map.'),
2859
  );
2860

    
2861
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2862
    '#type' => 'textfield',
2863
    '#title' => 'Distribution layer opacity',
2864
    '#default_value' => $map_distribution['distribution_opacity'],
2865
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2866
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2867
  );
2868

    
2869
  // --- Plain Image Settings --- //
2870
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2871
    '#type' => 'fieldset',
2872
    '#title' => 'Plain image map settings',
2873
    '#tree' => TRUE,
2874
    '#collapsible' => TRUE,
2875
    '#collapsed' => $open_layers_is_enabled,
2876
    '#description' => 'The settings in this section are still expertimental
2877
      and can only be used with the EDIT map service version 1.1 or above.',
2878
  );
2879
  $edit_mapserver_version = get_edit_map_service_version_number();
2880
  if ($edit_mapserver_version < 1.1) {
2881
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2882
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2883
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2884
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2885
  }
2886

    
2887
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2888
    '#type' => 'textfield',
2889
    '#title' => 'Width',
2890
    '#default_value' => $map_distribution['image_map']['width'],
2891
    '#maxlength' => 4,
2892
    '#size' => 4,
2893
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2894
  );
2895

    
2896
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2897
    '#type' => 'textfield',
2898
    '#title' => 'Background layer',
2899
    '#default_value' => $map_distribution['image_map']['base_layer'],
2900
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2901
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2902
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2903
    )),
2904
  );
2905

    
2906
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2907
    '#type' => 'textfield',
2908
    '#title' => 'Background color',
2909
    '#default_value' => $map_distribution['image_map']['bg_color'],
2910
  );
2911

    
2912
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2913
    '#type' => 'textfield',
2914
    '#title' => 'Background layer style',
2915
     // Only line color by now.
2916
    '#default_value' => $map_distribution['image_map']['layer_style'],
2917
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2918
  );
2919

    
2920
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2921
      '#type' => 'textfield',
2922
      '#title' => 'Projection',
2923
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2924
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2925
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2926
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2927
  );
2928

    
2929

    
2930
  // --- OpenLayers Settings --- //
2931
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2932
    '#type' => 'fieldset',
2933
    '#title' => 'OpenLayers settings',
2934
    '#tree' => TRUE,
2935
    '#collapsible' => TRUE,
2936
    '#collapsed' => !$open_layers_is_enabled,
2937
    '#description' => '',
2938
  );
2939

    
2940

    
2941
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2942
      '#type' => 'checkbox',
2943
      '#title' => 'Display outside max extent',
2944
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2945
      '#description' => t('Allows the map to display parts of the layers which are outside
2946
         the max extent if the aspect ratio of the map and of the baselayer
2947
         are not equal.'),
2948
  );
2949

    
2950

    
2951
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2952
      '#type' => 'checkbox',
2953
      '#title' => 'Show Layer Switcher',
2954
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2955
      '#description' => 'The Layer Switcher control displays a table of contents
2956
      for the map.  This allows the user interface to switch between
2957
      base layers and to show or hide overlays.  By default the switcher is
2958
      shown minimized on the right edge of the map, the user may expand it
2959
      by clicking on the handle.',
2960
  );
2961

    
2962
  if (!$open_layers_is_enabled) {
2963
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2964
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2965
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2966
  }
2967

    
2968
  // The default layer must always be enabled
2969
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2970
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2971

    
2972
  $baselayer_options = array(
2973
    /*
2974
   NOTICE: must correspond to the layers defined in
2975
   js/openlayers_,ap.js#getLayersByName()
2976
   */
2977
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
2978
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
2979
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
2980
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
2981
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2982
    // all others EPSG:900913
2983
    'mapnik' => 'OpenStreetMap',
2984
    'mapquest_open' => "MapQuest",
2985
    'mapquest_sat' => "MapQuest Sattelite",
2986
    'groadmap' => 'Google Roadmap',
2987
    'gsatellite' => 'Google Satellite',
2988
    'ghybrid' => 'Google Hybrid',
2989
    'gterrain' => 'Google Terrain',
2990
//     'veroad' => 'Virtual Earth Roads',
2991
//     'veaer' => 'Virtual Earth Aerial',
2992
//     'vehyb' => 'Virtual Earth Hybrid',
2993
    // 'yahoo' => 'Yahoo Street',
2994
    // 'yahoosat' => 'Yahoo Satellite',
2995
    // 'yahoohyb' => 'Yahoo Hybrid',
2996
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2997
  );
2998

    
2999
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3000
    '#type' => 'checkboxes_preferred',
3001
    '#title' => 'Base Layers',
3002
    '#options' => $baselayer_options,
3003
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3004
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3005
  );
3006

    
3007
  $google_maps_api_key = null;
3008
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3009
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3010
  }
3011
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3012
    '#type' => 'textfield',
3013
    '#title' => 'Google Maps API Key',
3014
    '#default_value' => $google_maps_api_key,
3015
    '#description' => 'In order to use any of the Google map layers you need to provide 
3016
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3017
  );
3018

    
3019
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
3020
      '#type' => 'fieldset',
3021
      '#title' => 'Custom WMS base layer',
3022
      '#tree' => TRUE,
3023
      '#collapsible' => FALSE,
3024
      '#collapsed' => FALSE,
3025
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
3026
  );
3027

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

    
3124
  /*
3125
   * Map Legend
3126
   */
3127
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3128
    '#type' => 'fieldset',
3129
    '#title' => 'Map legend',
3130
    '#tree' => TRUE,
3131
    '#collapsible' => TRUE,
3132
    '#collapsed' => TRUE,
3133
    '#description' => 'Configure the maps legend.',
3134
  );
3135

    
3136
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3137
    '#type' => 'checkbox',
3138
    '#title' => 'Display a map legend',
3139
    '#default_value' => $map_distribution['legend']['show'],
3140
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3141
  );
3142

    
3143
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3144
    '#type' => 'textfield',
3145
    '#title' => 'Legend opacity',
3146
    '#default_value' => $map_distribution['legend']['opacity'],
3147
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3148
                         to 0.0 will be not much visible.',
3149
  );
3150

    
3151
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3152
    '#type' => 'textfield',
3153
    '#title' => 'Font size',
3154
    '#default_value' => $map_distribution['legend']['font_size'],
3155
    '#description' => 'Font size in pixels.',
3156
  );
3157

    
3158
  $fontStyles = array(
3159
    0 => "plane",
3160
    1 => "italic",
3161
  );
3162
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3163
    '#type' => 'select',
3164
    '#title' => 'Available font styles',
3165
    '#default_value' => $map_distribution['legend']['font_style'],
3166
    '#options' => $fontStyles,
3167
    '#description' => 'Select a font style for the map legend.',
3168
  );
3169

    
3170
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3171
    '#type' => 'textfield',
3172
    '#title' => 'Icon width',
3173
    '#default_value' => $map_distribution['legend']['icon_width'],
3174
    '#description' => 'Legend icon width in pixels.',
3175
  );
3176
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3177
    '#type' => 'textfield',
3178
    '#title' => 'Icon height',
3179
    '#default_value' => $map_distribution['legend']['icon_height'],
3180
    '#description' => 'Legend icon height in pixels.',
3181
  );
3182

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

    
3190
  return system_settings_form($form);
3191
}
3192

    
3193

    
3194
/**
3195
 * @todo document this function.
3196
 */
3197
function cdm_settings_cache() {
3198

    
3199
  $form = array();
3200

    
3201
  $form['cache_settings'] = array(
3202
    '#type' => 'fieldset',
3203
    '#title' => t('Cache Settings'),
3204
    '#collapsible' => FALSE,
3205
    '#collapsed' => FALSE,
3206
    '#description' => t('<p>When caching is enabled all single taxon sites are
3207
      stored in an internal drupal cache doing the portal response of taxa pages
3208
      faster. This is possible because the sites are loaded from the cache and
3209
      are not created from scratch.</p>'),
3210
  );
3211

    
3212
  $form['cache_settings']['cdm_webservice_cache'] = array(
3213
    '#type' => 'checkbox',
3214
    '#title' => t('<strong>Enable caching</strong>'),
3215
    '#options' => cdm_help_general_cache(),
3216
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3217
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3218
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3219
       application the changes will be not visible till the cache is erased.
3220
       Therefore developers should deactived this feature when they are working
3221
       on the CDM Dataportal Module.</p>'),
3222
  );
3223

    
3224
  $form['cache_settings']['cdm_run_cache'] = array(
3225
    '#markup' => cdm_view_cache_site(),
3226
  );
3227

    
3228
  // @WA: D7 form api does not support reset buttons,
3229
  // so to mimic the D5 reset button we add one like this.
3230
  $form['actions']['reset'] = array(
3231
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3232
    '#weight' => 1000,
3233
  );
3234
  return system_settings_form($form);
3235
}
3236

    
3237
/**
3238
 * Walk and cache all taxon pages.
3239
 */
3240
function cdm_view_cache_site() {
3241

    
3242
  $out = '';
3243

    
3244
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3245

    
3246
  $request_params = array();
3247
  $request_params['class'] = "Taxon";
3248

    
3249
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3250
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3251
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3252

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

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

    
3262
  // Comment @WA: A form within a form is not valid html and not needed here.
3263
  // Also, it would be recommended just to include this part of the form in the
3264
  // rest of the form array in cdm_settings_cache().
3265
  // $out .= '<form id="cache_site">';
3266
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3267
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3268
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3269
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3270
  // $out .= '</form>';
3271
  $out .= '</div>';
3272
  /*
3273
  foreach($taxonPager->records as $taxon){
3274
    cdm_dataportal_taxon_view($uuid);
3275
  }
3276
  */
3277
  return $out;
3278
}
3279

    
3280

    
3281
function cdm_settings_layout_taxon_submit($form, &$form_state){
3282
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3283
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3284
    if(is_object($file)){
3285
      $file->status = FILE_STATUS_PERMANENT;
3286
      file_save($file);
3287
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3288
    }
3289
  }
3290
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3291
  $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]);
3292
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3293
  if($tab_lables_modified || $tabs_enabled_modified){
3294
    // we first need to set the variable to persist the changes setting
3295
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3296
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3297
    menu_rebuild();
3298
  }
3299
}
3300

    
3301
function cdm_settings_layout_search_submit($form, &$form_state){
3302
  // the visibility of media thumbnails also affects the ui of the search results
3303
  // so reset the according session variable
3304
  //    1. in order to give the user immediate
3305
  //       feedback on potential setting changes
3306
  //    2. let refresh the default if it has changed
3307
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3308
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3309
  }
3310
}
3311

    
3312
/**
3313
 * Form validation handler for cdm_settings_general
3314
 *
3315
 * @param $form
3316
 * @param $form_state
3317
 */
3318
function cdm_settings_general_validate($form, &$form_state) {
3319

    
3320
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3321
    $form_state['values']['cdm_webservice_url'] .= '/';
3322
  }
3323

    
3324
}
3325

    
3326
/**
3327
 * Form submit handler for settings general.
3328
 *
3329
 * tasks performed:
3330
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3331
 *
3332
 * @param $form
3333
 * @param $form_state
3334
 */
3335
function cdm_settings_general_submit($form, &$form_state){
3336
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3337
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3338
  unset($_SESSION['cdm_login']);
3339
}
3340

    
3341
/**
3342
 * Form validation handler for cdm_settings_cache
3343
 */
3344
function cdm_settings_cache_validate($form, &$form_state) {
3345
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3346
    cache_clear_all(NULL, 'cache_cdm_ws');
3347
    // Better clear secref_cache since I can not be sure if the cache has not
3348
    // be used during this response.
3349
    cdm_api_secref_cache_clear();
3350
  }
3351

    
3352
}
3353

    
3354
/**
3355
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3356
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3357
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3358
 *  - version: the version, e.g.: v1.1
3359
 *
3360
 * @return array
3361
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3362
 */
3363
function get_edit_map_service_settings() {
3364

    
3365
  $settings = variable_get('edit_map_server', array(
3366
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3367
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3368
      )
3369
  );
3370

    
3371
  return $settings;
3372
}
3373

    
3374
/**
3375
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3376
 *
3377
 * @return string
3378
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3379
 */
3380
function get_edit_map_service_full_uri() {
3381
  $settings = get_edit_map_service_settings();
3382
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3383
}
3384

    
3385

    
3386
/**
3387
 * Returns the version number of the currently selected edit mapserver as a float
3388
 *
3389
 * @return float
3390
 *   The version number of the currently selected edit mapserver as a float.
3391
 *   Returns 0 on error.
3392
 */
3393
function get_edit_map_service_version_number() {
3394

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

    
3397
  $settings = get_edit_map_service_settings();
3398
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3399
  if (isset($matches[1])) {
3400
    // Convert string to float.
3401
    $version = 1 + $matches[1][0] - 1;
3402
    return $version;
3403
  }
3404
  else {
3405
    // Report error.
3406
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3407
        array(
3408
          '!version' => $settings['version'],
3409
          'warning')
3410
        )
3411
      );
3412
    return 0;
3413
  }
3414
}
3415

    
3416
/**
3417
 * Returns the array of selected items in a options array
3418
 *
3419
 * @param array $options
3420
 *   An options array as generated by a form element like checkoxes, select ...,
3421
 */
3422
function get_selection($options) {
3423
  $selection = array();
3424
  foreach ($options as $key=>$val) {
3425
    if (!empty($val)) {
3426
      $selection[] = $val;
3427
    }
3428
  }
3429
  return $selection;
3430
}
3431

    
3432

    
3433
/**
3434
 * Implements hook_element_info().
3435
 *
3436
 * Allows modules to declare their own Form API element types and specify their default values.
3437
 *
3438
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3439
 */
3440
function cdm_dataportal_element_info() {
3441
  $type['checkboxes_preferred'] = array(
3442
    '#input' => TRUE,
3443
    '#process' => array('checkboxes_preferred_expand'),
3444
    '#after_build' => array('checkboxes_preferred_after_build'),
3445
    '#theme' => array('checkboxes_preferred'),
3446
    // '#theme_wrapper' => array('form_element'),
3447
  );
3448
  return $type;
3449
}
3450

    
3451
/**
3452
 * #process callback function for the custom form element type 'checkbox_preferred'
3453
 *
3454
 *
3455
 */
3456
function checkboxes_preferred_expand($element, &$form_state, $form) {
3457

    
3458
  // First of all create checkboxes for each of the elements
3459
  $element = form_process_checkboxes($element);
3460

    
3461
  // compose the element name
3462
  $parents = array();
3463
  array_deep_copy($element['#parents'], $parents);
3464
  $parents[count($parents) -1 ] .= '_preferred';
3465
  $element_name = $parents[0];
3466
  for ($i=1; $i < count($parents); $i++){
3467
    $element_name .= '[' . $parents[$i] . ']';
3468
  }
3469

    
3470
  $children = element_children($element);
3471

    
3472
  $element['table_start'] = array(
3473
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3474
    '#weight' => -1,
3475
  );
3476

    
3477
  // prepare first part each of the table rows which contains the row label
3478
  $weight = 0;
3479
  foreach ($children as $key) {
3480
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3481
    $element[$key]['#weight'] = $weight;
3482
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3483
    $element[$key]['#suffix'] = '</td>';
3484
    unset($element[$key]['#title']);
3485
    $weight += 2;
3486
  }
3487
  $weight = 0;
3488

    
3489
  // add a radio button to each of the checkboxes, the
3490
  // check boxes have already been created at the beginning
3491
  // of this function
3492
  if (count($element['#options']) > 0) {
3493
    foreach ($element['#options'] as $key => $choice) {
3494
      if (!isset($element[$key . '_preferred'])) {
3495
        $element[$key . '_preferred'] = array(
3496
          '#type' => 'radio',
3497
          '#name' => $element_name,
3498
          '#return_value' => check_plain($key),
3499
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3500
          '#attributes' => $element['#attributes'],
3501
          '#parents' => $element['#parents'],
3502
          // '#spawned' => TRUE,
3503
          '#weight' => $weight + 1,
3504
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3505
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3506
        );
3507
      }
3508
      $weight += 2;
3509
    }
3510
  }
3511

    
3512
  // end the table
3513
  $element['table_end'] = array(
3514
    '#markup' => '</table>',
3515
    '#weight' => $weight++,
3516
  );
3517

    
3518
  return $element;
3519
}
3520

    
3521
/**
3522
 * Theme function for the custom form field 'checkboxes_preferred'.
3523
 */
3524
function theme_checkboxes_preferred($variables) {
3525
  $element = $variables['element'];
3526
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3527
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3528
  $out .= drupal_render_children($element);
3529
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3530
  $out .= '</div>';
3531
  return $out;
3532
}
3533

    
3534
/**
3535
 * Callback for checkboxes preferred for widget which will
3536
 * be called after the form or element is built. The call
3537
 * back is configured in the form element by setting it as
3538
 * #after_build parameter.
3539
 *
3540
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3541
 *
3542
 * @param $element
3543
 *   Nested array of form elements that comprise the form.
3544
 * @param $form_state
3545
 *   A keyed array containing the current state of the form.
3546
 *   This includes the current persistent storage data for the form.
3547
 *   Additional information, like the sanitized $_POST data,
3548
 *   is also accumulated here in $form_state['input']
3549
 *
3550
 * @return the modified form array
3551
 */
3552
function checkboxes_preferred_after_build($element, &$form_state) {
3553

    
3554
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3555

    
3556
  if ($_POST && count($_POST) > 0) {
3557
    // TODO use  $form_state['input'] instead of POST !!!
3558
    // First pass of form processing.
3559
    $parents = array();
3560
    array_deep_copy($element['#parents'], $parents);
3561
    $parents[count($parents) - 1] .= '_preferred';
3562
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3563
    $element['#value']['PREFERRED'] = $preferred_layer;
3564
//     $form_state[$parent_id] = $element['#value'];
3565
//     $form_state['values']['baselayers'] = $element['#value'];
3566
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3567
    $form_state_element_values = $element['#value'];
3568
  }
3569
  else {
3570
    // Second pass of form processing.
3571
    $preferred_layer = $element['#value']['PREFERRED'];
3572
  }
3573

    
3574
  // Also set the chosen value (not sure if this is good Drupal style ....).
3575
  foreach ($children = element_children($element) as $key) {
3576
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3577
      $element[$key]['#value'] = $preferred_layer;
3578
    }
3579
  }
3580
  // The default layer must always be enabled.
3581
  $element[$preferred_layer]['#value'] = $preferred_layer;
3582

    
3583
  return $element;
3584
}
3585

    
3586
function radios_prepare_options_suffix(&$elements){
3587

    
3588
  $childrenKeys = element_children($elements);
3589
  foreach($childrenKeys as $key){
3590
    if(!is_array($elements[$key]['#theme_wrappers'])){
3591
      $elements[$key]['#theme_wrappers'] = array();
3592
    }
3593
    if(isset($elements['#options_suffixes'][$key])){
3594
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3595
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3596
    }
3597
  }
3598
  return $elements;
3599

    
3600
}
3601

    
3602
/**
3603
 * TODO
3604
 * @param unknown $variables
3605
 */
3606
function theme_radio_options_suffix($variables) {
3607
  $element = $variables['element'];
3608
  if(isset($element['#options_suffix'])) {
3609
    $element['#children'] .= $element['#options_suffix'];
3610
  }
3611
  return $element['#children'];
3612
}
3613

    
3614

    
3615
/**
3616
 * Element validate callback for text field and arrays containing json.
3617
 *
3618
 * @param $element
3619
 *   The form element to validate
3620
 * @param $form_state
3621
 *   A keyed array containing the current state of the form.
3622
 * @param $form
3623
 *   Nested array of form elements that comprise the form.
3624
 */
3625
function form_element_validate_json($element, &$form_state, $form) {
3626
   if (!empty($element['#value'])) {
3627
     json_decode($element['#value']);
3628
     if(json_last_error() != JSON_ERROR_NONE){
3629
       form_error($element,
3630
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3631
         . l('JSONLint', 'http://jsonlint.com/')
3632
       );
3633
     }
3634
   }
3635
}
3636

    
3637
/**
3638
 * Form submission handler for textareas and textfields containing JSON.
3639
 *
3640
 * The contained JSON will be converted into an php array
3641
 * or object and will be stored in the variables as such.
3642
 *
3643
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3644
 *
3645
 * @param $form
3646
 *   Nested array of form elements that comprise the form.
3647
 * @param $form_state
3648
 *   A keyed array containing the current state of the form.
3649
 *
3650
 */
3651
function submit_json_as_php_array($form, &$form_state) {
3652
  if (is_array($form['#json_elements'])) {
3653
    foreach ($form['#json_elements'] as $element){
3654
      if (trim($form_state['values'][$element])) {
3655
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3656
      } else {
3657
        $form_state['values'][$element] = NULL;
3658
      }
3659
    }
3660
  }
3661
}
(16-16/16)