Project

General

Profile

Download (143 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_TAXON_AUTO_SUGGEST', 0);
26
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 1);
27
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
28
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
29
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
30
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
31

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

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

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

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

    
54

    
55

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

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

    
102

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

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

    
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_DEFAULT', serialize(
133
  array(
134
    'general' => '-3',
135
    'synonymy' => '-2',
136
    'images' => '0',
137
    'specimens' => '1',
138
    'keys' => '3',
139
    'experts' => '5',
140
    )
141
));
142

    
143
$taxon_tab_options = get_taxon_tabs_list();
144
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
145

    
146
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
147

    
148
/**
149
 * @todo document this function.
150
 */
151
function get_taxon_options_list() {
152
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
153
  foreach ($taxon_tab_options as $key => $value) {
154
    $taxon_tab_options[$key] = t($key);
155
  }
156
  return $taxon_tab_options;
157

    
158
}
159

    
160
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
161
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
162
  array(
163
      'ZoologicalName' => array(
164
        'namePart' => array('name' => TRUE),
165
        'nameAuthorPart' => array('name' => TRUE),
166
        'referencePart' => array('authors' => TRUE),
167
        'microreferencePart' => array('microreference' => TRUE),
168
        'secReferencePart' => array('secReference' => TRUE,),
169
        'statusPart' => array('status' => TRUE),
170
        'descriptionPart' => array('description' => TRUE),
171
      ),
172
      'BotanicalName'=> array(
173
        'namePart' => array('name' => TRUE),
174
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
175
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
176
        'secReferencePart' => array('secReference' => TRUE,),
177
        'referenceYearPart' => array('reference.year' => TRUE),
178
        'statusPart' => array('status' => TRUE),
179
        'descriptionPart' => array('description' => TRUE),
180
      ),
181
     '#DEFAULT' => array(
182
        'namePart' => array(
183
            'name' => TRUE
184
        ),
185
        'nameAuthorPart' => array(
186
            'name' => TRUE,
187
            'authors' => TRUE
188
        ),
189
       'referencePart' => array(
190
         'reference' => TRUE
191
        ),
192
       'secReferencePart' => array(
193
         'secReference' => TRUE,
194
       ),
195
       'microreferencePart' => array(
196
          'microreference' => TRUE,
197
        ),
198
       'statusPart' => array(
199
          'status' => TRUE,
200
        ),
201
       'descriptionPart' => array(
202
          'description' => TRUE,
203
        ),
204
      )
205
    )
206
  )
207
);
208
  define('CDM_PART_DEFINITIONS_DEFAULT_PRE_380', serialize(
209
    array(
210
      'ZoologicalName' => array(
211
        'namePart' => array('name' => TRUE),
212
        'nameAuthorPart' => array('name' => TRUE),
213
        'referencePart' => array('authors' => TRUE),
214
        'microreferencePart' => array('microreference' => TRUE),
215
        'statusPart' => array('status' => TRUE),
216
        'descriptionPart' => array('description' => TRUE),
217
      ),
218
      'BotanicalName'=> array(
219
        'namePart' => array('name' => TRUE),
220
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
221
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
222
        'referenceYearPart' => array('reference.year' => TRUE),
223
        'statusPart' => array('status' => TRUE),
224
        'descriptionPart' => array('description' => TRUE),
225
      ),
226
      '#DEFAULT' => array(
227
        'namePart' => array(
228
          'name' => TRUE
229
        ),
230
        'nameAuthorPart' => array(
231
          'name' => TRUE,
232
          'authors' => TRUE
233
        ),
234
        'referencePart' => array(
235
          'reference' => TRUE
236
        ),
237
        'microreferencePart' => array(
238
          'microreference' => TRUE,
239
        ),
240
        'statusPart' => array(
241
          'status' => TRUE,
242
        ),
243
        'descriptionPart' => array(
244
          'description' => TRUE,
245
        ),
246
      )
247
    )
248
  )
249
  );
250

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

    
325
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
326
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
327
    // to unset a default enntry set the value to 0
328
    array(
329
      'doTaxa'=>'doTaxa',
330
      'doSynonyms' => 'doSynonyms',
331
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
332
      'doMisappliedNames' => 'doMisappliedNames'
333
    )
334
  )
335
);
336

    
337
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
338

    
339
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
340
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
341

    
342
/* Gallery variables. */
343
$gallery_settings = array(
344
    "cdm_dataportal_show_taxon_thumbnails" => 1,
345
    "cdm_dataportal_show_synonym_thumbnails" => 0,
346
    "cdm_dataportal_show_thumbnail_captions" => 1,
347
    "cdm_dataportal_media_maxextend" => 120,
348
    "cdm_dataportal_media_cols" => 3,
349
    "cdm_dataportal_media_maxRows" => 1,
350
);
351

    
352
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
353
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
354
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
355
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
356
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
357
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
358
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
359
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
360
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
361
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
362
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
363
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
364

    
365
/**
366
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
367
 * the snonymy.
368
 *
369
 * @var string
370
 */
371
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
372

    
373
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
374
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
375
    array(
376
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
377
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
378
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
379
    )
380
  )
381
);
382

    
383
/**
384
 * The drupal variable for the configuration of the information aggregation along
385
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
386
 *    - direct: the uuids of the taxon relationship types to take into account in invers
387
 *      direction.
388
 *    - invers: the uuids of the taxon relationship types to take into account in direct
389
 *      direction.
390
 *
391
 * @var String
392
 */
393
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
394
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
395
    array(
396
        'direct'=>array(),
397
        'invers'=>array()
398
     )
399
   ));
400
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
401
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
402
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
403

    
404
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
405
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
406
      array(
407
      'filter_rules' => array(
408
        'statusOrderPreference' => 0,
409
        'subAreaPreference' => 0,
410
      ),
411
      'hiddenAreaMarkerType' => array()
412
     )
413
));
414

    
415
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
416
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
417
  "level_0" => array(
418
    'label_suffix' => ':',
419
    'item_glue' => ' ',
420
    'item_group_prefix' => '',
421
    'item_group_postfix' => ''
422
  ),
423
  "level_1" => array(
424
    'label_suffix' => '',
425
    'item_glue' => '; ',
426
    'item_group_prefix' => ', ',
427
    'item_group_postfix' => ''
428
  ),
429
  "level_2" => array(
430
    'label_suffix' => '',
431
    'item_glue' => ', ',
432
    'item_group_prefix' => ' (',
433
    'item_group_postfix' => ')'
434
  )
435
)));
436

    
437
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
438
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
439
    array(
440
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
441
        'includeOccurrences' => 0,
442
        'includeTaxonNameDescriptions' => 0
443
     )
444
  ));
445

    
446
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
447
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
448
  // needs to be merged with user setting by drupal_array_merge_deep()
449
  // 'width' => 512, // optimum size for OSM layers is 512
450
  // 'height' => 512 / 2, // optimum size for OSM layers 256
451
  'aspect_ratio' => 2,
452
  'bbox' => '', // empty to allow automatic zooming to extend
453
  'show_labels' => FALSE,
454
  'caption' => '',
455
  'distribution_opacity' => '0.5',
456
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
457
  'image_map' => array(
458
    'base_layer' => '', // none, formerly this was cyprusdivs
459
    'bg_color' => '1874CD',
460
    'layer_style' => 'ffffff,606060,,',
461
  ),
462
  'openlayers' => array(
463
    'base_layers' =>  array(
464
      // A layer MUST NOT BE SET in the defaults,
465
      // otherwise it can not be overidden by the user settings:
466
      // 'mapproxy_vmap0' => 'mapproxy_vmap0',
467
      // it is sufficient to define the preferred layer,
468
      // since it will automatically be enabled:
469
      'PREFERRED' => 'mapproxy_vmap0'),
470
    'custom_wms_base_layer' => array(
471
      'name' => NULL,
472
      'url' => NULL,
473
      'params' =>  NULL,
474
      'projection' => NULL,
475
      'proj4js_def' => NULL,
476
      'max_extent' => NULL,
477
      'units' => NULL
478
    ),
479
    'show_layer_switcher' => TRUE,
480
    'display_outside_max_extent' => FALSE
481
  ),
482
  'legend' => array(
483
    'show' => TRUE,
484
    'opacity' => '0.5',
485
    'font_size' => 10,
486
    'font_style' => FALSE,
487
    'icon_width' => 35,
488
    'icon_height' => 15
489
  )
490
)));
491

    
492
/**
493
 * Merges the named array variable with the array of defaults.
494
 *
495
 * IMPORTANT: The array keys must be strings. When the keys are integers
496
 * the merging will not take place for these entities. Number keyed entities
497
 * are just appended to the result array.
498
 *
499
 * @param string $variable_name
500
 *     The variable name
501
 * @param string | array $default
502
 *     The array containing the default values either as array or serialized as string.
503
 *     Unserialization is cared for if necessary
504
 * @return array
505
 *     The merged array as returned by drupal_array_merge_deep()
506
 *
507
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
508
 * TODO force $default being an array
509
 */
510
function get_array_variable_merged($variable_name, $default){
511

    
512
    // unserialize if nessecary
513
    if(!is_array($default)){
514
      $default = unserialize($default);
515
    }
516
    $variable = variable_get($variable_name, array());
517
    $result = drupal_array_merge_deep($default, $variable);
518
    return $result;
519
}
520

    
521
/**
522
 * @todo document this function.
523
 */
524
function getGallerySettings($gallery_config_form_name) {
525
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
526
}
527

    
528
/**
529
 * Returns the string representation of the default tab.
530
 *
531
 * @param bool $returnTabIndex
532
 *   Defaults to FALSE, if set true this function will return the index number
533
 *   of the default tab. (used to supply default values to form elements).
534
 */
535
function get_default_taxon_tab($returnTabIndex = FALSE) {
536

    
537
  global $user;
538
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
539
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
540
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
541
  // Get the user value if the used has chosen to overwrite the system settings.
542
  $user_tab_on = variable_get($user_tab_active, FALSE);
543
  if ($user_tab_on) {
544
    $user_value = variable_get($user_tab, 0);
545
    $index_value = $user_value;
546
    // Get the system value.
547
  }
548
  else {
549
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
550
    $index_value = $system_value;
551
  }
552

    
553
  // Return the index value or the string representation.
554
  if ($returnTabIndex) {
555
    return $index_value;
556
  }
557
  else {
558
    return ($values[$index_value]);
559
  }
560
}
561

    
562

    
563
  /**
564
   * Provides the feature block settings for a specific feature which matches the $feature_uuid parameter.
565
   *
566
   * In case specifically configured settings array, like these which are stored in the drupal variables, is missing
567
   * one or more fields these fields are taken from the default. That is the specific settings are always merges
568
   * with the default.
569
   *
570
   * Note: These settings only apply to feature blocks which do not have a special rendering
571
   * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
572
   * 'special' element of the settings
573
   *
574
   * @param $feature_uuid
575
   *   The uuid string representation of the feature to return the settings for
576
   *
577
   * @return array
578
   *  an associative array of settings, with the following fields:
579
   *    - as_list: string
580
   *        this setting will be used in compose_feature_block_wrap_elements() as $enclosing_tag
581
   *        possible values are:
582
   *          div: not as list,
583
   *          ul: as bullet list,
584
   *          ol: as numbered list,
585
   *          dl: as definition list
586
   *        The tag used for the inner element, thus depends on the value of this field. The
587
   *        inner tag name can be retrieved by the function cdm_feature_block_element_tag_name()
588
   *    - link_to_reference: boolean,
589
   *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
590
   *    - link_to_name_used_in_source": boolean
591
   *        whether to show name is source information as link which will point to the according name page
592
   *    - sources_as_content (boolean)
593
   *        TRUE (int: 1):
594
   *          1. If element is of the CDM type TextData and the text is not empty the source references will be
595
   *             appended in brackets like "text (source references)". If the original source has name in source
596
   *             information it will be appended to the citation string,
597
   *             like : "(citation, as name in source; citation, as name in source)"
598
   *          2. if the text of the TextData is empty, the original source citations are the only content
599
   *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
600
   *             prepended to the citation string like: "name in source: citation"
601
   *        FALSE (int: 0):
602
   *          Original sources are put into the bibliography(=references) pseudo feature block. If the original source
603
   *          citations are the only content, the resulting feature block content would only consist of footnotes.
604
   *          In this case the display of the respective feature block is suppressed.
605
   *          TODO if the bibliography is not enabled the sources will be treated as footnotes like annotations,
606
   *               in future however they will in this case be shown in a separate references section for each
607
   *               feature block.
608
   *    - sources_as_content_to_bibliography  (boolean)
609
   *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
610
   *        in the bibliography.
611
   *    - sort_elements
612
   *        whether and how to sort the elements
613
   *        possible values are the constants SORT_ASC, SORT_DESC, NULL,
614
   *        some feature types (Distribution) also support: SORT_HIERARCHICAL (
615
   *        TODO option to exclude levels, put in special?,
616
   *        TODO make use of this setting in compose_feature_block_wrap_elements())
617
   *    - element_tag
618
   *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
619
   *        possible values are span | div. the proper inner tag name can be retrieved by the function
620
   *        cdm_feature_block_element_tag_name()
621
   *    - special: array()
622
   *        an array with further settings, this field can be used for special
623
   *        settings for specialized rendering like for distributions
624
   *  }
625
   *
626
   */
627
  function get_feature_block_settings($feature_uuid = 'DEFAULT') {
628
    // the default must conform to the default parameter values of
629
    // compose_feature_block_wrap_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
630
    // compose_description_element_text_data() : asListElement = NULL
631

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

    
634
    // ---- DEFAULTS settings
635

    
636
    // only needed as final option, when the settings are not having a default
637
    $default = array(
638
      'DEFAULT' => array(
639
        'as_list' => 'div',
640
        'link_to_reference' => 0,
641
        'link_to_name_used_in_source' => 1,
642
        'sources_as_content' => 0,
643
        'sources_as_content_to_bibliography' => 0,
644
        'sort_elements' => NO_SORT,
645
        'glue' => '',
646
        'element_tag' => NULL
647
      )
648
    );
649

    
650
    // will be used as preset in the settings
651
    $other_themes_default = array(
652
      'DEFAULT' => array(
653
        'as_list' => 'div',
654
        'link_to_reference' => 0,
655
        'link_to_name_used_in_source' => 1,
656
        'sources_as_content' => 0,
657
        'sources_as_content_to_bibliography' => 0,
658
        'sort_elements' => NO_SORT,
659
        'glue' => '',
660
        'element_tag' => NULL
661
      ),
662
      UUID_CITATION => array(
663
        'as_list' => 'div',
664
        'link_to_reference' => 0,
665
        'link_to_name_used_in_source' => 0,
666
        'sources_as_content' => 1,
667
        'sources_as_content_to_bibliography' => 0,
668
        'sort_elements' => SORT_ASC,
669
        'glue' => '',
670
        'element_tag' => 'div'
671
      ),
672
      UUID_DISTRIBUTION => array(
673
        'as_list' => 'div', // currently ignored
674
        'link_to_reference' => 0,
675
        'link_to_name_used_in_source' => 0,
676
        'sources_as_content' => 0,
677
        'sources_as_content_to_bibliography' => 0,
678
        'sort_elements' => NO_SORT, // will cause ...
679
        'glue' => '',
680
        'element_tag' => 'div',
681
        'special' => array()
682
      ),
683
      UUID_COMMON_NAME => array(
684
        'as_list' => 'div',
685
        'link_to_reference' => 0,
686
        'link_to_name_used_in_source' => 1,
687
        'sources_as_content' => 0,
688
        'sources_as_content_to_bibliography' => 0,
689
        'sort_elements' => NO_SORT,
690
        'glue' => '',
691
        'element_tag' => 'span'
692
      ),
693
    );
694

    
695
    // ---- Special DEFAULTS for existing portals
696
    // TODO:
697
    // this can be removed once the feature block
698
    // settings have been deployed for the first time to these portals
699

    
700
    $cichorieae_default = array(
701
      'DEFAULT' => array(
702
        'as_list' => 'div',
703
        'link_to_reference' => 1,
704
        'link_to_name_used_in_source' => 1,
705
        'sources_as_content' => 1,
706
        'sources_as_content_to_bibliography' => 0,
707
        'sort_elements' => NO_SORT,
708
        'glue' => '',
709
        'element_tag' => 'div'
710
      ),
711
      UUID_CITATION => array(
712
        'as_list' => 'div',
713
        'link_to_reference' => 0,
714
        'link_to_name_used_in_source' => 0,
715
        'sources_as_content' => 1,
716
        'sources_as_content_to_bibliography' => 0,
717
        'sort_elements' => SORT_ASC,
718
        'glue' => '',
719
        'element_tag' => 'div'
720
      ),
721
      UUID_CHROMOSOMES_NUMBERS => array(
722
        'as_list' => 'ul',
723
        'link_to_reference' => 1,
724
        'link_to_name_used_in_source' => 1,
725
        'sources_as_content' => 1,
726
        'sources_as_content_to_bibliography' => 0,
727
        'sort_elements' => NO_SORT,
728
        'glue' => '',
729
        'element_tag' => 'div'
730
      ),
731
      UUID_CHROMOSOMES => array(
732
        'as_list' => 'ul',
733
        'link_to_reference' => 0,
734
        'link_to_name_used_in_source' => 1,
735
        'sources_as_content' => 1,
736
        'sources_as_content_to_bibliography' => 0,
737
        'sort_elements' => NO_SORT,
738
        'glue' => '',
739
        'element_tag' => 'div'
740
      ),
741
      UUID_COMMON_NAME => array(
742
        'as_list' => 'div',
743
        'link_to_reference' => 0,
744
        'link_to_name_used_in_source' => 1,
745
        'sources_as_content' => 0,
746
        'sources_as_content_to_bibliography' => 0,
747
        'sort_elements' => NO_SORT,
748
        'glue' => '',
749
        'element_tag' => 'span'
750
      ),
751
    );
752

    
753
    $palmweb_default = array(
754
      'DEFAULT' => array(
755
        'as_list' => 'ul',
756
        'link_to_reference' => 1,
757
        'link_to_name_used_in_source' => 1,
758
        'sources_as_content' => 1,
759
        'sources_as_content_to_bibliography' => 1,
760
        'sort_elements' => NO_SORT,
761
        'glue' => '',
762
        'element_tag' => NULL
763
      ),
764
      UUID_CITATION => array(
765
        'as_list' => 'ul',
766
        'link_to_reference' => 1,
767
        'link_to_name_used_in_source' => 1,
768
        'sources_as_content' => 0,
769
        'sources_as_content_to_bibliography' => 1,
770
        'sort_elements' => SORT_ASC,
771
        'glue' => '',
772
        'element_tag' => 'div'
773
      ),
774
      UUID_DISTRIBUTION => array(
775
        'as_list' => 'div', // currently ignored
776
        'link_to_reference' => 1,
777
        'link_to_name_used_in_source' => 1,
778
        'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
779
        'sources_as_content_to_bibliography' => 1,
780
        'sort_elements' => NO_SORT, // will cause ...
781
        'glue' => '',
782
        'element_tag' => 'div',
783
        'special' => array()
784
      ),
785
    );
786

    
787
    $cyprus_default = $cichorieae_default;
788
    $cyprus_default[UUID_DISTRIBUTION] = array(
789
      'as_list' => 'div', // currently ignored
790
      'link_to_reference' => 0,
791
      'link_to_name_used_in_source' => 0,
792
      'sources_as_content' => 0,
793
      'sources_as_content_to_bibliography' => 0,
794
      'sort_elements' => NO_SORT, // will cause ...
795
      'glue' => '',
796
      'element_tag' => 'div',
797
      'special' => array()
798
    );
799

    
800
    $default_theme = variable_get('theme_default', NULL);
801

    
802
    switch ($default_theme) {
803
      case 'garland_cichorieae':
804
        $settings_for_theme = $cichorieae_default;
805
        break;
806
      case 'cyprus':
807
        // cyprus: no longer used in production,
808
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
809
        $settings_for_theme = $cyprus_default;
810
        break;
811
      case 'flore_afrique_centrale':
812
      case 'flora_malesiana':
813
      case 'flore_gabon':
814
        $settings_for_theme = $cichorieae_default;
815
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
816
        break;
817
      case 'palmweb_2':
818
        $settings_for_theme = $palmweb_default;
819
        break;
820
      default:
821
        $settings_for_theme = $other_themes_default;
822
    }
823
    // ---- END of DEFAULTS
824

    
825
    $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
826

    
827
    $feature_block_setting = null;
828

    
829
    if (isset($saved_settings[$feature_uuid])) {
830
      $feature_block_setting = $saved_settings[$feature_uuid];
831
    }
832
    else if (isset($settings_for_theme[$feature_uuid])) {
833
      $feature_block_setting = $settings_for_theme[$feature_uuid];
834
    }
835
    else if (isset($settings_for_theme['DEFAULT'])) {
836
      $feature_block_setting = $settings_for_theme['DEFAULT'];
837
    }
838

    
839
    // now merge the default and specific settings
840
    $settings_to_merge = array($default['DEFAULT']);
841
    if(is_array($saved_settings)){
842
      $settings_to_merge[] = $saved_settings['DEFAULT'];
843
    }
844
    if(isset($feature_block_setting)){
845
      $settings_to_merge[] = $feature_block_setting;
846
    }
847
    $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
848

    
849
    return $feature_block_setting;
850
}
851
  /**
852
 * returns the current setting for the original source bibliography
853
 *
854
 * Caches internally
855
 *
856
 * @return array
857
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
858
 *   - 'enabled': 1|0
859
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
860
 */
861
function get_bibliography_settings($clear_cache = false){
862
  static $bibliography_settings = null;
863
  if(!$bibliography_settings || $clear_cache){
864
    $bibliography_settings = get_array_variable_merged(
865
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
866
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
867
    );
868
  }
869
  return $bibliography_settings;
870
}
871

    
872
/**
873
 * @todo Please document this function.
874
 * @see http://drupal.org/node/1354
875
 */
876
function cdm_dataportal_menu_admin(&$items) {
877
  // Display section on admin/config page.
878
  $items['admin/config/cdm_dataportal'] = array(
879
    'title' => 'CDM Dataportal',
880
    'description' => 'Settings for the CDM DataPortal.',
881
    'position' => 'right',
882
    'weight' => 10,
883
    'page callback' => 'system_admin_menu_block_page',
884
    'access arguments' => array('administer cdm_dataportal'),
885
    'file' => 'system.admin.inc',
886
    'file path' => drupal_get_path('module', 'system'),
887
  );
888
  $items['admin/config/cdm_dataportal/settings'] = array(
889
    'title' => 'Settings',
890
    'description' => 'Settings for the CDM DataPortal.',
891
    'weight' => 0,
892
    'page callback' => 'drupal_get_form',
893
    'page arguments' => array('cdm_settings_general'),
894
    'access arguments' => array('administer cdm_dataportal'),
895
    'type' => MENU_NORMAL_ITEM,
896
  );
897
  $items['admin/config/cdm_dataportal/settings/general'] = array(
898
    'title' => 'General',
899
    'description' => 'General',
900
    'weight' => 0,
901
    'page callback' => 'drupal_get_form',
902
    'page arguments' => array('cdm_settings_general'),
903
    'access arguments' => array('administer cdm_dataportal'),
904
    'type' => MENU_DEFAULT_LOCAL_TASK,
905
  );
906

    
907
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
908
    'title' => 'Cache',
909
    'description' => 'Cache',
910
    'access arguments' => array('administer cdm_dataportal'),
911
    'page callback' => 'drupal_get_form',
912
    'page arguments' => array('cdm_settings_cache'),
913
    'weight' => 10,
914
    'type' => MENU_LOCAL_TASK,
915
  );
916

    
917
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
918
    'title' => 'Geo & Map',
919
    'description' => 'Geo & Map',
920
    'access arguments' => array('administer cdm_dataportal'),
921
    'page callback' => 'drupal_get_form',
922
    'page arguments' => array('cdm_settings_geo'),
923
    'weight' => 1,
924
    'type' => MENU_LOCAL_TASK,
925
  );
926

    
927
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
928
    'title' => 'Layout',
929
    'description' => 'Configure and adjust the layout of your DataPortal ',
930
    'access arguments' => array('administer cdm_dataportal'),
931
    'page callback' => 'drupal_get_form',
932
    'page arguments' => array('cdm_settings_layout'),
933
    'weight' => 2,
934
    'type' => MENU_LOCAL_TASK,
935
  );
936

    
937
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
938
    'title' => 'Taxon',
939
    'description' => 'Configure and adjust the layout of your DataPortal ',
940
    'access arguments' => array('administer cdm_dataportal'),
941
    'page callback' => 'drupal_get_form',
942
    'page arguments' => array('cdm_settings_layout_taxon'),
943
    'weight' => 1,
944
    'type' => MENU_LOCAL_TASK,
945
  );
946
  /*
947
  $items[] = array(
948
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
949
  'title' => t('Synonymy'),
950
  'description' => t('Configure and adjust the layout of your DataPortal '),
951
  'access' => user_access('administer cdm_dataportal'),
952
  'callback' => 'drupal_get_form',
953
  'callback arguments' => array('cdm_settings_layout_synonymy'),
954
  'weight' => 1,
955
  'type' => MENU_LOCAL_TASK,
956
  );
957

    
958
  $items[] = array(
959
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
960
  'title' => t('Specimens'),
961
  'description' => t('Configure and adjust the layout of your DataPortal '),
962
  'access' => user_access('administer cdm_dataportal'),
963
  'callback' => 'drupal_get_form',
964
  'callback arguments' => array('cdm_settings_layout_specimens'),
965
  'weight' => 1,
966
  'type' => MENU_LOCAL_TASK,
967
  );
968
  */
969
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
970
    'title' => 'Search',
971
    'description' => 'Configure and adjust the layout of your DataPortal ',
972
    'access arguments' => array('administer cdm_dataportal'),
973
    'page callback' => 'drupal_get_form',
974
    'page arguments' => array('cdm_settings_layout_search'),
975
    'weight' => 2,
976
    'type' => MENU_LOCAL_TASK,
977
  );
978

    
979
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
980
    'title' => 'Media',
981
    'description' => 'Configure and adjust the layout of your DataPortal ',
982
    'access arguments' => array('administer cdm_dataportal'),
983
    'page callback' => 'drupal_get_form',
984
    'page arguments' => array('cdm_settings_layout_media'),
985
    'weight' => 3,
986
    'type' => MENU_LOCAL_TASK,
987
  );
988

    
989
}
990

    
991
/**
992
 * @todo document this function.
993
 */
994
function cdm_help_general_cache() {
995
  $form = array();
996
  $form['cache_help'] = array(
997
    '#type' => 'fieldset',
998
    '#title' => t('Help'),
999
    '#collapsible' => TRUE,
1000
    '#collapsed' => TRUE,
1001
  );
1002
  $form['cache_help']['test'] = array('#value' => t('probando'));
1003
  return drupal_render($form);
1004
  $res = array();
1005
  $res['default'] = drupal_render($help);
1006
  return $res;
1007
}
1008

    
1009
/**
1010
 * Configures the settings form for the CDM-API module.
1011
 *
1012
 * @return array
1013
 *   Drupal settings form.
1014
 */
1015
function cdm_settings_general() {
1016

    
1017
  $form['cdm_webservice'] = array(
1018
    '#type' => 'fieldset',
1019
    '#title' => t('CDM Server'),
1020
    '#collapsible' => FALSE,
1021
    '#collapsed' => FALSE,
1022
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1023
        CDM data base to the web via RESTful web services and thus is the source of the data
1024
        to be displayed by a CDM DataPotal.'),
1025
  );
1026

    
1027
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1028
    '#type' => 'textfield',
1029
    '#title' => t('CDM web service URL') . ':',
1030
    '#description' => t('This is the URL to the CDM-Server exposing your data
1031
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1032
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1033
  );
1034

    
1035
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1036
    '#type' => 'markup',
1037
    '#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')
1038
      . ' visible only for administrators',
1039
  );
1040

    
1041
  $form['cdm_webservice']['freetext_index'] = array(
1042
    '#type' => 'fieldset',
1043
    '#title' => t('Freetext index'),
1044
    '#collapsible' => FALSE,
1045
    '#collapsed' => FALSE,
1046
  );
1047

    
1048
  // Check the cdmserver port number and display a waring if it is not port 80
1049
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1050
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1051
    $form['cdm_webservice']['freetext_index']['message'] = array(
1052
      '#markup' => "<div class=\"description\">"
1053
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'."
1054
      . " Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server."
1055
      . " You may want to contact the maintainer of the according CDM Server in order to solve this problem.", array('!port' => $portNumberMatch[1][0]))
1056
      . "</div>",
1057
    );
1058
  };
1059

    
1060
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1061
  $trigger_link_options = array(
1062
    'attributes' => array(
1063
      'class' => 'index-trigger',
1064
    ),
1065
  );
1066
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1067
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1068
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1069
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1070
      ))
1071
    . '<div id="index-progress"></div></div>',
1072
  );
1073
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1074

    
1075
    $form['cdm_webservice']['freetext_index']['cdm_dataportal_taxon_auto_suggest'] = array(
1076
        '#type' => 'checkbox',
1077
        '#title' => t('Enable auto-suggest for taxon search'),
1078
        '#default_value' => variable_get('cdm_dataportal_taxon_auto_suggest', CDM_DATAPORTAL_TAXON_AUTO_SUGGEST),
1079
        '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
1080
        This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
1081
    );
1082

    
1083
  $form['cdm_webservice']['proxy'] = array(
1084
    '#type' => 'fieldset',
1085
    '#title' => t('Proxy'),
1086
    '#collapsible' => TRUE,
1087
    '#collapsed' => TRUE,
1088
  );
1089

    
1090
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1091
    '#type' => 'textfield',
1092
    '#title' => t('Proxy URL') . ':',
1093
    '#description' => t('If this proxy url is set the cdm api tries
1094
    to connect the web service over the given proxy server.
1095
    Otherwise proxy usage is deactivated.'),
1096
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1097
  );
1098

    
1099
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1100
    '#type' => 'textfield',
1101
    '#title' => t('Proxy port') . ':',
1102
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1103
  );
1104

    
1105
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1106
    '#type' => 'textfield',
1107
    '#title' => t('Login') . ':',
1108
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1109
  );
1110

    
1111
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1112
    '#type' => 'textfield',
1113
    '#title' => t('Password') . ':',
1114
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1115
  );
1116

    
1117
  // TODO: settings are still incomplete, compare with
1118
  // trunk/dataportal/inc/config_default.php.inc.
1119
  $form['taxon_tree'] = array(
1120
    '#type' => 'fieldset',
1121
    '#title' => t('Taxon Tree'),
1122
    '#collapsible' => FALSE,
1123
    '#collapsed' => TRUE,
1124
    '#description' => t('<p>When you explore your collection, you can navigate
1125
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1126
      able to navigate through your collection the
1127
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1128
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1129
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1130
      </a></p>'),
1131
  );
1132

    
1133
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1134
    '#type' => 'select',
1135
    '#title' => t('Available classifications') . ':',
1136
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1137
    '#options' => cdm_get_taxontrees_as_options(),
1138
    '#description' => t('Select the default taxa classification for your
1139
      <em>taxon tree</em>, the other classifications will be also available but
1140
      with a manual user change.'),
1141
  );
1142

    
1143
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1144
    '#type' => 'select',
1145
    '#title' => t('Rank of highest displayed taxon') . ':',
1146
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1147
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1148
    '#options' => cdm_rankVocabulary_as_option(),
1149
    '#description' => t('This is the rank of the highest displayed taxon in the
1150
      <em>taxon tree</em>. You can select here which rank should be at the top
1151
      level of the tree structure.'),
1152
  );
1153

    
1154
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1155
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1156
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1157
      '#type' => 'checkboxes',
1158
      '#title' => t('Included Classifications') . ':',
1159
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1160
      '#options' => cdm_get_taxontrees_as_options(),
1161
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1162
  );
1163

    
1164
  $form['distribution'] = array(
1165
      '#type' => 'fieldset',
1166
      '#title' => t('Distributions'),
1167
      '#collapsible' => FALSE,
1168
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1169
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1170
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1171
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1172
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1173
          '<p>
1174
          </p>',
1175
  );
1176

    
1177
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1178
      '#type' => 'fieldset',
1179
      '#title' => 'Distribution filter',
1180
      '#collapsible' => FALSE,
1181
      '#collapsed' => FALSE,
1182
      '#tree' => TRUE,
1183
      '#description' => 'The Distribution filter offers the following options
1184
      <ul>
1185
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1186
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1187
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1188
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1189
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1190
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1191
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1192
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1193
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1194
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1195
      </ul>'
1196
  );
1197

    
1198
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1199
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1200
      '#type' => 'checkboxes',
1201
      '#title' => 'Filter rules',
1202
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1203
      '#options' => array(
1204
          'statusOrderPreference' => 'Status order preference rule',
1205
          'subAreaPreference' => 'Sub area preference rule'
1206
      ),
1207
  );
1208

    
1209
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1210
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1211
      '#type' => 'checkboxes',
1212
      '#title' => 'Hide marked area filter',
1213
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1214
      '#options' => $marker_type_options,
1215
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1216
  );
1217

    
1218
  $form['aggregation'] = array(
1219
      '#type' => 'fieldset',
1220
      '#title' => t('Aggregation of data'),
1221
      '#collapsible' => FALSE,
1222
      '#description' => 'This section covers the different aspects of aggregating information.
1223
          <p>
1224
          </p>',
1225
  );
1226

    
1227
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1228
      '#type' => 'checkboxes',
1229
      '#title' => 'Taxon media filter',
1230
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1231
      '#options' => array(
1232
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1233
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1234
          'includeOccurrences' => 'Media related to specimens and occurrences',
1235
      ),
1236
      '#description' => 'This filter configures which images should be taken into account.',
1237
  );
1238

    
1239
  $form['aggregation']['notice'] = array(
1240
      '#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
1241
          want to make use of the caching capabilities of the dataportal.',
1242
  );
1243

    
1244
  $form['aggregation']['media_aggregation'] = array(
1245
      '#type' => 'fieldset',
1246
      '#title' => t('Media aggregation'),
1247
      '#collapsible' => FALSE,
1248
      '#collapsed' => TRUE,
1249
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1250

    
1251
  );
1252
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1253
      '#type' => 'select',
1254
      '#title' => t('Aggregation of taxon pictures') . ':',
1255
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1256
      '#options' => array(
1257
          0 => "Show only pictures of the current taxon",
1258
          1 => "Include pictures of taxonomic children",
1259
      ),
1260
      '#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."),
1261
  );
1262

    
1263
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1264
      '#type' => 'fieldset',
1265
      '#attributes' => array('class' => array('clearfix')),
1266
      '#title' => t('Aggregation via taxon relationsships'),
1267
      '#collapsible' => TRUE,
1268
      '#collapsed' => TRUE,
1269
      '#tree' => TRUE,
1270
      '#description' => t('Information on taxa will be aggregated along the below chosen
1271
          taxon relation ships. This will affect images and occurrences (specimens).
1272
          Taxon relation ships are directed and point form one taxon to another. The taxon
1273
          relationships to be taken into accunt can therefore configured for the direct direction
1274
          and for the inverse.'),
1275
  );
1276

    
1277
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1278
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1279

    
1280
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1281
      '#type' => 'checkboxes',
1282
      '#title' => t('Direct'),
1283
      '#options' => $taxonRelationshipTypeOptions,
1284
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1285
  );
1286
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1287
      '#type' => 'checkboxes',
1288
      '#title' => t('Invers'),
1289
      '#options' => $taxonRelationshipTypeOptions,
1290
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1291
  );
1292

    
1293
  $form['drupal_integration'] = array(
1294
    '#type' => 'fieldset',
1295
    '#attributes' => array('class'=> array('clearfix')),
1296
    '#title' => t('Drupal integration'),
1297
    '#collapsible' => FALSE,
1298
    '#collapsed' => FALSE,
1299
    '#tree' => FALSE
1300
  );
1301

    
1302
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1303
    '#type' => 'checkbox',
1304
    '#title' => 'Create drupal nodes',
1305
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1306
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1307
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1308
    cdm pages it is required that drupal nodes are created and stored in the database.'
1309
  );
1310

    
1311

    
1312

    
1313
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1314
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1315
    <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>',
1316
  );
1317
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1318
    '#type' => 'submit',
1319
    '#value' => t('Drop all cdm nodes'),
1320
    '#submit' => array('drop_all_cdm_nodes_submit')
1321
  );
1322

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

    
1327
    // ----------------------
1328
  $form['cdm_js_devel_mode'] = array(
1329
      '#type' => 'checkbox',
1330
      '#title' => 'Java-script developer mode',
1331
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1332
      '#description' => 'In production envirionments the java script libraries
1333
      the cdm_dataportal is making use of are compressed and optimized. This
1334
      is good for performance but a caveat if you need to debug java-script. When the
1335
      java-script developer mode is enabled the uncompressed and commented developer
1336
      versions of java-script libraries will be used where possible.
1337
      <br/><strong>Do not use this option in production!</strong>'
1338
  );
1339
  // ----------------------
1340
  $form['cdm_debug_mode'] = array(
1341
      '#type' => 'checkbox',
1342
      '#title' => 'CDM page debug mode',
1343
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1344
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1345
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1346
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1347
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1348
      The log is written by the drupal devel module function <code>dd()</code>.
1349
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1350
  );
1351

    
1352
  // Comment @WA: D7 form api does not support reset buttons,
1353
  // so to mimic the D5 reset button we add one like this.
1354
  $form['actions']['reset'] = array(
1355
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1356
    '#weight' => 1000,
1357
  );
1358

    
1359
  $form['#submit'][] = 'cdm_settings_general_submit';
1360

    
1361
  return system_settings_form($form);
1362
}
1363

    
1364
/**
1365
 * Submit callback; drops all cdm nodes.
1366
 *
1367
 * @ingroup forms
1368
 */
1369
function drop_all_cdm_nodes_submit($form, &$form_state) {
1370
  cdm_delete_all_cdm_nodes();
1371
  drupal_set_message(t('All cdm nodes dropped.'));
1372
}
1373

    
1374

    
1375
/**
1376
 * LAYOUT settings
1377
 * @return
1378
 *   todo
1379
 */
1380
function cdm_settings_layout() {
1381

    
1382
  $form = array();
1383

    
1384
  $form['about'] = array(
1385
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1386
      layout. If you want to configure the specific sites layout visit the
1387
      respective configuration site for taxon, search or media.') . '</p>',
1388
  );
1389

    
1390
  // ---- footnotes --- //
1391
  $form['footnotes'] = array(
1392
    '#type' => 'fieldset',
1393
    '#title' => t('Footnotes'),
1394
    '#collapsible' => FALSE,
1395
    '#collapsed' => FALSE,
1396
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1397
      media or distribution areas may have annotations or footnotes. When the
1398
      footnotes are enabled they will be visible (if they exist).'),
1399
  );
1400

    
1401
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1402
    '#type' => 'checkbox',
1403
    '#title' => t('Do not show footnotes'),
1404
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1405
    '#description' => t('Check this if you do not want to show any footnotes'),
1406
  );
1407

    
1408
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1409
    '#type' => 'checkbox',
1410
    '#title' => t('Do not show annotation footnotes'),
1411
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1412
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1413
  );
1414

    
1415
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1416
  // Additional option for the NULL case.
1417
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1418
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1419
    '#type' => 'checkboxes',
1420
    '#title' => t('Annotation types as footnotes'),
1421
    '#description' => t("Only annotations of the selected type will be displayed
1422
       as footnotes. You may want to turn 'technical annotations' off."),
1423
    '#options' => $annotationTypeOptions,
1424
  );
1425
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1426
  if (!empty($annotationsTypesAsFootnotes)) {
1427
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1428
  }
1429

    
1430
  // ---- original source --- //
1431
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1432
      '#type' => 'fieldset',
1433
      '#tree' => TRUE,
1434
      '#title' => t('Source Citations'),
1435
      '#collapsible' => FALSE,
1436
      '#collapsed' => FALSE,
1437
  );
1438

    
1439
  $bibliography_settings = get_bibliography_settings(true);
1440

    
1441
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1442
      '#type' => 'checkbox',
1443
      '#title' => t('Original Source in bibliography'),
1444
      '#default_value' => $bibliography_settings['enabled'],
1445
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1446
       annotations in each feature block.'),
1447
  );
1448

    
1449
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1450
    '#type' => 'select',
1451
    '#title' => t('The format of the key numerals'),
1452
    '#default_value' => $bibliography_settings['key_format'],
1453
    '#options' => array('latin' => 'Latin',
1454
      'ROMAN' => 'Roman (upper case)',
1455
      'roman' => 'Roman (lower case)',
1456
      'ALPHA'=> 'Alphabet (upper case)',
1457
      'alpha' => 'Alphabet (lower case)')
1458
  );
1459

    
1460
  // --- Advanced Search --- //
1461
  $form['asearch'] = array(
1462
      '#type' => 'fieldset',
1463
      '#title' => t('Advanced search'),
1464
      '#collapsible' => FALSE,
1465
      '#collapsed' => FALSE,
1466
  );
1467
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1468
      '#type' => 'checkbox',
1469
      '#title' => t('Show advanced search link'),
1470
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1471
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1472
  );
1473

    
1474
  // ---- Taxon Name Rendering --- //
1475
  $form['taxon_name'] = array(
1476
      '#type' => 'fieldset',
1477
      '#title' => t('Taxon name display'),
1478
      '#collapsible' => TRUE,
1479
      '#collapsed' => TRUE,
1480
      '#description' => t('The display of taxon names is configured by two parts.'
1481
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
1482
          . 'The name parts are defined in the <stong>part definitions</strong>'),
1483
  );
1484

    
1485
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1486
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1487
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1488
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1489

    
1490
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1491
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1492
    $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.)';
1493
  } else if($is_custom_part_definition){
1494
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1495
  } else  {
1496
    $which_version_message = '(These are the default part definition.)';
1497
  }
1498

    
1499
  $diff_viewer_markup = '';
1500
  if($is_custom_part_definition){
1501
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1502
  }
1503

    
1504
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1505
    . $which_version_message
1506
    . '</div>'
1507
    . $diff_viewer_markup;
1508

    
1509
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1510
      '#type' => 'textarea',
1511
      '#title' => t('Part definitions'),
1512
      '#element_validate' => array('form_element_validate_json'),
1513
      '#default_value' =>  $current_part_definition_json,
1514
      '#description' => '
1515
          <p>' . $which_version_message . '</p>
1516
          <p>
1517
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1518
          </p>
1519
          <p>
1520
           A full taxon name plus additional information can consist of the following elements:
1521
          <ul>
1522
             <li>name: the taxon name inclugin rank nbut without author</li>
1523
             <li>authors:  The authors of a reference, also used in taxon names</li>
1524
             <li>reference: the nomenclatural reference,</li>
1525
             <li>microreference:  Volume, page number etc.</li>
1526
             <li>status:  The nomenclatural status of a name</li>
1527
             <li>description: name descriptions like protologues etc ...</li>
1528
          </ul>
1529
          </p>
1530
          <p>
1531
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1532
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1533
           The following parts can be formed and are recognized by the system:
1534
          <ul>
1535
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1536
            <li>authorshipPart: the author (for example: "L.")</li>
1537
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1538
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1539
               be combined when a link to the taxon is rendered.</li>
1540
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1541
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1542
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1543
            <li>statusPart: the nomenclatorical status</li>
1544
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1545
          </ul>
1546
          </p>
1547
          <p>
1548
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1549
           specific parts part definitions:
1550
          <ul>
1551
            <li>BotanicalName</li>
1552
            <li>ZoologicalName</li>
1553
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1554
          </ul>
1555
           An example:
1556
          <pre>
1557
           {
1558
            "ZoologicalName": {
1559
              "namePart": {
1560
                "name": true
1561
              },
1562
              "referencePart": {
1563
                "authors": true
1564
              },
1565
              "microreferencePart": {
1566
                "microreference": true
1567
              },
1568
              "statusPart": {
1569
                "status": true
1570
              },
1571
              "descriptionPart": {
1572
                "description": true
1573
              }
1574
            },
1575
            "BotanicalName": {
1576
              "namePart": {
1577
                "name": true,
1578
                "authors": true
1579
              },
1580
              "referencePart": {
1581
                "reference": true,
1582
                "microreference": true
1583
              },
1584
              "secReferencePart": {
1585
                "secReference": true
1586
              },
1587
              "statusPart": {
1588
                "status": true
1589
              },
1590
              "descriptionPart": {
1591
                "description": true
1592
              }
1593
            }
1594
          }
1595
           </pre>',
1596
  );
1597

    
1598
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1599
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1600
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1601
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1602
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1603

    
1604
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1605
    $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.)';
1606
  } else if($is_custom_render_template){
1607
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1608
  } else {
1609
    $which_version_message = '(These are the default render templates.)';
1610
  }
1611

    
1612
  $diff_viewer_markup = '';
1613
  if($is_custom_render_template){
1614
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1615
  }
1616

    
1617
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1618
    . $which_version_message
1619
    . '</div>'
1620
    . $diff_viewer_markup;
1621

    
1622
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1623
      '#type' => 'textarea',
1624
      '#title' => t('Name render templates'),
1625
      '#element_validate' => array('form_element_validate_json'),
1626
      '#default_value' =>  $current_render_templates_json,
1627
      '#description' => '
1628
          <p>' . $which_version_message . '</p>
1629
          <p>
1630
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1631
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1632
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1633
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1634
          The following render Path keys are currently recognized:
1635
          <ul>
1636
            <li>list_of_taxa</li>
1637
            <li>acceptedFor</li>
1638
            <li>homonym</li>
1639
            <li>taxon_page_synonymy</li>
1640
            <li>typedesignations</li>
1641
            <li>taxon_page_title</li>
1642
            <li>polytomousKey</li>
1643
            <li>na: name + authorship</li>
1644
            <li>nar:name + authorship + reference</li>
1645
            <li>#DEFAULT</li>
1646
          </ul>
1647
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1648
          array element should be a comma separated list of render paths, without any whitespace!.
1649
          </p>
1650
          <p>
1651
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1652
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1653
          <p>
1654
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1655
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1656
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1657
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1658
          links if the paramters $nameLink or $refenceLink are given to the name render function
1659
          (this is hard coded and cannot be configured here).',
1660
  );
1661

    
1662
  // @WA: D7 form api does not support reset buttons,
1663
  // so to mimic the D5 reset button we add one like this.
1664
  $form['actions']['reset'] = array(
1665
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1666
    '#weight' => 1000,
1667
  );
1668

    
1669
  $form['#submit'] = array('submit_json_as_php_array');
1670
  // #json_elements especially defined for submit_json_as_php_array()
1671
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1672
  return system_settings_form($form);
1673
}
1674

    
1675

    
1676

    
1677
  /**
1678
 * @todo Please document this function.
1679
 * @see http://drupal.org/node/1354
1680
 */
1681
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1682
  $form[$form_name] = array(
1683
    '#type' => 'fieldset',
1684
    '#title' => t($form_title),
1685
    '#collapsible' => TRUE,
1686
    '#collapsed' => $collapsed,
1687
    '#tree' => TRUE,
1688
    '#description' => t($form_description),
1689
  );
1690

    
1691
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1692
  $gallery_settings = variable_get($form_name, $default_values);
1693
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1694
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1695
    /*
1696
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1697
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1698
    '#type' => 'textfield',
1699
    '#title' => t('Search Page Size'),
1700
    '#default_value' => $test,
1701
    '#description' => t('Number of Names to display per page in search results.')
1702
    );
1703
    */
1704
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1705
      '#type' => 'checkbox',
1706
      '#title' => t('Show media thumbnails for accepted taxa'),
1707
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1708
    );
1709

    
1710
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1711
      '#type' => 'checkbox',
1712
      '#title' => t('Show media thumbnails for synonyms'),
1713
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1714
      '#description' => '',
1715
    );
1716
  }
1717

    
1718
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1719
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1720
    '#type' => 'checkbox',
1721
    '#title' => t('Show captions under thumbnails'),
1722
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1723
    '#description' => '',
1724
  );
1725

    
1726
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1727
    '#type' => 'textfield',
1728
    '#title' => t('Thumbnail size') . ':',
1729
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1730
    '#description' => t('Select the size of each individual thumbnail.'),
1731
  );
1732

    
1733
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1734
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1735
      '#type' => 'textfield',
1736
      '#title' => t('Number of columns') . ':',
1737
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1738
      '#description' => t('Group the thumbnails in columns: select how many
1739
        columns the gallery should display.'),
1740
    );
1741
  }
1742

    
1743
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1744
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1745
      '#type' => 'textfield',
1746
      '#title' => t('Maximum number of rows') . ':',
1747
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1748
      '#description' => t('You can group the thumbnails in rows, select in how
1749
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1750
        If you want an unlimited number of rows please set to 0.'),
1751
    );
1752
  }
1753

    
1754
  return $form;
1755
}
1756

    
1757
/**
1758
 * @todo document this function.
1759
 */
1760
function cdm_settings_layout_taxon() {
1761
  $collapsed = FALSE;
1762
  $form = array();
1763

    
1764
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1765

    
1766
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1767
      '#type' => 'checkbox',
1768
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1769
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1770
      '#description' => t('<p>If checked the link to search results is rendered at
1771
       the top of the taxon site. Clicking on the link the last search performed
1772
       is rendered again.</p>'),
1773
  );
1774

    
1775
  // --------- TABBED TAXON ------- //
1776
  $form['taxon_tabs'] = array(
1777
    '#type' => 'fieldset',
1778
    '#title' => t('Taxon tabs'),
1779
    '#collapsible' => TRUE,
1780
    '#collapsed' => TRUE,
1781
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1782
      be splitted in four diferent tabs; General, Synonymy, Images and
1783
      Specimens. If the taxon has no information for any of the tabs/sections
1784
      such tab will be not displayed.'),
1785
  );
1786

    
1787
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1788
    '#type' => 'checkbox',
1789
    '#title' => t('Tabbed taxon page'),
1790
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1791
    '#description' => t('<p>If selected split the taxon page into individual
1792
      tabs for description, images, synonymy and specimens. If not the taxon
1793
      data is rendered as a long single page without tabs.</p>'),
1794
  );
1795

    
1796
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1797
    '#type' => 'checkboxes',
1798
    '#title' => t('Tabs visibility options') . ':',
1799
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1800
    '#options' => get_taxon_options_list(),
1801
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1802
  );
1803

    
1804
  // WEIGHT
1805
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1806
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1807
      '#tree' => true
1808
  );
1809
  // Weights range from -delta to +delta, so delta should be at least half
1810
  // of the amount of tabs present.
1811
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1812
  foreach (get_taxon_tabs_list() as $label) {
1813
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1814
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1815
        '#title' => $label,
1816
        '#type'  => 'weight',
1817
        '#default_value' => $taxontabs_weights[$key],
1818
        '#delta' => $tab_weight_delta
1819
    );
1820
  }
1821

    
1822
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1823
    '#type' => 'select',
1824
    '#title' => t('Default tab to display') . ':',
1825
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1826
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1827
    '#description' => t('<p>Select the default tab to display when visiting a
1828
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1829
      <strong>Note:</strong> After performing a search and clicking in any
1830
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1831
      taxon and not the above selected tab.'),
1832
  );
1833

    
1834
  /* ======  TAXON_PROFILE ====== */
1835
  $form['taxon_profile'] = array(
1836
    '#type' => 'fieldset',
1837
    '#title' => t('Taxon profile (tab)'),
1838
    '#description' => t('<p>This section covers the settings related to the taxon
1839
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1840
    '#collapsible' => TRUE,
1841
    '#collapsed' => TRUE,
1842
  );
1843

    
1844
  // ---- PROFILE PICTURE ----//
1845

    
1846
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1847
    '#type' => 'fieldset',
1848
    '#tree' => TRUE,
1849
    '#title' => t('Taxon profile picture'),
1850
    '#collapsible' => TRUE,
1851
    '#collapsed' => FALSE,
1852
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1853
  );
1854

    
1855
  //FIXME migrate variables:
1856
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1857
  // FIXME
1858
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1859

    
1860
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1861

    
1862
  /*
1863
   * 'show' => 1,
1864
   * 'maxextend' => 184,
1865
   * 'media_uri_query' => ''
1866
   * 'custom_placeholder_image_on' => 1,
1867
   * 'custom_placeholder_image_fid' => ''
1868
   */
1869
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1870
    '#type' => 'checkbox',
1871
    '#title' => t('Enable profile picture'),
1872
    '#description' => t('Show the profile picture.'),
1873
    '#default_value' => $taxon_profile_image_settings['show'],
1874
  );
1875

    
1876
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1877
      '#type' => 'textfield',
1878
      '#tree' => TRUE,
1879
      '#title' => t('Profile picture maximum extend'),
1880
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1881
      '#field_suffix' => 'px',
1882
      '#maxlength' => 4,
1883
      '#size' => 4,
1884
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1885
  );
1886

    
1887
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1888
      '#type' => 'textfield',
1889
      '#tree' => TRUE,
1890
      '#title' => t('Additional URI query parameter'),
1891
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1892
      '#maxlength' => 1024,
1893
      '#size' => 60,
1894
      '#description' => t('Additional query parameters to be used when requesting for the '
1895
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1896
          . 'The query parameters will be appended to the uri of the media representation part'
1897
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1898
  );
1899

    
1900
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1901
    '#type' => 'checkbox',
1902
    '#title' => t('Show the placeholder image'),
1903
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
1904
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1905
  );
1906

    
1907
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1908
      '#type' => 'checkbox',
1909
      '#title' => t('Use a custom placeholder image'),
1910
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1911
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1912
  );
1913

    
1914
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1915
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1916
        '#type' => 'managed_file',
1917
        '#title' => t('Custom placeholder image file'),
1918
        '#progress_indicator' => 'bar',
1919
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1920
    //       '#name' => 'custom_placeholder_image',
1921
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1922
    );
1923

    
1924
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1925
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1926
      $url = file_create_url($profile_image_file->uri);
1927
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1928
                '#type' => 'item',
1929
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1930
      );
1931
    }
1932
  } else {
1933
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1934
      '#type' => 'hidden',
1935
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1936
    );
1937
  }
1938

    
1939
  $options = cdm_rankVocabulary_as_option();
1940
  array_unshift($options, '-- DISABLED --');
1941
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1942
    '#type' => 'select',
1943
    '#title' => t('Hide profile picture for higher ranks') . ':',
1944
    '#default_value' => variable_get('image_hide_rank', '0'),
1945
    '#options' => $options,
1946
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1947
  );
1948

    
1949
  // -- MEDIA THUMBNAILS -- //
1950
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1951
  $form_title = 'Taxon Profile Images';
1952
  $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>';
1953
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1954

    
1955
  // ---- FEATURE TREE BLOCKS ---- //
1956
  $form['taxon_profile']['feature_blocks'] = array(
1957
    '#type' => 'fieldset',
1958
    '#title' => t('Feature Blocks'),
1959
    '#collapsible' => TRUE,
1960
    '#collapsed' => FALSE,
1961
    '#description' => t("This section covers settings related to the taxon's
1962
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1963
      features such as description, distribution, common names"),
1964
  );
1965
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1966
  $profile_feature_tree = get_profile_feature_tree();
1967
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
1968
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
1969
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
1970
  }
1971
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
1972
    '#type' => 'radios',
1973
    '#title' => t('Taxon profile feature tree') . ':',
1974
    '#default_value' => $profile_feature_tree_uuid,
1975
    '#options' =>  $featureTrees['options'],
1976
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1977
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1978
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
1979
      profile page.'
1980
    ),
1981
  );
1982

    
1983
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
1984
  $profile_feature_tree = get_profile_feature_tree();
1985

    
1986
  if (isset($profile_feature_tree->root->childNodes)) {
1987

    
1988
    $form_feature_block_layout = array(
1989
      '#type' => 'fieldset',
1990
      '#tree' => true,
1991
      '#title' => t('Taxon profile feature block settings'),
1992
      '#collapsible' => TRUE,
1993
      '#collapsed' => FALSE,
1994
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
1995
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
1996
      The subforms have the following settings in common:<br />
1997
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
1998
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
1999
      <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>
2000
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2001
            <ol>
2002
            <li>If element is of the CDM type TextData and the text is not empty the source references will be
2003
                appended in brackets like "text (source references)". If the original source has name in source
2004
                information it will be appended to the citation string,
2005
                like : "(citation, as name in source; citation, as name in source)"</li>
2006
             <li>if the text of the TextData is empty, the original source citations are the only content
2007
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2008
                prepended to the citation string like: "name in source: citation"</li>
2009
            </ol>
2010
            <strong>If disabled:</strong><br />
2011
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2012
             citations are the only content, the resulting feature block content would only consist of footnotes.
2013
             In this case the display of the respective feature block is suppressed.</div>
2014
      </dl>
2015
      <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
2016
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2017
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2018
        . '</em></div>
2019
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2020
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2021
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2022
      <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>
2023
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2024
           cdm_feature_block_element_tag_name()</div>',
2025
    );
2026

    
2027

    
2028
    $feature_list_layout_settings_disabled = FALSE;
2029

    
2030
    // creating helper object to retrieve the default settings
2031
    $featureNode = new stdClass();
2032
    $featureNode->feature = new stdClass();
2033
    $featureNode->feature->uuid="DEFAULT";
2034
    $featureNode->feature->representation_L10n = "Default";
2035
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2036

    
2037
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2038

    
2039
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2040

    
2041
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2042
        $subform_id = $featureNode->feature->uuid;
2043
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2044

    
2045
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2046

    
2047
        $form_feature_block_layout[$subform_id] = array(
2048
          '#type' => 'fieldset',
2049
          '#tree' => TRUE,
2050
          '#title' => $featureNode->feature->representation_L10n,
2051
          '#collapsible' => FALSE,
2052
          '#collapsed' => FALSE,
2053
        );
2054
        if($featureNode->feature->uuid == "DEFAULT"){
2055
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2056
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2057
          references</em> and <em>names in source</em> is only possible in the defaults';
2058
        }
2059

    
2060
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2061
          '#type' => 'select',
2062
          '#title' => 'List type',
2063
          '#default_value' => $feature_block_setting['as_list'],
2064
          '#options' => array(
2065
            'div' => 'not as list',
2066
            'ul' => 'bullet list',
2067
            'ol' => 'numbered list',
2068
            'dl' => 'definition list'
2069
          ),
2070
        );
2071

    
2072
        if($featureNode->feature->uuid == "DEFAULT"){
2073
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2074
            '#type' => 'checkbox',
2075
            '#title' => t('Link to reference'),
2076
            '#default_value' => $feature_block_setting['link_to_reference'],
2077
          );
2078

    
2079
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2080
            '#type' => 'checkbox',
2081
            '#title' => 'Link to name used in source',
2082
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2083
          );
2084
        }
2085

    
2086
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2087
          '#type' => 'checkbox',
2088
          '#title' => 'Sources as content',
2089
          '#default_value' => $feature_block_setting['sources_as_content'],
2090
        );
2091

    
2092
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2093
          '#type' => 'checkbox',
2094
          '#title' => 'Put sources also as content to bibliography',
2095
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2096
        );
2097

    
2098
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2099
          '#type' => 'select',
2100
          '#title' => t('Sort elements'),
2101
          '#default_value' => $feature_block_setting['sort_elements'],
2102
          '#options' => array(
2103
            NO_SORT => 'No sorting',
2104
            SORT_ASC => 'Ascending',
2105
            SORT_DESC => 'Descending',
2106
            SORT_HIERARCHICAL => 'Hierarchical'
2107
          ),
2108
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2109
          <dl>
2110
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2111
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2112
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2113
          <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>
2114
          </dl>',
2115
        );
2116

    
2117
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2118
          '#type' => 'select',
2119
          '#title' => t('Element tag'),
2120
          '#options' => array(
2121
            'span' => 'span',
2122
            'div' => 'div'
2123
          ),
2124
          '#default_value' => $feature_block_setting['element_tag'],
2125
        );
2126
      }
2127
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2128
    }
2129
  }
2130

    
2131
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2132
  $form['taxon_profile']['structured_description_featuretree'] = array(
2133
    '#type' => 'fieldset',
2134
    '#title' => t('Structured Description Feature Tree'),
2135
    '#collapsible' => TRUE,
2136
    '#collapsed' => FALSE,
2137
  );
2138
  $featureTrees = cdm_get_featureTrees_as_options();
2139
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2140
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2141
    $profile_feature_tree_uuid = NULL;
2142
  }
2143
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2144
    '#type' => 'radios',
2145
    '#title' => t('Natural language representation of structured descriptions') . ':',
2146
    '#default_value' => $profile_feature_tree_uuid,
2147
    '#options' => $featureTrees['options'],
2148
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2149
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2150
    '#description' => t('Taxon descriptions can be stored in a highly structured
2151
      form. The feature tree selected here will be used to generate textual
2152
      representation in natural language.'
2153
    ),
2154
  );
2155

    
2156

    
2157

    
2158
  // ---- DISTRIBUTION LAYOUT ---- //
2159
  $form['taxon_profile']['distribution_layout'] = array(
2160
    '#title' => t('Distribution'),
2161
    '#collapsible' => TRUE,
2162
    '#collapsed' => FALSE,
2163
    '#type' => 'fieldset',
2164
    '#description' => 'This section covers general settings regarding the textual representation of distributions.
2165
        Map related settings are found in the '
2166
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2167
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2168
      . l(
2169
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2170
        array('fragment' => 'edit-feature-block-settings')
2171
      )
2172
      . ' More general settings regrading the filtering of Distributions are found at '
2173
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2174
      . '. (These settings here will be merged in future releases into the feature block settings)',
2175

    
2176
  );
2177

    
2178
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2179
    '#type' => 'checkbox',
2180
    '#title' => t('Condensed distribution'),
2181
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2182
    '#description' => 'This option enables the display of a very compact representation
2183
    of the distribution which includes also information on the status.',
2184
  );
2185

    
2186
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2187
    '#type' => 'select',
2188
    '#title' => t('Condensed distribution recipe'),
2189
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2190
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2191
    '#description' => 'Recipe for creating the condensed distribution.',
2192
  );
2193

    
2194
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2195
    '#type' => 'textfield',
2196
    '#title' => t('Condensed distribution info path'),
2197
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2198
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2199
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2200
  );
2201

    
2202

    
2203
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2204
    '#type' => 'radios',
2205
    '#title' => t('Display mode') . ':',
2206
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2207
    '#options' => array(
2208
      'FLAT_ALPHA' => t('Flat list'),
2209
      'TREE' => t('Hierarchically ordered'),
2210
    ),
2211
    '#description' => 'Taxon distribution information is displayed with
2212
    focus on the area of the distribution. The list of areas can either be shown
2213
    as flat list ordered alphabetically or in the hierarchical of the parent
2214
    area and subarea relationship. Fall back areas areas with no Distribution data
2215
    are hidden from the area hierarchy so that their sub areas will move one level up.
2216
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2217
    ' for details on the <em>Marked area filter</em>.',
2218
  );
2219

    
2220
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2221
    '#type' => 'fieldset',
2222
    '#tree' => true,
2223
    '#title' => t('Distribution hierarchy style')
2224
  );
2225

    
2226
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2227
  foreach(array_keys($hierarchy_styles) as $level) {
2228
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2229
      '#type' => 'fieldset',
2230
      '#tree' => true,
2231
      '#title' => t(drupal_ucfirst((str_replace('_', ' ', $level)))),
2232
      '#attributes' => array('class' => array('fieldset-float'))
2233
    );
2234
    foreach ($hierarchy_styles[$level] as $key => $value) {
2235
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2236
        '#type' => 'textfield',
2237
        '#title' => t(drupal_ucfirst((str_replace('_', ' ', $key)))),
2238
        '#default_value' => $hierarchy_styles[$level][$key],
2239
        '#maxlength' => 4,
2240
        '#size' => 4
2241
      );
2242
    }
2243
  }
2244

    
2245
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, CDM_ORDER_BY_ORDER_INDEX_ASC);
2246
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2247
    '#type' => 'checkboxes',
2248
    '#title' => 'Omit area levels',
2249
    '#options' => $level_options,
2250
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2251
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2252
    Areas which belong to the selected area levels will be hidden in the portal.',
2253
  );
2254

    
2255
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2256
    '#type' => 'checkbox',
2257
    '#title' => t('Show TextData elements on top of the map'),
2258
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2259
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2260
      elements on top of the map. Otherwise all <code>TextData</code>
2261
      distribution elements will be listed below the other area elements.
2262
      This option is useful if you need to have descriptive texts for each
2263
      distribution map.'),
2264
  );
2265

    
2266
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2267
      '#type' => 'textarea',
2268
      '#title' => t('Custom status colors'),
2269
      '#element_validate' => array('form_element_validate_json'),
2270
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2271
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2272
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2273
          reference list of the idInVocabulary values of absence and presence terms:
2274
<pre>
2275
Presence Term
2276
p	present
2277
pd	present: doubtfully present
2278
n	native
2279
nq	native: presence questionable
2280
nd	native: doubtfully native
2281
c	cultivated
2282
i	introduced
2283
iq	introduced: presence questionable
2284
id	introduced: doubtfully introduced (perhaps cultivated only)
2285
ip	introduced: uncertain degree of naturalisation
2286
ia	introduced: adventitious (casual)
2287
in	introduced: naturalized
2288
ic	introduced: cultivated
2289
e	endemic for the relevant area
2290
na	naturalised
2291
iv	invasive
2292

    
2293
AbsenceTerm
2294
a	absent
2295
f	reported in error
2296
nf	native: reported in error
2297
if	introduced: reported in error
2298
cf	cultivated: reported in error
2299
ne	native: formerly native
2300
ie	introduced: formerly introduced
2301

    
2302
</pre>'),
2303
  );
2304

    
2305

    
2306
  /* ====== SYNONYMY ====== */
2307
  $form['taxon_synonymy'] = array(
2308
    '#type' => 'fieldset',
2309
    '#title' => t('Taxon synonymy (tab)'),
2310
    '#collapsible' => TRUE,
2311
    '#collapsed' => TRUE,
2312
    '#description' => t('This section covers the settings related to the taxon
2313
      <strong>synonymy</strong> tab.'),
2314
  );
2315

    
2316
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2317
    '#type' => 'checkbox',
2318
    '#title' => t('Show accepted taxon on top of the synonymy'),
2319
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2320
    '#description' => t('If checked, the first homotypic taxon is a repetition
2321
      of the accepted taxon most likely with the full nomenclatural reference
2322
      (depending on the currently chosen theme).'),
2323
  );
2324

    
2325
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2326
    '#type' => 'checkbox',
2327
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2328
      coming from a synonym link.'),
2329
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2330
    '#description' => t('Check this if after doing a search and clicking on a
2331
      synonym you want to see the "accept of" text for the accepted synonym.'),
2332
  );
2333

    
2334
  /* === currently unused ===
2335
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2336
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2337
    '#type' => 'checkboxes',
2338
    '#title' => t('Display name relationships') . ':',
2339
    '#default_value' => variable_get('name_relationships_to_show', 0),
2340
    '#options' => $nameRelationshipTypeOptions,
2341
    '#description' => t('Select the name relationships you want to show for the
2342
      accepted taxa.'),
2343
  );
2344
 */
2345

    
2346
  $form['taxon_synonymy']['taxon_relations'] = array(
2347
    '#type' => 'fieldset',
2348
    '#title' => t('Taxon relationships'),
2349
    '#collapsible' => FALSE,
2350
    '#collapsed' => FALSE
2351
  );
2352

    
2353
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2354
    '#type' => 'checkbox',
2355
    '#title' => t('Show taxon relations ships of accepted taxon'),
2356
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2357
    '#description' => t('If this option is enabled the synonymy will show the
2358
      below selected taxon relationships of accepted taxa.'),
2359
  );
2360

    
2361
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2362
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2363
    '#type' => 'checkboxes',
2364
    '#title' => t('Taxon relationship types') . ':',
2365
    '#description' => t('Only taxon relationships of the selected type will be
2366
      displayed'),
2367
    '#options' => $taxonRelationshipTypeOptions,
2368
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2369
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2370
  );
2371

    
2372
  $form['taxon_synonymy']['name_relations'] = array(
2373
    '#type' => 'fieldset',
2374
    '#title' => t('Name relationships'),
2375
    '#collapsible' => FALSE,
2376
    '#collapsed' => FALSE
2377
  );
2378

    
2379
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2380
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2381
    '#type' => 'checkboxes',
2382
    '#title' => t('Name relationship types') . ':',
2383
    '#description' => t('Only name relationships of the selected type will be
2384
      displayed'),
2385
    '#options' => $taxonRelationshipTypeOptions,
2386
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2387
  );
2388

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

    
2399
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2400
        '#type' => 'checkbox',
2401
        '#title' => t('Show specimen derivatives in a compressed table'),
2402
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2403
        '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2404
        a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2405
    );
2406
    
2407
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2408
        '#type' => 'checkbox',
2409
        '#title' => t('Show "Associated with" in specimen table.'),
2410
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2411
    );
2412

    
2413
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2414
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2415
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2416
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2417
  }
2418
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2419
      '#type' => 'radios',
2420
      '#title' => t('Specimen description feature tree') . ':',
2421
      '#default_value' => $profile_feature_tree_uuid,
2422
      '#options' =>  $featureTrees['options'],
2423
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2424
      '#options_suffixes' => $featureTrees['treeRepresentations'],
2425
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2426
      ),
2427
  );
2428

    
2429
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2430
  $form_title = t('Specimen media');
2431
  $form_description = t('Specimens may have media which is displayed at the
2432
     Specimen tab/section as a gallery. It is possible to configure the
2433
     thumbnails gallery here, however for configuring how a single media should
2434
     be displayed please go to !url.</p>',
2435
     array(
2436
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2437
     ));
2438
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2439

    
2440
  // --- MEDIA GALLERY ---- //
2441
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2442
  $form_title = 'Media gallery (tab)';
2443
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2444
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2445
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2446
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2447
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2448
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2449
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2450

    
2451
  // Comment @WA: D7 form api does not support reset buttons,
2452
  // so to mimic the D5 reset button we add one like this.
2453
  $form['actions']['reset'] = array(
2454
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2455
    '#weight' => 1000,
2456
  );
2457
  return system_settings_form($form);
2458
}
2459

    
2460
/**
2461
 * @todo document this function.
2462
 */
2463
function cdm_settings_layout_search() {
2464

    
2465
  $form = array();
2466

    
2467
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2468

    
2469
  $form['search_settings'] = array(
2470
    '#type' => 'fieldset',
2471
    '#title' => t('Taxa Search'),
2472
    '#collapsible' => FALSE,
2473
    '#collapsed' => FALSE,
2474
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2475
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2476
         where they can write the text to be searched. You can find Drupal block configuration
2477
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2478
  );
2479

    
2480
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2481
      '#type' => 'checkbox',
2482
      '#title' => t('Ignore the chosen classification in simple search'),
2483
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2484
      '#description' => t('The simple search, which can be executed via the search block,
2485
          will by default search on the classification selected in the classification browser
2486
          selector. Set the tick if you want your portal to search on all classifications.'),
2487
  );
2488

    
2489
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2490
    '#type' => 'checkbox',
2491
    '#title' => t('Run simple search with free-text search backend.'),
2492
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2493
    '#description' => t('The simple search uses by default another search
2494
      backend as the advances search. By checking this option the simple search can be
2495
      configured to also use the free-text search backend.'),
2496
  );
2497

    
2498
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2499
    '#type' => 'textfield',
2500
    '#title' => t('Results per page') . ':',
2501
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2502
    '#description' => t('Number of results to display per page.'),
2503
  );
2504

    
2505
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2506
    '#type' => 'checkbox',
2507
    '#title' => t('Show the <i>Show Image Thumbnails</i> button') . ':',
2508
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2509
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2510
  );
2511

    
2512
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2513
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2514
      '#type' => 'checkboxes',
2515
      '#title' => 'Search mode',
2516
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2517
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2518
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2519
          defaults set here.',
2520
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2521
      '#default_value' => $search_mode_default
2522
      );
2523

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

    
2529
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2530
  );
2531

    
2532
  // --- SEARCH TAXA GALLERY ---- //
2533
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2534
  $collapsed = FALSE;
2535
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2536
  $form_title = 'Taxa Search thumbnails';
2537
  $form_description = 'Search results may show thumbnails. ';
2538
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2539

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

    
2549
/**
2550
 * @todo document this function.
2551
 */
2552
function cdm_settings_layout_media() {
2553

    
2554
  $form = array();
2555

    
2556
  $form['media_settings'] = array(
2557
    '#type' => 'fieldset',
2558
    '#title' => t('Media settings'),
2559
    '#collapsible' => FALSE,
2560
    '#collapsed' => FALSE,
2561
    '#description' => 'This section covers layout settings for media pages.'
2562
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2563
  );
2564

    
2565
  $form['media_settings']['image_gallery_viewer'] = array(
2566
    '#type' => 'select',
2567
    '#title' => t('Image viewer') . ':',
2568
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2569
    '#options' => array(
2570
      'default' => t('Standard image viewer'),
2571
      'fsi' => t('FSI viewer (requires FSI server!)'),
2572
    ),
2573
  );
2574

    
2575
  // --- MEDIA GALLERY ---- //
2576
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2577
  $form_title = 'Standard viewer';
2578
  $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>';
2579
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2580
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2581

    
2582
  // @WA: D7 form api does not support reset buttons,
2583
  // so to mimic the D5 reset button we add one like this.
2584
  $form['actions']['reset'] = array(
2585
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2586
    '#weight' => 1000,
2587
  );
2588
  return system_settings_form($form);
2589
}
2590

    
2591
/**
2592
 * GEOSERVICE and Map settings.
2593
 */
2594
function cdm_settings_geo($form, &$form_state) {
2595

    
2596
  $current_geoserver_settings = get_edit_map_service_settings();
2597
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2598

    
2599

    
2600
  $form = array();
2601

    
2602
  $dummy_distribution_query = NULL;
2603
  if($map_distribution['map_type'] != 1){
2604
    // we need to apply a dummy query since the map service requires for image maps
2605
    // at least as and ad to be defined
2606
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2607
  }
2608

    
2609
  $form['map_preview'] = array(
2610
      '#type' => 'fieldset',
2611
      '#tree' => FALSE,
2612
      '#title' => t('Map preview'),
2613
      '#collapsible' => FALSE,
2614
      '#description' => 'The preview of the map'
2615
       . ($dummy_distribution_query != null ?
2616
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2617
           '.<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.')
2618
  );
2619
  $form['map_preview']['openlayers_map'] = compose_map(NULL, $dummy_distribution_query, NULL,
2620
    array(
2621
      'move' => "this.cdmOpenlayersMap.printInfo",
2622
      '#execute' => "this.cdmOpenlayersMap.printInfo"
2623
    ),
2624
    true // resizable
2625
  );
2626

    
2627
  /*
2628
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2629
  );
2630
  */
2631

    
2632
  /*
2633
   * GEO SERVER
2634
   */
2635
  $form['edit_map_server'] = array(
2636
    '#type' => 'fieldset',
2637
    '#tree' => true,
2638
    '#title' => t('EDIT map service'),
2639
    '#collapsible' => TRUE,
2640
    '#collapsed' => TRUE,
2641
    '#description' => t('Configuration and selection of your geo server.
2642
      The Geo Server is responsible for generating the maps.'),
2643
  );
2644

    
2645
  $form['edit_map_server']['base_uri'] = array(
2646
    '#type' => 'select',
2647
    '#title' => t('EDIT map service') . ':',
2648
    '#default_value' => $current_geoserver_settings['base_uri'],
2649
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2650
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2651
  );
2652
  $form['edit_map_server']['version'] = array(
2653
      '#type' => 'select',
2654
      '#title' => t('Version') . ':',
2655
      '#default_value' => $current_geoserver_settings['version'],
2656
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2657
      '#description' => t('The version of the EDIT map services'),
2658
  );
2659

    
2660
  /*
2661
   * MAP SETTINGS
2662
   */
2663

    
2664
  $form[CDM_MAP_DISTRIBUTION] = array(
2665
    '#type' => 'fieldset',
2666
    '#tree' => TRUE,
2667
    '#title' => t('Maps settings'),
2668
    '#collapsible' => TRUE,
2669
    '#collapsed' => TRUE,
2670
    '#description' => t('General configuration for all map types.'),
2671
  );
2672

    
2673
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2674
    '#type' => 'radios',
2675
    '#title' => 'Map types',
2676
    '#options' => array(
2677
      1 => "OpenLayers dynamic map viewer",
2678
      0 => "Plain image",
2679
    ),
2680
    '#default_value' => $map_distribution['map_type'],
2681
    '#description' => 'Two different map types are available :
2682
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2683
      which allows zooming and panning. If enabled you can configure the default layer
2684
      (background of your maps) below.</li>
2685
      <li><em>Plain image</em>: The map will be static non interactive
2686
      image.</li></ul>',
2687
  );
2688
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2689

    
2690
  /*
2691
   * settings for the distribution map are used also for specimens map!!!!
2692
   */
2693

    
2694
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2695
      '#type' => 'textfield',
2696
      '#title' => 'Aspect ratio',
2697
      '#default_value' => $map_distribution['aspect_ratio'],
2698
      '#maxlength' => 4,
2699
      '#size' => 4,
2700
      '#element_validate' => array('element_validate_number'),
2701
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2702
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2703
      width by the height:</br>
2704
      <pre>aspect ratio = w / h</pre>
2705
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2706
      for a square map use <strong>1</strong>.',
2707
  );
2708

    
2709
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2710
    '#type' => 'textfield',
2711
    '#title' => 'Bounding box',
2712
    '#default_value' => $map_distribution['bbox'],
2713
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2714
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2715
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2716
      <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.
2717
      (Maybe you need to change the map base layer to OpeLayers.)
2718
      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
2719
      below the map from where you can copy the bbox string.</p>'),
2720
  );
2721

    
2722
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2723
    '#type' => 'checkbox',
2724
    '#title' => 'Display area labels',
2725
    '#default_value' => $map_distribution['show_labels'],
2726
    '#description' => t('The map will show name labels of the areas'),
2727
  );
2728

    
2729
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2730
    '#type' => 'textfield',
2731
    '#title' => 'Map caption',
2732
    '#default_value' => $map_distribution['caption'],
2733
    '#description' => t('The caption will be shown below the map.'),
2734
  );
2735

    
2736
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2737
    '#type' => 'textfield',
2738
    '#title' => 'Distribution layer opacity',
2739
    '#default_value' => $map_distribution['distribution_opacity'],
2740
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2741
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2742
  );
2743

    
2744
  // --- Plain Image Settings --- //
2745
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2746
    '#type' => 'fieldset',
2747
    '#title' => 'Plain image map settings',
2748
    '#tree' => TRUE,
2749
    '#collapsible' => TRUE,
2750
    '#collapsed' => $open_layers_is_enabled,
2751
    '#description' => 'The settings in this section are still expertimental
2752
      and can only be used with the EDIT map service version 1.1 or above.',
2753
  );
2754
  $edit_mapserver_version = get_edit_map_service_version_number();
2755
  if ($edit_mapserver_version < 1.1) {
2756
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">' . t("The chosen EDIT map service version ($edit_mapserver_version) is too low, it must be at least 1.1") . '</div>'
2757
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2758
  }
2759

    
2760
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2761
    '#type' => 'textfield',
2762
    '#title' => 'Width',
2763
    '#default_value' => $map_distribution['image_map']['width'],
2764
    '#maxlength' => 4,
2765
    '#size' => 4,
2766
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2767
  );
2768

    
2769
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2770
    '#type' => 'textfield',
2771
    '#title' => 'Background layer',
2772
    '#default_value' => $map_distribution['image_map']['base_layer'],
2773
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2774
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2775
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2776
    )),
2777
  );
2778

    
2779
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2780
    '#type' => 'textfield',
2781
    '#title' => 'Background color',
2782
    '#default_value' => $map_distribution['image_map']['bg_color'],
2783
  );
2784

    
2785
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2786
    '#type' => 'textfield',
2787
    '#title' => 'Background layer style',
2788
     // Only line color by now.
2789
    '#default_value' => $map_distribution['image_map']['layer_style'],
2790
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2791
  );
2792

    
2793
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2794
      '#type' => 'textfield',
2795
      '#title' => 'Projection',
2796
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2797
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2798
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2799
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2800
  );
2801

    
2802

    
2803
  // --- OpenLayers Settings --- //
2804
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2805
    '#type' => 'fieldset',
2806
    '#title' => 'OpenLayers settings',
2807
    '#tree' => TRUE,
2808
    '#collapsible' => TRUE,
2809
    '#collapsed' => !$open_layers_is_enabled,
2810
    '#description' => '',
2811
  );
2812

    
2813

    
2814
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2815
      '#type' => 'checkbox',
2816
      '#title' => 'Display outside max extent',
2817
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2818
      '#description' => t('Allows the map to display parts of the layers which are outside
2819
         the max extent if the aspect ratio of the map and of the baselayer
2820
         are not equal.'),
2821
  );
2822

    
2823

    
2824
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2825
      '#type' => 'checkbox',
2826
      '#title' => 'Show Layer Switcher',
2827
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2828
      '#description' => 'The Layer Switcher control displays a table of contents
2829
      for the map.  This allows the user interface to switch between
2830
      base layers and to show or hide overlays.  By default the switcher is
2831
      shown minimized on the right edge of the map, the user may expand it
2832
      by clicking on the handle.',
2833
  );
2834

    
2835
  if (!$open_layers_is_enabled) {
2836
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2837
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2838
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2839
  }
2840

    
2841
  // The default layer must always be enabled
2842
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2843
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2844

    
2845
  $baselayer_options = array(
2846
    /*
2847
   NOTICE: must correspond to the layers defined in
2848
   js/openlayers_,ap.js#getLayersByName()
2849
   */
2850
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
2851
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
2852
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
2853
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
2854
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2855
    // all others EPSG:900913
2856
    'mapnik' => 'OpenStreetMap',
2857
    'mapquest_open' => "MapQuest",
2858
    'mapquest_sat' => "MapQuest Sattelite",
2859
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2860
//    'gmap' => 'Google Streets',
2861
//    'gsat' => 'Google Satellite',
2862
//    'ghyb' => 'Google Hybrid',
2863
//     'veroad' => 'Virtual Earth Roads',
2864
//     'veaer' => 'Virtual Earth Aerial',
2865
//     'vehyb' => 'Virtual Earth Hybrid',
2866
    // 'yahoo' => 'Yahoo Street',
2867
    // 'yahoosat' => 'Yahoo Satellite',
2868
    // 'yahoohyb' => 'Yahoo Hybrid',
2869
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2870
  );
2871

    
2872
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2873
    '#type' => 'checkboxes_preferred',
2874
    '#title' => 'Base Layers',
2875
    '#options' => $baselayer_options,
2876
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2877
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2878
  );
2879

    
2880
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2881
      '#type' => 'fieldset',
2882
      '#title' => 'Custom WMS base layer',
2883
      '#tree' => TRUE,
2884
      '#collapsible' => FALSE,
2885
      '#collapsed' => FALSE,
2886
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2887
  );
2888

    
2889
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2890
      '#type' => 'textfield',
2891
      '#title' => 'Layer name',
2892
      // Only line color by now.
2893
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2894
      '#description' => 'A arbitrary name for the layer.',
2895
  );
2896
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2897
      '#type' => 'textfield',
2898
      '#title' => 'WMS url',
2899
      // Only line color by now.
2900
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2901
      '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
2902
  );
2903
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2904
      '#type' => 'textarea',
2905
      '#title' => 'WMS parameters',
2906
      '#element_validate' => array('form_element_validate_json'),
2907
      // Only line color by now.
2908
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2909
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2910
<pre> {
2911
  "Layers": "topp:em_tiny_jan2003",
2912
  "Format": "image/png",
2913
  "BGCOLOR": "0xe0faff"
2914
}
2915
</pre>'
2916
  );
2917
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2918
      '#type' => 'textfield',
2919
      '#title' => 'Projection',
2920
      // Only line color by now.
2921
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2922
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2923
  );
2924
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2925
      '#type' => 'textfield',
2926
      '#maxlength' => 256,
2927
      '#title' => 'proj4js definition',
2928
      // Only line color by now.
2929
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2930
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2931
            The definitions for
2932
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2933
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2934
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2935
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2936
            choose to display the proj4js definition string.
2937
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2938
            <pre>
2939
+a         Semimajor radius of the ellipsoid axis
2940
+alpha     ? Used with Oblique Mercator and possibly a few others
2941
+axis      Axis orientation (new in 4.8.0)
2942
+b         Semiminor radius of the ellipsoid axis
2943
+datum     Datum name (see `proj -ld`)
2944
+ellps     Ellipsoid name (see `proj -le`)
2945
+k         Scaling factor (old name)
2946
+k_0       Scaling factor (new name)
2947
+lat_0     Latitude of origin
2948
+lat_1     Latitude of first standard parallel
2949
+lat_2     Latitude of second standard parallel
2950
+lat_ts    Latitude of true scale
2951
+lon_0     Central meridian
2952
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
2953
+lon_wrap  Center longitude to use for wrapping (see below)
2954
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
2955
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
2956
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
2957
+pm        Alternate prime meridian (typically a city name, see below)
2958
+proj      Projection name (see `proj -l`)
2959
+south     Denotes southern hemisphere UTM zone
2960
+to_meter  Multiplier to convert map units to 1.0m
2961
+towgs84   3 or 7 term datum transform parameters (see below)
2962
+units     meters, US survey feet, etc.
2963
+vto_meter vertical conversion to meters.
2964
+vunits    vertical units.
2965
+x_0       False easting
2966
+y_0       False northing
2967
+zone      UTM zone
2968
            </pre>
2969
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
2970
  );
2971
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
2972
      '#type' => 'textfield',
2973
      '#title' => 'Maximum extent',
2974
      // Only line color by now.
2975
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
2976
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
2977
  );
2978
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
2979
      '#type' => 'textfield',
2980
      '#title' => 'Units',
2981
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
2982
      '#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.'
2983
  );
2984

    
2985
  /*
2986
   * Map Legend
2987
   */
2988
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2989
    '#type' => 'fieldset',
2990
    '#title' => 'Map legend',
2991
    '#tree' => TRUE,
2992
    '#collapsible' => TRUE,
2993
    '#collapsed' => TRUE,
2994
    '#description' => 'Configure the maps legend.',
2995
  );
2996

    
2997
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2998
    '#type' => 'checkbox',
2999
    '#title' => 'Display a map legend',
3000
    '#default_value' => $map_distribution['legend']['show'],
3001
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3002
  );
3003

    
3004
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3005
    '#type' => 'textfield',
3006
    '#title' => 'Legend opacity',
3007
    '#default_value' => $map_distribution['legend']['opacity'],
3008
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3009
                         to 0.0 will be not much visible.',
3010
  );
3011

    
3012
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3013
    '#type' => 'textfield',
3014
    '#title' => 'Font size',
3015
    '#default_value' => $map_distribution['legend']['font_size'],
3016
    '#description' => 'Font size in pixels.',
3017
  );
3018

    
3019
  $fontStyles = array(
3020
    0 => "plane",
3021
    1 => "italic",
3022
  );
3023
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3024
    '#type' => 'select',
3025
    '#title' => 'Available font styles',
3026
    '#default_value' => $map_distribution['legend']['font_style'],
3027
    '#options' => $fontStyles,
3028
    '#description' => 'Select a font style for the map legend.',
3029
  );
3030

    
3031
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3032
    '#type' => 'textfield',
3033
    '#title' => 'Icon width',
3034
    '#default_value' => $map_distribution['legend']['icon_width'],
3035
    '#description' => 'Legend icon width in pixels.',
3036
  );
3037
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3038
    '#type' => 'textfield',
3039
    '#title' => 'Icon height',
3040
    '#default_value' => $map_distribution['legend']['icon_height'],
3041
    '#description' => 'Legend icon height in pixels.',
3042
  );
3043

    
3044
  // @WA: D7 form api does not support reset buttons,
3045
  // so to mimic the D5 reset button we add one like this.
3046
  $form['actions']['reset'] = array(
3047
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3048
    '#weight' => 1000,
3049
  );
3050

    
3051
  return system_settings_form($form);
3052
}
3053

    
3054

    
3055
/**
3056
 * @todo document this function.
3057
 */
3058
function cdm_settings_cache() {
3059

    
3060
  $form = array();
3061

    
3062
  $form['cache_settings'] = array(
3063
    '#type' => 'fieldset',
3064
    '#title' => t('Cache Settings'),
3065
    '#collapsible' => FALSE,
3066
    '#collapsed' => FALSE,
3067
    '#description' => t('<p>When caching is enabled all single taxon sites are
3068
      stored in an internal drupal cache doing the portal response of taxa pages
3069
      faster. This is possible because the sites are loaded from the cache and
3070
      are not created from scratch.</p>'),
3071
  );
3072

    
3073
  $form['cache_settings']['cdm_webservice_cache'] = array(
3074
    '#type' => 'checkbox',
3075
    '#title' => t('<strong>Enable caching</strong>'),
3076
    '#options' => cdm_help_general_cache(),
3077
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3078
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3079
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3080
       application the changes will be not visible till the cache is erased.
3081
       Therefore developers should deactived this feature when they are working
3082
       on the CDM Dataportal Module.</p>'),
3083
  );
3084

    
3085
  $form['cache_settings']['cdm_run_cache'] = array(
3086
    '#markup' => cdm_view_cache_site(),
3087
  );
3088

    
3089
  // @WA: D7 form api does not support reset buttons,
3090
  // so to mimic the D5 reset button we add one like this.
3091
  $form['actions']['reset'] = array(
3092
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3093
    '#weight' => 1000,
3094
  );
3095
  return system_settings_form($form);
3096
}
3097

    
3098
/**
3099
 * Walk and cache all taxon pages.
3100
 */
3101
function cdm_view_cache_site() {
3102

    
3103
  $out = '';
3104

    
3105
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3106

    
3107
  $request_params = array();
3108
  $request_params['class'] = "Taxon";
3109

    
3110
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3111
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3112
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3113

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

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

    
3123
  // Comment @WA: A form within a form is not valid html and not needed here.
3124
  // Also, it would be recommended just to include this part of the form in the
3125
  // rest of the form array in cdm_settings_cache().
3126
  // $out .= '<form id="cache_site">';
3127
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3128
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3129
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3130
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3131
  // $out .= '</form>';
3132
  $out .= '</div>';
3133
  /*
3134
  foreach($taxonPager->records as $taxon){
3135
    cdm_dataportal_taxon_view($uuid);
3136
  }
3137
  */
3138
  return $out;
3139
}
3140

    
3141

    
3142
function cdm_settings_layout_taxon_submit($form, &$form_state){
3143
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3144
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3145
    if(is_object($file)){
3146
      $file->status = FILE_STATUS_PERMANENT;
3147
      file_save($file);
3148
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3149
    }
3150
  }
3151
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
3152
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
3153
    // we first need to set the variable to persist the changes setting
3154
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3155
    menu_rebuild();
3156
  }
3157
}
3158

    
3159
function cdm_settings_layout_search_submit($form, &$form_state){
3160
  // the visibility of media thumbnails also affects the ui of the search results
3161
  // so reset the according session variable
3162
  //    1. in order to give the user immediate
3163
  //       feedback on potential setting changes
3164
  //    2. let refresh the default if it has changed
3165
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3166
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3167
  }
3168
}
3169

    
3170
/**
3171
 * Form validation handler for cdm_settings_general
3172
 *
3173
 * @param $form
3174
 * @param $form_state
3175
 */
3176
function cdm_settings_general_validate($form, &$form_state) {
3177

    
3178
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3179
    $form_state['values']['cdm_webservice_url'] .= '/';
3180
  }
3181

    
3182
}
3183

    
3184
/**
3185
 * Form submit handler for settings general.
3186
 *
3187
 * tasks performed:
3188
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3189
 *
3190
 * @param $form
3191
 * @param $form_state
3192
 */
3193
function cdm_settings_general_submit($form, &$form_state){
3194
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3195
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3196
}
3197

    
3198
/**
3199
 * Form validation handler for cdm_settings_cache
3200
 */
3201
function cdm_settings_cache_validate($form, &$form_state) {
3202
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3203
    cache_clear_all(NULL, 'cache_cdm_ws');
3204
    // Better clear secref_cache since I can not be sure if the cache has not
3205
    // be used during this response.
3206
    cdm_api_secref_cache_clear();
3207
  }
3208

    
3209
}
3210

    
3211
/**
3212
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3213
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3214
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3215
 *  - version: the version, e.g.: v1.1
3216
 *
3217
 * @return array
3218
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3219
 */
3220
function get_edit_map_service_settings() {
3221

    
3222
  $settings = variable_get('edit_map_server', array(
3223
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3224
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3225
      )
3226
  );
3227

    
3228
  return $settings;
3229
}
3230

    
3231
/**
3232
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3233
 *
3234
 * @return string
3235
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3236
 */
3237
function get_edit_map_service_full_uri() {
3238
  $settings = get_edit_map_service_settings();
3239
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3240
}
3241

    
3242

    
3243
/**
3244
 * Returns the version number of the currently selected edit mapserver as a float
3245
 *
3246
 * @return float
3247
 *   The version number of the currently selected edit mapserver as a float.
3248
 *   Returns 0 on error.
3249
 */
3250
function get_edit_map_service_version_number() {
3251

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

    
3254
  $settings = get_edit_map_service_settings();
3255
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3256
  if (isset($matches[1])) {
3257
    // Convert string to float.
3258
    $version = 1 + $matches[1][0] - 1;
3259
    return $version;
3260
  }
3261
  else {
3262
    // Report error.
3263
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3264
        array(
3265
          '!version' => $settings['version'],
3266
          'warning')
3267
        )
3268
      );
3269
    return 0;
3270
  }
3271
}
3272

    
3273
/**
3274
 * Returns the array of selected items in a options array
3275
 *
3276
 * @param array $options
3277
 *   An options array as generated by a form element like checkoxes, select ...,
3278
 */
3279
function get_selection($options) {
3280
  $selection = array();
3281
  foreach ($options as $key=>$val) {
3282
    if (!empty($val)) {
3283
      $selection[] = $val;
3284
    }
3285
  }
3286
  return $selection;
3287
}
3288

    
3289

    
3290
/**
3291
 * Implements hook_element_info().
3292
 *
3293
 * Allows modules to declare their own Form API element types and specify their default values.
3294
 *
3295
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3296
 */
3297
function cdm_dataportal_element_info() {
3298
  $type['checkboxes_preferred'] = array(
3299
    '#input' => TRUE,
3300
    '#process' => array('checkboxes_preferred_expand'),
3301
    '#after_build' => array('checkboxes_preferred_after_build'),
3302
    '#theme' => array('checkboxes_preferred'),
3303
    // '#theme_wrapper' => array('form_element'),
3304
  );
3305
  return $type;
3306
}
3307

    
3308
/**
3309
 * #process callback function for the custom form element type 'checkbox_preferred'
3310
 *
3311
 *
3312
 */
3313
function checkboxes_preferred_expand($element, &$form_state, $form) {
3314

    
3315
  // First of all create checkboxes for each of the elements
3316
  $element = form_process_checkboxes($element);
3317

    
3318
  // compose the element name
3319
  $parents = array();
3320
  array_deep_copy($element['#parents'], $parents);
3321
  $parents[count($parents) -1 ] .= '_preferred';
3322
  $element_name = $parents[0];
3323
  for ($i=1; $i < count($parents); $i++){
3324
    $element_name .= '[' . $parents[$i] . ']';
3325
  }
3326

    
3327
  $children = element_children($element);
3328

    
3329
  $element['table_start'] = array(
3330
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3331
    '#weight' => -1,
3332
  );
3333

    
3334
  // prepare first part each of the table rows which contains the row label
3335
  $weight = 0;
3336
  foreach ($children as $key) {
3337
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3338
    $element[$key]['#weight'] = $weight;
3339
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
3340
    $element[$key]['#suffix'] = '</td>';
3341
    unset($element[$key]['#title']);
3342
    $weight += 2;
3343
  }
3344
  $weight = 0;
3345

    
3346
  // add a radio button to each of the checkboxes, the
3347
  // check boxes have already been created at the beginning
3348
  // of this function
3349
  if (count($element['#options']) > 0) {
3350
    foreach ($element['#options'] as $key => $choice) {
3351
      if (!isset($element[$key . '_preferred'])) {
3352
        $element[$key . '_preferred'] = array(
3353
          '#type' => 'radio',
3354
          '#name' => $element_name,
3355
          '#return_value' => check_plain($key),
3356
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3357
          '#attributes' => $element['#attributes'],
3358
          '#parents' => $element['#parents'],
3359
          // '#spawned' => TRUE,
3360
          '#weight' => $weight + 1,
3361
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3362
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3363
        );
3364
      }
3365
      $weight += 2;
3366
    }
3367
  }
3368

    
3369
  // end the table
3370
  $element['table_end'] = array(
3371
    '#markup' => '</table>',
3372
    '#weight' => $weight++,
3373
  );
3374

    
3375
  return $element;
3376
}
3377

    
3378
/**
3379
 * Theme function for the custom form field 'checkboxes_preferred'.
3380
 */
3381
function theme_checkboxes_preferred($variables) {
3382
  $element = $variables['element'];
3383
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3384
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3385
  $out .= drupal_render_children($element);
3386
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3387
  $out .= '</div>';
3388
  return $out;
3389
}
3390

    
3391
/**
3392
 * Callback for checkboxes preferred for widget which will
3393
 * be called after the form or element is built. The call
3394
 * back is configured in the form element by setting it as
3395
 * #after_build parameter.
3396
 *
3397
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3398
 *
3399
 * @param $element
3400
 *   Nested array of form elements that comprise the form.
3401
 * @param $form_state
3402
 *   A keyed array containing the current state of the form.
3403
 *   This includes the current persistent storage data for the form.
3404
 *   Additional information, like the sanitized $_POST data,
3405
 *   is also accumulated here in $form_state['input']
3406
 *
3407
 * @return the modified form array
3408
 */
3409
function checkboxes_preferred_after_build($element, &$form_state) {
3410

    
3411
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3412

    
3413
  if ($_POST && count($_POST) > 0) {
3414
    // TODO use  $form_state['input'] instead of POST !!!
3415
    // First pass of form processing.
3416
    $parents = array();
3417
    array_deep_copy($element['#parents'], $parents);
3418
    $parents[count($parents) - 1] .= '_preferred';
3419
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3420
    $element['#value']['PREFERRED'] = $preferred_layer;
3421
//     $form_state[$parent_id] = $element['#value'];
3422
//     $form_state['values']['baselayers'] = $element['#value'];
3423
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3424
    $form_state_element_values = $element['#value'];
3425
  }
3426
  else {
3427
    // Second pass of form processing.
3428
    $preferred_layer = $element['#value']['PREFERRED'];
3429
  }
3430

    
3431
  // Also set the chosen value (not sure if this is good Drupal style ....).
3432
  foreach ($children = element_children($element) as $key) {
3433
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3434
      $element[$key]['#value'] = $preferred_layer;
3435
    }
3436
  }
3437
  // The default layer must always be enabled.
3438
  $element[$preferred_layer]['#value'] = $preferred_layer;
3439

    
3440
  return $element;
3441
}
3442

    
3443
function radios_prepare_options_suffix(&$elements){
3444

    
3445
  $childrenKeys = element_children($elements);
3446
  foreach($childrenKeys as $key){
3447
    if(!is_array($elements[$key]['#theme_wrappers'])){
3448
      $elements[$key]['#theme_wrappers'] = array();
3449
    }
3450
    if(isset($elements['#options_suffixes'][$key])){
3451
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3452
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3453
    }
3454
  }
3455
  return $elements;
3456

    
3457
}
3458

    
3459
/**
3460
 * TODO
3461
 * @param unknown $variables
3462
 */
3463
function theme_radio_options_suffix($variables) {
3464
  $element = $variables['element'];
3465
  if(isset($element['#options_suffix'])) {
3466
    $element['#children'] .= $element['#options_suffix'];
3467
  }
3468
  return $element['#children'];
3469
}
3470

    
3471

    
3472
/**
3473
 * Element validate callback for text field and arrays containing json.
3474
 *
3475
 * @param $element
3476
 *   The form element to validate
3477
 * @param $form_state
3478
 *   A keyed array containing the current state of the form.
3479
 * @param $form
3480
 *   Nested array of form elements that comprise the form.
3481
 */
3482
function form_element_validate_json($element, &$form_state, $form) {
3483
   if (!empty($element['#value'])) {
3484
     json_decode($element['#value']);
3485
     if(json_last_error() != JSON_ERROR_NONE){
3486
       form_error($element, t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title'])) . l('JSONLint', 'http://jsonlint.com/'));
3487
     }
3488
   }
3489
}
3490

    
3491
/**
3492
 * Form submission handler for textareas and textfields containing JSON.
3493
 *
3494
 * The contained JSON will be converted into an php array
3495
 * or object and will be stored in the variables as such.
3496
 *
3497
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3498
 *
3499
 * @param $form
3500
 *   Nested array of form elements that comprise the form.
3501
 * @param $form_state
3502
 *   A keyed array containing the current state of the form.
3503
 *
3504
 */
3505
function submit_json_as_php_array($form, &$form_state) {
3506
  if (is_array($form['#json_elements'])) {
3507
    foreach ($form['#json_elements'] as $element){
3508
      if (trim($form_state['values'][$element])) {
3509
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3510
      } else {
3511
        $form_state['values'][$element] = NULL;
3512
      }
3513
    }
3514
  }
3515
}
(16-16/16)