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

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

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

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

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

    
53

    
54

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

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

    
101

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

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

    
110

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

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

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

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

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

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

    
157
}
158

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
561

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

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

    
633
    // ---- DEFAULTS settings
634

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

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

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

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

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

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

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

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

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

    
826
    $feature_block_setting = null;
827

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

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

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

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

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

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

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

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

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

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

    
988
}
989

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

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

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

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

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

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

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

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

    
1074
  $form['cdm_webservice']['proxy'] = array(
1075
    '#type' => 'fieldset',
1076
    '#title' => t('Proxy'),
1077
    '#collapsible' => TRUE,
1078
    '#collapsed' => TRUE,
1079
  );
1080

    
1081
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1082
    '#type' => 'textfield',
1083
    '#title' => t('Proxy URL') . ':',
1084
    '#description' => t('If this proxy url is set the cdm api tries
1085
    to connect the web service over the given proxy server.
1086
    Otherwise proxy usage is deactivated.'),
1087
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1088
  );
1089

    
1090
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1091
    '#type' => 'textfield',
1092
    '#title' => t('Proxy port') . ':',
1093
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1094
  );
1095

    
1096
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1097
    '#type' => 'textfield',
1098
    '#title' => t('Login') . ':',
1099
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1100
  );
1101

    
1102
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1103
    '#type' => 'textfield',
1104
    '#title' => t('Password') . ':',
1105
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1106
  );
1107

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

    
1124
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1125
    '#type' => 'select',
1126
    '#title' => t('Available classifications') . ':',
1127
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1128
    '#options' => cdm_get_taxontrees_as_options(),
1129
    '#description' => t('Select the default taxa classification for your
1130
      <em>taxon tree</em>, the other classifications will be also available but
1131
      with a manual user change.'),
1132
  );
1133

    
1134
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1135
    '#type' => 'select',
1136
    '#title' => t('Rank of highest displayed taxon') . ':',
1137
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1138
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1139
    '#options' => cdm_rankVocabulary_as_option(),
1140
    '#description' => t('This is the rank of the highest displayed taxon in the
1141
      <em>taxon tree</em>. You can select here which rank should be at the top
1142
      level of the tree structure.'),
1143
  );
1144

    
1145
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1146
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1147
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1148
      '#type' => 'checkboxes',
1149
      '#title' => t('Included Classifications') . ':',
1150
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1151
      '#options' => cdm_get_taxontrees_as_options(),
1152
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1153
  );
1154

    
1155
  $form['distribution'] = array(
1156
      '#type' => 'fieldset',
1157
      '#title' => t('Distributions'),
1158
      '#collapsible' => FALSE,
1159
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1160
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1161
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1162
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1163
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1164
          '<p>
1165
          </p>',
1166
  );
1167

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

    
1189
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1190
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1191
      '#type' => 'checkboxes',
1192
      '#title' => 'Filter rules',
1193
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1194
      '#options' => array(
1195
          'statusOrderPreference' => 'Status order preference rule',
1196
          'subAreaPreference' => 'Sub area preference rule'
1197
      ),
1198
  );
1199

    
1200
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1201
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1202
      '#type' => 'checkboxes',
1203
      '#title' => 'Hide marked area filter',
1204
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1205
      '#options' => $marker_type_options,
1206
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1207
  );
1208

    
1209
  $form['aggregation'] = array(
1210
      '#type' => 'fieldset',
1211
      '#title' => t('Aggregation of data'),
1212
      '#collapsible' => FALSE,
1213
      '#description' => 'This section covers the different aspects of aggregating information.
1214
          <p>
1215
          </p>',
1216
  );
1217

    
1218
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1219
      '#type' => 'checkboxes',
1220
      '#title' => 'Taxon media filter',
1221
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1222
      '#options' => array(
1223
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1224
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1225
          'includeOccurrences' => 'Media related to specimens and occurrences',
1226
      ),
1227
      '#description' => 'This filter configures which images should be taken into account.',
1228
  );
1229

    
1230
  $form['aggregation']['notice'] = array(
1231
      '#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
1232
          want to make use of the caching capabilities of the dataportal.',
1233
  );
1234

    
1235
  $form['aggregation']['media_aggregation'] = array(
1236
      '#type' => 'fieldset',
1237
      '#title' => t('Media aggregation'),
1238
      '#collapsible' => FALSE,
1239
      '#collapsed' => TRUE,
1240
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1241

    
1242
  );
1243
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1244
      '#type' => 'select',
1245
      '#title' => t('Aggregation of taxon pictures') . ':',
1246
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1247
      '#options' => array(
1248
          0 => "Show only pictures of the current taxon",
1249
          1 => "Include pictures of taxonomic children",
1250
      ),
1251
      '#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."),
1252
  );
1253

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

    
1268
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1269
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1270

    
1271
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1272
      '#type' => 'checkboxes',
1273
      '#title' => t('Direct'),
1274
      '#options' => $taxonRelationshipTypeOptions,
1275
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1276
  );
1277
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1278
      '#type' => 'checkboxes',
1279
      '#title' => t('Invers'),
1280
      '#options' => $taxonRelationshipTypeOptions,
1281
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1282
  );
1283

    
1284
  $form['drupal_integration'] = array(
1285
    '#type' => 'fieldset',
1286
    '#attributes' => array('class'=> array('clearfix')),
1287
    '#title' => t('Drupal integration'),
1288
    '#collapsible' => FALSE,
1289
    '#collapsed' => FALSE,
1290
    '#tree' => FALSE
1291
  );
1292

    
1293
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1294
    '#type' => 'checkbox',
1295
    '#title' => 'Create drupal nodes',
1296
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1297
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1298
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1299
    cdm pages it is required that drupal nodes are created and stored in the database.'
1300
  );
1301

    
1302

    
1303

    
1304
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1305
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1306
    <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>',
1307
  );
1308
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1309
    '#type' => 'submit',
1310
    '#value' => t('Drop all cdm nodes'),
1311
    '#submit' => array('drop_all_cdm_nodes_submit')
1312
  );
1313

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

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

    
1343
  // Comment @WA: D7 form api does not support reset buttons,
1344
  // so to mimic the D5 reset button we add one like this.
1345
  $form['actions']['reset'] = array(
1346
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1347
    '#weight' => 1000,
1348
  );
1349

    
1350
  $form['#submit'][] = 'cdm_settings_general_submit';
1351

    
1352
  return system_settings_form($form);
1353
}
1354

    
1355
/**
1356
 * Submit callback; drops all cdm nodes.
1357
 *
1358
 * @ingroup forms
1359
 */
1360
function drop_all_cdm_nodes_submit($form, &$form_state) {
1361
  cdm_delete_all_cdm_nodes();
1362
  drupal_set_message(t('All cdm nodes dropped.'));
1363
}
1364

    
1365

    
1366
/**
1367
 * LAYOUT settings
1368
 * @return
1369
 *   todo
1370
 */
1371
function cdm_settings_layout() {
1372

    
1373
  $form = array();
1374

    
1375
  $form['about'] = array(
1376
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1377
      layout. If you want to configure the specific sites layout visit the
1378
      respective configuration site for taxon, search or media.') . '</p>',
1379
  );
1380

    
1381
  // ---- footnotes --- //
1382
  $form['footnotes'] = array(
1383
    '#type' => 'fieldset',
1384
    '#title' => t('Footnotes'),
1385
    '#collapsible' => FALSE,
1386
    '#collapsed' => FALSE,
1387
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1388
      media or distribution areas may have annotations or footnotes. When the
1389
      footnotes are enabled they will be visible (if they exist).'),
1390
  );
1391

    
1392
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1393
    '#type' => 'checkbox',
1394
    '#title' => t('Do not show footnotes'),
1395
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1396
    '#description' => t('Check this if you do not want to show any footnotes'),
1397
  );
1398

    
1399
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1400
    '#type' => 'checkbox',
1401
    '#title' => t('Do not show annotation footnotes'),
1402
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1403
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1404
  );
1405

    
1406
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1407
  // Additional option for the NULL case.
1408
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1409
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1410
    '#type' => 'checkboxes',
1411
    '#title' => t('Annotation types as footnotes'),
1412
    '#description' => t("Only annotations of the selected type will be displayed
1413
       as footnotes. You may want to turn 'technical annotations' off."),
1414
    '#options' => $annotationTypeOptions,
1415
  );
1416
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1417
  if (!empty($annotationsTypesAsFootnotes)) {
1418
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1419
  }
1420

    
1421
  // ---- original source --- //
1422
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1423
      '#type' => 'fieldset',
1424
      '#tree' => TRUE,
1425
      '#title' => t('Source Citations'),
1426
      '#collapsible' => FALSE,
1427
      '#collapsed' => FALSE,
1428
  );
1429

    
1430
  $bibliography_settings = get_bibliography_settings(true);
1431

    
1432
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1433
      '#type' => 'checkbox',
1434
      '#title' => t('Original Source in bibliography'),
1435
      '#default_value' => $bibliography_settings['enabled'],
1436
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1437
       annotations in each feature block.'),
1438
  );
1439

    
1440
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1441
    '#type' => 'select',
1442
    '#title' => t('The format of the key numerals'),
1443
    '#default_value' => $bibliography_settings['key_format'],
1444
    '#options' => array('latin' => 'Latin',
1445
      'ROMAN' => 'Roman (upper case)',
1446
      'roman' => 'Roman (lower case)',
1447
      'ALPHA'=> 'Alphabet (upper case)',
1448
      'alpha' => 'Alphabet (lower case)')
1449
  );
1450

    
1451
  // --- Advanced Search --- //
1452
  $form['asearch'] = array(
1453
      '#type' => 'fieldset',
1454
      '#title' => t('Advanced search'),
1455
      '#collapsible' => FALSE,
1456
      '#collapsed' => FALSE,
1457
  );
1458
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1459
      '#type' => 'checkbox',
1460
      '#title' => t('Show advanced search link'),
1461
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1462
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1463
  );
1464

    
1465
  // ---- Taxon Name Rendering --- //
1466
  $form['taxon_name'] = array(
1467
      '#type' => 'fieldset',
1468
      '#title' => t('Taxon name display'),
1469
      '#collapsible' => TRUE,
1470
      '#collapsed' => TRUE,
1471
      '#description' => t('The display of taxon names is configured by two parts.'
1472
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
1473
          . 'The name parts are defined in the <stong>part definitions</strong>'),
1474
  );
1475

    
1476
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1477
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1478
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1479
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1480

    
1481
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1482
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1483
    $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.)';
1484
  } else if($is_custom_part_definition){
1485
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1486
  } else  {
1487
    $which_version_message = '(These are the default part definition.)';
1488
  }
1489

    
1490
  $diff_viewer_markup = '';
1491
  if($is_custom_part_definition){
1492
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1493
  }
1494

    
1495
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1496
    . $which_version_message
1497
    . '</div>'
1498
    . $diff_viewer_markup;
1499

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

    
1589
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1590
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1591
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1592
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1593
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1594

    
1595
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1596
    $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.)';
1597
  } else if($is_custom_render_template){
1598
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1599
  } else {
1600
    $which_version_message = '(These are the default render templates.)';
1601
  }
1602

    
1603
  $diff_viewer_markup = '';
1604
  if($is_custom_render_template){
1605
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1606
  }
1607

    
1608
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1609
    . $which_version_message
1610
    . '</div>'
1611
    . $diff_viewer_markup;
1612

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

    
1653
  // @WA: D7 form api does not support reset buttons,
1654
  // so to mimic the D5 reset button we add one like this.
1655
  $form['actions']['reset'] = array(
1656
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1657
    '#weight' => 1000,
1658
  );
1659

    
1660
  $form['#submit'] = array('submit_json_as_php_array');
1661
  // #json_elements especially defined for submit_json_as_php_array()
1662
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1663
  return system_settings_form($form);
1664
}
1665

    
1666

    
1667

    
1668
  /**
1669
 * @todo Please document this function.
1670
 * @see http://drupal.org/node/1354
1671
 */
1672
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1673
  $form[$form_name] = array(
1674
    '#type' => 'fieldset',
1675
    '#title' => t($form_title),
1676
    '#collapsible' => TRUE,
1677
    '#collapsed' => $collapsed,
1678
    '#tree' => TRUE,
1679
    '#description' => t($form_description),
1680
  );
1681

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

    
1701
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1702
      '#type' => 'checkbox',
1703
      '#title' => t('Show media thumbnails for synonyms'),
1704
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1705
      '#description' => '',
1706
    );
1707
  }
1708

    
1709
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1710
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1711
    '#type' => 'checkbox',
1712
    '#title' => t('Show captions under thumbnails'),
1713
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1714
    '#description' => '',
1715
  );
1716

    
1717
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1718
    '#type' => 'textfield',
1719
    '#title' => t('Thumbnail size') . ':',
1720
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1721
    '#description' => t('Select the size of each individual thumbnail.'),
1722
  );
1723

    
1724
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1725
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1726
      '#type' => 'textfield',
1727
      '#title' => t('Number of columns') . ':',
1728
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1729
      '#description' => t('Group the thumbnails in columns: select how many
1730
        columns the gallery should display.'),
1731
    );
1732
  }
1733

    
1734
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1735
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1736
      '#type' => 'textfield',
1737
      '#title' => t('Maximum number of rows') . ':',
1738
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1739
      '#description' => t('You can group the thumbnails in rows, select in how
1740
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1741
        If you want an unlimited number of rows please set to 0.'),
1742
    );
1743
  }
1744

    
1745
  return $form;
1746
}
1747

    
1748
/**
1749
 * @todo document this function.
1750
 */
1751
function cdm_settings_layout_taxon() {
1752
  $collapsed = FALSE;
1753
  $form = array();
1754

    
1755
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1756

    
1757
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1758
      '#type' => 'checkbox',
1759
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1760
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1761
      '#description' => t('<p>If checked the link to search results is rendered at
1762
       the top of the taxon site. Clicking on the link the last search performed
1763
       is rendered again.</p>'),
1764
  );
1765

    
1766
  // --------- TABBED TAXON ------- //
1767
  $form['taxon_tabs'] = array(
1768
    '#type' => 'fieldset',
1769
    '#title' => t('Taxon tabs'),
1770
    '#collapsible' => TRUE,
1771
    '#collapsed' => TRUE,
1772
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1773
      be splitted in four diferent tabs; General, Synonymy, Images and
1774
      Specimens. If the taxon has no information for any of the tabs/sections
1775
      such tab will be not displayed.'),
1776
  );
1777

    
1778
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1779
    '#type' => 'checkbox',
1780
    '#title' => t('Tabbed taxon page'),
1781
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1782
    '#description' => t('<p>If selected split the taxon page into individual
1783
      tabs for description, images, synonymy and specimens. If not the taxon
1784
      data is rendered as a long single page without tabs.</p>'),
1785
  );
1786

    
1787
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1788
    '#type' => 'checkboxes',
1789
    '#title' => t('Tabs visibility options') . ':',
1790
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1791
    '#options' => get_taxon_options_list(),
1792
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1793
  );
1794

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

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

    
1825
  /* ======  TAXON_PROFILE ====== */
1826
  $form['taxon_profile'] = array(
1827
    '#type' => 'fieldset',
1828
    '#title' => t('Taxon profile (tab)'),
1829
    '#description' => t('<p>This section covers the settings related to the taxon
1830
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1831
    '#collapsible' => TRUE,
1832
    '#collapsed' => TRUE,
1833
  );
1834

    
1835
  // ---- PROFILE PICTURE ----//
1836

    
1837
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1838
    '#type' => 'fieldset',
1839
    '#tree' => TRUE,
1840
    '#title' => t('Taxon profile picture'),
1841
    '#collapsible' => TRUE,
1842
    '#collapsed' => FALSE,
1843
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1844
  );
1845

    
1846
  //FIXME migrate variables:
1847
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1848
  // FIXME
1849
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1850

    
1851
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1852

    
1853
  /*
1854
   * 'show' => 1,
1855
   * 'maxextend' => 184,
1856
   * 'media_uri_query' => ''
1857
   * 'custom_placeholder_image_on' => 1,
1858
   * 'custom_placeholder_image_fid' => ''
1859
   */
1860
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1861
    '#type' => 'checkbox',
1862
    '#title' => t('Enable profile picture'),
1863
    '#description' => t('Show the profile picture.'),
1864
    '#default_value' => $taxon_profile_image_settings['show'],
1865
  );
1866

    
1867
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1868
      '#type' => 'textfield',
1869
      '#tree' => TRUE,
1870
      '#title' => t('Profile picture maximum extend'),
1871
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1872
      '#field_suffix' => 'px',
1873
      '#maxlength' => 4,
1874
      '#size' => 4,
1875
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1876
  );
1877

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

    
1891
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1892
    '#type' => 'checkbox',
1893
    '#title' => t('Show the placeholder image'),
1894
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
1895
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1896
  );
1897

    
1898
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1899
      '#type' => 'checkbox',
1900
      '#title' => t('Use a custom placeholder image'),
1901
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1902
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1903
  );
1904

    
1905
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1906
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1907
        '#type' => 'managed_file',
1908
        '#title' => t('Custom placeholder image file'),
1909
        '#progress_indicator' => 'bar',
1910
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1911
    //       '#name' => 'custom_placeholder_image',
1912
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1913
    );
1914

    
1915
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1916
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1917
      $url = file_create_url($profile_image_file->uri);
1918
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1919
                '#type' => 'item',
1920
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1921
      );
1922
    }
1923
  } else {
1924
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1925
      '#type' => 'hidden',
1926
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1927
    );
1928
  }
1929

    
1930
  $options = cdm_rankVocabulary_as_option();
1931
  array_unshift($options, '-- DISABLED --');
1932
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1933
    '#type' => 'select',
1934
    '#title' => t('Hide profile picture for higher ranks') . ':',
1935
    '#default_value' => variable_get('image_hide_rank', '0'),
1936
    '#options' => $options,
1937
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1938
  );
1939

    
1940
  // -- MEDIA THUMBNAILS -- //
1941
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1942
  $form_title = 'Taxon Profile Images';
1943
  $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>';
1944
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1945

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

    
1974
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
1975
  $profile_feature_tree = get_profile_feature_tree();
1976

    
1977
  if (isset($profile_feature_tree->root->childNodes)) {
1978

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

    
2018

    
2019
    $feature_list_layout_settings_disabled = FALSE;
2020

    
2021
    // creating helper object to retrieve the default settings
2022
    $featureNode = new stdClass();
2023
    $featureNode->feature = new stdClass();
2024
    $featureNode->feature->uuid="DEFAULT";
2025
    $featureNode->feature->representation_L10n = "Default";
2026
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2027

    
2028
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2029

    
2030
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2031

    
2032
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2033
        $subform_id = $featureNode->feature->uuid;
2034
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2035

    
2036
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2037

    
2038
        $form_feature_block_layout[$subform_id] = array(
2039
          '#type' => 'fieldset',
2040
          '#tree' => TRUE,
2041
          '#title' => $featureNode->feature->representation_L10n,
2042
          '#collapsible' => FALSE,
2043
          '#collapsed' => FALSE,
2044
        );
2045
        if($featureNode->feature->uuid == "DEFAULT"){
2046
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2047
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2048
          references</em> and <em>names in source</em> is only possible in the defaults';
2049
        }
2050

    
2051
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2052
          '#type' => 'select',
2053
          '#title' => 'List type',
2054
          '#default_value' => $feature_block_setting['as_list'],
2055
          '#options' => array(
2056
            'div' => 'not as list',
2057
            'ul' => 'bullet list',
2058
            'ol' => 'numbered list',
2059
            'dl' => 'definition list'
2060
          ),
2061
        );
2062

    
2063
        if($featureNode->feature->uuid == "DEFAULT"){
2064
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2065
            '#type' => 'checkbox',
2066
            '#title' => t('Link to reference'),
2067
            '#default_value' => $feature_block_setting['link_to_reference'],
2068
          );
2069

    
2070
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2071
            '#type' => 'checkbox',
2072
            '#title' => 'Link to name used in source',
2073
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2074
          );
2075
        }
2076

    
2077
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2078
          '#type' => 'checkbox',
2079
          '#title' => 'Sources as content',
2080
          '#default_value' => $feature_block_setting['sources_as_content'],
2081
        );
2082

    
2083
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2084
          '#type' => 'checkbox',
2085
          '#title' => 'Put sources also as content to bibliography',
2086
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2087
        );
2088

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

    
2108
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2109
          '#type' => 'select',
2110
          '#title' => t('Element tag'),
2111
          '#options' => array(
2112
            'span' => 'span',
2113
            'div' => 'div'
2114
          ),
2115
          '#default_value' => $feature_block_setting['element_tag'],
2116
        );
2117
      }
2118
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2119
    }
2120
  }
2121

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

    
2147

    
2148

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

    
2167
  );
2168

    
2169
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2170
    '#type' => 'checkbox',
2171
    '#title' => t('Condensed distribution'),
2172
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2173
    '#description' => 'This option enables the display of a very compact representation
2174
    of the distribution which includes also information on the status.',
2175
  );
2176

    
2177
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2178
    '#type' => 'select',
2179
    '#title' => t('Condensed distribution recipe'),
2180
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2181
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2182
    '#description' => 'Recipe for creating the condensed distribution.',
2183
  );
2184

    
2185
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2186
    '#type' => 'textfield',
2187
    '#title' => t('Condensed distribution info path'),
2188
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2189
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2190
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2191
  );
2192

    
2193

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

    
2211
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2212
    '#type' => 'fieldset',
2213
    '#tree' => true,
2214
    '#title' => t('Distribution hierarchy style')
2215
  );
2216

    
2217
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2218
  foreach(array_keys($hierarchy_styles) as $level) {
2219
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2220
      '#type' => 'fieldset',
2221
      '#tree' => true,
2222
      '#title' => t(drupal_ucfirst((str_replace('_', ' ', $level)))),
2223
      '#attributes' => array('class' => array('fieldset-float'))
2224
    );
2225
    foreach ($hierarchy_styles[$level] as $key => $value) {
2226
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2227
        '#type' => 'textfield',
2228
        '#title' => t(drupal_ucfirst((str_replace('_', ' ', $key)))),
2229
        '#default_value' => $hierarchy_styles[$level][$key],
2230
        '#maxlength' => 4,
2231
        '#size' => 4
2232
      );
2233
    }
2234
  }
2235

    
2236
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, CDM_ORDER_BY_ORDER_INDEX_ASC);
2237
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2238
    '#type' => 'checkboxes',
2239
    '#title' => 'Omit area levels',
2240
    '#options' => $level_options,
2241
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2242
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2243
    Areas which belong to the selected area levels will be hidden in the portal.',
2244
  );
2245

    
2246
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2247
    '#type' => 'checkbox',
2248
    '#title' => t('Show TextData elements on top of the map'),
2249
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2250
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2251
      elements on top of the map. Otherwise all <code>TextData</code>
2252
      distribution elements will be listed below the other area elements.
2253
      This option is useful if you need to have descriptive texts for each
2254
      distribution map.'),
2255
  );
2256

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

    
2284
AbsenceTerm
2285
a	absent
2286
f	reported in error
2287
nf	native: reported in error
2288
if	introduced: reported in error
2289
cf	cultivated: reported in error
2290
ne	native: formerly native
2291
ie	introduced: formerly introduced
2292

    
2293
</pre>'),
2294
  );
2295

    
2296

    
2297
  /* ====== SYNONYMY ====== */
2298
  $form['taxon_synonymy'] = array(
2299
    '#type' => 'fieldset',
2300
    '#title' => t('Taxon synonymy (tab)'),
2301
    '#collapsible' => TRUE,
2302
    '#collapsed' => TRUE,
2303
    '#description' => t('This section covers the settings related to the taxon
2304
      <strong>synonymy</strong> tab.'),
2305
  );
2306

    
2307
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2308
    '#type' => 'checkbox',
2309
    '#title' => t('Show accepted taxon on top of the synonymy'),
2310
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2311
    '#description' => t('If checked, the first homotypic taxon is a repetition
2312
      of the accepted taxon most likely with the full nomenclatural reference
2313
      (depending on the currently chosen theme).'),
2314
  );
2315

    
2316
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2317
    '#type' => 'checkbox',
2318
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2319
      coming from a synonym link.'),
2320
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2321
    '#description' => t('Check this if after doing a search and clicking on a
2322
      synonym you want to see the "accept of" text for the accepted synonym.'),
2323
  );
2324

    
2325
  /* === currently unused ===
2326
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2327
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2328
    '#type' => 'checkboxes',
2329
    '#title' => t('Display name relationships') . ':',
2330
    '#default_value' => variable_get('name_relationships_to_show', 0),
2331
    '#options' => $nameRelationshipTypeOptions,
2332
    '#description' => t('Select the name relationships you want to show for the
2333
      accepted taxa.'),
2334
  );
2335
 */
2336

    
2337
  $form['taxon_synonymy']['taxon_relations'] = array(
2338
    '#type' => 'fieldset',
2339
    '#title' => t('Taxon relationships'),
2340
    '#collapsible' => FALSE,
2341
    '#collapsed' => FALSE
2342
  );
2343

    
2344
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2345
    '#type' => 'checkbox',
2346
    '#title' => t('Show taxon relations ships of accepted taxon'),
2347
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2348
    '#description' => t('If this option is enabled the synonymy will show the
2349
      below selected taxon relationships of accepted taxa.'),
2350
  );
2351

    
2352
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2353
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2354
    '#type' => 'checkboxes',
2355
    '#title' => t('Taxon relationship types') . ':',
2356
    '#description' => t('Only taxon relationships of the selected type will be
2357
      displayed'),
2358
    '#options' => $taxonRelationshipTypeOptions,
2359
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2360
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2361
  );
2362

    
2363
  $form['taxon_synonymy']['name_relations'] = array(
2364
    '#type' => 'fieldset',
2365
    '#title' => t('Name relationships'),
2366
    '#collapsible' => FALSE,
2367
    '#collapsed' => FALSE
2368
  );
2369

    
2370
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2371
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2372
    '#type' => 'checkboxes',
2373
    '#title' => t('Name relationship types') . ':',
2374
    '#description' => t('Only name relationships of the selected type will be
2375
      displayed'),
2376
    '#options' => $taxonRelationshipTypeOptions,
2377
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2378
  );
2379

    
2380
  // ====== SPECIMENS ====== //
2381
  $form['taxon_specimens'] = array(
2382
    '#type' => 'fieldset',
2383
    '#title' => t('Taxon specimens (tab)'),
2384
    '#collapsible' => TRUE,
2385
    '#collapsed' => TRUE,
2386
    '#description' => t('This section covers the settings related to the taxon
2387
      <strong>specimens</strong> tab.'),
2388
  );
2389

    
2390
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2391
        '#type' => 'checkbox',
2392
        '#title' => t('Show specimen derivatives in a compressed table'),
2393
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2394
        '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2395
        a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2396
    );
2397
    
2398
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2399
        '#type' => 'checkbox',
2400
        '#title' => t('Show "Associated with" in specimen table.'),
2401
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2402
    );
2403

    
2404
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2405
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2406
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2407
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2408
  }
2409
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2410
      '#type' => 'radios',
2411
      '#title' => t('Specimen description feature tree') . ':',
2412
      '#default_value' => $profile_feature_tree_uuid,
2413
      '#options' =>  $featureTrees['options'],
2414
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2415
      '#options_suffixes' => $featureTrees['treeRepresentations'],
2416
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2417
      ),
2418
  );
2419

    
2420
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2421
  $form_title = t('Specimen media');
2422
  $form_description = t('Specimens may have media which is displayed at the
2423
     Specimen tab/section as a gallery. It is possible to configure the
2424
     thumbnails gallery here, however for configuring how a single media should
2425
     be displayed please go to !url.</p>',
2426
     array(
2427
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2428
     ));
2429
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2430

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

    
2442
  // Comment @WA: D7 form api does not support reset buttons,
2443
  // so to mimic the D5 reset button we add one like this.
2444
  $form['actions']['reset'] = array(
2445
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2446
    '#weight' => 1000,
2447
  );
2448
  return system_settings_form($form);
2449
}
2450

    
2451
/**
2452
 * @todo document this function.
2453
 */
2454
function cdm_settings_layout_search() {
2455

    
2456
  $form = array();
2457

    
2458
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2459

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

    
2471
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2472
      '#type' => 'checkbox',
2473
      '#title' => t('Ignore the chosen classification in simple search'),
2474
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2475
      '#description' => t('The simple search, which can be executed via the search block,
2476
          will by default search on the classification selected in the classification browser
2477
          selector. Set the tick if you want your portal to search on all classifications.'),
2478
  );
2479

    
2480
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2481
    '#type' => 'checkbox',
2482
    '#title' => t('Run simple search with free-text search backend.'),
2483
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2484
    '#description' => t('The simple search uses by default another search
2485
      backend as the advances search. By checking this option the simple search can be
2486
      configured to also use the free-text search backend.'),
2487
  );
2488

    
2489
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2490
    '#type' => 'textfield',
2491
    '#title' => t('Results per page') . ':',
2492
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2493
    '#description' => t('Number of results to display per page.'),
2494
  );
2495

    
2496
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2497
    '#type' => 'checkbox',
2498
    '#title' => t('Show the <i>Show Image Thumbnails</i> button') . ':',
2499
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2500
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2501
  );
2502

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

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

    
2520
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2521
  );
2522

    
2523
  // --- SEARCH TAXA GALLERY ---- //
2524
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2525
  $collapsed = FALSE;
2526
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2527
  $form_title = 'Taxa Search thumbnails';
2528
  $form_description = 'Search results may show thumbnails. ';
2529
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2530

    
2531
  // Comment @WA: D7 form api does not support reset buttons,
2532
  // so to mimic the D5 reset button we add one like this.
2533
  $form['actions']['reset'] = array(
2534
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2535
    '#weight' => 1000,
2536
  );
2537
  return system_settings_form($form);
2538
}
2539

    
2540
/**
2541
 * @todo document this function.
2542
 */
2543
function cdm_settings_layout_media() {
2544

    
2545
  $form = array();
2546

    
2547
  $form['media_settings'] = array(
2548
    '#type' => 'fieldset',
2549
    '#title' => t('Media settings'),
2550
    '#collapsible' => FALSE,
2551
    '#collapsed' => FALSE,
2552
    '#description' => 'This section covers layout settings for media pages.'
2553
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2554
  );
2555

    
2556
  $form['media_settings']['image_gallery_viewer'] = array(
2557
    '#type' => 'select',
2558
    '#title' => t('Image viewer') . ':',
2559
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2560
    '#options' => array(
2561
      'default' => t('Standard image viewer'),
2562
      'fsi' => t('FSI viewer (requires FSI server!)'),
2563
    ),
2564
  );
2565

    
2566
  // --- MEDIA GALLERY ---- //
2567
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2568
  $form_title = 'Standard viewer';
2569
  $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>';
2570
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2571
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2572

    
2573
  // @WA: D7 form api does not support reset buttons,
2574
  // so to mimic the D5 reset button we add one like this.
2575
  $form['actions']['reset'] = array(
2576
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2577
    '#weight' => 1000,
2578
  );
2579
  return system_settings_form($form);
2580
}
2581

    
2582
/**
2583
 * GEOSERVICE and Map settings.
2584
 */
2585
function cdm_settings_geo($form, &$form_state) {
2586

    
2587
  $current_geoserver_settings = get_edit_map_service_settings();
2588
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2589

    
2590

    
2591
  $form = array();
2592

    
2593
  $dummy_distribution_query = NULL;
2594
  if($map_distribution['map_type'] != 1){
2595
    // we need to apply a dummy query since the map service requires for image maps
2596
    // at least as and ad to be defined
2597
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2598
  }
2599

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

    
2618
  /*
2619
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2620
  );
2621
  */
2622

    
2623
  /*
2624
   * GEO SERVER
2625
   */
2626
  $form['edit_map_server'] = array(
2627
    '#type' => 'fieldset',
2628
    '#tree' => true,
2629
    '#title' => t('EDIT map service'),
2630
    '#collapsible' => TRUE,
2631
    '#collapsed' => TRUE,
2632
    '#description' => t('Configuration and selection of your geo server.
2633
      The Geo Server is responsible for generating the maps.'),
2634
  );
2635

    
2636
  $form['edit_map_server']['base_uri'] = array(
2637
    '#type' => 'select',
2638
    '#title' => t('EDIT map service') . ':',
2639
    '#default_value' => $current_geoserver_settings['base_uri'],
2640
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2641
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2642
  );
2643
  $form['edit_map_server']['version'] = array(
2644
      '#type' => 'select',
2645
      '#title' => t('Version') . ':',
2646
      '#default_value' => $current_geoserver_settings['version'],
2647
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2648
      '#description' => t('The version of the EDIT map services'),
2649
  );
2650

    
2651
  /*
2652
   * MAP SETTINGS
2653
   */
2654

    
2655
  $form[CDM_MAP_DISTRIBUTION] = array(
2656
    '#type' => 'fieldset',
2657
    '#tree' => TRUE,
2658
    '#title' => t('Maps settings'),
2659
    '#collapsible' => TRUE,
2660
    '#collapsed' => TRUE,
2661
    '#description' => t('General configuration for all map types.'),
2662
  );
2663

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

    
2681
  /*
2682
   * settings for the distribution map are used also for specimens map!!!!
2683
   */
2684

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

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

    
2713
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2714
    '#type' => 'checkbox',
2715
    '#title' => 'Display area labels',
2716
    '#default_value' => $map_distribution['show_labels'],
2717
    '#description' => t('The map will show name labels of the areas'),
2718
  );
2719

    
2720
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2721
    '#type' => 'textfield',
2722
    '#title' => 'Map caption',
2723
    '#default_value' => $map_distribution['caption'],
2724
    '#description' => t('The caption will be shown below the map.'),
2725
  );
2726

    
2727
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2728
    '#type' => 'textfield',
2729
    '#title' => 'Distribution layer opacity',
2730
    '#default_value' => $map_distribution['distribution_opacity'],
2731
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2732
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2733
  );
2734

    
2735
  // --- Plain Image Settings --- //
2736
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2737
    '#type' => 'fieldset',
2738
    '#title' => 'Plain image map settings',
2739
    '#tree' => TRUE,
2740
    '#collapsible' => TRUE,
2741
    '#collapsed' => $open_layers_is_enabled,
2742
    '#description' => 'The settings in this section are still expertimental
2743
      and can only be used with the EDIT map service version 1.1 or above.',
2744
  );
2745
  $edit_mapserver_version = get_edit_map_service_version_number();
2746
  if ($edit_mapserver_version < 1.1) {
2747
    $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>'
2748
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2749
  }
2750

    
2751
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2752
    '#type' => 'textfield',
2753
    '#title' => 'Width',
2754
    '#default_value' => $map_distribution['image_map']['width'],
2755
    '#maxlength' => 4,
2756
    '#size' => 4,
2757
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2758
  );
2759

    
2760
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2761
    '#type' => 'textfield',
2762
    '#title' => 'Background layer',
2763
    '#default_value' => $map_distribution['image_map']['base_layer'],
2764
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2765
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2766
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2767
    )),
2768
  );
2769

    
2770
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2771
    '#type' => 'textfield',
2772
    '#title' => 'Background color',
2773
    '#default_value' => $map_distribution['image_map']['bg_color'],
2774
  );
2775

    
2776
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2777
    '#type' => 'textfield',
2778
    '#title' => 'Background layer style',
2779
     // Only line color by now.
2780
    '#default_value' => $map_distribution['image_map']['layer_style'],
2781
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2782
  );
2783

    
2784
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2785
      '#type' => 'textfield',
2786
      '#title' => 'Projection',
2787
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2788
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2789
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2790
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2791
  );
2792

    
2793

    
2794
  // --- OpenLayers Settings --- //
2795
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2796
    '#type' => 'fieldset',
2797
    '#title' => 'OpenLayers settings',
2798
    '#tree' => TRUE,
2799
    '#collapsible' => TRUE,
2800
    '#collapsed' => !$open_layers_is_enabled,
2801
    '#description' => '',
2802
  );
2803

    
2804

    
2805
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2806
      '#type' => 'checkbox',
2807
      '#title' => 'Display outside max extent',
2808
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2809
      '#description' => t('Allows the map to display parts of the layers which are outside
2810
         the max extent if the aspect ratio of the map and of the baselayer
2811
         are not equal.'),
2812
  );
2813

    
2814

    
2815
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2816
      '#type' => 'checkbox',
2817
      '#title' => 'Show Layer Switcher',
2818
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2819
      '#description' => 'The Layer Switcher control displays a table of contents
2820
      for the map.  This allows the user interface to switch between
2821
      base layers and to show or hide overlays.  By default the switcher is
2822
      shown minimized on the right edge of the map, the user may expand it
2823
      by clicking on the handle.',
2824
  );
2825

    
2826
  if (!$open_layers_is_enabled) {
2827
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2828
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2829
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2830
  }
2831

    
2832
  // The default layer must always be enabled
2833
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2834
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2835

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

    
2863
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2864
    '#type' => 'checkboxes_preferred',
2865
    '#title' => 'Base Layers',
2866
    '#options' => $baselayer_options,
2867
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2868
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2869
  );
2870

    
2871
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2872
      '#type' => 'fieldset',
2873
      '#title' => 'Custom WMS base layer',
2874
      '#tree' => TRUE,
2875
      '#collapsible' => FALSE,
2876
      '#collapsed' => FALSE,
2877
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2878
  );
2879

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

    
2976
  /*
2977
   * Map Legend
2978
   */
2979
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2980
    '#type' => 'fieldset',
2981
    '#title' => 'Map legend',
2982
    '#tree' => TRUE,
2983
    '#collapsible' => TRUE,
2984
    '#collapsed' => TRUE,
2985
    '#description' => 'Configure the maps legend.',
2986
  );
2987

    
2988
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2989
    '#type' => 'checkbox',
2990
    '#title' => 'Display a map legend',
2991
    '#default_value' => $map_distribution['legend']['show'],
2992
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2993
  );
2994

    
2995
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2996
    '#type' => 'textfield',
2997
    '#title' => 'Legend opacity',
2998
    '#default_value' => $map_distribution['legend']['opacity'],
2999
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3000
                         to 0.0 will be not much visible.',
3001
  );
3002

    
3003
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3004
    '#type' => 'textfield',
3005
    '#title' => 'Font size',
3006
    '#default_value' => $map_distribution['legend']['font_size'],
3007
    '#description' => 'Font size in pixels.',
3008
  );
3009

    
3010
  $fontStyles = array(
3011
    0 => "plane",
3012
    1 => "italic",
3013
  );
3014
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3015
    '#type' => 'select',
3016
    '#title' => 'Available font styles',
3017
    '#default_value' => $map_distribution['legend']['font_style'],
3018
    '#options' => $fontStyles,
3019
    '#description' => 'Select a font style for the map legend.',
3020
  );
3021

    
3022
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3023
    '#type' => 'textfield',
3024
    '#title' => 'Icon width',
3025
    '#default_value' => $map_distribution['legend']['icon_width'],
3026
    '#description' => 'Legend icon width in pixels.',
3027
  );
3028
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3029
    '#type' => 'textfield',
3030
    '#title' => 'Icon height',
3031
    '#default_value' => $map_distribution['legend']['icon_height'],
3032
    '#description' => 'Legend icon height in pixels.',
3033
  );
3034

    
3035
  // @WA: D7 form api does not support reset buttons,
3036
  // so to mimic the D5 reset button we add one like this.
3037
  $form['actions']['reset'] = array(
3038
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3039
    '#weight' => 1000,
3040
  );
3041

    
3042
  return system_settings_form($form);
3043
}
3044

    
3045

    
3046
/**
3047
 * @todo document this function.
3048
 */
3049
function cdm_settings_cache() {
3050

    
3051
  $form = array();
3052

    
3053
  $form['cache_settings'] = array(
3054
    '#type' => 'fieldset',
3055
    '#title' => t('Cache Settings'),
3056
    '#collapsible' => FALSE,
3057
    '#collapsed' => FALSE,
3058
    '#description' => t('<p>When caching is enabled all single taxon sites are
3059
      stored in an internal drupal cache doing the portal response of taxa pages
3060
      faster. This is possible because the sites are loaded from the cache and
3061
      are not created from scratch.</p>'),
3062
  );
3063

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

    
3076
  $form['cache_settings']['cdm_run_cache'] = array(
3077
    '#markup' => cdm_view_cache_site(),
3078
  );
3079

    
3080
  // @WA: D7 form api does not support reset buttons,
3081
  // so to mimic the D5 reset button we add one like this.
3082
  $form['actions']['reset'] = array(
3083
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3084
    '#weight' => 1000,
3085
  );
3086
  return system_settings_form($form);
3087
}
3088

    
3089
/**
3090
 * Walk and cache all taxon pages.
3091
 */
3092
function cdm_view_cache_site() {
3093

    
3094
  $out = '';
3095

    
3096
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3097

    
3098
  $request_params = array();
3099
  $request_params['class'] = "Taxon";
3100

    
3101
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3102
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3103
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3104

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

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

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

    
3132

    
3133
function cdm_settings_layout_taxon_submit($form, &$form_state){
3134
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3135
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3136
    if(is_object($file)){
3137
      $file->status = FILE_STATUS_PERMANENT;
3138
      file_save($file);
3139
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3140
    }
3141
  }
3142
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
3143
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
3144
    // we first need to set the variable to persist the changes setting
3145
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3146
    menu_rebuild();
3147
  }
3148
}
3149

    
3150
function cdm_settings_layout_search_submit($form, &$form_state){
3151
  // the visibility of media thumbnails also affects the ui of the search results
3152
  // so reset the according session variable
3153
  //    1. in order to give the user immediate
3154
  //       feedback on potential setting changes
3155
  //    2. let refresh the default if it has changed
3156
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3157
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3158
  }
3159
}
3160

    
3161
/**
3162
 * Form validation handler for cdm_settings_general
3163
 *
3164
 * @param $form
3165
 * @param $form_state
3166
 */
3167
function cdm_settings_general_validate($form, &$form_state) {
3168

    
3169
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3170
    $form_state['values']['cdm_webservice_url'] .= '/';
3171
  }
3172

    
3173
}
3174

    
3175
/**
3176
 * Form submit handler for settings general.
3177
 *
3178
 * tasks performed:
3179
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3180
 *
3181
 * @param $form
3182
 * @param $form_state
3183
 */
3184
function cdm_settings_general_submit($form, &$form_state){
3185
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3186
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3187
}
3188

    
3189
/**
3190
 * Form validation handler for cdm_settings_cache
3191
 */
3192
function cdm_settings_cache_validate($form, &$form_state) {
3193
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3194
    cache_clear_all(NULL, 'cache_cdm_ws');
3195
    // Better clear secref_cache since I can not be sure if the cache has not
3196
    // be used during this response.
3197
    cdm_api_secref_cache_clear();
3198
  }
3199

    
3200
}
3201

    
3202
/**
3203
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3204
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3205
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3206
 *  - version: the version, e.g.: v1.1
3207
 *
3208
 * @return array
3209
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3210
 */
3211
function get_edit_map_service_settings() {
3212

    
3213
  $settings = variable_get('edit_map_server', array(
3214
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3215
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3216
      )
3217
  );
3218

    
3219
  return $settings;
3220
}
3221

    
3222
/**
3223
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3224
 *
3225
 * @return string
3226
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3227
 */
3228
function get_edit_map_service_full_uri() {
3229
  $settings = get_edit_map_service_settings();
3230
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3231
}
3232

    
3233

    
3234
/**
3235
 * Returns the version number of the currently selected edit mapserver as a float
3236
 *
3237
 * @return float
3238
 *   The version number of the currently selected edit mapserver as a float.
3239
 *   Returns 0 on error.
3240
 */
3241
function get_edit_map_service_version_number() {
3242

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

    
3245
  $settings = get_edit_map_service_settings();
3246
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3247
  if (isset($matches[1])) {
3248
    // Convert string to float.
3249
    $version = 1 + $matches[1][0] - 1;
3250
    return $version;
3251
  }
3252
  else {
3253
    // Report error.
3254
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3255
        array(
3256
          '!version' => $settings['version'],
3257
          'warning')
3258
        )
3259
      );
3260
    return 0;
3261
  }
3262
}
3263

    
3264
/**
3265
 * Returns the array of selected items in a options array
3266
 *
3267
 * @param array $options
3268
 *   An options array as generated by a form element like checkoxes, select ...,
3269
 */
3270
function get_selection($options) {
3271
  $selection = array();
3272
  foreach ($options as $key=>$val) {
3273
    if (!empty($val)) {
3274
      $selection[] = $val;
3275
    }
3276
  }
3277
  return $selection;
3278
}
3279

    
3280

    
3281
/**
3282
 * Implements hook_element_info().
3283
 *
3284
 * Allows modules to declare their own Form API element types and specify their default values.
3285
 *
3286
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3287
 */
3288
function cdm_dataportal_element_info() {
3289
  $type['checkboxes_preferred'] = array(
3290
    '#input' => TRUE,
3291
    '#process' => array('checkboxes_preferred_expand'),
3292
    '#after_build' => array('checkboxes_preferred_after_build'),
3293
    '#theme' => array('checkboxes_preferred'),
3294
    // '#theme_wrapper' => array('form_element'),
3295
  );
3296
  return $type;
3297
}
3298

    
3299
/**
3300
 * #process callback function for the custom form element type 'checkbox_preferred'
3301
 *
3302
 *
3303
 */
3304
function checkboxes_preferred_expand($element, &$form_state, $form) {
3305

    
3306
  // First of all create checkboxes for each of the elements
3307
  $element = form_process_checkboxes($element);
3308

    
3309
  // compose the element name
3310
  $parents = array();
3311
  array_deep_copy($element['#parents'], $parents);
3312
  $parents[count($parents) -1 ] .= '_preferred';
3313
  $element_name = $parents[0];
3314
  for ($i=1; $i < count($parents); $i++){
3315
    $element_name .= '[' . $parents[$i] . ']';
3316
  }
3317

    
3318
  $children = element_children($element);
3319

    
3320
  $element['table_start'] = array(
3321
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3322
    '#weight' => -1,
3323
  );
3324

    
3325
  // prepare first part each of the table rows which contains the row label
3326
  $weight = 0;
3327
  foreach ($children as $key) {
3328
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3329
    $element[$key]['#weight'] = $weight;
3330
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
3331
    $element[$key]['#suffix'] = '</td>';
3332
    unset($element[$key]['#title']);
3333
    $weight += 2;
3334
  }
3335
  $weight = 0;
3336

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

    
3360
  // end the table
3361
  $element['table_end'] = array(
3362
    '#markup' => '</table>',
3363
    '#weight' => $weight++,
3364
  );
3365

    
3366
  return $element;
3367
}
3368

    
3369
/**
3370
 * Theme function for the custom form field 'checkboxes_preferred'.
3371
 */
3372
function theme_checkboxes_preferred($variables) {
3373
  $element = $variables['element'];
3374
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3375
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3376
  $out .= drupal_render_children($element);
3377
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3378
  $out .= '</div>';
3379
  return $out;
3380
}
3381

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

    
3402
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3403

    
3404
  if ($_POST && count($_POST) > 0) {
3405
    // TODO use  $form_state['input'] instead of POST !!!
3406
    // First pass of form processing.
3407
    $parents = array();
3408
    array_deep_copy($element['#parents'], $parents);
3409
    $parents[count($parents) - 1] .= '_preferred';
3410
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3411
    $element['#value']['PREFERRED'] = $preferred_layer;
3412
//     $form_state[$parent_id] = $element['#value'];
3413
//     $form_state['values']['baselayers'] = $element['#value'];
3414
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3415
    $form_state_element_values = $element['#value'];
3416
  }
3417
  else {
3418
    // Second pass of form processing.
3419
    $preferred_layer = $element['#value']['PREFERRED'];
3420
  }
3421

    
3422
  // Also set the chosen value (not sure if this is good Drupal style ....).
3423
  foreach ($children = element_children($element) as $key) {
3424
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3425
      $element[$key]['#value'] = $preferred_layer;
3426
    }
3427
  }
3428
  // The default layer must always be enabled.
3429
  $element[$preferred_layer]['#value'] = $preferred_layer;
3430

    
3431
  return $element;
3432
}
3433

    
3434
function radios_prepare_options_suffix(&$elements){
3435

    
3436
  $childrenKeys = element_children($elements);
3437
  foreach($childrenKeys as $key){
3438
    if(!is_array($elements[$key]['#theme_wrappers'])){
3439
      $elements[$key]['#theme_wrappers'] = array();
3440
    }
3441
    if(isset($elements['#options_suffixes'][$key])){
3442
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3443
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3444
    }
3445
  }
3446
  return $elements;
3447

    
3448
}
3449

    
3450
/**
3451
 * TODO
3452
 * @param unknown $variables
3453
 */
3454
function theme_radio_options_suffix($variables) {
3455
  $element = $variables['element'];
3456
  if(isset($element['#options_suffix'])) {
3457
    $element['#children'] .= $element['#options_suffix'];
3458
  }
3459
  return $element['#children'];
3460
}
3461

    
3462

    
3463
/**
3464
 * Element validate callback for text field and arrays containing json.
3465
 *
3466
 * @param $element
3467
 *   The form element to validate
3468
 * @param $form_state
3469
 *   A keyed array containing the current state of the form.
3470
 * @param $form
3471
 *   Nested array of form elements that comprise the form.
3472
 */
3473
function form_element_validate_json($element, &$form_state, $form) {
3474
   if (!empty($element['#value'])) {
3475
     json_decode($element['#value']);
3476
     if(json_last_error() != JSON_ERROR_NONE){
3477
       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/'));
3478
     }
3479
   }
3480
}
3481

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