Project

General

Profile

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

    
7

    
8
  // TODO Genus UUID.
9

    
10
  define('DEFAULT_TAXONTREE_RANKLIMIT', '1b11c34c-48a8-4efa-98d5-84f7f66ef43a');
11
  define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
12
  define('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
13

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

    
17
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
18
  define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
19
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
20
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 1);
21
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
22
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
23
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
24
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
25

    
26
  /* annotationTypeKeys */
27
  $annotationTypeKeys = array_keys(cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE));
28
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
29
    $annotationTypeKeys = array_flip($annotationTypeKeys);
30

    
31
    // Technical annotation are off by default.
32
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
33
    $annotationTypeKeys = array_flip($annotationTypeKeys);
34
    // Additional value for the NULL case.
35
    $annotationTypeKeys[] = 'NULL_VALUE';
36
  }
37
  define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
38

    
39
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
40
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
41
    'enabled' => 0,
42
    'key_format' => 'ALPHA'
43
  )));
44

    
45
  /* taxonRelationshipTypes */
46
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
47

    
48

    
49

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

    
81
    // --- Taxon profile settings --- /
82
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
83
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
84
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
85
      array(
86
          'show' => 0,
87
          'maxextend' => 184,
88
          'media_uri_query' => '',
89
          'custom_placeholder_enabled' => 1,
90
          'custom_placeholder_image_on' => 0,
91
          'custom_placeholder_image_fid' => ''
92
      )
93
    )
94
  );
95
  define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
96
  define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
97

    
98
  define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
99
  define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
100
  define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
101
  define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
102

    
103
/**
104
 * Returns the array of implemented taxon page tabs.
105
 * The array has fixed integer keys which must not be changed.
106
 */
107
function get_taxon_tabs_list() {
108
  return array(
109
    0 => 'General',
110
    1 => 'Synonymy',
111
    2 => 'Images',
112
    3 => 'Specimens',
113
    4 => 'Keys',
114
    5 => 'Experts',
115
  );
116
}
117

    
118
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
119
  array('general' => '-3', 'synonymy' => '-2', 'images' => '0', 'specimens' => '1', 'keys' => '3')
120
));
121

    
122
$taxon_tab_options = get_taxon_tabs_list();
123
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
124

    
125
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
126

    
127
/**
128
 * @todo document this function.
129
 */
130
function get_taxon_options_list() {
131
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
132
  foreach ($taxon_tab_options as $key => $value) {
133
    $taxon_tab_options[$key] = t($key);
134
  }
135
  return $taxon_tab_options;
136

    
137
}
138

    
139
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
140
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
141
  array(
142
      'ZoologicalName' => array(
143
        'namePart' => array('name' => TRUE),
144
        'nameAuthorPart' => array('name' => TRUE),
145
        'referencePart' => array('authors' => TRUE),
146
        'secReferencePart' => array('secReference' => TRUE,),
147
        'microreferencePart' => array('microreference' => TRUE),
148
        'statusPart' => array('status' => TRUE),
149
        'descriptionPart' => array('description' => TRUE),
150
      ),
151
      'BotanicalName'=> array(
152
        'namePart' => array('name' => TRUE),
153
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
154
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
155
        'secReferencePart' => array('secReference' => TRUE,),
156
        'referenceYearPart' => array('reference.year' => TRUE),
157
        'statusPart' => array('status' => TRUE),
158
        'descriptionPart' => array('description' => TRUE),
159
      ),
160
     '#DEFAULT' => array(
161
        'namePart' => array(
162
            'name' => TRUE
163
        ),
164
        'nameAuthorPart' => array(
165
            'name' => TRUE,
166
            'authors' => TRUE
167
        ),
168
       'referencePart' => array(
169
         'reference' => TRUE
170
        ),
171
       'secReferencePart' => array(
172
         'secReference' => TRUE,
173
       ),
174
       'microreferencePart' => array(
175
          'microreference' => TRUE,
176
        ),
177
       'statusPart' => array(
178
          'status' => TRUE,
179
        ),
180
       'descriptionPart' => array(
181
          'description' => TRUE,
182
        ),
183
      )
184
    )
185
  )
186
);
187
  define('CDM_PART_DEFINITIONS_DEFAULT_PRE_380', serialize(
188
    array(
189
      'ZoologicalName' => array(
190
        'namePart' => array('name' => TRUE),
191
        'nameAuthorPart' => array('name' => TRUE),
192
        'referencePart' => array('authors' => TRUE),
193
        'microreferencePart' => array('microreference' => TRUE),
194
        'statusPart' => array('status' => TRUE),
195
        'descriptionPart' => array('description' => TRUE),
196
      ),
197
      'BotanicalName'=> array(
198
        'namePart' => array('name' => TRUE),
199
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
200
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
201
        'referenceYearPart' => array('reference.year' => TRUE),
202
        'statusPart' => array('status' => TRUE),
203
        'descriptionPart' => array('description' => TRUE),
204
      ),
205
      '#DEFAULT' => array(
206
        'namePart' => array(
207
          'name' => TRUE
208
        ),
209
        'nameAuthorPart' => array(
210
          'name' => TRUE,
211
          'authors' => TRUE
212
        ),
213
        'referencePart' => array(
214
          'reference' => TRUE
215
        ),
216
        'microreferencePart' => array(
217
          'microreference' => TRUE,
218
        ),
219
        'statusPart' => array(
220
          'status' => TRUE,
221
        ),
222
        'descriptionPart' => array(
223
          'description' => TRUE,
224
        ),
225
      )
226
    )
227
  )
228
  );
229

    
230
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
231
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
232
   array (
233
     'taxon_page_title,polytomousKey'=> array(
234
          'namePart' => array('#uri' => TRUE),
235
        ),
236
      'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy,related_taxon'=> array(
237
          'nameAuthorPart' => array('#uri' => TRUE),
238
          'referencePart' => TRUE,
239
          'statusPart' => TRUE,
240
          'descriptionPart' => TRUE,
241
        ),
242
       'homonym'=> array(
243
            'nameAuthorPart' => array('#uri' => TRUE),
244
            'referenceYearPart' => TRUE,
245
        ),
246
      'acceptedFor,typedesignations,list_of_taxa' => array(
247
          'nameAuthorPart' => array('#uri' => TRUE),
248
          'referencePart' => TRUE,
249
        ),
250
      '#DEFAULT' => array(
251
          'nameAuthorPart' => array('#uri' => TRUE),
252
          'referencePart' => TRUE,
253
       )
254
    )
255
));
256
  define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
257
    array (
258
      'taxon_page_title,polytomousKey'=> array(
259
        'namePart' => array('#uri' => TRUE),
260
      ),
261
      'taxon_page_synonymy,related_taxon'=> array(
262
        'nameAuthorPart' => array('#uri' => TRUE),
263
        'referencePart' => TRUE,
264
        'statusPart' => TRUE,
265
        'descriptionPart' => TRUE,
266
      ),
267
      'homonym'=> array(
268
        'nameAuthorPart' => array('#uri' => TRUE),
269
        'referenceYearPart' => TRUE,
270
      ),
271
      'acceptedFor,typedesignations,list_of_taxa' => array(
272
        'nameAuthorPart' => array('#uri' => TRUE),
273
        'referencePart' => TRUE,
274
      ),
275
      '#DEFAULT' => array(
276
        'nameAuthorPart' => array('#uri' => TRUE),
277
        'referencePart' => TRUE,
278
      )
279
    )
280
  ));
281

    
282
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
283
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
284
    // to unset a default enntry set the value to 0
285
    array(
286
      'doTaxa'=>'doTaxa',
287
      'doSynonyms' => 'doSynonyms',
288
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
289
      'doMisappliedNames' => 'doMisappliedNames'
290
    )
291
  )
292
);
293

    
294
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
295
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
296

    
297
/* Gallery variables. */
298
$gallery_settings = array(
299
    "cdm_dataportal_show_taxon_thumbnails" => 1,
300
    "cdm_dataportal_show_synonym_thumbnails" => 0,
301
    "cdm_dataportal_show_thumbnail_captions" => 1,
302
    "cdm_dataportal_media_maxextend" => 120,
303
    "cdm_dataportal_media_cols" => 3,
304
    "cdm_dataportal_media_maxRows" => 1,
305
);
306

    
307
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
308
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
309
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
310
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
311
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
312
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
313
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
314
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
315
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
316
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
317
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
318
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
319
/**
320
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
321
 * the snonymy.
322
 *
323
 * @var string
324
 */
325
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
326
/**
327
 * The drupal variable for the configuration of the information aggregation along
328
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
329
 *    - direct: the uuids of the taxon relationship types to take into account in invers
330
 *      direction.
331
 *    - invers: the uuids of the taxon relationship types to take into account in direct
332
 *      direction.
333
 *
334
 * @var String
335
 */
336
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
337
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
338
    array(
339
        'direct'=>array(),
340
        'invers'=>array()
341
     )
342
   ));
343
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
344
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
345
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
346

    
347
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
348
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
349
      array(
350
      'filter_rules' => array(
351
        'statusOrderPreference' => 0,
352
        'subAreaPreference' => 0,
353
      ),
354
      'hiddenAreaMarkerType' => array()
355
     )
356
));
357

    
358

    
359
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
360
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
361
    array(
362
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
363
        'includeOccurrences' => 0,
364
        'includeTaxonNameDescriptions' => 0
365
     )
366
  ));
367

    
368
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
369
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
370
  // needs to be merged with user setting by drupal_array_merge_deep()
371
  'width' => 512, // optimum size for OSM layers is 512
372
  'height' => 512 / 2, // optimum size for OSM layers 256
373
  'bbox' => '', // empty to allow automatic zooming to extend
374
  'show_labels' => FALSE,
375
  'caption' => '',
376
  'distribution_opacity' => '0.5',
377
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
378
  'image_map' => array(
379
    'base_layer' => '', // none, formerly this was cyprusdivs
380
    'bg_color' => '1874CD',
381
    'layer_style' => 'ffffff,606060,,',
382
  ),
383
  'openlayers' => array(
384
    'base_layers' =>  array(
385
      // A layer MUST NOT BE SET in the defaults,
386
      // otherwise it can not be overidden by the user settings:
387
      // 'osgeo_vmap0' => 'osgeo_vmap0',
388
      // it is sufficient to define the preferred layer,
389
      // since it will automatically be enabled:
390
      'PREFERRED' => 'osgeo_vmap0'),
391
    'custom_wms_base_layer' => array(
392
      'name' => NULL,
393
      'url' => NULL,
394
      'params' =>  NULL,
395
      'projection' => NULL,
396
      'proj4js_def' => NULL,
397
      'max_extent' => NULL,
398
      'units' => NULL
399
    ),
400
    'show_layer_switcher' => TRUE,
401
    'display_outside_max_extent' => FALSE
402
  ),
403
  'legend' => array(
404
    'show' => TRUE,
405
    'opacity' => '0.5',
406
    'font_size' => 10,
407
    'font_style' => FALSE,
408
    'icon_width' => 35,
409
    'icon_height' => 15
410
  )
411
)));
412

    
413
/**
414
 * Merges the named array variable with the array of defaults.
415
 *
416
 * IMPORTANT: The array keys must be strings. When the keys are integers
417
 * the merging will not take place for these entities. Number keyed entities
418
 * are just appended to the result array.
419
 *
420
 * @param string $variable_name
421
 *     The variable name
422
 * @param string | array $default
423
 *     The array containing the default values either as array or serialized as string.
424
 *     Unserialization is cared for if necessary
425
 * @return array
426
 *     The merged array as returned by drupal_array_merge_deep()
427
 *
428
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
429
 * TODO force $default being an array
430
 */
431
function get_array_variable_merged($variable_name, $default){
432

    
433
    // unserialize if nessecary
434
    if(!is_array($default)){
435
      $default = unserialize($default);
436
    }
437
    $variable = variable_get($variable_name, array());
438
    $result = drupal_array_merge_deep($default, $variable);
439
    return $result;
440
}
441

    
442
/**
443
 * @todo document this function.
444
 */
445
function getGallerySettings($gallery_config_form_name) {
446
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
447
}
448

    
449
/**
450
 * Returns the string representation of the default tab.
451
 *
452
 * @param bool $returnTabIndex
453
 *   Defaults to FALSE, if set true this function will return the index number
454
 *   of the default tab. (used to supply default values to form elements).
455
 */
456
function get_default_taxon_tab($returnTabIndex = FALSE) {
457

    
458
  global $user;
459
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
460
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
461
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
462
  // Get the user value if the used has chosen to overwrite the system settings.
463
  $user_tab_on = variable_get($user_tab_active, FALSE);
464
  if ($user_tab_on) {
465
    $user_value = variable_get($user_tab, 0);
466
    $index_value = $user_value;
467
    // Get the system value.
468
  }
469
  else {
470
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
471
    $index_value = $system_value;
472
  }
473

    
474
  // Return the index value or the string representation.
475
  if ($returnTabIndex) {
476
    return $index_value;
477
  }
478
  else {
479
    return ($values[$index_value]);
480
  }
481
}
482

    
483

    
484
  /**
485
   * Provides the feature block settings for a specific feature which matches the $feature_uuid parameter.
486
   *
487
   * In case specifically configured settings array, like these which are stored in the drupal variables, is missing
488
   * one or more fields these fields are taken from the default. That is the specific settings are always merges
489
   * with the default.
490
   *
491
   * Note: These settings only apply to feature blocks which do not have a special rendering
492
   * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
493
   * 'special' element of the settings
494
   *
495
   * @param $feature_uuid
496
   *   The uuid string representation of the feature to return the settings for
497
   *
498
   * @return array
499
   *  an associative array of settings, with the following fields:
500
   *    - as_list: string
501
   *        this setting will be used in compose_cdm_feature_block_elements() as $enclosing_tag
502
   *        possible values are:
503
   *          div: not as list,
504
   *          ul: as bullet list,
505
   *          ol: as numbered list,
506
   *          dl: as definition list
507
   *        The tag used for the inner element, thus depends on the value of this field. The
508
   *        inner tag name can be retrieved by the function cdm_feature_block_element_tag_name()
509
   *    - link_to_reference: boolean,
510
   *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
511
   *    - link_to_name_used_in_source": boolean
512
   *        whether to show name is source information as link which will point to the according name page
513
   *    - sources_as_content (boolean)
514
   *        TRUE (int: 1):
515
   *          1. If element is of the CDM type TextData and the text is not empty the source references will be
516
   *             appended in brackets like "text (source references)". If the original source has name in source
517
   *             information it will be appended to the citation string,
518
   *             like : "(citation, as name in source; citation, as name in source)"
519
   *          2. if the text of the TextData is empty, the original source citations are the only content
520
   *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
521
   *             prepended to the citation string like: "name in source: citation"
522
   *        FALSE (int: 0):
523
   *          Original sources are put into the bibliography(=references) pseudo feature block. If the original source
524
   *          citations are the only content, the resulting feature block content would only consist of footnotes.
525
   *          In this case the display of the respective feature block is suppressed.
526
   *          TODO if the bibliography is not enabled the sources will be treated as footnotes like annotations,
527
   *               in future however they will in this case be shown in a separate references section for each
528
   *               feature block.
529
   *    - sources_as_content_to_bibliography  (boolean)
530
   *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
531
   *        in the bibliography.
532
   *    - sort_elements
533
   *        whether and how to sort the elements
534
   *        possible values are the constants SORT_ASC, SORT_DESC, NULL,
535
   *        some feature types (Distribution) also support: SORT_HIERARCHICAL (
536
   *        TODO option to exclude levels, put in special?,
537
   *        TODO make use of this setting in compose_cdm_feature_block_elements())
538
   *    - element_tag
539
   *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
540
   *        possible values are span | div. the proper inner tag name can be retrieved by the function
541
   *        cdm_feature_block_element_tag_name()
542
   *    - special: array()
543
   *        an array with further settings, this field can be used for special
544
   *        settings for specialized rendering like for distributions
545
   *  }
546
   *
547
   */
548
  function get_feature_block_settings($feature_uuid = 'DEFAULT') {
549
    // the default must conform to the default parameter values of
550
    // compose_cdm_feature_block_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
551
    // compose_cdm_descriptionElementTextData() : asListElement = NULL
552

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

    
555
    // ---- DEFAULTS settings
556

    
557
    // only needed as final option, when the settings are not having a default
558
    $default = array(
559
      'DEFAULT' => array(
560
        'as_list' => 'div',
561
        'link_to_reference' => 0,
562
        'link_to_name_used_in_source' => 1,
563
        'sources_as_content' => 0,
564
        'sources_as_content_to_bibliography' => 0,
565
        'sort_elements' => NO_SORT,
566
        'glue' => '',
567
        'element_tag' => NULL
568
      )
569
    );
570

    
571
    // will be used as preset in the settings
572
    $other_themes_default = array(
573
      'DEFAULT' => array(
574
        'as_list' => 'div',
575
        'link_to_reference' => 0,
576
        'link_to_name_used_in_source' => 1,
577
        'sources_as_content' => 0,
578
        'sources_as_content_to_bibliography' => 0,
579
        'sort_elements' => NO_SORT,
580
        'glue' => '',
581
        'element_tag' => NULL
582
      ),
583
      UUID_CITATION => array(
584
        'as_list' => 'div',
585
        'link_to_reference' => 0,
586
        'link_to_name_used_in_source' => 0,
587
        'sources_as_content' => 1,
588
        'sources_as_content_to_bibliography' => 0,
589
        'sort_elements' => SORT_ASC,
590
        'glue' => '',
591
        'element_tag' => 'div'
592
      ),
593
      UUID_DISTRIBUTION => array(
594
        'as_list' => 'div', // currently ignored
595
        'link_to_reference' => 0,
596
        'link_to_name_used_in_source' => 0,
597
        'sources_as_content' => 0,
598
        'sources_as_content_to_bibliography' => 0,
599
        'sort_elements' => NO_SORT, // will cause ...
600
        'glue' => '',
601
        'element_tag' => 'div',
602
        'special' => array()
603
      ),
604
      UUID_COMMON_NAME => array(
605
        'as_list' => 'div',
606
        'link_to_reference' => 0,
607
        'link_to_name_used_in_source' => 1,
608
        'sources_as_content' => 0,
609
        'sources_as_content_to_bibliography' => 0,
610
        'sort_elements' => NO_SORT,
611
        'glue' => '',
612
        'element_tag' => 'span'
613
      ),
614
    );
615

    
616
    // ---- Special DEFAULTS for existing portals
617
    // TODO:
618
    // this can be removed once the feature block
619
    // settings have been deployed for the first time to these portals
620

    
621
    $cichorieae_default = array(
622
      'DEFAULT' => array(
623
        'as_list' => 'div',
624
        'link_to_reference' => 1,
625
        'link_to_name_used_in_source' => 1,
626
        'sources_as_content' => 1,
627
        'sources_as_content_to_bibliography' => 0,
628
        'sort_elements' => NO_SORT,
629
        'glue' => '',
630
        'element_tag' => 'div'
631
      ),
632
      UUID_CITATION => array(
633
        'as_list' => 'div',
634
        'link_to_reference' => 0,
635
        'link_to_name_used_in_source' => 0,
636
        'sources_as_content' => 1,
637
        'sources_as_content_to_bibliography' => 0,
638
        'sort_elements' => SORT_ASC,
639
        'glue' => '',
640
        'element_tag' => 'div'
641
      ),
642
      UUID_CHROMOSOMES_NUMBERS => array(
643
        'as_list' => 'ul',
644
        'link_to_reference' => 1,
645
        'link_to_name_used_in_source' => 1,
646
        'sources_as_content' => 1,
647
        'sources_as_content_to_bibliography' => 0,
648
        'sort_elements' => NO_SORT,
649
        'glue' => '',
650
        'element_tag' => 'div'
651
      ),
652
      UUID_CHROMOSOMES => array(
653
        'as_list' => 'ul',
654
        'link_to_reference' => 0,
655
        'link_to_name_used_in_source' => 1,
656
        'sources_as_content' => 1,
657
        'sources_as_content_to_bibliography' => 0,
658
        'sort_elements' => NO_SORT,
659
        'glue' => '',
660
        'element_tag' => 'div'
661
      ),
662
      UUID_COMMON_NAME => array(
663
        'as_list' => 'div',
664
        'link_to_reference' => 0,
665
        'link_to_name_used_in_source' => 1,
666
        'sources_as_content' => 0,
667
        'sources_as_content_to_bibliography' => 0,
668
        'sort_elements' => NO_SORT,
669
        'glue' => '',
670
        'element_tag' => 'span'
671
      ),
672
    );
673

    
674
    $palmweb_default = array(
675
      'DEFAULT' => array(
676
        'as_list' => 'ul',
677
        'link_to_reference' => 1,
678
        'link_to_name_used_in_source' => 1,
679
        'sources_as_content' => 1,
680
        'sources_as_content_to_bibliography' => 1,
681
        'sort_elements' => NO_SORT,
682
        'glue' => '',
683
        'element_tag' => NULL
684
      ),
685
      UUID_CITATION => array(
686
        'as_list' => 'ul',
687
        'link_to_reference' => 1,
688
        'link_to_name_used_in_source' => 1,
689
        'sources_as_content' => 0,
690
        'sources_as_content_to_bibliography' => 1,
691
        'sort_elements' => SORT_ASC,
692
        'glue' => '',
693
        'element_tag' => 'div'
694
      ),
695
      UUID_DISTRIBUTION => array(
696
        'as_list' => 'div', // currently ignored
697
        'link_to_reference' => 1,
698
        'link_to_name_used_in_source' => 1,
699
        'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
700
        'sources_as_content_to_bibliography' => 1,
701
        'sort_elements' => NO_SORT, // will cause ...
702
        'glue' => '',
703
        'element_tag' => 'div',
704
        'special' => array()
705
      ),
706
    );
707

    
708
    $cyprus_default = $cichorieae_default;
709
    $cyprus_default[UUID_DISTRIBUTION] = array(
710
      'as_list' => 'div', // currently ignored
711
      'link_to_reference' => 0,
712
      'link_to_name_used_in_source' => 0,
713
      'sources_as_content' => 0,
714
      'sources_as_content_to_bibliography' => 0,
715
      'sort_elements' => NO_SORT, // will cause ...
716
      'glue' => '',
717
      'element_tag' => 'div',
718
      'special' => array()
719
    );
720

    
721
    $default_theme = variable_get('theme_default', NULL);
722

    
723
    switch ($default_theme) {
724
      case 'garland_cichorieae':
725
        $settings_for_theme = $cichorieae_default;
726
        break;
727
      case 'cyprus':
728
        // cyprus: no longer used in production,
729
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
730
        $settings_for_theme = $cyprus_default;
731
        break;
732
      case 'flore_afrique_centrale':
733
      case 'flora_malesiana':
734
      case 'flore_gabon':
735
        $settings_for_theme = $cichorieae_default;
736
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
737
        break;
738
      case 'palmweb_2':
739
        $settings_for_theme = $palmweb_default;
740
        break;
741
      default:
742
        $settings_for_theme = $other_themes_default;
743
    }
744
    // ---- END of DEFAULTS
745

    
746
    $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
747

    
748
    $feature_block_setting = null;
749

    
750
    if (isset($saved_settings[$feature_uuid])) {
751
      $feature_block_setting = $saved_settings[$feature_uuid];
752
    }
753
    else if (isset($settings_for_theme[$feature_uuid])) {
754
      $feature_block_setting = $settings_for_theme[$feature_uuid];
755
    }
756
    else if (isset($settings_for_theme['DEFAULT'])) {
757
      $feature_block_setting = $settings_for_theme['DEFAULT'];
758
    }
759

    
760
    // now merge the default and specific settings
761
    $settings_to_merge = array($default['DEFAULT']);
762
    if(is_array($saved_settings)){
763
      $settings_to_merge[] = $saved_settings['DEFAULT'];
764
    }
765
    if(isset($feature_block_setting)){
766
      $settings_to_merge[] = $feature_block_setting;
767
    }
768
    $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
769

    
770
    return $feature_block_setting;
771
}
772
  /**
773
 * returns the current setting for the original source bibliography
774
 *
775
 * Caches internally
776
 *
777
 * @return array
778
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
779
 *   - 'enabled': 1|0
780
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
781
 */
782
function get_bibliography_settings($clear_cache = false){
783
  static $bibliography_settings = null;
784
  if(!$bibliography_settings || $clear_cache){
785
    $bibliography_settings = get_array_variable_merged(
786
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
787
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
788
    );
789
  }
790
  return $bibliography_settings;
791
}
792

    
793
/**
794
 * @todo Please document this function.
795
 * @see http://drupal.org/node/1354
796
 */
797
function cdm_dataportal_menu_admin(&$items) {
798
  // Display section on admin/config page.
799
  $items['admin/config/cdm_dataportal'] = array(
800
    'title' => 'CDM Dataportal',
801
    'description' => 'Settings for the CDM DataPortal.',
802
    'position' => 'right',
803
    'weight' => 10,
804
    'page callback' => 'system_admin_menu_block_page',
805
    'access arguments' => array('administer cdm_dataportal'),
806
    'file' => 'system.admin.inc',
807
    'file path' => drupal_get_path('module', 'system'),
808
  );
809
  $items['admin/config/cdm_dataportal/settings'] = array(
810
    'title' => 'Settings',
811
    'description' => 'Settings for the CDM DataPortal.',
812
    'weight' => 0,
813
    'page callback' => 'drupal_get_form',
814
    'page arguments' => array('cdm_settings_general'),
815
    'access arguments' => array('administer cdm_dataportal'),
816
    'type' => MENU_NORMAL_ITEM,
817
  );
818
  $items['admin/config/cdm_dataportal/settings/general'] = array(
819
    'title' => 'General',
820
    'description' => 'General',
821
    'weight' => 0,
822
    'page callback' => 'drupal_get_form',
823
    'page arguments' => array('cdm_settings_general'),
824
    'access arguments' => array('administer cdm_dataportal'),
825
    'type' => MENU_DEFAULT_LOCAL_TASK,
826
  );
827

    
828
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
829
    'title' => 'Cache',
830
    'description' => 'Cache',
831
    'access arguments' => array('administer cdm_dataportal'),
832
    'page callback' => 'drupal_get_form',
833
    'page arguments' => array('cdm_settings_cache'),
834
    'weight' => 10,
835
    'type' => MENU_LOCAL_TASK,
836
  );
837

    
838
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
839
    'title' => 'Geo & Map',
840
    'description' => 'Geo & Map',
841
    'access arguments' => array('administer cdm_dataportal'),
842
    'page callback' => 'drupal_get_form',
843
    'page arguments' => array('cdm_settings_geo'),
844
    'weight' => 1,
845
    'type' => MENU_LOCAL_TASK,
846
  );
847

    
848
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
849
    'title' => 'Layout',
850
    'description' => 'Configure and adjust the layout of your DataPortal ',
851
    'access arguments' => array('administer cdm_dataportal'),
852
    'page callback' => 'drupal_get_form',
853
    'page arguments' => array('cdm_settings_layout'),
854
    'weight' => 2,
855
    'type' => MENU_LOCAL_TASK,
856
  );
857

    
858
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
859
    'title' => 'Taxon',
860
    'description' => 'Configure and adjust the layout of your DataPortal ',
861
    'access arguments' => array('administer cdm_dataportal'),
862
    'page callback' => 'drupal_get_form',
863
    'page arguments' => array('cdm_settings_layout_taxon'),
864
    'weight' => 1,
865
    'type' => MENU_LOCAL_TASK,
866
  );
867
  /*
868
  $items[] = array(
869
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
870
  'title' => t('Synonymy'),
871
  'description' => t('Configure and adjust the layout of your DataPortal '),
872
  'access' => user_access('administer cdm_dataportal'),
873
  'callback' => 'drupal_get_form',
874
  'callback arguments' => array('cdm_settings_layout_synonymy'),
875
  'weight' => 1,
876
  'type' => MENU_LOCAL_TASK,
877
  );
878

    
879
  $items[] = array(
880
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
881
  'title' => t('Specimens'),
882
  'description' => t('Configure and adjust the layout of your DataPortal '),
883
  'access' => user_access('administer cdm_dataportal'),
884
  'callback' => 'drupal_get_form',
885
  'callback arguments' => array('cdm_settings_layout_specimens'),
886
  'weight' => 1,
887
  'type' => MENU_LOCAL_TASK,
888
  );
889
  */
890
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
891
    'title' => 'Search',
892
    'description' => 'Configure and adjust the layout of your DataPortal ',
893
    'access arguments' => array('administer cdm_dataportal'),
894
    'page callback' => 'drupal_get_form',
895
    'page arguments' => array('cdm_settings_layout_search'),
896
    'weight' => 2,
897
    'type' => MENU_LOCAL_TASK,
898
  );
899

    
900
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
901
    'title' => 'Media',
902
    'description' => 'Configure and adjust the layout of your DataPortal ',
903
    'access arguments' => array('administer cdm_dataportal'),
904
    'page callback' => 'drupal_get_form',
905
    'page arguments' => array('cdm_settings_layout_media'),
906
    'weight' => 3,
907
    'type' => MENU_LOCAL_TASK,
908
  );
909

    
910
}
911

    
912
/**
913
 * @todo document this function.
914
 */
915
function cdm_help_general_cache() {
916
  $form = array();
917
  $form['cache_help'] = array(
918
    '#type' => 'fieldset',
919
    '#title' => t('Help'),
920
    '#collapsible' => TRUE,
921
    '#collapsed' => TRUE,
922
  );
923
  $form['cache_help']['test'] = array('#value' => t('probando'));
924
  return drupal_render($form);
925
  $res = array();
926
  $res['default'] = drupal_render($help);
927
  return $res;
928
}
929

    
930
/**
931
 * Configures the settings form for the CDM-API module.
932
 *
933
 * @return array
934
 *   Drupal settings form.
935
 */
936
function cdm_settings_general() {
937

    
938
  $form['cdm_webservice'] = array(
939
    '#type' => 'fieldset',
940
    '#title' => t('CDM Server'),
941
    '#collapsible' => FALSE,
942
    '#collapsed' => FALSE,
943
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
944
        CDM data base to the web via RESTful web services and thus is the source of the data
945
        to be displayed by a CDM DataPotal.'),
946
  );
947

    
948
  $form['cdm_webservice']['cdm_webservice_url'] = array(
949
    '#type' => 'textfield',
950
    '#title' => t('CDM web service URL') . ':',
951
    '#description' => t('This is the URL to the CDM-Server exposing your data
952
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
953
    '#default_value' => variable_get('cdm_webservice_url', NULL),
954
  );
955

    
956
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
957
    '#type' => 'markup',
958
    '#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')
959
      . ' visible only for administrators',
960
  );
961

    
962
  $form['cdm_webservice']['freetext_index'] = array(
963
    '#type' => 'fieldset',
964
    '#title' => t('Freetext index'),
965
    '#collapsible' => FALSE,
966
    '#collapsed' => FALSE,
967
  );
968

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

    
981
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
982
  $trigger_link_options = array(
983
    'attributes' => array(
984
      'class' => 'index-trigger',
985
    ),
986
  );
987
  $form['cdm_webservice']['freetext_index']['operations'] = array(
988
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
989
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
990
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
991
      ))
992
    . '<div id="index-progress"></div></div>',
993
  );
994
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
995

    
996
  $form['cdm_webservice']['proxy'] = array(
997
    '#type' => 'fieldset',
998
    '#title' => t('Proxy'),
999
    '#collapsible' => TRUE,
1000
    '#collapsed' => TRUE,
1001
  );
1002

    
1003
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1004
    '#type' => 'textfield',
1005
    '#title' => t('Proxy URL') . ':',
1006
    '#description' => t('If this proxy url is set the cdm api tries
1007
    to connect the web service over the given proxy server.
1008
    Otherwise proxy usage is deactivated.'),
1009
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1010
  );
1011

    
1012
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1013
    '#type' => 'textfield',
1014
    '#title' => t('Proxy port') . ':',
1015
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1016
  );
1017

    
1018
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1019
    '#type' => 'textfield',
1020
    '#title' => t('Login') . ':',
1021
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1022
  );
1023

    
1024
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1025
    '#type' => 'textfield',
1026
    '#title' => t('Password') . ':',
1027
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1028
  );
1029

    
1030
  // TODO: settings are still incomplete, compare with
1031
  // trunk/dataportal/inc/config_default.php.inc.
1032
  $form['taxon_tree'] = array(
1033
    '#type' => 'fieldset',
1034
    '#title' => t('Taxon Tree'),
1035
    '#collapsible' => FALSE,
1036
    '#collapsed' => TRUE,
1037
    '#description' => t('<p>When you explore your collection, you can navigate
1038
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1039
      able to navigate through your collection the
1040
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1041
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1042
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1043
      </a></p>'),
1044
  );
1045

    
1046
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1047
    '#type' => 'select',
1048
    '#title' => t('Available classifications') . ':',
1049
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1050
    '#options' => cdm_get_taxontrees_as_options(),
1051
    '#description' => t('Select the default taxa classification for your
1052
      <em>taxon tree</em>, the other classifications will be also available but
1053
      with a manual user change.'),
1054
  );
1055

    
1056
  $form['taxon_tree']['taxontree_ranklimit'] = array(
1057
    '#type' => 'select',
1058
    '#title' => t('Rank of highest displayed taxon') . ':',
1059
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1060
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
1061
    '#options' => cdm_rankVocabulary_as_option(),
1062
    '#description' => t('This is the rank of the highest displayed taxon in the
1063
      <em>taxon tree</em>. You can select here which rank should be at the top
1064
      level of the tree structure.'),
1065
  );
1066

    
1067
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1068
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1069
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1070
      '#type' => 'checkboxes',
1071
      '#title' => t('Included Classifications') . ':',
1072
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1073
      '#options' => cdm_get_taxontrees_as_options(),
1074
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1075
  );
1076

    
1077
  $form['distribution'] = array(
1078
      '#type' => 'fieldset',
1079
      '#title' => t('Distributions'),
1080
      '#collapsible' => FALSE,
1081
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1082
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1083
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1084
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1085
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1086
          '<p>
1087
          </p>',
1088
  );
1089

    
1090
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1091
      '#type' => 'fieldset',
1092
      '#title' => 'Distribution filter',
1093
      '#collapsible' => FALSE,
1094
      '#collapsed' => FALSE,
1095
      '#tree' => TRUE,
1096
      '#description' => 'The Distribution filter offers the following options
1097
      <ul>
1098
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1099
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1100
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1101
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1102
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1103
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1104
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1105
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1106
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1107
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1108
      </ul>'
1109
  );
1110

    
1111
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1112
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1113
      '#type' => 'checkboxes',
1114
      '#title' => 'Filter rules',
1115
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1116
      '#options' => array(
1117
          'statusOrderPreference' => 'Status order preference rule',
1118
          'subAreaPreference' => 'Sub area preference rule'
1119
      ),
1120
  );
1121

    
1122
  $marker_type_options = cdm_terms_as_options( cdm_ws_fetch_all('term', array('class' => 'MarkerType' )) );
1123
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1124
      '#type' => 'checkboxes',
1125
      '#title' => 'Hide marked area filter',
1126
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1127
      '#options' => $marker_type_options,
1128
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1129
  );
1130

    
1131
  $form['aggregation'] = array(
1132
      '#type' => 'fieldset',
1133
      '#title' => t('Aggregation of data'),
1134
      '#collapsible' => FALSE,
1135
      '#description' => 'This section covers the different aspects of aggregating information.
1136
          <p>
1137
          </p>',
1138
  );
1139

    
1140
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1141
      '#type' => 'checkboxes',
1142
      '#title' => 'Taxon media filter',
1143
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1144
      '#options' => array(
1145
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1146
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1147
          'includeOccurrences' => 'Media related to specimens and occurrences',
1148
      ),
1149
      '#description' => 'This filter configures which images should be taken into account.',
1150
  );
1151

    
1152
  $form['aggregation']['notice'] = array(
1153
      '#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
1154
          want to make use of the caching capabilities of the dataportal.',
1155
  );
1156

    
1157
  $form['aggregation']['media_aggregation'] = array(
1158
      '#type' => 'fieldset',
1159
      '#title' => t('Media aggregation'),
1160
      '#collapsible' => FALSE,
1161
      '#collapsed' => TRUE,
1162
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1163

    
1164
  );
1165
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1166
      '#type' => 'select',
1167
      '#title' => t('Aggregation of taxon pictures') . ':',
1168
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1169
      '#options' => array(
1170
          0 => "Show only pictures of the current taxon",
1171
          1 => "Include pictures of taxonomic children",
1172
      ),
1173
      '#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."),
1174
  );
1175

    
1176
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1177
      '#type' => 'fieldset',
1178
      '#attributes' => array('class'=>array('clearfix')),
1179
      '#title' => t('Aggregation via taxon relationsships'),
1180
      '#collapsible' => TRUE,
1181
      '#collapsed' => TRUE,
1182
      '#tree' => TRUE,
1183
      '#description' => t('Information on taxa will be aggregated along the below chosen
1184
          taxon relation ships. This will affect images and occurrences (specimens).
1185
          Taxon relation ships are directed and point form one taxon to another. The taxon
1186
          relationships to be taken into accunt can therefore configured for the direct direction
1187
          and for the inverse.'),
1188
  );
1189

    
1190
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1191
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1192

    
1193
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1194
      '#type' => 'checkboxes',
1195
      '#title' => t('Direct'),
1196
      '#options' => $taxonRelationshipTypeOptions,
1197
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1198
  );
1199
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1200
      '#type' => 'checkboxes',
1201
      '#title' => t('Invers'),
1202
      '#options' => $taxonRelationshipTypeOptions,
1203
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1204
  );
1205

    
1206
  // ----------------------
1207
  $form['cdm_js_devel_mode'] = array(
1208
      '#type' => 'checkbox',
1209
      '#title' => 'Java-script developer mode',
1210
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1211
      '#description' => 'In production envirionments the java script libraries
1212
      the cdm_dataportal is making use of are compressed and optimized. This
1213
      is good for performance but a caveat if you need to debug java-script. When the
1214
      java-script developer mode is enabled the uncompressed and commented developer
1215
      versions of java-script libraries will be used where possible.
1216
      <br/><strong>Do not use this option in production!</strong>'
1217
  );
1218
  // ----------------------
1219
  $form['cdm_debug_mode'] = array(
1220
      '#type' => 'checkbox',
1221
      '#title' => 'CDM page debug mode',
1222
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1223
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1224
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1225
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1226
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1227
      The log is written by the drupal devel module function <code>dd()</code>.
1228
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1229
  );
1230

    
1231
  // Comment @WA: D7 form api does not support reset buttons,
1232
  // so to mimic the D5 reset button we add one like this.
1233
  $form['actions']['reset'] = array(
1234
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1235
    '#weight' => 1000,
1236
  );
1237

    
1238
  $form['#submit'][] = 'cdm_settings_general_submit';
1239

    
1240
  return system_settings_form($form);
1241
}
1242

    
1243

    
1244
/**
1245
 * LAYOUT settings
1246
 * @return
1247
 *   todo
1248
 */
1249
function cdm_settings_layout() {
1250

    
1251
  $form = array();
1252

    
1253
  $form['about'] = array(
1254
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1255
      layout. If you want to configure the specific sites layout visit the
1256
      respective configuration site for taxon, search or media.') . '</p>',
1257
  );
1258

    
1259
  // ---- footnotes --- //
1260
  $form['footnotes'] = array(
1261
    '#type' => 'fieldset',
1262
    '#title' => t('Footnotes'),
1263
    '#collapsible' => FALSE,
1264
    '#collapsed' => FALSE,
1265
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1266
      media or distribution areas may have annotations or footnotes. When the
1267
      footnotes are enabled they will be visible (if they exist).'),
1268
  );
1269

    
1270
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1271
    '#type' => 'checkbox',
1272
    '#title' => t('Do not show footnotes'),
1273
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1274
    '#description' => t('Check this if you do not want to show any footnotes'),
1275
  );
1276

    
1277
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1278
    '#type' => 'checkbox',
1279
    '#title' => t('Do not show annotation footnotes'),
1280
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1281
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1282
  );
1283

    
1284
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType', SORT_ASC);
1285
  // Additional option for the NULL case.
1286
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1287
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1288
    '#type' => 'checkboxes',
1289
    '#title' => t('Annotation types as footnotes'),
1290
    '#description' => t("Only annotations of the selected type will be displayed
1291
       as footnotes. You may want to turn 'technical annotations' off."),
1292
    '#options' => $annotationTypeOptions,
1293
  );
1294
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1295
  if (!empty($annotationsTypesAsFootnotes)) {
1296
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1297
  }
1298

    
1299
  // ---- original source --- //
1300
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1301
      '#type' => 'fieldset',
1302
      '#tree' => TRUE,
1303
      '#title' => t('Source Citations'),
1304
      '#collapsible' => FALSE,
1305
      '#collapsed' => FALSE,
1306
  );
1307

    
1308
  $bibliography_settings = get_bibliography_settings(true);
1309

    
1310
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1311
      '#type' => 'checkbox',
1312
      '#title' => t('Original Source in bibliography'),
1313
      '#default_value' => $bibliography_settings['enabled'],
1314
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1315
       annotations in each feature block.'),
1316
  );
1317

    
1318
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1319
    '#type' => 'select',
1320
    '#title' => t('The format of the key numerals'),
1321
    '#default_value' => $bibliography_settings['key_format'],
1322
    '#options' => array('latin' => 'Latin',
1323
      'ROMAN' => 'Roman (upper case)',
1324
      'roman' => 'Roman (lower case)',
1325
      'ALPHA'=> 'Alphabet (upper case)',
1326
      'alpha' => 'Alphabet (lower case)')
1327
  );
1328

    
1329
  // --- Advanced Search --- //
1330
  $form['asearch'] = array(
1331
      '#type' => 'fieldset',
1332
      '#title' => t('Advanced search'),
1333
      '#collapsible' => FALSE,
1334
      '#collapsed' => FALSE,
1335
  );
1336
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1337
      '#type' => 'checkbox',
1338
      '#title' => t('Show advanced search link'),
1339
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1340
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1341
  );
1342

    
1343
  // ---- Taxon Name Rendering --- //
1344
  $form['taxon_name'] = array(
1345
      '#type' => 'fieldset',
1346
      '#title' => t('Taxon name display'),
1347
      '#collapsible' => TRUE,
1348
      '#collapsed' => TRUE,
1349
      '#description' => t('The display of taxon names is configured by two parts.'
1350
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
1351
          . 'The name parts are defined in the <stong>part definitions</strong>'),
1352
  );
1353

    
1354
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1355
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1356
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1357
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1358

    
1359
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1360
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1361
    $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.)';
1362
  } else if($is_custom_part_definition){
1363
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1364
  } else  {
1365
    $which_version_message = '(These are the default part definition.)';
1366
  }
1367

    
1368
  $diff_viewer_markup = '';
1369
  if($is_custom_part_definition){
1370
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1371
  }
1372

    
1373
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1374
    . $which_version_message
1375
    . '</div>'
1376
    . $diff_viewer_markup;
1377

    
1378
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1379
      '#type' => 'textarea',
1380
      '#title' => t('Part definitions'),
1381
      '#element_validate' => array('form_element_validate_json'),
1382
      '#default_value' =>  $current_part_definition_json,
1383
      '#description' => '
1384
          <p>' . $which_version_message . '</p>
1385
          <p>
1386
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1387
          </p>
1388
          <p>
1389
           A full taxon name plus additional information can consist of the following elements:
1390
          <ul>
1391
             <li>name: the taxon name inclugin rank nbut without author</li>
1392
             <li>authors:  The authors of a reference, also used in taxon names</li>
1393
             <li>reference: the nomenclatural reference,</li>
1394
             <li>microreference:  Volume, page number etc.</li>
1395
             <li>status:  The nomenclatural status of a name</li>
1396
             <li>description: name descriptions like protologues etc ...</li>
1397
          </ul>
1398
          </p>
1399
          <p>
1400
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1401
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1402
           The following parts can be formed and are recognized by the system:
1403
          <ul>
1404
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1405
            <li>authorshipPart: the author (for example: "L.")</li>
1406
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1407
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1408
               be combined when a link to the taxon is rendered.</li>
1409
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1410
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1411
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1412
            <li>statusPart: the nomenclatorical status</li>
1413
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1414
          </ul>
1415
          </p>
1416
          <p>
1417
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1418
           specific parts part definitions:
1419
          <ul>
1420
            <li>BotanicalName</li>
1421
            <li>ZoologicalName</li>
1422
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1423
          </ul>
1424
           An example:
1425
          <pre>
1426
           {
1427
            "ZoologicalName": {
1428
              "namePart": {
1429
                "name": true
1430
              },
1431
              "referencePart": {
1432
                "authors": true
1433
              },
1434
              "microreferencePart": {
1435
                "microreference": true
1436
              },
1437
              "statusPart": {
1438
                "status": true
1439
              },
1440
              "descriptionPart": {
1441
                "description": true
1442
              }
1443
            },
1444
            "BotanicalName": {
1445
              "namePart": {
1446
                "name": true,
1447
                "authors": true
1448
              },
1449
              "referencePart": {
1450
                "reference": true,
1451
                "microreference": true
1452
              },
1453
              "secReferencePart": {
1454
                "secReference": true
1455
              },
1456
              "statusPart": {
1457
                "status": true
1458
              },
1459
              "descriptionPart": {
1460
                "description": true
1461
              }
1462
            }
1463
          }
1464
           </pre>',
1465
  );
1466

    
1467
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1468
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1469
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1470
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1471
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1472

    
1473
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1474
    $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.)';
1475
  } else if($is_custom_render_template){
1476
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1477
  } else {
1478
    $which_version_message = '(These are the default render templates.)';
1479
  }
1480

    
1481
  $diff_viewer_markup = '';
1482
  if($is_custom_render_template){
1483
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1484
  }
1485

    
1486
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1487
    . $which_version_message
1488
    . '</div>'
1489
    . $diff_viewer_markup;
1490

    
1491
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1492
      '#type' => 'textarea',
1493
      '#title' => t('Name render templates'),
1494
      '#element_validate' => array('form_element_validate_json'),
1495
      '#default_value' =>  $current_render_templates_json,
1496
      '#description' => '
1497
          <p>' . $which_version_message . '</p>
1498
          <p>
1499
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1500
          render path. The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1501
          The following render Path keys are curretly recognized:
1502
          <ul>
1503
            <li>list_of_taxa</li>
1504
            <li>acceptedFor</li>
1505
            <li>homonym</li>
1506
            <li>taxon_page_synonymy</li>
1507
            <li>typedesignations</li>
1508
            <li>taxon_page_title</li>
1509
            <li>polytomousKey</li>
1510
            <li>na: name + authorship</li>
1511
            <li>nar:name + authorship + reference</li>
1512
            <li>#DEFAULT</li>
1513
          </ul>
1514
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1515
          array element should be a comma separated list of render paths, without any whitespace!.
1516
          </p>
1517
          <p>
1518
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1519
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1520
          <p>
1521
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1522
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1523
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1524
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1525
          links if the paramters $nameLink or $refenceLink are given to the name render function
1526
          (this is hard coded and cannot be configured here).',
1527
  );
1528

    
1529
  // @WA: D7 form api does not support reset buttons,
1530
  // so to mimic the D5 reset button we add one like this.
1531
  $form['actions']['reset'] = array(
1532
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1533
    '#weight' => 1000,
1534
  );
1535

    
1536
  $form['#submit'] = array('submit_json_as_php_array');
1537
  // #json_elements especially defined for submit_json_as_php_array()
1538
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1539
  return system_settings_form($form);
1540
}
1541

    
1542

    
1543

    
1544
  /**
1545
 * @todo Please document this function.
1546
 * @see http://drupal.org/node/1354
1547
 */
1548
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1549
  $form[$form_name] = array(
1550
    '#type' => 'fieldset',
1551
    '#title' => t($form_title),
1552
    '#collapsible' => TRUE,
1553
    '#collapsed' => $collapsed,
1554
    '#tree' => TRUE,
1555
    '#description' => t($form_description),
1556
  );
1557

    
1558
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1559
  $gallery_settings = variable_get($form_name, $default_values);
1560
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1561
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1562
    /*
1563
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1564
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1565
    '#type' => 'textfield',
1566
    '#title' => t('Search Page Size'),
1567
    '#default_value' => $test,
1568
    '#description' => t('Number of Names to display per page in search results.')
1569
    );
1570
    */
1571
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1572
      '#type' => 'checkbox',
1573
      '#title' => t('Show media thumbnails for accepted taxa'),
1574
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1575
    );
1576

    
1577
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1578
      '#type' => 'checkbox',
1579
      '#title' => t('Show media thumbnails for synonyms'),
1580
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1581
      '#description' => '',
1582
    );
1583
  }
1584

    
1585
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1586
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1587
    '#type' => 'checkbox',
1588
    '#title' => t('Show captions under thumbnails'),
1589
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1590
    '#description' => '',
1591
  );
1592

    
1593
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1594
    '#type' => 'textfield',
1595
    '#title' => t('Thumbnail size') . ':',
1596
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1597
    '#description' => t('Select the size of each individual thumbnail.'),
1598
  );
1599

    
1600
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1601
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1602
      '#type' => 'textfield',
1603
      '#title' => t('Number of columns') . ':',
1604
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1605
      '#description' => t('Group the thumbnails in columns: select how many
1606
        columns the gallery should display.'),
1607
    );
1608
  }
1609

    
1610
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1611
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1612
      '#type' => 'textfield',
1613
      '#title' => t('Maximum number of rows') . ':',
1614
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1615
      '#description' => t('You can group the thumbnails in rows, select in how
1616
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1617
        If you want an unlimited number of rows please set to 0.'),
1618
    );
1619
  }
1620

    
1621
  return $form;
1622
}
1623

    
1624
/**
1625
 * @todo document this function.
1626
 */
1627
function cdm_settings_layout_taxon() {
1628
  $collapsed = FALSE;
1629
  $form = array();
1630

    
1631
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1632

    
1633
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1634
      '#type' => 'checkbox',
1635
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1636
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1637
      '#description' => t('<p>If checked the link to search results is rendered at
1638
       the top of the taxon site. Clicking on the link the last search performed
1639
       is rendered again.</p>'),
1640
  );
1641

    
1642
  // --------- TABBED TAXON ------- //
1643
  $form['taxon_tabs'] = array(
1644
    '#type' => 'fieldset',
1645
    '#title' => t('Taxon tabs'),
1646
    '#collapsible' => TRUE,
1647
    '#collapsed' => FALSE,
1648
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1649
      be splitted in four diferent tabs; General, Synonymy, Images and
1650
      Specimens. If the taxon has no information for any of the tabs/sections
1651
      such tab will be not displayed.'),
1652
  );
1653

    
1654
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1655
    '#type' => 'checkbox',
1656
    '#title' => t('Tabbed taxon page'),
1657
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1658
    '#description' => t('<p>If selected split the taxon page into individual
1659
      tabs for description, images, synonymy and specimens. If not the taxon
1660
      data is rendered as a long single page without tabs.</p>'),
1661
  );
1662

    
1663
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1664
    '#type' => 'checkboxes',
1665
    '#title' => t('Tabs visibility options') . ':',
1666
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1667
    '#options' => get_taxon_options_list(),
1668
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1669
  );
1670

    
1671
  // WEIGHT
1672
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1673
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1674
      '#tree' => true
1675
  );
1676
  // Weights range from -delta to +delta, so delta should be at least half
1677
  // of the amount of tabs present.
1678
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1679
  foreach (get_taxon_tabs_list() as $label) {
1680
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1681
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1682
        '#title' => $label,
1683
        '#type'  => 'weight',
1684
        '#default_value' => $taxontabs_weights[$key],
1685
        '#delta' => $tab_weight_delta
1686
    );
1687
  }
1688

    
1689
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1690
    '#type' => 'select',
1691
    '#title' => t('Default tab to display') . ':',
1692
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1693
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1694
    '#description' => t('<p>Select the default tab to display when visiting a
1695
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1696
      <strong>Note:</strong> After performing a search and clicking in any
1697
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1698
      taxon and not the above selected tab.'),
1699
  );
1700

    
1701
  /* ======  TAXON_PROFILE ====== */
1702
  $form['taxon_profile'] = array(
1703
    '#type' => 'fieldset',
1704
    '#title' => t('Taxon profile (tab)'),
1705
    '#description' => t('<p>This section covers the settings related to the taxon
1706
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1707
    '#collapsible' => TRUE,
1708
    '#collapsed' => FALSE,
1709
  );
1710

    
1711
  // ---- PROFILE PICTURE ----//
1712

    
1713
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1714
    '#type' => 'fieldset',
1715
    '#tree' => TRUE,
1716
    '#title' => t('Taxon profile picture'),
1717
    '#collapsible' => TRUE,
1718
    '#collapsed' => FALSE,
1719
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1720
  );
1721

    
1722
  //FIXME migrate variables:
1723
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1724
  // FIXME
1725
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1726

    
1727
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1728

    
1729
  /*
1730
   * 'show' => 1,
1731
   * 'maxextend' => 184,
1732
   * 'media_uri_query' => ''
1733
   * 'custom_placeholder_image_on' => 1,
1734
   * 'custom_placeholder_image_fid' => ''
1735
   */
1736
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1737
    '#type' => 'checkbox',
1738
    '#title' => t('Enable profil picture'),
1739
    '#description' => t('Show the profil picture.'),
1740
    '#default_value' => $taxon_profile_image_settings['show'],
1741
  );
1742

    
1743
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1744
      '#type' => 'textfield',
1745
      '#tree' => TRUE,
1746
      '#title' => t('Profil picture maximum extend'),
1747
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1748
      '#field_suffix' => 'px',
1749
      '#maxlength' => 4,
1750
      '#size' => 4,
1751
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1752
  );
1753

    
1754
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1755
      '#type' => 'textfield',
1756
      '#tree' => TRUE,
1757
      '#title' => t('Additional URI query parameter'),
1758
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1759
      '#maxlength' => 1024,
1760
      '#size' => 60,
1761
      '#description' => t('Additional query parameters to be used when requesting for the '
1762
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1763
          . 'The query parameters will be appended to the uri of the media representation part'
1764
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1765
  );
1766

    
1767
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1768
    '#type' => 'checkbox',
1769
    '#title' => t('Show the placeholder image'),
1770
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
1771
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1772
  );
1773

    
1774
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1775
      '#type' => 'checkbox',
1776
      '#title' => t('Use a custom placeholder image'),
1777
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1778
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1779
  );
1780

    
1781
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1782
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1783
        '#type' => 'managed_file',
1784
        '#title' => t('Custom placeholder image file'),
1785
        '#progress_indicator' => 'bar',
1786
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1787
    //       '#name' => 'custom_placeholder_image',
1788
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1789
    );
1790

    
1791
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1792
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1793
      $url = file_create_url($profile_image_file->uri);
1794
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1795
                '#type' => 'item',
1796
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1797
      );
1798
    }
1799
  } else {
1800
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1801
      '#type' => 'hidden',
1802
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1803
    );
1804
  }
1805

    
1806
  $options = cdm_rankVocabulary_as_option();
1807
  array_unshift($options, '-- DISABLED --');
1808
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1809
    '#type' => 'select',
1810
    '#title' => t('Hide profile picture for higher ranks') . ':',
1811
    '#default_value' => variable_get('image_hide_rank', '0'),
1812
    '#options' => $options,
1813
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1814
  );
1815

    
1816
  // -- MEDIA THUMBNAILS -- //
1817
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1818
  $form_title = 'Taxon Profile Images';
1819
  $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>';
1820
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1821

    
1822
  // ---- FEATURE TREE BLOCKS ---- //
1823
  $form['taxon_profile']['feature_blocks'] = array(
1824
    '#type' => 'fieldset',
1825
    '#title' => t('Feature Blocks'),
1826
    '#collapsible' => TRUE,
1827
    '#collapsed' => FALSE,
1828
    '#description' => t("This section covers settings related to the taxon's
1829
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1830
      features such as description, distribution, common names"),
1831
  );
1832
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1833
  $profile_feature_tree = get_profile_feature_tree();
1834
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
1835
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
1836
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
1837
  }
1838
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
1839
    '#type' => 'radios',
1840
    '#title' => t('Taxon profile feature tree') . ':',
1841
    '#default_value' => $profile_feature_tree_uuid,
1842
    '#options' =>  $featureTrees['options'],
1843
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1844
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1845
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
1846
      profile page.'
1847
    ),
1848
  );
1849

    
1850
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
1851
  $profile_feature_tree = get_profile_feature_tree();
1852

    
1853
  if (isset($profile_feature_tree->root->childNodes)) {
1854

    
1855
    $form_feature_block_layout = array(
1856
      '#type' => 'fieldset',
1857
      '#tree' => true,
1858
      '#title' => t('Taxon profile feature block settings'),
1859
      '#collapsible' => TRUE,
1860
      '#collapsed' => FALSE,
1861
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
1862
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
1863
      The subforms have the following settings in common:<br />
1864
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
1865
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
1866
      <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>
1867
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
1868
            <ol>
1869
            <li>If element is of the CDM type TextData and the text is not empty the source references will be
1870
                appended in brackets like "text (source references)". If the original source has name in source
1871
                information it will be appended to the citation string,
1872
                like : "(citation, as name in source; citation, as name in source)"</li>
1873
             <li>if the text of the TextData is empty, the original source citations are the only content
1874
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
1875
                prepended to the citation string like: "name in source: citation"</li>
1876
            </ol>
1877
            <strong>If disabled:</strong><br />
1878
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
1879
             citations are the only content, the resulting feature block content would only consist of footnotes.
1880
             In this case the display of the respective feature block is suppressed.</div>
1881
      </dl>
1882
      <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
1883
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
1884
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
1885
        . '</em></div>
1886
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
1887
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
1888
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
1889
      <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>
1890
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
1891
           cdm_feature_block_element_tag_name()</div>',
1892
    );
1893

    
1894

    
1895
    $feature_list_layout_settings_disabled = FALSE;
1896

    
1897
    // creating helper object to retrieve the default settings
1898
    $featureNode = new stdClass();
1899
    $featureNode->feature = new stdClass();
1900
    $featureNode->feature->uuid="DEFAULT";
1901
    $featureNode->feature->representation_L10n = "Default";
1902
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
1903

    
1904
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
1905

    
1906
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1907

    
1908
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
1909
        $subform_id = $featureNode->feature->uuid;
1910
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
1911

    
1912
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1913

    
1914
        $form_feature_block_layout[$subform_id] = array(
1915
          '#type' => 'fieldset',
1916
          '#tree' => TRUE,
1917
          '#title' => $featureNode->feature->representation_L10n,
1918
          '#collapsible' => FALSE,
1919
          '#collapsed' => FALSE,
1920
        );
1921
        if($featureNode->feature->uuid == "DEFAULT"){
1922
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
1923
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
1924
          references</em> and <em>names in source</em> is only possible in the defaults';
1925
        }
1926

    
1927
        $form_feature_block_layout[$subform_id]['as_list'] = array(
1928
          '#type' => 'select',
1929
          '#title' => 'List type',
1930
          '#default_value' => $feature_block_setting['as_list'],
1931
          '#options' => array(
1932
            'div' => 'not as list',
1933
            'ul' => 'bullet list',
1934
            'ol' => 'numbered list',
1935
            'dl' => 'definition list'
1936
          ),
1937
        );
1938

    
1939
        if($featureNode->feature->uuid == "DEFAULT"){
1940
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
1941
            '#type' => 'checkbox',
1942
            '#title' => t('Link to reference'),
1943
            '#default_value' => $feature_block_setting['link_to_reference'],
1944
          );
1945

    
1946
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
1947
            '#type' => 'checkbox',
1948
            '#title' => 'Link to name used in source',
1949
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
1950
          );
1951
        }
1952

    
1953
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
1954
          '#type' => 'checkbox',
1955
          '#title' => 'Sources as content',
1956
          '#default_value' => $feature_block_setting['sources_as_content'],
1957
        );
1958

    
1959
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
1960
          '#type' => 'checkbox',
1961
          '#title' => 'Put sources also as content to bibliography',
1962
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
1963
        );
1964

    
1965
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
1966
          '#type' => 'select',
1967
          '#title' => t('Sort elements'),
1968
          '#default_value' => $feature_block_setting['sort_elements'],
1969
          '#options' => array(
1970
            NO_SORT => 'No sorting',
1971
            SORT_ASC => 'Ascending',
1972
            SORT_DESC => 'Descending',
1973
            SORT_HIERARCHICAL => 'Hierachical'
1974
          ),
1975
          '#description' => 'NOT YET USED! only in preparation',
1976
        );
1977

    
1978
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
1979
          '#type' => 'select',
1980
          '#title' => t('Element tag'),
1981
          '#options' => array(
1982
            'span' => 'span',
1983
            'div' => 'div'
1984
          ),
1985
          '#default_value' => $feature_block_setting['element_tag'],
1986
        );
1987
      }
1988
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
1989
    }
1990
  }
1991

    
1992
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
1993
  $form['taxon_profile']['structured_description_featuretree'] = array(
1994
    '#type' => 'fieldset',
1995
    '#title' => t('Structured Description Feature Tree'),
1996
    '#collapsible' => TRUE,
1997
    '#collapsed' => FALSE,
1998
  );
1999
  $featureTrees = cdm_get_featureTrees_as_options();
2000
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2001
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2002
    $profile_feature_tree_uuid = NULL;
2003
  }
2004
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2005
    '#type' => 'radios',
2006
    '#title' => t('Natural language representation of structured descriptions') . ':',
2007
    '#default_value' => $profile_feature_tree_uuid,
2008
    '#options' => $featureTrees['options'],
2009
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2010
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2011
    '#description' => t('Taxon descriptions can be stored in a highly structured
2012
      form. The feature tree selected here will be used to generate textual
2013
      representation in natural language.'
2014
    ),
2015
  );
2016

    
2017

    
2018

    
2019
  // ---- DISTRIBUTION LAYOUT ---- //
2020
  $form['taxon_profile']['distribution_layout'] = array(
2021
    '#title' => t('Distribution'),
2022
    '#collapsible' => TRUE,
2023
    '#collapsed' => FALSE,
2024
    '#type' => 'fieldset',
2025
    '#description' => 'This section covers general settings regarding the textual representation of distributions.
2026
        Map related settings are found in the '
2027
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2028
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2029
      . l(
2030
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2031
        array('fragment' => 'edit-feature-block-settings')
2032
      )
2033
      . ' More general settings regrading the filtering of Distributions are found at '
2034
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2035
      . '. (These settings here will be merged in future releases into the feature block settings)',
2036

    
2037
  );
2038

    
2039
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2040
    '#type' => 'checkbox',
2041
    '#title' => t('Condensed distribution'),
2042
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2043
    '#description' => 'This option enables the display of a very compact representation
2044
    of the distribution which includes also information on the status.',
2045
  );
2046

    
2047

    
2048
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2049
    '#type' => 'radios',
2050
    '#title' => t('Order mode') . ':',
2051
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2052
    '#options' => array(
2053
      'FLAT_ALPHA' => t('Flat list'),
2054
      'TREE' => t('Hierarchically ordered'),
2055
    ),
2056
    '#description' => 'Taxon distribution information is displayed with
2057
    focus on the area of the distribution. The list of areas can either be shown
2058
    as flat list ordered alphabetically or in the hierarchical of the parent
2059
    area and subarea relationship. Fall back areas areas with no Distribution data
2060
    are hidden from the area hierarchy so that their sub areas will move one level up.
2061
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2062
    ' for details on the <em>Maked area filter</em>.',
2063
  );
2064

    
2065
  $level_options = cdm_Vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, SORT_ASC);
2066
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2067
    '#type' => 'checkboxes',
2068
    '#title' => 'Omit area levels',
2069
    '#options' => $level_options,
2070
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2071
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2072
    Areas which belong to the selected area levels will be hidden in the portal.',
2073
  );
2074

    
2075
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2076
    '#type' => 'checkbox',
2077
    '#title' => t('Show TextData elements on top of the map'),
2078
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2079
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2080
      elements on top of the map. Otherwise all <code>TextData</code>
2081
      distribution elements will be listed below the other area elements.
2082
      This option is useful if you need to have descriptive texts for each
2083
      distribution map.'),
2084
  );
2085

    
2086
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2087
      '#type' => 'textarea',
2088
      '#title' => t('Custom status colors'),
2089
      '#element_validate' => array('form_element_validate_json'),
2090
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2091
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2092
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2093
          reference list of the idInVocabulary values of absence and presence terms:
2094
<pre>
2095
Presence Term
2096
p	present
2097
pd	present: doubtfully present
2098
n	native
2099
nq	native: presence questionable
2100
nd	native: doubtfully native
2101
c	cultivated
2102
i	introduced
2103
iq	introduced: presence questionable
2104
id	introduced: doubtfully introduced (perhaps cultivated only)
2105
ip	introduced: uncertain degree of naturalisation
2106
ia	introduced: adventitious (casual)
2107
in	introduced: naturalized
2108
ic	introduced: cultivated
2109
e	endemic for the relevant area
2110
na	naturalised
2111
iv	invasive
2112

    
2113
AbsenceTerm
2114
a	absent
2115
f	reported in error
2116
nf	native: reported in error
2117
if	introduced: reported in error
2118
cf	cultivated: reported in error
2119
ne	native: formerly native
2120
ie	introduced: formerly introduced
2121

    
2122
</pre>'),
2123
  );
2124

    
2125

    
2126
  /* ====== SYNONYMY ====== */
2127
  $form['taxon_synonymy'] = array(
2128
    '#type' => 'fieldset',
2129
    '#title' => t('Taxon synonymy (tab)'),
2130
    '#collapsible' => TRUE,
2131
    '#collapsed' => TRUE,
2132
    '#description' => t('This section covers the settings related to the taxon
2133
      <strong>synonymy</strong> tab.'),
2134
  );
2135

    
2136
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2137
    '#type' => 'checkbox',
2138
    '#title' => t('Show accepted taxon on top of the synonymy'),
2139
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2140
    '#description' => t('If checked, the first homotypic taxon is a repetition
2141
      of the accepted taxon most likely with the full nomenclatural reference
2142
      (depending on the currently chosen theme).'),
2143
  );
2144

    
2145
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2146
    '#type' => 'checkbox',
2147
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2148
      coming from a synonym link.'),
2149
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2150
    '#description' => t('Check this if after doing a search and clicking on a
2151
      synonym you want to see the "accept of" text for the accepted synonym.'),
2152
  );
2153

    
2154
  /* === currently unused ===
2155
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2156
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2157
    '#type' => 'checkboxes',
2158
    '#title' => t('Display name relationships') . ':',
2159
    '#default_value' => variable_get('name_relationships_to_show', 0),
2160
    '#options' => $nameRelationshipTypeOptions,
2161
    '#description' => t('Select the name relationships you want to show for the
2162
      accepted taxa.'),
2163
  );
2164
 */
2165

    
2166
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2167
    '#type' => 'checkbox',
2168
    '#title' => t('Show taxon relations ships of accepted taxon'),
2169
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2170
    '#description' => t('If this option is enabled the synonymy will show the
2171
      below selected taxon relationships of accepted taxa.'),
2172
  );
2173

    
2174
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2175
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2176
    '#type' => 'checkboxes',
2177
    '#title' => t('Taxon relationship types') . ':',
2178
    '#description' => t('Only taxon relationships of the selected type will be
2179
      displayed'),
2180
    '#options' => $taxonRelationshipTypeOptions,
2181
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2182
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2183
  );
2184

    
2185
  // ====== SPECIMENS ====== //
2186
  $form['taxon_specimens'] = array(
2187
    '#type' => 'fieldset',
2188
    '#title' => t('Taxon specimens (tab)'),
2189
    '#collapsible' => TRUE,
2190
    '#collapsed' => TRUE,
2191
    '#description' => t('This section covers the settings related to the taxon
2192
      <strong>specimens</strong> tab.'),
2193
  );
2194

    
2195
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2196
        '#type' => 'checkbox',
2197
        '#title' => t('Show specimen derivates in a compressed table'),
2198
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2199
        '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2200
        a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2201
    );
2202
    
2203
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2204
        '#type' => 'checkbox',
2205
        '#title' => t('Show "Determined as" in specimen table.'),
2206
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS),
2207
        '#description' => t('Note: only the current determination will be shown.'),
2208
    );
2209

    
2210
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2211
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2212
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2213
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2214
  }
2215
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2216
      '#type' => 'radios',
2217
      '#title' => t('Specimen description feature tree') . ':',
2218
      '#default_value' => $profile_feature_tree_uuid,
2219
      '#options' =>  $featureTrees['options'],
2220
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2221
      '#options_suffixes' => $featureTrees['treeRepresentations'],
2222
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2223
      ),
2224
  );
2225

    
2226
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2227
  $form_title = t('Specimen media');
2228
  $form_description = t('Specimens may have media which is displayed at the
2229
     Specimen tab/section as a gallery. It is possible to configure the
2230
     thumbnails gallery here, however for configuring how a single media should
2231
     be displayed please go to !url.</p>',
2232
     array(
2233
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2234
     ));
2235
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2236

    
2237
  // --- MEDIA GALLERY ---- //
2238
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2239
  $form_title = 'Media gallery (tab)';
2240
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2241
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2242
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2243
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2244
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2245
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2246
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2247

    
2248
  // Comment @WA: D7 form api does not support reset buttons,
2249
  // so to mimic the D5 reset button we add one like this.
2250
  $form['actions']['reset'] = array(
2251
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2252
    '#weight' => 1000,
2253
  );
2254
  return system_settings_form($form);
2255
}
2256

    
2257
/**
2258
 * @todo document this function.
2259
 */
2260
function cdm_settings_layout_search() {
2261

    
2262
  $form = array();
2263

    
2264
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2265

    
2266
  $form['search_settings'] = array(
2267
    '#type' => 'fieldset',
2268
    '#title' => t('Taxa Search'),
2269
    '#collapsible' => FALSE,
2270
    '#collapsed' => FALSE,
2271
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2272
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2273
         where they can write the text to be searched. You can find Drupal block configuration
2274
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2275
  );
2276

    
2277
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2278
      '#type' => 'checkbox',
2279
      '#title' => t('Ignore the chosen classification in simple search'),
2280
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2281
      '#description' => t('The simple search, which can be executed via the search block,
2282
          will by default search on the classification selected in the classification browser
2283
          selector. Set the tick if you want your portal to search on all classifications.'),
2284
  );
2285

    
2286
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2287
    '#type' => 'checkbox',
2288
    '#title' => t('Run simple search with free-text search backend.'),
2289
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2290
    '#description' => t('The simple search uses by default another search
2291
      backend as the advances search. By checking this option the simple search can be
2292
      configured to also use the free-text search backend.'),
2293
  );
2294

    
2295
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2296
    '#type' => 'textfield',
2297
    '#title' => t('Results per page') . ':',
2298
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2299
    '#description' => t('Number of results to display per page.'),
2300
  );
2301

    
2302
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2303
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2304
      '#type' => 'checkboxes',
2305
      '#title' => 'Search mode',
2306
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2307
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2308
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2309
          defaults set here.',
2310
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2311
      '#default_value' => $search_mode_default
2312
      );
2313

    
2314
  // --- SEARCH TAXA GALLERY ---- //
2315
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2316
  $collapsed = FALSE;
2317
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2318
  $form_title = 'Taxa Search thumbnails';
2319
  $form_description = 'Search results may show thumbnails. ';
2320
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2321

    
2322
  // Comment @WA: D7 form api does not support reset buttons,
2323
  // so to mimic the D5 reset button we add one like this.
2324
  $form['actions']['reset'] = array(
2325
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2326
    '#weight' => 1000,
2327
  );
2328
  return system_settings_form($form);
2329
}
2330

    
2331
/**
2332
 * @todo document this function.
2333
 */
2334
function cdm_settings_layout_media() {
2335

    
2336
  $form = array();
2337

    
2338
  $form['media_settings'] = array(
2339
    '#type' => 'fieldset',
2340
    '#title' => t('Media settings'),
2341
    '#collapsible' => FALSE,
2342
    '#collapsed' => FALSE,
2343
    '#description' => 'This section covers layout settings for media pages.'
2344
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2345
  );
2346

    
2347
  $form['media_settings']['image_gallery_viewer'] = array(
2348
    '#type' => 'select',
2349
    '#title' => t('Image viewer') . ':',
2350
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2351
    '#options' => array(
2352
      'default' => t('Standard image viewer'),
2353
      'fsi' => t('FSI viewer (requires FSI server!)'),
2354
    ),
2355
  );
2356

    
2357
  // --- MEDIA GALLERY ---- //
2358
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2359
  $form_title = 'Standard viewer';
2360
  $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>';
2361
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2362
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2363

    
2364
  // @WA: D7 form api does not support reset buttons,
2365
  // so to mimic the D5 reset button we add one like this.
2366
  $form['actions']['reset'] = array(
2367
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2368
    '#weight' => 1000,
2369
  );
2370
  return system_settings_form($form);
2371
}
2372

    
2373
/**
2374
 * GEOSERVICE and Map settings.
2375
 */
2376
function cdm_settings_geo($form, &$form_state) {
2377

    
2378
  $current_geoserver_settings = get_edit_map_service_settings();
2379
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2380
  // The default layer must always be enabled
2381
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2382
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2383

    
2384
  $form = array();
2385

    
2386
  $dummy_distribution_query = NULL;
2387
  if($map_distribution['map_type'] != 1){
2388
    // we need to apply a dummy query since the map serice requires for image maps
2389
    // at least as and ad to be defined
2390
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2391
  }
2392
  $form['map_preview'] = array(
2393
      '#type' => 'fieldset',
2394
      '#tree' => FALSE,
2395
      '#title' => t('Map preview'),
2396
      '#collapsible' => FALSE,
2397
      '#description' => 'The preview of the map'
2398
       . ($dummy_distribution_query != null ?
2399
           ' may not be accurate in case if image maps, please check the map display in the taxon pages.':
2400
           '.<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.')
2401
  );
2402
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL,
2403
      array(
2404
          'move' => "this.cdmOpenlayersMap.printInfo",
2405
          '#execute' => "this.cdmOpenlayersMap.printInfo"
2406
      )
2407
  );
2408

    
2409

    
2410
  /*
2411
   * GEO SERVER
2412
   */
2413
  $form['edit_map_server'] = array(
2414
    '#type' => 'fieldset',
2415
    '#tree' => true,
2416
    '#title' => t('EDIT map service'),
2417
    '#collapsible' => TRUE,
2418
    '#collapsed' => TRUE,
2419
    '#description' => t('Configuration and selection of your geo server.
2420
      The Geo Server is responsible for generating the maps.'),
2421
  );
2422

    
2423
  $form['edit_map_server']['base_uri'] = array(
2424
    '#type' => 'select',
2425
    '#title' => t('EDIT map service') . ':',
2426
    '#default_value' => $current_geoserver_settings['base_uri'],
2427
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2428
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2429
  );
2430
  $form['edit_map_server']['version'] = array(
2431
      '#type' => 'select',
2432
      '#title' => t('Version') . ':',
2433
      '#default_value' => $current_geoserver_settings['version'],
2434
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2435
      '#description' => t('The version of the EDIT map services'),
2436
  );
2437

    
2438
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
2439
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
2440
  $form['gmap_api_key'] = array(
2441
      '#type' => 'textfield',
2442
      '#title' => t('Google maps API key') . ':',
2443
      '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
2444
      '#description' => t('If you want to use the Google Maps Layer, a key is
2445
      needed. If you need a key, visit
2446
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
2447
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
2448
      is the default key for the localhost (127.0.0.1).',
2449
      array('!localhostkey' => $localhostkey)),
2450
  );
2451

    
2452

    
2453
  /*
2454
   * MAP SETTINGS
2455
   */
2456

    
2457
  $form[CDM_MAP_DISTRIBUTION] = array(
2458
    '#type' => 'fieldset',
2459
    '#tree' => TRUE,
2460
    '#title' => t('Maps settings'),
2461
    '#collapsible' => TRUE,
2462
    '#collapsed' => TRUE,
2463
    '#description' => t('General configuration for all map types.'),
2464
  );
2465

    
2466
  /*
2467
   * settings for the distribution map are used also for specimens map!!!!
2468
   */
2469

    
2470
  $form[CDM_MAP_DISTRIBUTION]['width'] = array(
2471
    '#type' => 'textfield',
2472
    '#title' => 'Width',
2473
    '#default_value' => $map_distribution['width'],
2474
    '#maxlength' => 4,
2475
    '#size' => 4,
2476
    '#description' => 'Width of the map. To allow OSM baselayers to zoom out to the full extend of the world the map width must be
2477
      a multiple of 256px since the osm tiles from tile.openstreetmap.org have a size of 256px x 256px and frational zoom
2478
      levels are not possible in this case.',
2479
  );
2480
  $form[CDM_MAP_DISTRIBUTION]['height'] = array(
2481
      '#type' => 'textfield',
2482
      '#title' => 'Height',
2483
      '#default_value' => $map_distribution['height'],
2484
      '#maxlength' => 4,
2485
      '#size' => 4,
2486
      '#description' => 'Height of the map. Depending on the chosen base layer you may want to choose the height equal
2487
      to the width or half of the width. Any other aspect ratio is also possible if desired.',
2488
  );
2489

    
2490
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2491
    '#type' => 'textfield',
2492
    '#title' => 'Bounding box',
2493
    '#default_value' => $map_distribution['bbox'],
2494
    '#description' => t('The bounding box (left, bottom, right, top) defines the area to be initially displayed in maps.
2495
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2496
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2497
      <strong>TIP: </strong>You can use the map preview above to choose a bbox from the map. Maybe you need to change the map type to OpeLayers.
2498
      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
2499
      below the map from where you can copy the bbox string.</p>'),
2500
  );
2501

    
2502
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2503
    '#type' => 'checkbox',
2504
    '#title' => 'Display area labels',
2505
    '#default_value' => $map_distribution['show_labels'],
2506
    '#description' => t('The map will show name labels of the areas'),
2507
  );
2508

    
2509
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2510
    '#type' => 'textfield',
2511
    '#title' => 'Map caption',
2512
    '#default_value' => $map_distribution['caption'],
2513
    '#description' => t('The caption will be shown below the map.'),
2514
  );
2515

    
2516
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2517
    '#type' => 'textfield',
2518
    '#title' => 'Distribution layer opacity',
2519
    '#default_value' => $map_distribution['distribution_opacity'],
2520
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
2521
                           fully visible, while a value near to 0.0 will be not much visible.'),
2522
  );
2523

    
2524
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2525
    '#type' => 'radios',
2526
    '#title' => 'Map types',
2527
    '#options' => array(
2528
      1 => "OpenLayers dynamic map viewer",
2529
      0 => "Plain image",
2530
    ),
2531
    '#default_value' => $map_distribution['map_type'],
2532
    '#description' => 'Two different map types are available :
2533
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2534
      which allows zooming and panning. If enabled you can configure the default layer
2535
      (background of your maps) below.</li>
2536
      <li><em>Plain image</em>: The map will be static non interactive
2537
      image.</li></ul>',
2538
  );
2539
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2540

    
2541

    
2542
  // --- Plain Image Settings --- //
2543
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2544
    '#type' => 'fieldset',
2545
    '#title' => 'Plain image map settings',
2546
    '#tree' => TRUE,
2547
    '#collapsible' => TRUE,
2548
    '#collapsed' => $open_layers_is_enabled,
2549
    '#description' => 'The settings in this section are still expertimental
2550
      and can only be used with the EDIT map service version 1.1 or above.',
2551
  );
2552
  $edit_mapserver_version = get_edit_map_service_version_number();
2553
  if ($edit_mapserver_version < 1.1) {
2554
    $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>'
2555
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2556
  }
2557

    
2558
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2559
    '#type' => 'textfield',
2560
    '#title' => 'Background layer',
2561
    '#default_value' => $map_distribution['image_map']['base_layer'],
2562
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2563
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2564
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2565
    )),
2566
  );
2567

    
2568
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2569
    '#type' => 'textfield',
2570
    '#title' => 'Background color',
2571
    '#default_value' => $map_distribution['image_map']['bg_color'],
2572
  );
2573

    
2574
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2575
    '#type' => 'textfield',
2576
    '#title' => 'Background layer style',
2577
     // Only line color by now.
2578
    '#default_value' => $map_distribution['image_map']['layer_style'],
2579
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2580
  );
2581

    
2582
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2583
      '#type' => 'textfield',
2584
      '#title' => 'Projection',
2585
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2586
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2587
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2588
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2589
  );
2590

    
2591

    
2592
  // --- OpenLayers Settings --- //
2593
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2594
    '#type' => 'fieldset',
2595
    '#title' => 'OpenLayers settings',
2596
    '#tree' => TRUE,
2597
    '#collapsible' => TRUE,
2598
    '#collapsed' => !$open_layers_is_enabled,
2599
    '#description' => '',
2600
  );
2601

    
2602

    
2603
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2604
      '#type' => 'checkbox',
2605
      '#title' => 'Display outside max extent',
2606
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2607
      '#description' => t('Allows the map to display parts of the layers which are outside
2608
         the max extent if the aspect ratio of the map and of the baselayer
2609
         are not equal.'),
2610
  );
2611

    
2612

    
2613
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2614
      '#type' => 'checkbox',
2615
      '#title' => 'Show Layer Switcher',
2616
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2617
      '#description' => 'The Layer Switcher control displays a table of contents
2618
      for the map.  This allows the user interface to switch between
2619
      base layers and to show or hide overlays.  By default the switcher is
2620
      shown minimized on the right edge of the map, the user may expand it
2621
      by clicking on the handle.',
2622
  );
2623

    
2624
  if (!$open_layers_is_enabled) {
2625
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2626
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2627
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2628
  }
2629

    
2630
  $baselayer_options = array(
2631
    /*
2632
   NOTICE: must correspond to the layers defined in
2633
   js/openlayers_,ap.js#getLayersByName()
2634
   */
2635
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
2636
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
2637
    // all others EPSG:900913
2638
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
2639
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2640
    'mapnik' => 'OpenStreetMap',
2641
    'mapquest_open' => "MapQuest",
2642
    'mapquest_sat' => "MapQuest Sattelite",
2643
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2644
    'gmap' => 'Google Streets',
2645
    'gsat' => 'Google Satellite',
2646
    'ghyb' => 'Google Hybrid',
2647
//     'veroad' => 'Virtual Earth Roads',
2648
//     'veaer' => 'Virtual Earth Aerial',
2649
//     'vehyb' => 'Virtual Earth Hybrid',
2650
    // 'yahoo' => 'Yahoo Street',
2651
    // 'yahoosat' => 'Yahoo Satellite',
2652
    // 'yahoohyb' => 'Yahoo Hybrid',
2653
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2654
  );
2655

    
2656
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2657
    '#type' => 'checkboxes_preferred',
2658
    '#title' => 'Base Layers',
2659
    '#options' => $baselayer_options,
2660
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2661
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2662
  );
2663

    
2664
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2665
      '#type' => 'fieldset',
2666
      '#title' => 'Custom WMS base layer',
2667
      '#tree' => TRUE,
2668
      '#collapsible' => FALSE,
2669
      '#collapsed' => FALSE,
2670
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2671
  );
2672

    
2673
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2674
      '#type' => 'textfield',
2675
      '#title' => 'Layer name',
2676
      // Only line color by now.
2677
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2678
      '#description' => 'A arbitrary name for the layer.',
2679
  );
2680
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2681
      '#type' => 'textfield',
2682
      '#title' => 'WMS url',
2683
      // Only line color by now.
2684
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2685
      '#description' => 'Base url for the WMS (e.g.  http://wms.jpl.nasa.gov/wms.cgi)'
2686
  );
2687
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2688
      '#type' => 'textarea',
2689
      '#title' => 'WMS parameters',
2690
      '#element_validate' => array('form_element_validate_json'),
2691
      // Only line color by now.
2692
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2693
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2694
<pre> {
2695
  "Layers": "topp:em_tiny_jan2003",
2696
  "Format": "image/png",
2697
  "BGCOLOR": "0xe0faff"
2698
}
2699
</pre>'
2700
  );
2701
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2702
      '#type' => 'textfield',
2703
      '#title' => 'Projection',
2704
      // Only line color by now.
2705
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2706
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2707
  );
2708
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2709
      '#type' => 'textfield',
2710
      '#maxlength' => 256,
2711
      '#title' => 'proj4js definition',
2712
      // Only line color by now.
2713
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2714
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2715
            The definitions for
2716
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2717
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2718
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2719
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2720
            choose to display the proj4js definition string.
2721
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2722
            <pre>
2723
+a         Semimajor radius of the ellipsoid axis
2724
+alpha     ? Used with Oblique Mercator and possibly a few others
2725
+axis      Axis orientation (new in 4.8.0)
2726
+b         Semiminor radius of the ellipsoid axis
2727
+datum     Datum name (see `proj -ld`)
2728
+ellps     Ellipsoid name (see `proj -le`)
2729
+k         Scaling factor (old name)
2730
+k_0       Scaling factor (new name)
2731
+lat_0     Latitude of origin
2732
+lat_1     Latitude of first standard parallel
2733
+lat_2     Latitude of second standard parallel
2734
+lat_ts    Latitude of true scale
2735
+lon_0     Central meridian
2736
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
2737
+lon_wrap  Center longitude to use for wrapping (see below)
2738
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
2739
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
2740
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
2741
+pm        Alternate prime meridian (typically a city name, see below)
2742
+proj      Projection name (see `proj -l`)
2743
+south     Denotes southern hemisphere UTM zone
2744
+to_meter  Multiplier to convert map units to 1.0m
2745
+towgs84   3 or 7 term datum transform parameters (see below)
2746
+units     meters, US survey feet, etc.
2747
+vto_meter vertical conversion to meters.
2748
+vunits    vertical units.
2749
+x_0       False easting
2750
+y_0       False northing
2751
+zone      UTM zone
2752
            </pre>
2753
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
2754
  );
2755
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
2756
      '#type' => 'textfield',
2757
      '#title' => 'Maximum extent',
2758
      // Only line color by now.
2759
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
2760
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
2761
  );
2762
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
2763
      '#type' => 'textfield',
2764
      '#title' => 'Units',
2765
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
2766
      '#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.'
2767
  );
2768

    
2769
  /*
2770
   * Map Legend
2771
   */
2772
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2773
    '#type' => 'fieldset',
2774
    '#title' => 'Map legend',
2775
    '#tree' => TRUE,
2776
    '#collapsible' => TRUE,
2777
    '#collapsed' => TRUE,
2778
    '#description' => 'Configure the maps legend.',
2779
  );
2780

    
2781
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2782
    '#type' => 'checkbox',
2783
    '#title' => 'Display a map legend',
2784
    '#default_value' => $map_distribution['legend']['show'],
2785
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2786
  );
2787

    
2788
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2789
    '#type' => 'textfield',
2790
    '#title' => 'Legend opacity',
2791
    '#default_value' => $map_distribution['legend']['opacity'],
2792
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2793
                         to 0.0 will be not much visible.',
2794
  );
2795

    
2796
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2797
    '#type' => 'textfield',
2798
    '#title' => 'Font size',
2799
    '#default_value' => $map_distribution['legend']['font_size'],
2800
    '#description' => 'Font size in pixels.',
2801
  );
2802

    
2803
  $fontStyles = array(
2804
    0 => "plane",
2805
    1 => "italic",
2806
  );
2807
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2808
    '#type' => 'select',
2809
    '#title' => 'Available font styles',
2810
    '#default_value' => $map_distribution['legend']['font_style'],
2811
    '#options' => $fontStyles,
2812
    '#description' => 'Select a font style for the map legend.',
2813
  );
2814

    
2815
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2816
    '#type' => 'textfield',
2817
    '#title' => 'Icon width',
2818
    '#default_value' => $map_distribution['legend']['icon_width'],
2819
    '#description' => 'Legend icon width in pixels.',
2820
  );
2821
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2822
    '#type' => 'textfield',
2823
    '#title' => 'Icon height',
2824
    '#default_value' => $map_distribution['legend']['icon_height'],
2825
    '#description' => 'Legend icon height in pixels.',
2826
  );
2827

    
2828
  // @WA: D7 form api does not support reset buttons,
2829
  // so to mimic the D5 reset button we add one like this.
2830
  $form['actions']['reset'] = array(
2831
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2832
    '#weight' => 1000,
2833
  );
2834

    
2835
  return system_settings_form($form);
2836
}
2837

    
2838
/**
2839
 * @todo document this function.
2840
 */
2841
function cdm_settings_cache() {
2842

    
2843
  $form = array();
2844

    
2845
  $form['cache_settings'] = array(
2846
    '#type' => 'fieldset',
2847
    '#title' => t('Cache Settings'),
2848
    '#collapsible' => FALSE,
2849
    '#collapsed' => FALSE,
2850
    '#description' => t('<p>When caching is enabled all single taxon sites are
2851
      stored in an internal drupal cache doing the portal response of taxa pages
2852
      faster. This is possible because the sites are loaded from the cache and
2853
      are not created from scratch.</p>'),
2854
  );
2855

    
2856
  $form['cache_settings']['cdm_webservice_cache'] = array(
2857
    '#type' => 'checkbox',
2858
    '#title' => t('<strong>Enable caching</strong>'),
2859
    '#options' => cdm_help_general_cache(),
2860
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2861
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2862
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2863
       application the changes will be not visible till the cache is erased.
2864
       Therefore developers should deactived this feature when they are working
2865
       on the CDM Dataportal Module.</p>'),
2866
  );
2867

    
2868
  $form['cache_settings']['cdm_run_cache'] = array(
2869
    '#markup' => cdm_view_cache_site(),
2870
  );
2871

    
2872
  // @WA: D7 form api does not support reset buttons,
2873
  // so to mimic the D5 reset button we add one like this.
2874
  $form['actions']['reset'] = array(
2875
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2876
    '#weight' => 1000,
2877
  );
2878
  return system_settings_form($form);
2879
}
2880

    
2881
/**
2882
 * Walk and cache all taxon pages.
2883
 */
2884
function cdm_view_cache_site() {
2885

    
2886
  $out = '';
2887

    
2888
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2889

    
2890
  $request_params = array();
2891
  $request_params['class'] = "Taxon";
2892

    
2893
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2894
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2895
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2896

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

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

    
2906
  // Comment @WA: A form within a form is not valid html and not needed here.
2907
  // Also, it would be recommended just to include this part of the form in the
2908
  // rest of the form array in cdm_settings_cache().
2909
  // $out .= '<form id="cache_site">';
2910
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2911
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2912
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2913
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2914
  // $out .= '</form>';
2915
  $out .= '</div>';
2916
  /*
2917
  foreach($taxonPager->records as $taxon){
2918
    cdm_dataportal_taxon_view($uuid);
2919
  }
2920
  */
2921
  return $out;
2922
}
2923

    
2924

    
2925
function cdm_settings_layout_taxon_submit($form, &$form_state){
2926
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2927
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2928
    if(is_object($file)){
2929
      $file->status = FILE_STATUS_PERMANENT;
2930
      file_save($file);
2931
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2932
    }
2933
  }
2934
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2935
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2936
    // we first need to set the variable to persist the changes setting
2937
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
2938
    menu_rebuild();
2939
  }
2940
}
2941

    
2942
function cdm_settings_layout_search_submit($form, &$form_state){
2943
  // the visibility of media thumbnails also affects the ui of the search results
2944
  // so reset the according session variable
2945
  //    1. in order to give the user immediate
2946
  //       feedback on potential setting changes
2947
  //    2. let refresh the default if it has changed
2948
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2949
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
2950
  }
2951
}
2952

    
2953
/**
2954
 * Form validation handler for cdm_settings_general
2955
 *
2956
 * @param $form
2957
 * @param $form_state
2958
 */
2959
function cdm_settings_general_validate($form, &$form_state) {
2960

    
2961
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2962
    $form_state['values']['cdm_webservice_url'] .= '/';
2963
  }
2964

    
2965
}
2966

    
2967
/**
2968
 * Form submit handler for settings general.
2969
 *
2970
 * tasks performed:
2971
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2972
 *
2973
 * @param $form
2974
 * @param $form_state
2975
 */
2976
function cdm_settings_general_submit($form, &$form_state){
2977
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2978
  unset($_SESSION['cdm']['taxonomictree_uuid']);
2979
}
2980

    
2981
/**
2982
 * Form validation handler for cdm_settings_cache
2983
 */
2984
function cdm_settings_cache_validate($form, &$form_state) {
2985
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2986
    cache_clear_all(NULL, 'cache_cdm_ws');
2987
    // Better clear secref_cache since I can not be sure if the cache has not
2988
    // be used during this response.
2989
    cdm_api_secref_cache_clear();
2990
  }
2991

    
2992
}
2993

    
2994
/**
2995
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
2996
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
2997
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
2998
 *  - version: the version, e.g.: v1.1
2999
 *
3000
 * @return array
3001
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3002
 */
3003
function get_edit_map_service_settings() {
3004

    
3005
  $settings = variable_get('edit_map_server', array(
3006
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3007
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3008
      )
3009
  );
3010

    
3011
  return $settings;
3012
}
3013

    
3014
/**
3015
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3016
 *
3017
 * @return string
3018
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3019
 */
3020
function get_edit_map_service_full_uri() {
3021
  $settings = get_edit_map_service_settings();
3022
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3023
}
3024

    
3025

    
3026
/**
3027
 * Returns the version number of the currently selected edit mapserver as a float
3028
 *
3029
 * @return float
3030
 *   The version number of the currently selected edit mapserver as a float.
3031
 *   Returns 0 on error.
3032
 */
3033
function get_edit_map_service_version_number() {
3034

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

    
3037
  $settings = get_edit_map_service_settings();
3038
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3039
  if (isset($matches[1])) {
3040
    // Convert string to float.
3041
    $version = 1 + $matches[1][0] - 1;
3042
    return $version;
3043
  }
3044
  else {
3045
    // Report error.
3046
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3047
        array(
3048
          '!version' => $settings['version'],
3049
          'warning')
3050
        )
3051
      );
3052
    return 0;
3053
  }
3054
}
3055

    
3056
/**
3057
 * Returns the array of selected items in a options array
3058
 *
3059
 * @param array $options
3060
 *   An options array as generated by a form element like checkoxes, select ...,
3061
 */
3062
function get_selection($options) {
3063
  $selection = array();
3064
  foreach ($options as $key=>$val) {
3065
    if (!empty($val)) {
3066
      $selection[] = $val;
3067
    }
3068
  }
3069
  return $selection;
3070
}
3071

    
3072

    
3073
/**
3074
 * Implements hook_element_info().
3075
 *
3076
 * Allows modules to declare their own Form API element types and specify their default values.
3077
 *
3078
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3079
 */
3080
function cdm_dataportal_element_info() {
3081
  $type['checkboxes_preferred'] = array(
3082
    '#input' => TRUE,
3083
    '#process' => array('checkboxes_preferred_expand'),
3084
    '#after_build' => array('checkboxes_preferred_after_build'),
3085
    '#theme' => array('checkboxes_preferred'),
3086
    // '#theme_wrapper' => array('form_element'),
3087
  );
3088
  return $type;
3089
}
3090

    
3091
/**
3092
 * #process callback function for the custom form element type 'checkbox_preferred'
3093
 *
3094
 *
3095
 */
3096
function checkboxes_preferred_expand($element, &$form_state, $form) {
3097

    
3098
  // First of all create checkboxes for each of the elements
3099
  $element = form_process_checkboxes($element);
3100

    
3101
  // compose the element name
3102
  $parents = array();
3103
  array_deep_copy($element['#parents'], $parents);
3104
  $parents[count($parents) -1 ] .= '_preferred';
3105
  $element_name = $parents[0];
3106
  for ($i=1; $i < count($parents); $i++){
3107
    $element_name .= '[' . $parents[$i] . ']';
3108
  }
3109

    
3110
  $children = element_children($element);
3111

    
3112
  $element['table_start'] = array(
3113
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3114
    '#weight' => -1,
3115
  );
3116

    
3117
  // prepare first part each of the table rows which contains the row label
3118
  $weight = 0;
3119
  foreach ($children as $key) {
3120
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3121
    $element[$key]['#weight'] = $weight;
3122
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
3123
    $element[$key]['#suffix'] = '</td>';
3124
    unset($element[$key]['#title']);
3125
    $weight += 2;
3126
  }
3127
  $weight = 0;
3128

    
3129
  // add a radio button to each of the checkboxes, the
3130
  // check boxes have already been created at the beginning
3131
  // of this function
3132
  if (count($element['#options']) > 0) {
3133
    foreach ($element['#options'] as $key => $choice) {
3134
      if (!isset($element[$key . '_preferred'])) {
3135
        $element[$key . '_preferred'] = array(
3136
          '#type' => 'radio',
3137
          '#name' => $element_name,
3138
          '#return_value' => check_plain($key),
3139
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3140
          '#attributes' => $element['#attributes'],
3141
          '#parents' => $element['#parents'],
3142
          // '#spawned' => TRUE,
3143
          '#weight' => $weight + 1,
3144
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3145
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3146
        );
3147
      }
3148
      $weight += 2;
3149
    }
3150
  }
3151

    
3152
  // end the table
3153
  $element['table_end'] = array(
3154
    '#markup' => '</table>',
3155
    '#weight' => $weight++,
3156
  );
3157

    
3158
  return $element;
3159
}
3160

    
3161
/**
3162
 * Theme function for the custom form field 'checkboxes_preferred'.
3163
 */
3164
function theme_checkboxes_preferred($variables) {
3165
  $element = $variables['element'];
3166
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3167
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3168
  $out .= drupal_render_children($element);
3169
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3170
  $out .= '</div>';
3171
  return $out;
3172
}
3173

    
3174
/**
3175
 * Callback for checkboxes preferred for widget which will
3176
 * be called after the form or element is built. The call
3177
 * back is configured in the form element by setting it as
3178
 * #after_build parameter.
3179
 *
3180
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3181
 *
3182
 * @param $element
3183
 *   Nested array of form elements that comprise the form.
3184
 * @param $form_state
3185
 *   A keyed array containing the current state of the form.
3186
 *   This includes the current persistent storage data for the form.
3187
 *   Additional information, like the sanitized $_POST data,
3188
 *   is also accumulated here in $form_state['input']
3189
 *
3190
 * @return the modified form array
3191
 */
3192
function checkboxes_preferred_after_build($element, &$form_state) {
3193

    
3194
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3195

    
3196
  if ($_POST && count($_POST) > 0) {
3197
    // TODO use  $form_state['input'] instead of POST !!!
3198
    // First pass of form processing.
3199
    $parents = array();
3200
    array_deep_copy($element['#parents'], $parents);
3201
    $parents[count($parents) - 1] .= '_preferred';
3202
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3203
    $element['#value']['PREFERRED'] = $preferred_layer;
3204
//     $form_state[$parent_id] = $element['#value'];
3205
//     $form_state['values']['baselayers'] = $element['#value'];
3206
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3207
    $form_state_element_values = $element['#value'];
3208
  }
3209
  else {
3210
    // Second pass of form processing.
3211
    $preferred_layer = $element['#value']['PREFERRED'];
3212
  }
3213

    
3214
  // Also set the chosen value (not sure if this is good Drupal style ....).
3215
  foreach ($children = element_children($element) as $key) {
3216
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3217
      $element[$key]['#value'] = $preferred_layer;
3218
    }
3219
  }
3220
  // The default layer must always be enabled.
3221
  $element[$preferred_layer]['#value'] = $preferred_layer;
3222

    
3223
  return $element;
3224
}
3225

    
3226
function radios_prepare_options_suffix(&$elements){
3227

    
3228
  $childrenKeys = element_children($elements);
3229
  foreach($childrenKeys as $key){
3230
    if(!is_array($elements[$key]['#theme_wrappers'])){
3231
      $elements[$key]['#theme_wrappers'] = array();
3232
    }
3233
    if(isset($elements['#options_suffixes'][$key])){
3234
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3235
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3236
    }
3237
  }
3238
  return $elements;
3239

    
3240
}
3241

    
3242
/**
3243
 * TODO
3244
 * @param unknown $variables
3245
 */
3246
function theme_radio_options_suffix($variables) {
3247
  $element = $variables['element'];
3248
  if(isset($element['#options_suffix'])) {
3249
    $element['#children'] .= $element['#options_suffix'];
3250
  }
3251
  return $element['#children'];
3252
}
3253

    
3254

    
3255
/**
3256
 * Element validate callback for text field and arrays containing json.
3257
 *
3258
 * @param $element
3259
 *   The form element to validate
3260
 * @param $form_state
3261
 *   A keyed array containing the current state of the form.
3262
 * @param $form
3263
 *   Nested array of form elements that comprise the form.
3264
 */
3265
function form_element_validate_json($element, &$form_state, $form) {
3266
   if (!empty($element['#value'])) {
3267
     json_decode($element['#value']);
3268
     if(json_last_error() != JSON_ERROR_NONE){
3269
       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/'));
3270
     }
3271
   }
3272
}
3273

    
3274
/**
3275
 * Form submission handler for textareas and textfields containing JSON.
3276
 *
3277
 * The contained JSON will be converted into an php array
3278
 * or object and will be stored in the variables as such.
3279
 *
3280
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3281
 *
3282
 * @param $form
3283
 *   Nested array of form elements that comprise the form.
3284
 * @param $form_state
3285
 *   A keyed array containing the current state of the form.
3286
 *
3287
 */
3288
function submit_json_as_php_array($form, &$form_state) {
3289
  if (is_array($form['#json_elements'])) {
3290
    foreach ($form['#json_elements'] as $element){
3291
      if (trim($form_state['values'][$element])) {
3292
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3293
      } else {
3294
        $form_state['values'][$element] = NULL;
3295
      }
3296
    }
3297
  }
3298
}
(15-15/15)