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(
120
    'general' => '-3',
121
    'synonymy' => '-2',
122
    'images' => '0',
123
    'specimens' => '1',
124
    'keys' => '3',
125
    'experts' => '5',
126
    )
127
));
128

    
129
$taxon_tab_options = get_taxon_tabs_list();
130
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
131

    
132
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
133

    
134
/**
135
 * @todo document this function.
136
 */
137
function get_taxon_options_list() {
138
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
139
  foreach ($taxon_tab_options as $key => $value) {
140
    $taxon_tab_options[$key] = t($key);
141
  }
142
  return $taxon_tab_options;
143

    
144
}
145

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

    
237
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
238
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
239
   array (
240
     'taxon_page_title,polytomousKey'=> array(
241
          'namePart' => array('#uri' => TRUE),
242
        ),
243
      'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy'=> array(
244
          'nameAuthorPart' => array('#uri' => TRUE),
245
          'referencePart' => TRUE,
246
          'statusPart' => TRUE,
247
          'descriptionPart' => TRUE,
248
        ),
249
       'related_taxon'=> array(
250
         'nameAuthorPart' => array('#uri' => TRUE),
251
         'referencePart' => TRUE,
252
         'statusPart' => TRUE,
253
         'secReferencePart' => TRUE,
254
         'descriptionPart' => TRUE,
255
       ),
256
       'homonym'=> array(
257
            'nameAuthorPart' => array('#uri' => TRUE),
258
            'referenceYearPart' => TRUE,
259
        ),
260
      'acceptedFor,typedesignations,list_of_taxa' => array(
261
          'nameAuthorPart' => array('#uri' => TRUE),
262
          'referencePart' => TRUE,
263
        ),
264
      '#DEFAULT' => array(
265
          'nameAuthorPart' => array('#uri' => TRUE),
266
          'referencePart' => TRUE,
267
       )
268
    )
269
));
270
  define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
271
    array (
272
      'taxon_page_title,polytomousKey'=> array(
273
        'namePart' => array('#uri' => TRUE),
274
      ),
275
      'taxon_page_synonymy,related_taxon'=> array(
276
        'nameAuthorPart' => array('#uri' => TRUE),
277
        'referencePart' => TRUE,
278
        'statusPart' => TRUE,
279
        'descriptionPart' => TRUE,
280
      ),
281
      'homonym'=> array(
282
        'nameAuthorPart' => array('#uri' => TRUE),
283
        'referenceYearPart' => TRUE,
284
      ),
285
      'acceptedFor,typedesignations,list_of_taxa' => array(
286
        'nameAuthorPart' => array('#uri' => TRUE),
287
        'referencePart' => TRUE,
288
      ),
289
      '#DEFAULT' => array(
290
        'nameAuthorPart' => array('#uri' => TRUE),
291
        'referencePart' => TRUE,
292
      )
293
    )
294
  ));
295

    
296
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
297
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
298
    // to unset a default enntry set the value to 0
299
    array(
300
      'doTaxa'=>'doTaxa',
301
      'doSynonyms' => 'doSynonyms',
302
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
303
      'doMisappliedNames' => 'doMisappliedNames'
304
    )
305
  )
306
);
307

    
308
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
309
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
310

    
311
/* Gallery variables. */
312
$gallery_settings = array(
313
    "cdm_dataportal_show_taxon_thumbnails" => 1,
314
    "cdm_dataportal_show_synonym_thumbnails" => 0,
315
    "cdm_dataportal_show_thumbnail_captions" => 1,
316
    "cdm_dataportal_media_maxextend" => 120,
317
    "cdm_dataportal_media_cols" => 3,
318
    "cdm_dataportal_media_maxRows" => 1,
319
);
320

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

    
361
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
362
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
363
      array(
364
      'filter_rules' => array(
365
        'statusOrderPreference' => 0,
366
        'subAreaPreference' => 0,
367
      ),
368
      'hiddenAreaMarkerType' => array()
369
     )
370
));
371

    
372

    
373
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
374
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
375
    array(
376
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
377
        'includeOccurrences' => 0,
378
        'includeTaxonNameDescriptions' => 0
379
     )
380
  ));
381

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

    
428
/**
429
 * Merges the named array variable with the array of defaults.
430
 *
431
 * IMPORTANT: The array keys must be strings. When the keys are integers
432
 * the merging will not take place for these entities. Number keyed entities
433
 * are just appended to the result array.
434
 *
435
 * @param string $variable_name
436
 *     The variable name
437
 * @param string | array $default
438
 *     The array containing the default values either as array or serialized as string.
439
 *     Unserialization is cared for if necessary
440
 * @return array
441
 *     The merged array as returned by drupal_array_merge_deep()
442
 *
443
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
444
 * TODO force $default being an array
445
 */
446
function get_array_variable_merged($variable_name, $default){
447

    
448
    // unserialize if nessecary
449
    if(!is_array($default)){
450
      $default = unserialize($default);
451
    }
452
    $variable = variable_get($variable_name, array());
453
    $result = drupal_array_merge_deep($default, $variable);
454
    return $result;
455
}
456

    
457
/**
458
 * @todo document this function.
459
 */
460
function getGallerySettings($gallery_config_form_name) {
461
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
462
}
463

    
464
/**
465
 * Returns the string representation of the default tab.
466
 *
467
 * @param bool $returnTabIndex
468
 *   Defaults to FALSE, if set true this function will return the index number
469
 *   of the default tab. (used to supply default values to form elements).
470
 */
471
function get_default_taxon_tab($returnTabIndex = FALSE) {
472

    
473
  global $user;
474
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
475
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
476
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
477
  // Get the user value if the used has chosen to overwrite the system settings.
478
  $user_tab_on = variable_get($user_tab_active, FALSE);
479
  if ($user_tab_on) {
480
    $user_value = variable_get($user_tab, 0);
481
    $index_value = $user_value;
482
    // Get the system value.
483
  }
484
  else {
485
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
486
    $index_value = $system_value;
487
  }
488

    
489
  // Return the index value or the string representation.
490
  if ($returnTabIndex) {
491
    return $index_value;
492
  }
493
  else {
494
    return ($values[$index_value]);
495
  }
496
}
497

    
498

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

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

    
570
    // ---- DEFAULTS settings
571

    
572
    // only needed as final option, when the settings are not having a default
573
    $default = array(
574
      'DEFAULT' => array(
575
        'as_list' => 'div',
576
        'link_to_reference' => 0,
577
        'link_to_name_used_in_source' => 1,
578
        'sources_as_content' => 0,
579
        'sources_as_content_to_bibliography' => 0,
580
        'sort_elements' => NO_SORT,
581
        'glue' => '',
582
        'element_tag' => NULL
583
      )
584
    );
585

    
586
    // will be used as preset in the settings
587
    $other_themes_default = array(
588
      'DEFAULT' => array(
589
        'as_list' => 'div',
590
        'link_to_reference' => 0,
591
        'link_to_name_used_in_source' => 1,
592
        'sources_as_content' => 0,
593
        'sources_as_content_to_bibliography' => 0,
594
        'sort_elements' => NO_SORT,
595
        'glue' => '',
596
        'element_tag' => NULL
597
      ),
598
      UUID_CITATION => array(
599
        'as_list' => 'div',
600
        'link_to_reference' => 0,
601
        'link_to_name_used_in_source' => 0,
602
        'sources_as_content' => 1,
603
        'sources_as_content_to_bibliography' => 0,
604
        'sort_elements' => SORT_ASC,
605
        'glue' => '',
606
        'element_tag' => 'div'
607
      ),
608
      UUID_DISTRIBUTION => array(
609
        'as_list' => 'div', // currently ignored
610
        'link_to_reference' => 0,
611
        'link_to_name_used_in_source' => 0,
612
        'sources_as_content' => 0,
613
        'sources_as_content_to_bibliography' => 0,
614
        'sort_elements' => NO_SORT, // will cause ...
615
        'glue' => '',
616
        'element_tag' => 'div',
617
        'special' => array()
618
      ),
619
      UUID_COMMON_NAME => array(
620
        'as_list' => 'div',
621
        'link_to_reference' => 0,
622
        'link_to_name_used_in_source' => 1,
623
        'sources_as_content' => 0,
624
        'sources_as_content_to_bibliography' => 0,
625
        'sort_elements' => NO_SORT,
626
        'glue' => '',
627
        'element_tag' => 'span'
628
      ),
629
    );
630

    
631
    // ---- Special DEFAULTS for existing portals
632
    // TODO:
633
    // this can be removed once the feature block
634
    // settings have been deployed for the first time to these portals
635

    
636
    $cichorieae_default = array(
637
      'DEFAULT' => array(
638
        'as_list' => 'div',
639
        'link_to_reference' => 1,
640
        'link_to_name_used_in_source' => 1,
641
        'sources_as_content' => 1,
642
        'sources_as_content_to_bibliography' => 0,
643
        'sort_elements' => NO_SORT,
644
        'glue' => '',
645
        'element_tag' => 'div'
646
      ),
647
      UUID_CITATION => array(
648
        'as_list' => 'div',
649
        'link_to_reference' => 0,
650
        'link_to_name_used_in_source' => 0,
651
        'sources_as_content' => 1,
652
        'sources_as_content_to_bibliography' => 0,
653
        'sort_elements' => SORT_ASC,
654
        'glue' => '',
655
        'element_tag' => 'div'
656
      ),
657
      UUID_CHROMOSOMES_NUMBERS => array(
658
        'as_list' => 'ul',
659
        'link_to_reference' => 1,
660
        'link_to_name_used_in_source' => 1,
661
        'sources_as_content' => 1,
662
        'sources_as_content_to_bibliography' => 0,
663
        'sort_elements' => NO_SORT,
664
        'glue' => '',
665
        'element_tag' => 'div'
666
      ),
667
      UUID_CHROMOSOMES => array(
668
        'as_list' => 'ul',
669
        'link_to_reference' => 0,
670
        'link_to_name_used_in_source' => 1,
671
        'sources_as_content' => 1,
672
        'sources_as_content_to_bibliography' => 0,
673
        'sort_elements' => NO_SORT,
674
        'glue' => '',
675
        'element_tag' => 'div'
676
      ),
677
      UUID_COMMON_NAME => array(
678
        'as_list' => 'div',
679
        'link_to_reference' => 0,
680
        'link_to_name_used_in_source' => 1,
681
        'sources_as_content' => 0,
682
        'sources_as_content_to_bibliography' => 0,
683
        'sort_elements' => NO_SORT,
684
        'glue' => '',
685
        'element_tag' => 'span'
686
      ),
687
    );
688

    
689
    $palmweb_default = array(
690
      'DEFAULT' => array(
691
        'as_list' => 'ul',
692
        'link_to_reference' => 1,
693
        'link_to_name_used_in_source' => 1,
694
        'sources_as_content' => 1,
695
        'sources_as_content_to_bibliography' => 1,
696
        'sort_elements' => NO_SORT,
697
        'glue' => '',
698
        'element_tag' => NULL
699
      ),
700
      UUID_CITATION => array(
701
        'as_list' => 'ul',
702
        'link_to_reference' => 1,
703
        'link_to_name_used_in_source' => 1,
704
        'sources_as_content' => 0,
705
        'sources_as_content_to_bibliography' => 1,
706
        'sort_elements' => SORT_ASC,
707
        'glue' => '',
708
        'element_tag' => 'div'
709
      ),
710
      UUID_DISTRIBUTION => array(
711
        'as_list' => 'div', // currently ignored
712
        'link_to_reference' => 1,
713
        'link_to_name_used_in_source' => 1,
714
        'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
715
        'sources_as_content_to_bibliography' => 1,
716
        'sort_elements' => NO_SORT, // will cause ...
717
        'glue' => '',
718
        'element_tag' => 'div',
719
        'special' => array()
720
      ),
721
    );
722

    
723
    $cyprus_default = $cichorieae_default;
724
    $cyprus_default[UUID_DISTRIBUTION] = array(
725
      'as_list' => 'div', // currently ignored
726
      'link_to_reference' => 0,
727
      'link_to_name_used_in_source' => 0,
728
      'sources_as_content' => 0,
729
      'sources_as_content_to_bibliography' => 0,
730
      'sort_elements' => NO_SORT, // will cause ...
731
      'glue' => '',
732
      'element_tag' => 'div',
733
      'special' => array()
734
    );
735

    
736
    $default_theme = variable_get('theme_default', NULL);
737

    
738
    switch ($default_theme) {
739
      case 'garland_cichorieae':
740
        $settings_for_theme = $cichorieae_default;
741
        break;
742
      case 'cyprus':
743
        // cyprus: no longer used in production,
744
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
745
        $settings_for_theme = $cyprus_default;
746
        break;
747
      case 'flore_afrique_centrale':
748
      case 'flora_malesiana':
749
      case 'flore_gabon':
750
        $settings_for_theme = $cichorieae_default;
751
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
752
        break;
753
      case 'palmweb_2':
754
        $settings_for_theme = $palmweb_default;
755
        break;
756
      default:
757
        $settings_for_theme = $other_themes_default;
758
    }
759
    // ---- END of DEFAULTS
760

    
761
    $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
762

    
763
    $feature_block_setting = null;
764

    
765
    if (isset($saved_settings[$feature_uuid])) {
766
      $feature_block_setting = $saved_settings[$feature_uuid];
767
    }
768
    else if (isset($settings_for_theme[$feature_uuid])) {
769
      $feature_block_setting = $settings_for_theme[$feature_uuid];
770
    }
771
    else if (isset($settings_for_theme['DEFAULT'])) {
772
      $feature_block_setting = $settings_for_theme['DEFAULT'];
773
    }
774

    
775
    // now merge the default and specific settings
776
    $settings_to_merge = array($default['DEFAULT']);
777
    if(is_array($saved_settings)){
778
      $settings_to_merge[] = $saved_settings['DEFAULT'];
779
    }
780
    if(isset($feature_block_setting)){
781
      $settings_to_merge[] = $feature_block_setting;
782
    }
783
    $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
784

    
785
    return $feature_block_setting;
786
}
787
  /**
788
 * returns the current setting for the original source bibliography
789
 *
790
 * Caches internally
791
 *
792
 * @return array
793
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
794
 *   - 'enabled': 1|0
795
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
796
 */
797
function get_bibliography_settings($clear_cache = false){
798
  static $bibliography_settings = null;
799
  if(!$bibliography_settings || $clear_cache){
800
    $bibliography_settings = get_array_variable_merged(
801
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
802
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
803
    );
804
  }
805
  return $bibliography_settings;
806
}
807

    
808
/**
809
 * @todo Please document this function.
810
 * @see http://drupal.org/node/1354
811
 */
812
function cdm_dataportal_menu_admin(&$items) {
813
  // Display section on admin/config page.
814
  $items['admin/config/cdm_dataportal'] = array(
815
    'title' => 'CDM Dataportal',
816
    'description' => 'Settings for the CDM DataPortal.',
817
    'position' => 'right',
818
    'weight' => 10,
819
    'page callback' => 'system_admin_menu_block_page',
820
    'access arguments' => array('administer cdm_dataportal'),
821
    'file' => 'system.admin.inc',
822
    'file path' => drupal_get_path('module', 'system'),
823
  );
824
  $items['admin/config/cdm_dataportal/settings'] = array(
825
    'title' => 'Settings',
826
    'description' => 'Settings for the CDM DataPortal.',
827
    'weight' => 0,
828
    'page callback' => 'drupal_get_form',
829
    'page arguments' => array('cdm_settings_general'),
830
    'access arguments' => array('administer cdm_dataportal'),
831
    'type' => MENU_NORMAL_ITEM,
832
  );
833
  $items['admin/config/cdm_dataportal/settings/general'] = array(
834
    'title' => 'General',
835
    'description' => 'General',
836
    'weight' => 0,
837
    'page callback' => 'drupal_get_form',
838
    'page arguments' => array('cdm_settings_general'),
839
    'access arguments' => array('administer cdm_dataportal'),
840
    'type' => MENU_DEFAULT_LOCAL_TASK,
841
  );
842

    
843
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
844
    'title' => 'Cache',
845
    'description' => 'Cache',
846
    'access arguments' => array('administer cdm_dataportal'),
847
    'page callback' => 'drupal_get_form',
848
    'page arguments' => array('cdm_settings_cache'),
849
    'weight' => 10,
850
    'type' => MENU_LOCAL_TASK,
851
  );
852

    
853
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
854
    'title' => 'Geo & Map',
855
    'description' => 'Geo & Map',
856
    'access arguments' => array('administer cdm_dataportal'),
857
    'page callback' => 'drupal_get_form',
858
    'page arguments' => array('cdm_settings_geo'),
859
    'weight' => 1,
860
    'type' => MENU_LOCAL_TASK,
861
  );
862

    
863
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
864
    'title' => 'Layout',
865
    'description' => 'Configure and adjust the layout of your DataPortal ',
866
    'access arguments' => array('administer cdm_dataportal'),
867
    'page callback' => 'drupal_get_form',
868
    'page arguments' => array('cdm_settings_layout'),
869
    'weight' => 2,
870
    'type' => MENU_LOCAL_TASK,
871
  );
872

    
873
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
874
    'title' => 'Taxon',
875
    'description' => 'Configure and adjust the layout of your DataPortal ',
876
    'access arguments' => array('administer cdm_dataportal'),
877
    'page callback' => 'drupal_get_form',
878
    'page arguments' => array('cdm_settings_layout_taxon'),
879
    'weight' => 1,
880
    'type' => MENU_LOCAL_TASK,
881
  );
882
  /*
883
  $items[] = array(
884
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
885
  'title' => t('Synonymy'),
886
  'description' => t('Configure and adjust the layout of your DataPortal '),
887
  'access' => user_access('administer cdm_dataportal'),
888
  'callback' => 'drupal_get_form',
889
  'callback arguments' => array('cdm_settings_layout_synonymy'),
890
  'weight' => 1,
891
  'type' => MENU_LOCAL_TASK,
892
  );
893

    
894
  $items[] = array(
895
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
896
  'title' => t('Specimens'),
897
  'description' => t('Configure and adjust the layout of your DataPortal '),
898
  'access' => user_access('administer cdm_dataportal'),
899
  'callback' => 'drupal_get_form',
900
  'callback arguments' => array('cdm_settings_layout_specimens'),
901
  'weight' => 1,
902
  'type' => MENU_LOCAL_TASK,
903
  );
904
  */
905
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
906
    'title' => 'Search',
907
    'description' => 'Configure and adjust the layout of your DataPortal ',
908
    'access arguments' => array('administer cdm_dataportal'),
909
    'page callback' => 'drupal_get_form',
910
    'page arguments' => array('cdm_settings_layout_search'),
911
    'weight' => 2,
912
    'type' => MENU_LOCAL_TASK,
913
  );
914

    
915
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
916
    'title' => 'Media',
917
    'description' => 'Configure and adjust the layout of your DataPortal ',
918
    'access arguments' => array('administer cdm_dataportal'),
919
    'page callback' => 'drupal_get_form',
920
    'page arguments' => array('cdm_settings_layout_media'),
921
    'weight' => 3,
922
    'type' => MENU_LOCAL_TASK,
923
  );
924

    
925
}
926

    
927
/**
928
 * @todo document this function.
929
 */
930
function cdm_help_general_cache() {
931
  $form = array();
932
  $form['cache_help'] = array(
933
    '#type' => 'fieldset',
934
    '#title' => t('Help'),
935
    '#collapsible' => TRUE,
936
    '#collapsed' => TRUE,
937
  );
938
  $form['cache_help']['test'] = array('#value' => t('probando'));
939
  return drupal_render($form);
940
  $res = array();
941
  $res['default'] = drupal_render($help);
942
  return $res;
943
}
944

    
945
/**
946
 * Configures the settings form for the CDM-API module.
947
 *
948
 * @return array
949
 *   Drupal settings form.
950
 */
951
function cdm_settings_general() {
952

    
953
  $form['cdm_webservice'] = array(
954
    '#type' => 'fieldset',
955
    '#title' => t('CDM Server'),
956
    '#collapsible' => FALSE,
957
    '#collapsed' => FALSE,
958
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
959
        CDM data base to the web via RESTful web services and thus is the source of the data
960
        to be displayed by a CDM DataPotal.'),
961
  );
962

    
963
  $form['cdm_webservice']['cdm_webservice_url'] = array(
964
    '#type' => 'textfield',
965
    '#title' => t('CDM web service URL') . ':',
966
    '#description' => t('This is the URL to the CDM-Server exposing your data
967
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
968
    '#default_value' => variable_get('cdm_webservice_url', NULL),
969
  );
970

    
971
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
972
    '#type' => 'markup',
973
    '#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')
974
      . ' visible only for administrators',
975
  );
976

    
977
  $form['cdm_webservice']['freetext_index'] = array(
978
    '#type' => 'fieldset',
979
    '#title' => t('Freetext index'),
980
    '#collapsible' => FALSE,
981
    '#collapsed' => FALSE,
982
  );
983

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

    
996
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
997
  $trigger_link_options = array(
998
    'attributes' => array(
999
      'class' => 'index-trigger',
1000
    ),
1001
  );
1002
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1003
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1004
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1005
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1006
      ))
1007
    . '<div id="index-progress"></div></div>',
1008
  );
1009
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1010

    
1011
  $form['cdm_webservice']['proxy'] = array(
1012
    '#type' => 'fieldset',
1013
    '#title' => t('Proxy'),
1014
    '#collapsible' => TRUE,
1015
    '#collapsed' => TRUE,
1016
  );
1017

    
1018
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1019
    '#type' => 'textfield',
1020
    '#title' => t('Proxy URL') . ':',
1021
    '#description' => t('If this proxy url is set the cdm api tries
1022
    to connect the web service over the given proxy server.
1023
    Otherwise proxy usage is deactivated.'),
1024
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1025
  );
1026

    
1027
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1028
    '#type' => 'textfield',
1029
    '#title' => t('Proxy port') . ':',
1030
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1031
  );
1032

    
1033
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1034
    '#type' => 'textfield',
1035
    '#title' => t('Login') . ':',
1036
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1037
  );
1038

    
1039
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1040
    '#type' => 'textfield',
1041
    '#title' => t('Password') . ':',
1042
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1043
  );
1044

    
1045
  // TODO: settings are still incomplete, compare with
1046
  // trunk/dataportal/inc/config_default.php.inc.
1047
  $form['taxon_tree'] = array(
1048
    '#type' => 'fieldset',
1049
    '#title' => t('Taxon Tree'),
1050
    '#collapsible' => FALSE,
1051
    '#collapsed' => TRUE,
1052
    '#description' => t('<p>When you explore your collection, you can navigate
1053
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1054
      able to navigate through your collection the
1055
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1056
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1057
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1058
      </a></p>'),
1059
  );
1060

    
1061
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1062
    '#type' => 'select',
1063
    '#title' => t('Available classifications') . ':',
1064
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1065
    '#options' => cdm_get_taxontrees_as_options(),
1066
    '#description' => t('Select the default taxa classification for your
1067
      <em>taxon tree</em>, the other classifications will be also available but
1068
      with a manual user change.'),
1069
  );
1070

    
1071
  $form['taxon_tree']['taxontree_ranklimit'] = array(
1072
    '#type' => 'select',
1073
    '#title' => t('Rank of highest displayed taxon') . ':',
1074
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1075
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
1076
    '#options' => cdm_rankVocabulary_as_option(),
1077
    '#description' => t('This is the rank of the highest displayed taxon in the
1078
      <em>taxon tree</em>. You can select here which rank should be at the top
1079
      level of the tree structure.'),
1080
  );
1081

    
1082
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1083
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1084
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1085
      '#type' => 'checkboxes',
1086
      '#title' => t('Included Classifications') . ':',
1087
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1088
      '#options' => cdm_get_taxontrees_as_options(),
1089
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1090
  );
1091

    
1092
  $form['distribution'] = array(
1093
      '#type' => 'fieldset',
1094
      '#title' => t('Distributions'),
1095
      '#collapsible' => FALSE,
1096
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1097
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1098
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1099
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1100
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1101
          '<p>
1102
          </p>',
1103
  );
1104

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

    
1126
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1127
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1128
      '#type' => 'checkboxes',
1129
      '#title' => 'Filter rules',
1130
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1131
      '#options' => array(
1132
          'statusOrderPreference' => 'Status order preference rule',
1133
          'subAreaPreference' => 'Sub area preference rule'
1134
      ),
1135
  );
1136

    
1137
  $marker_type_options = cdm_terms_as_options( cdm_ws_fetch_all('term', array('class' => 'MarkerType' )) );
1138
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1139
      '#type' => 'checkboxes',
1140
      '#title' => 'Hide marked area filter',
1141
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1142
      '#options' => $marker_type_options,
1143
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1144
  );
1145

    
1146
  $form['aggregation'] = array(
1147
      '#type' => 'fieldset',
1148
      '#title' => t('Aggregation of data'),
1149
      '#collapsible' => FALSE,
1150
      '#description' => 'This section covers the different aspects of aggregating information.
1151
          <p>
1152
          </p>',
1153
  );
1154

    
1155
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1156
      '#type' => 'checkboxes',
1157
      '#title' => 'Taxon media filter',
1158
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1159
      '#options' => array(
1160
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1161
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1162
          'includeOccurrences' => 'Media related to specimens and occurrences',
1163
      ),
1164
      '#description' => 'This filter configures which images should be taken into account.',
1165
  );
1166

    
1167
  $form['aggregation']['notice'] = array(
1168
      '#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
1169
          want to make use of the caching capabilities of the dataportal.',
1170
  );
1171

    
1172
  $form['aggregation']['media_aggregation'] = array(
1173
      '#type' => 'fieldset',
1174
      '#title' => t('Media aggregation'),
1175
      '#collapsible' => FALSE,
1176
      '#collapsed' => TRUE,
1177
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1178

    
1179
  );
1180
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1181
      '#type' => 'select',
1182
      '#title' => t('Aggregation of taxon pictures') . ':',
1183
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1184
      '#options' => array(
1185
          0 => "Show only pictures of the current taxon",
1186
          1 => "Include pictures of taxonomic children",
1187
      ),
1188
      '#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."),
1189
  );
1190

    
1191
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1192
      '#type' => 'fieldset',
1193
      '#attributes' => array('class'=>array('clearfix')),
1194
      '#title' => t('Aggregation via taxon relationsships'),
1195
      '#collapsible' => TRUE,
1196
      '#collapsed' => TRUE,
1197
      '#tree' => TRUE,
1198
      '#description' => t('Information on taxa will be aggregated along the below chosen
1199
          taxon relation ships. This will affect images and occurrences (specimens).
1200
          Taxon relation ships are directed and point form one taxon to another. The taxon
1201
          relationships to be taken into accunt can therefore configured for the direct direction
1202
          and for the inverse.'),
1203
  );
1204

    
1205
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1206
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1207

    
1208
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1209
      '#type' => 'checkboxes',
1210
      '#title' => t('Direct'),
1211
      '#options' => $taxonRelationshipTypeOptions,
1212
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1213
  );
1214
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1215
      '#type' => 'checkboxes',
1216
      '#title' => t('Invers'),
1217
      '#options' => $taxonRelationshipTypeOptions,
1218
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1219
  );
1220

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

    
1246
  // Comment @WA: D7 form api does not support reset buttons,
1247
  // so to mimic the D5 reset button we add one like this.
1248
  $form['actions']['reset'] = array(
1249
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1250
    '#weight' => 1000,
1251
  );
1252

    
1253
  $form['#submit'][] = 'cdm_settings_general_submit';
1254

    
1255
  return system_settings_form($form);
1256
}
1257

    
1258

    
1259
/**
1260
 * LAYOUT settings
1261
 * @return
1262
 *   todo
1263
 */
1264
function cdm_settings_layout() {
1265

    
1266
  $form = array();
1267

    
1268
  $form['about'] = array(
1269
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1270
      layout. If you want to configure the specific sites layout visit the
1271
      respective configuration site for taxon, search or media.') . '</p>',
1272
  );
1273

    
1274
  // ---- footnotes --- //
1275
  $form['footnotes'] = array(
1276
    '#type' => 'fieldset',
1277
    '#title' => t('Footnotes'),
1278
    '#collapsible' => FALSE,
1279
    '#collapsed' => FALSE,
1280
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1281
      media or distribution areas may have annotations or footnotes. When the
1282
      footnotes are enabled they will be visible (if they exist).'),
1283
  );
1284

    
1285
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1286
    '#type' => 'checkbox',
1287
    '#title' => t('Do not show footnotes'),
1288
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1289
    '#description' => t('Check this if you do not want to show any footnotes'),
1290
  );
1291

    
1292
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1293
    '#type' => 'checkbox',
1294
    '#title' => t('Do not show annotation footnotes'),
1295
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1296
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1297
  );
1298

    
1299
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType', SORT_ASC);
1300
  // Additional option for the NULL case.
1301
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1302
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1303
    '#type' => 'checkboxes',
1304
    '#title' => t('Annotation types as footnotes'),
1305
    '#description' => t("Only annotations of the selected type will be displayed
1306
       as footnotes. You may want to turn 'technical annotations' off."),
1307
    '#options' => $annotationTypeOptions,
1308
  );
1309
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1310
  if (!empty($annotationsTypesAsFootnotes)) {
1311
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1312
  }
1313

    
1314
  // ---- original source --- //
1315
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1316
      '#type' => 'fieldset',
1317
      '#tree' => TRUE,
1318
      '#title' => t('Source Citations'),
1319
      '#collapsible' => FALSE,
1320
      '#collapsed' => FALSE,
1321
  );
1322

    
1323
  $bibliography_settings = get_bibliography_settings(true);
1324

    
1325
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1326
      '#type' => 'checkbox',
1327
      '#title' => t('Original Source in bibliography'),
1328
      '#default_value' => $bibliography_settings['enabled'],
1329
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1330
       annotations in each feature block.'),
1331
  );
1332

    
1333
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1334
    '#type' => 'select',
1335
    '#title' => t('The format of the key numerals'),
1336
    '#default_value' => $bibliography_settings['key_format'],
1337
    '#options' => array('latin' => 'Latin',
1338
      'ROMAN' => 'Roman (upper case)',
1339
      'roman' => 'Roman (lower case)',
1340
      'ALPHA'=> 'Alphabet (upper case)',
1341
      'alpha' => 'Alphabet (lower case)')
1342
  );
1343

    
1344
  // --- Advanced Search --- //
1345
  $form['asearch'] = array(
1346
      '#type' => 'fieldset',
1347
      '#title' => t('Advanced search'),
1348
      '#collapsible' => FALSE,
1349
      '#collapsed' => FALSE,
1350
  );
1351
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1352
      '#type' => 'checkbox',
1353
      '#title' => t('Show advanced search link'),
1354
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1355
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1356
  );
1357

    
1358
  // ---- Taxon Name Rendering --- //
1359
  $form['taxon_name'] = array(
1360
      '#type' => 'fieldset',
1361
      '#title' => t('Taxon name display'),
1362
      '#collapsible' => TRUE,
1363
      '#collapsed' => TRUE,
1364
      '#description' => t('The display of taxon names is configured by two parts.'
1365
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
1366
          . 'The name parts are defined in the <stong>part definitions</strong>'),
1367
  );
1368

    
1369
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1370
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1371
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1372
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1373

    
1374
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1375
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1376
    $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.)';
1377
  } else if($is_custom_part_definition){
1378
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1379
  } else  {
1380
    $which_version_message = '(These are the default part definition.)';
1381
  }
1382

    
1383
  $diff_viewer_markup = '';
1384
  if($is_custom_part_definition){
1385
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1386
  }
1387

    
1388
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1389
    . $which_version_message
1390
    . '</div>'
1391
    . $diff_viewer_markup;
1392

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

    
1482
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1483
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1484
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1485
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1486
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1487

    
1488
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1489
    $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.)';
1490
  } else if($is_custom_render_template){
1491
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1492
  } else {
1493
    $which_version_message = '(These are the default render templates.)';
1494
  }
1495

    
1496
  $diff_viewer_markup = '';
1497
  if($is_custom_render_template){
1498
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1499
  }
1500

    
1501
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1502
    . $which_version_message
1503
    . '</div>'
1504
    . $diff_viewer_markup;
1505

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

    
1544
  // @WA: D7 form api does not support reset buttons,
1545
  // so to mimic the D5 reset button we add one like this.
1546
  $form['actions']['reset'] = array(
1547
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1548
    '#weight' => 1000,
1549
  );
1550

    
1551
  $form['#submit'] = array('submit_json_as_php_array');
1552
  // #json_elements especially defined for submit_json_as_php_array()
1553
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1554
  return system_settings_form($form);
1555
}
1556

    
1557

    
1558

    
1559
  /**
1560
 * @todo Please document this function.
1561
 * @see http://drupal.org/node/1354
1562
 */
1563
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1564
  $form[$form_name] = array(
1565
    '#type' => 'fieldset',
1566
    '#title' => t($form_title),
1567
    '#collapsible' => TRUE,
1568
    '#collapsed' => $collapsed,
1569
    '#tree' => TRUE,
1570
    '#description' => t($form_description),
1571
  );
1572

    
1573
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1574
  $gallery_settings = variable_get($form_name, $default_values);
1575
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1576
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1577
    /*
1578
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1579
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1580
    '#type' => 'textfield',
1581
    '#title' => t('Search Page Size'),
1582
    '#default_value' => $test,
1583
    '#description' => t('Number of Names to display per page in search results.')
1584
    );
1585
    */
1586
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1587
      '#type' => 'checkbox',
1588
      '#title' => t('Show media thumbnails for accepted taxa'),
1589
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1590
    );
1591

    
1592
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1593
      '#type' => 'checkbox',
1594
      '#title' => t('Show media thumbnails for synonyms'),
1595
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1596
      '#description' => '',
1597
    );
1598
  }
1599

    
1600
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1601
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1602
    '#type' => 'checkbox',
1603
    '#title' => t('Show captions under thumbnails'),
1604
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1605
    '#description' => '',
1606
  );
1607

    
1608
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1609
    '#type' => 'textfield',
1610
    '#title' => t('Thumbnail size') . ':',
1611
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1612
    '#description' => t('Select the size of each individual thumbnail.'),
1613
  );
1614

    
1615
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1616
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1617
      '#type' => 'textfield',
1618
      '#title' => t('Number of columns') . ':',
1619
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1620
      '#description' => t('Group the thumbnails in columns: select how many
1621
        columns the gallery should display.'),
1622
    );
1623
  }
1624

    
1625
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1626
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1627
      '#type' => 'textfield',
1628
      '#title' => t('Maximum number of rows') . ':',
1629
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1630
      '#description' => t('You can group the thumbnails in rows, select in how
1631
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1632
        If you want an unlimited number of rows please set to 0.'),
1633
    );
1634
  }
1635

    
1636
  return $form;
1637
}
1638

    
1639
/**
1640
 * @todo document this function.
1641
 */
1642
function cdm_settings_layout_taxon() {
1643
  $collapsed = FALSE;
1644
  $form = array();
1645

    
1646
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1647

    
1648
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1649
      '#type' => 'checkbox',
1650
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1651
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1652
      '#description' => t('<p>If checked the link to search results is rendered at
1653
       the top of the taxon site. Clicking on the link the last search performed
1654
       is rendered again.</p>'),
1655
  );
1656

    
1657
  // --------- TABBED TAXON ------- //
1658
  $form['taxon_tabs'] = array(
1659
    '#type' => 'fieldset',
1660
    '#title' => t('Taxon tabs'),
1661
    '#collapsible' => TRUE,
1662
    '#collapsed' => FALSE,
1663
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1664
      be splitted in four diferent tabs; General, Synonymy, Images and
1665
      Specimens. If the taxon has no information for any of the tabs/sections
1666
      such tab will be not displayed.'),
1667
  );
1668

    
1669
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1670
    '#type' => 'checkbox',
1671
    '#title' => t('Tabbed taxon page'),
1672
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1673
    '#description' => t('<p>If selected split the taxon page into individual
1674
      tabs for description, images, synonymy and specimens. If not the taxon
1675
      data is rendered as a long single page without tabs.</p>'),
1676
  );
1677

    
1678
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1679
    '#type' => 'checkboxes',
1680
    '#title' => t('Tabs visibility options') . ':',
1681
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1682
    '#options' => get_taxon_options_list(),
1683
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1684
  );
1685

    
1686
  // WEIGHT
1687
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1688
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1689
      '#tree' => true
1690
  );
1691
  // Weights range from -delta to +delta, so delta should be at least half
1692
  // of the amount of tabs present.
1693
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1694
  foreach (get_taxon_tabs_list() as $label) {
1695
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1696
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1697
        '#title' => $label,
1698
        '#type'  => 'weight',
1699
        '#default_value' => $taxontabs_weights[$key],
1700
        '#delta' => $tab_weight_delta
1701
    );
1702
  }
1703

    
1704
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1705
    '#type' => 'select',
1706
    '#title' => t('Default tab to display') . ':',
1707
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1708
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1709
    '#description' => t('<p>Select the default tab to display when visiting a
1710
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1711
      <strong>Note:</strong> After performing a search and clicking in any
1712
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1713
      taxon and not the above selected tab.'),
1714
  );
1715

    
1716
  /* ======  TAXON_PROFILE ====== */
1717
  $form['taxon_profile'] = array(
1718
    '#type' => 'fieldset',
1719
    '#title' => t('Taxon profile (tab)'),
1720
    '#description' => t('<p>This section covers the settings related to the taxon
1721
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1722
    '#collapsible' => TRUE,
1723
    '#collapsed' => FALSE,
1724
  );
1725

    
1726
  // ---- PROFILE PICTURE ----//
1727

    
1728
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1729
    '#type' => 'fieldset',
1730
    '#tree' => TRUE,
1731
    '#title' => t('Taxon profile picture'),
1732
    '#collapsible' => TRUE,
1733
    '#collapsed' => FALSE,
1734
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1735
  );
1736

    
1737
  //FIXME migrate variables:
1738
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1739
  // FIXME
1740
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1741

    
1742
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1743

    
1744
  /*
1745
   * 'show' => 1,
1746
   * 'maxextend' => 184,
1747
   * 'media_uri_query' => ''
1748
   * 'custom_placeholder_image_on' => 1,
1749
   * 'custom_placeholder_image_fid' => ''
1750
   */
1751
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1752
    '#type' => 'checkbox',
1753
    '#title' => t('Enable profil picture'),
1754
    '#description' => t('Show the profil picture.'),
1755
    '#default_value' => $taxon_profile_image_settings['show'],
1756
  );
1757

    
1758
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1759
      '#type' => 'textfield',
1760
      '#tree' => TRUE,
1761
      '#title' => t('Profil picture maximum extend'),
1762
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1763
      '#field_suffix' => 'px',
1764
      '#maxlength' => 4,
1765
      '#size' => 4,
1766
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1767
  );
1768

    
1769
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1770
      '#type' => 'textfield',
1771
      '#tree' => TRUE,
1772
      '#title' => t('Additional URI query parameter'),
1773
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1774
      '#maxlength' => 1024,
1775
      '#size' => 60,
1776
      '#description' => t('Additional query parameters to be used when requesting for the '
1777
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1778
          . 'The query parameters will be appended to the uri of the media representation part'
1779
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1780
  );
1781

    
1782
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1783
    '#type' => 'checkbox',
1784
    '#title' => t('Show the placeholder image'),
1785
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
1786
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1787
  );
1788

    
1789
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1790
      '#type' => 'checkbox',
1791
      '#title' => t('Use a custom placeholder image'),
1792
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1793
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1794
  );
1795

    
1796
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1797
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1798
        '#type' => 'managed_file',
1799
        '#title' => t('Custom placeholder image file'),
1800
        '#progress_indicator' => 'bar',
1801
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1802
    //       '#name' => 'custom_placeholder_image',
1803
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1804
    );
1805

    
1806
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1807
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1808
      $url = file_create_url($profile_image_file->uri);
1809
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1810
                '#type' => 'item',
1811
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1812
      );
1813
    }
1814
  } else {
1815
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1816
      '#type' => 'hidden',
1817
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1818
    );
1819
  }
1820

    
1821
  $options = cdm_rankVocabulary_as_option();
1822
  array_unshift($options, '-- DISABLED --');
1823
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1824
    '#type' => 'select',
1825
    '#title' => t('Hide profile picture for higher ranks') . ':',
1826
    '#default_value' => variable_get('image_hide_rank', '0'),
1827
    '#options' => $options,
1828
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1829
  );
1830

    
1831
  // -- MEDIA THUMBNAILS -- //
1832
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1833
  $form_title = 'Taxon Profile Images';
1834
  $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>';
1835
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1836

    
1837
  // ---- FEATURE TREE BLOCKS ---- //
1838
  $form['taxon_profile']['feature_blocks'] = array(
1839
    '#type' => 'fieldset',
1840
    '#title' => t('Feature Blocks'),
1841
    '#collapsible' => TRUE,
1842
    '#collapsed' => FALSE,
1843
    '#description' => t("This section covers settings related to the taxon's
1844
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1845
      features such as description, distribution, common names"),
1846
  );
1847
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1848
  $profile_feature_tree = get_profile_feature_tree();
1849
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
1850
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
1851
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
1852
  }
1853
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
1854
    '#type' => 'radios',
1855
    '#title' => t('Taxon profile feature tree') . ':',
1856
    '#default_value' => $profile_feature_tree_uuid,
1857
    '#options' =>  $featureTrees['options'],
1858
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1859
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1860
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
1861
      profile page.'
1862
    ),
1863
  );
1864

    
1865
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
1866
  $profile_feature_tree = get_profile_feature_tree();
1867

    
1868
  if (isset($profile_feature_tree->root->childNodes)) {
1869

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

    
1909

    
1910
    $feature_list_layout_settings_disabled = FALSE;
1911

    
1912
    // creating helper object to retrieve the default settings
1913
    $featureNode = new stdClass();
1914
    $featureNode->feature = new stdClass();
1915
    $featureNode->feature->uuid="DEFAULT";
1916
    $featureNode->feature->representation_L10n = "Default";
1917
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
1918

    
1919
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
1920

    
1921
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1922

    
1923
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
1924
        $subform_id = $featureNode->feature->uuid;
1925
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
1926

    
1927
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1928

    
1929
        $form_feature_block_layout[$subform_id] = array(
1930
          '#type' => 'fieldset',
1931
          '#tree' => TRUE,
1932
          '#title' => $featureNode->feature->representation_L10n,
1933
          '#collapsible' => FALSE,
1934
          '#collapsed' => FALSE,
1935
        );
1936
        if($featureNode->feature->uuid == "DEFAULT"){
1937
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
1938
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
1939
          references</em> and <em>names in source</em> is only possible in the defaults';
1940
        }
1941

    
1942
        $form_feature_block_layout[$subform_id]['as_list'] = array(
1943
          '#type' => 'select',
1944
          '#title' => 'List type',
1945
          '#default_value' => $feature_block_setting['as_list'],
1946
          '#options' => array(
1947
            'div' => 'not as list',
1948
            'ul' => 'bullet list',
1949
            'ol' => 'numbered list',
1950
            'dl' => 'definition list'
1951
          ),
1952
        );
1953

    
1954
        if($featureNode->feature->uuid == "DEFAULT"){
1955
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
1956
            '#type' => 'checkbox',
1957
            '#title' => t('Link to reference'),
1958
            '#default_value' => $feature_block_setting['link_to_reference'],
1959
          );
1960

    
1961
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
1962
            '#type' => 'checkbox',
1963
            '#title' => 'Link to name used in source',
1964
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
1965
          );
1966
        }
1967

    
1968
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
1969
          '#type' => 'checkbox',
1970
          '#title' => 'Sources as content',
1971
          '#default_value' => $feature_block_setting['sources_as_content'],
1972
        );
1973

    
1974
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
1975
          '#type' => 'checkbox',
1976
          '#title' => 'Put sources also as content to bibliography',
1977
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
1978
        );
1979

    
1980
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
1981
          '#type' => 'select',
1982
          '#title' => t('Sort elements'),
1983
          '#default_value' => $feature_block_setting['sort_elements'],
1984
          '#options' => array(
1985
            NO_SORT => 'No sorting',
1986
            SORT_ASC => 'Ascending',
1987
            SORT_DESC => 'Descending',
1988
            SORT_HIERARCHICAL => 'Hierachical'
1989
          ),
1990
          '#description' => 'NOT YET USED! only in preparation',
1991
        );
1992

    
1993
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
1994
          '#type' => 'select',
1995
          '#title' => t('Element tag'),
1996
          '#options' => array(
1997
            'span' => 'span',
1998
            'div' => 'div'
1999
          ),
2000
          '#default_value' => $feature_block_setting['element_tag'],
2001
        );
2002
      }
2003
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2004
    }
2005
  }
2006

    
2007
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2008
  $form['taxon_profile']['structured_description_featuretree'] = array(
2009
    '#type' => 'fieldset',
2010
    '#title' => t('Structured Description Feature Tree'),
2011
    '#collapsible' => TRUE,
2012
    '#collapsed' => FALSE,
2013
  );
2014
  $featureTrees = cdm_get_featureTrees_as_options();
2015
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2016
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2017
    $profile_feature_tree_uuid = NULL;
2018
  }
2019
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2020
    '#type' => 'radios',
2021
    '#title' => t('Natural language representation of structured descriptions') . ':',
2022
    '#default_value' => $profile_feature_tree_uuid,
2023
    '#options' => $featureTrees['options'],
2024
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2025
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2026
    '#description' => t('Taxon descriptions can be stored in a highly structured
2027
      form. The feature tree selected here will be used to generate textual
2028
      representation in natural language.'
2029
    ),
2030
  );
2031

    
2032

    
2033

    
2034
  // ---- DISTRIBUTION LAYOUT ---- //
2035
  $form['taxon_profile']['distribution_layout'] = array(
2036
    '#title' => t('Distribution'),
2037
    '#collapsible' => TRUE,
2038
    '#collapsed' => FALSE,
2039
    '#type' => 'fieldset',
2040
    '#description' => 'This section covers general settings regarding the textual representation of distributions.
2041
        Map related settings are found in the '
2042
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2043
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2044
      . l(
2045
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2046
        array('fragment' => 'edit-feature-block-settings')
2047
      )
2048
      . ' More general settings regrading the filtering of Distributions are found at '
2049
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2050
      . '. (These settings here will be merged in future releases into the feature block settings)',
2051

    
2052
  );
2053

    
2054
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2055
    '#type' => 'checkbox',
2056
    '#title' => t('Condensed distribution'),
2057
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2058
    '#description' => 'This option enables the display of a very compact representation
2059
    of the distribution which includes also information on the status.',
2060
  );
2061

    
2062

    
2063
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2064
    '#type' => 'radios',
2065
    '#title' => t('Order mode') . ':',
2066
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2067
    '#options' => array(
2068
      'FLAT_ALPHA' => t('Flat list'),
2069
      'TREE' => t('Hierarchically ordered'),
2070
    ),
2071
    '#description' => 'Taxon distribution information is displayed with
2072
    focus on the area of the distribution. The list of areas can either be shown
2073
    as flat list ordered alphabetically or in the hierarchical of the parent
2074
    area and subarea relationship. Fall back areas areas with no Distribution data
2075
    are hidden from the area hierarchy so that their sub areas will move one level up.
2076
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2077
    ' for details on the <em>Maked area filter</em>.',
2078
  );
2079

    
2080
  $level_options = cdm_Vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, SORT_ASC);
2081
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2082
    '#type' => 'checkboxes',
2083
    '#title' => 'Omit area levels',
2084
    '#options' => $level_options,
2085
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2086
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2087
    Areas which belong to the selected area levels will be hidden in the portal.',
2088
  );
2089

    
2090
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2091
    '#type' => 'checkbox',
2092
    '#title' => t('Show TextData elements on top of the map'),
2093
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2094
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2095
      elements on top of the map. Otherwise all <code>TextData</code>
2096
      distribution elements will be listed below the other area elements.
2097
      This option is useful if you need to have descriptive texts for each
2098
      distribution map.'),
2099
  );
2100

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

    
2128
AbsenceTerm
2129
a	absent
2130
f	reported in error
2131
nf	native: reported in error
2132
if	introduced: reported in error
2133
cf	cultivated: reported in error
2134
ne	native: formerly native
2135
ie	introduced: formerly introduced
2136

    
2137
</pre>'),
2138
  );
2139

    
2140

    
2141
  /* ====== SYNONYMY ====== */
2142
  $form['taxon_synonymy'] = array(
2143
    '#type' => 'fieldset',
2144
    '#title' => t('Taxon synonymy (tab)'),
2145
    '#collapsible' => TRUE,
2146
    '#collapsed' => TRUE,
2147
    '#description' => t('This section covers the settings related to the taxon
2148
      <strong>synonymy</strong> tab.'),
2149
  );
2150

    
2151
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2152
    '#type' => 'checkbox',
2153
    '#title' => t('Show accepted taxon on top of the synonymy'),
2154
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2155
    '#description' => t('If checked, the first homotypic taxon is a repetition
2156
      of the accepted taxon most likely with the full nomenclatural reference
2157
      (depending on the currently chosen theme).'),
2158
  );
2159

    
2160
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2161
    '#type' => 'checkbox',
2162
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2163
      coming from a synonym link.'),
2164
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2165
    '#description' => t('Check this if after doing a search and clicking on a
2166
      synonym you want to see the "accept of" text for the accepted synonym.'),
2167
  );
2168

    
2169
  /* === currently unused ===
2170
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2171
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2172
    '#type' => 'checkboxes',
2173
    '#title' => t('Display name relationships') . ':',
2174
    '#default_value' => variable_get('name_relationships_to_show', 0),
2175
    '#options' => $nameRelationshipTypeOptions,
2176
    '#description' => t('Select the name relationships you want to show for the
2177
      accepted taxa.'),
2178
  );
2179
 */
2180

    
2181
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2182
    '#type' => 'checkbox',
2183
    '#title' => t('Show taxon relations ships of accepted taxon'),
2184
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2185
    '#description' => t('If this option is enabled the synonymy will show the
2186
      below selected taxon relationships of accepted taxa.'),
2187
  );
2188

    
2189
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2190
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2191
    '#type' => 'checkboxes',
2192
    '#title' => t('Taxon relationship types') . ':',
2193
    '#description' => t('Only taxon relationships of the selected type will be
2194
      displayed'),
2195
    '#options' => $taxonRelationshipTypeOptions,
2196
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2197
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2198
  );
2199

    
2200
  // ====== SPECIMENS ====== //
2201
  $form['taxon_specimens'] = array(
2202
    '#type' => 'fieldset',
2203
    '#title' => t('Taxon specimens (tab)'),
2204
    '#collapsible' => TRUE,
2205
    '#collapsed' => TRUE,
2206
    '#description' => t('This section covers the settings related to the taxon
2207
      <strong>specimens</strong> tab.'),
2208
  );
2209

    
2210
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2211
        '#type' => 'checkbox',
2212
        '#title' => t('Show specimen derivatives in a compressed table'),
2213
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2214
        '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2215
        a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2216
    );
2217
    
2218
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2219
        '#type' => 'checkbox',
2220
        '#title' => t('Show "Associated with" in specimen table.'),
2221
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2222
    );
2223

    
2224
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2225
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2226
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2227
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2228
  }
2229
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2230
      '#type' => 'radios',
2231
      '#title' => t('Specimen description feature tree') . ':',
2232
      '#default_value' => $profile_feature_tree_uuid,
2233
      '#options' =>  $featureTrees['options'],
2234
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2235
      '#options_suffixes' => $featureTrees['treeRepresentations'],
2236
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2237
      ),
2238
  );
2239

    
2240
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2241
  $form_title = t('Specimen media');
2242
  $form_description = t('Specimens may have media which is displayed at the
2243
     Specimen tab/section as a gallery. It is possible to configure the
2244
     thumbnails gallery here, however for configuring how a single media should
2245
     be displayed please go to !url.</p>',
2246
     array(
2247
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2248
     ));
2249
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2250

    
2251
  // --- MEDIA GALLERY ---- //
2252
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2253
  $form_title = 'Media gallery (tab)';
2254
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2255
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2256
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2257
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2258
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2259
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2260
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2261

    
2262
  // Comment @WA: D7 form api does not support reset buttons,
2263
  // so to mimic the D5 reset button we add one like this.
2264
  $form['actions']['reset'] = array(
2265
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2266
    '#weight' => 1000,
2267
  );
2268
  return system_settings_form($form);
2269
}
2270

    
2271
/**
2272
 * @todo document this function.
2273
 */
2274
function cdm_settings_layout_search() {
2275

    
2276
  $form = array();
2277

    
2278
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2279

    
2280
  $form['search_settings'] = array(
2281
    '#type' => 'fieldset',
2282
    '#title' => t('Taxa Search'),
2283
    '#collapsible' => FALSE,
2284
    '#collapsed' => FALSE,
2285
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2286
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2287
         where they can write the text to be searched. You can find Drupal block configuration
2288
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2289
  );
2290

    
2291
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2292
      '#type' => 'checkbox',
2293
      '#title' => t('Ignore the chosen classification in simple search'),
2294
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2295
      '#description' => t('The simple search, which can be executed via the search block,
2296
          will by default search on the classification selected in the classification browser
2297
          selector. Set the tick if you want your portal to search on all classifications.'),
2298
  );
2299

    
2300
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2301
    '#type' => 'checkbox',
2302
    '#title' => t('Run simple search with free-text search backend.'),
2303
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2304
    '#description' => t('The simple search uses by default another search
2305
      backend as the advances search. By checking this option the simple search can be
2306
      configured to also use the free-text search backend.'),
2307
  );
2308

    
2309
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2310
    '#type' => 'textfield',
2311
    '#title' => t('Results per page') . ':',
2312
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2313
    '#description' => t('Number of results to display per page.'),
2314
  );
2315

    
2316
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2317
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2318
      '#type' => 'checkboxes',
2319
      '#title' => 'Search mode',
2320
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2321
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2322
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2323
          defaults set here.',
2324
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2325
      '#default_value' => $search_mode_default
2326
      );
2327

    
2328
  // --- SEARCH TAXA GALLERY ---- //
2329
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2330
  $collapsed = FALSE;
2331
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2332
  $form_title = 'Taxa Search thumbnails';
2333
  $form_description = 'Search results may show thumbnails. ';
2334
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2335

    
2336
  // Comment @WA: D7 form api does not support reset buttons,
2337
  // so to mimic the D5 reset button we add one like this.
2338
  $form['actions']['reset'] = array(
2339
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2340
    '#weight' => 1000,
2341
  );
2342
  return system_settings_form($form);
2343
}
2344

    
2345
/**
2346
 * @todo document this function.
2347
 */
2348
function cdm_settings_layout_media() {
2349

    
2350
  $form = array();
2351

    
2352
  $form['media_settings'] = array(
2353
    '#type' => 'fieldset',
2354
    '#title' => t('Media settings'),
2355
    '#collapsible' => FALSE,
2356
    '#collapsed' => FALSE,
2357
    '#description' => 'This section covers layout settings for media pages.'
2358
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2359
  );
2360

    
2361
  $form['media_settings']['image_gallery_viewer'] = array(
2362
    '#type' => 'select',
2363
    '#title' => t('Image viewer') . ':',
2364
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2365
    '#options' => array(
2366
      'default' => t('Standard image viewer'),
2367
      'fsi' => t('FSI viewer (requires FSI server!)'),
2368
    ),
2369
  );
2370

    
2371
  // --- MEDIA GALLERY ---- //
2372
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2373
  $form_title = 'Standard viewer';
2374
  $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>';
2375
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2376
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2377

    
2378
  // @WA: D7 form api does not support reset buttons,
2379
  // so to mimic the D5 reset button we add one like this.
2380
  $form['actions']['reset'] = array(
2381
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2382
    '#weight' => 1000,
2383
  );
2384
  return system_settings_form($form);
2385
}
2386

    
2387
/**
2388
 * GEOSERVICE and Map settings.
2389
 */
2390
function cdm_settings_geo($form, &$form_state) {
2391

    
2392
  $current_geoserver_settings = get_edit_map_service_settings();
2393
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2394

    
2395

    
2396
  $form = array();
2397

    
2398
  $dummy_distribution_query = NULL;
2399
  if($map_distribution['map_type'] != 1){
2400
    // we need to apply a dummy query since the map service requires for image maps
2401
    // at least as and ad to be defined
2402
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2403
  }
2404

    
2405
  $form['map_preview'] = array(
2406
      '#type' => 'fieldset',
2407
      '#tree' => FALSE,
2408
      '#title' => t('Map preview'),
2409
      '#collapsible' => FALSE,
2410
      '#description' => 'The preview of the map'
2411
       . ($dummy_distribution_query != null ?
2412
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2413
           '.<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.')
2414
  );
2415
  $form['map_preview']['openlayers_map'] = compose_map(NULL, $dummy_distribution_query, NULL,
2416
    array(
2417
      'move' => "this.cdmOpenlayersMap.printInfo",
2418
      '#execute' => "this.cdmOpenlayersMap.printInfo"
2419
    ),
2420
    true // resizable
2421
  );
2422

    
2423
  /*
2424
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2425
  );
2426
  */
2427

    
2428
  /*
2429
   * GEO SERVER
2430
   */
2431
  $form['edit_map_server'] = array(
2432
    '#type' => 'fieldset',
2433
    '#tree' => true,
2434
    '#title' => t('EDIT map service'),
2435
    '#collapsible' => TRUE,
2436
    '#collapsed' => TRUE,
2437
    '#description' => t('Configuration and selection of your geo server.
2438
      The Geo Server is responsible for generating the maps.'),
2439
  );
2440

    
2441
  $form['edit_map_server']['base_uri'] = array(
2442
    '#type' => 'select',
2443
    '#title' => t('EDIT map service') . ':',
2444
    '#default_value' => $current_geoserver_settings['base_uri'],
2445
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2446
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2447
  );
2448
  $form['edit_map_server']['version'] = array(
2449
      '#type' => 'select',
2450
      '#title' => t('Version') . ':',
2451
      '#default_value' => $current_geoserver_settings['version'],
2452
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2453
      '#description' => t('The version of the EDIT map services'),
2454
  );
2455

    
2456
  /*
2457
   * MAP SETTINGS
2458
   */
2459

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

    
2469
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2470
    '#type' => 'radios',
2471
    '#title' => 'Map types',
2472
    '#options' => array(
2473
      1 => "OpenLayers dynamic map viewer",
2474
      0 => "Plain image",
2475
    ),
2476
    '#default_value' => $map_distribution['map_type'],
2477
    '#description' => 'Two different map types are available :
2478
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2479
      which allows zooming and panning. If enabled you can configure the default layer
2480
      (background of your maps) below.</li>
2481
      <li><em>Plain image</em>: The map will be static non interactive
2482
      image.</li></ul>',
2483
  );
2484
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2485

    
2486
  /*
2487
   * settings for the distribution map are used also for specimens map!!!!
2488
   */
2489

    
2490
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2491
      '#type' => 'textfield',
2492
      '#title' => 'Aspect ratio',
2493
      '#default_value' => $map_distribution['aspect_ratio'],
2494
      '#maxlength' => 4,
2495
      '#size' => 4,
2496
      '#element_validate' => array('element_validate_number'),
2497
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2498
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2499
      width by the height:</br>
2500
      <pre>aspect ratio = w / h</pre>
2501
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2502
      for a square map use <strong>1</strong>.',
2503
  );
2504

    
2505
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2506
    '#type' => 'textfield',
2507
    '#title' => 'Bounding box',
2508
    '#default_value' => $map_distribution['bbox'],
2509
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2510
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2511
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2512
      <strong>TIP:</strong> You can use the map preview above to choose the <span class="map-extent-bbox"><strong>map extent bbox</strong> in <strong class="degree-value"">degree</strong></span> from the map.
2513
      (Maybe you need to change the map base layer to OpeLayers.)
2514
      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
2515
      below the map from where you can copy the bbox string.</p>'),
2516
  );
2517

    
2518
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2519
    '#type' => 'checkbox',
2520
    '#title' => 'Display area labels',
2521
    '#default_value' => $map_distribution['show_labels'],
2522
    '#description' => t('The map will show name labels of the areas'),
2523
  );
2524

    
2525
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2526
    '#type' => 'textfield',
2527
    '#title' => 'Map caption',
2528
    '#default_value' => $map_distribution['caption'],
2529
    '#description' => t('The caption will be shown below the map.'),
2530
  );
2531

    
2532
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2533
    '#type' => 'textfield',
2534
    '#title' => 'Distribution layer opacity',
2535
    '#default_value' => $map_distribution['distribution_opacity'],
2536
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2537
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2538
  );
2539

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

    
2556
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2557
    '#type' => 'textfield',
2558
    '#title' => 'Width',
2559
    '#default_value' => $map_distribution['image_map']['width'],
2560
    '#maxlength' => 4,
2561
    '#size' => 4,
2562
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2563
  );
2564

    
2565
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2566
    '#type' => 'textfield',
2567
    '#title' => 'Background layer',
2568
    '#default_value' => $map_distribution['image_map']['base_layer'],
2569
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2570
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2571
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2572
    )),
2573
  );
2574

    
2575
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2576
    '#type' => 'textfield',
2577
    '#title' => 'Background color',
2578
    '#default_value' => $map_distribution['image_map']['bg_color'],
2579
  );
2580

    
2581
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2582
    '#type' => 'textfield',
2583
    '#title' => 'Background layer style',
2584
     // Only line color by now.
2585
    '#default_value' => $map_distribution['image_map']['layer_style'],
2586
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2587
  );
2588

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

    
2598

    
2599
  // --- OpenLayers Settings --- //
2600
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2601
    '#type' => 'fieldset',
2602
    '#title' => 'OpenLayers settings',
2603
    '#tree' => TRUE,
2604
    '#collapsible' => TRUE,
2605
    '#collapsed' => !$open_layers_is_enabled,
2606
    '#description' => '',
2607
  );
2608

    
2609

    
2610
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2611
      '#type' => 'checkbox',
2612
      '#title' => 'Display outside max extent',
2613
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2614
      '#description' => t('Allows the map to display parts of the layers which are outside
2615
         the max extent if the aspect ratio of the map and of the baselayer
2616
         are not equal.'),
2617
  );
2618

    
2619

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

    
2631
  if (!$open_layers_is_enabled) {
2632
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2633
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2634
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2635
  }
2636

    
2637
  // The default layer must always be enabled
2638
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2639
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2640

    
2641
  $baselayer_options = array(
2642
    /*
2643
   NOTICE: must correspond to the layers defined in
2644
   js/openlayers_,ap.js#getLayersByName()
2645
   */
2646
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
2647
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
2648
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
2649
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
2650
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2651
    // all others EPSG:900913
2652
    'mapnik' => 'OpenStreetMap',
2653
    'mapquest_open' => "MapQuest",
2654
    'mapquest_sat' => "MapQuest Sattelite",
2655
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2656
//    'gmap' => 'Google Streets',
2657
//    'gsat' => 'Google Satellite',
2658
//    'ghyb' => 'Google Hybrid',
2659
//     'veroad' => 'Virtual Earth Roads',
2660
//     'veaer' => 'Virtual Earth Aerial',
2661
//     'vehyb' => 'Virtual Earth Hybrid',
2662
    // 'yahoo' => 'Yahoo Street',
2663
    // 'yahoosat' => 'Yahoo Satellite',
2664
    // 'yahoohyb' => 'Yahoo Hybrid',
2665
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2666
  );
2667

    
2668
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2669
    '#type' => 'checkboxes_preferred',
2670
    '#title' => 'Base Layers',
2671
    '#options' => $baselayer_options,
2672
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2673
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2674
  );
2675

    
2676
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2677
      '#type' => 'fieldset',
2678
      '#title' => 'Custom WMS base layer',
2679
      '#tree' => TRUE,
2680
      '#collapsible' => FALSE,
2681
      '#collapsed' => FALSE,
2682
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2683
  );
2684

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

    
2781
  /*
2782
   * Map Legend
2783
   */
2784
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2785
    '#type' => 'fieldset',
2786
    '#title' => 'Map legend',
2787
    '#tree' => TRUE,
2788
    '#collapsible' => TRUE,
2789
    '#collapsed' => TRUE,
2790
    '#description' => 'Configure the maps legend.',
2791
  );
2792

    
2793
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2794
    '#type' => 'checkbox',
2795
    '#title' => 'Display a map legend',
2796
    '#default_value' => $map_distribution['legend']['show'],
2797
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2798
  );
2799

    
2800
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2801
    '#type' => 'textfield',
2802
    '#title' => 'Legend opacity',
2803
    '#default_value' => $map_distribution['legend']['opacity'],
2804
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2805
                         to 0.0 will be not much visible.',
2806
  );
2807

    
2808
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2809
    '#type' => 'textfield',
2810
    '#title' => 'Font size',
2811
    '#default_value' => $map_distribution['legend']['font_size'],
2812
    '#description' => 'Font size in pixels.',
2813
  );
2814

    
2815
  $fontStyles = array(
2816
    0 => "plane",
2817
    1 => "italic",
2818
  );
2819
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2820
    '#type' => 'select',
2821
    '#title' => 'Available font styles',
2822
    '#default_value' => $map_distribution['legend']['font_style'],
2823
    '#options' => $fontStyles,
2824
    '#description' => 'Select a font style for the map legend.',
2825
  );
2826

    
2827
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2828
    '#type' => 'textfield',
2829
    '#title' => 'Icon width',
2830
    '#default_value' => $map_distribution['legend']['icon_width'],
2831
    '#description' => 'Legend icon width in pixels.',
2832
  );
2833
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2834
    '#type' => 'textfield',
2835
    '#title' => 'Icon height',
2836
    '#default_value' => $map_distribution['legend']['icon_height'],
2837
    '#description' => 'Legend icon height in pixels.',
2838
  );
2839

    
2840
  // @WA: D7 form api does not support reset buttons,
2841
  // so to mimic the D5 reset button we add one like this.
2842
  $form['actions']['reset'] = array(
2843
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2844
    '#weight' => 1000,
2845
  );
2846

    
2847
  return system_settings_form($form);
2848
}
2849

    
2850

    
2851
/**
2852
 * @todo document this function.
2853
 */
2854
function cdm_settings_cache() {
2855

    
2856
  $form = array();
2857

    
2858
  $form['cache_settings'] = array(
2859
    '#type' => 'fieldset',
2860
    '#title' => t('Cache Settings'),
2861
    '#collapsible' => FALSE,
2862
    '#collapsed' => FALSE,
2863
    '#description' => t('<p>When caching is enabled all single taxon sites are
2864
      stored in an internal drupal cache doing the portal response of taxa pages
2865
      faster. This is possible because the sites are loaded from the cache and
2866
      are not created from scratch.</p>'),
2867
  );
2868

    
2869
  $form['cache_settings']['cdm_webservice_cache'] = array(
2870
    '#type' => 'checkbox',
2871
    '#title' => t('<strong>Enable caching</strong>'),
2872
    '#options' => cdm_help_general_cache(),
2873
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2874
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2875
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2876
       application the changes will be not visible till the cache is erased.
2877
       Therefore developers should deactived this feature when they are working
2878
       on the CDM Dataportal Module.</p>'),
2879
  );
2880

    
2881
  $form['cache_settings']['cdm_run_cache'] = array(
2882
    '#markup' => cdm_view_cache_site(),
2883
  );
2884

    
2885
  // @WA: D7 form api does not support reset buttons,
2886
  // so to mimic the D5 reset button we add one like this.
2887
  $form['actions']['reset'] = array(
2888
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2889
    '#weight' => 1000,
2890
  );
2891
  return system_settings_form($form);
2892
}
2893

    
2894
/**
2895
 * Walk and cache all taxon pages.
2896
 */
2897
function cdm_view_cache_site() {
2898

    
2899
  $out = '';
2900

    
2901
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2902

    
2903
  $request_params = array();
2904
  $request_params['class'] = "Taxon";
2905

    
2906
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2907
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2908
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2909

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

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

    
2919
  // Comment @WA: A form within a form is not valid html and not needed here.
2920
  // Also, it would be recommended just to include this part of the form in the
2921
  // rest of the form array in cdm_settings_cache().
2922
  // $out .= '<form id="cache_site">';
2923
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2924
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2925
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2926
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2927
  // $out .= '</form>';
2928
  $out .= '</div>';
2929
  /*
2930
  foreach($taxonPager->records as $taxon){
2931
    cdm_dataportal_taxon_view($uuid);
2932
  }
2933
  */
2934
  return $out;
2935
}
2936

    
2937

    
2938
function cdm_settings_layout_taxon_submit($form, &$form_state){
2939
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2940
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2941
    if(is_object($file)){
2942
      $file->status = FILE_STATUS_PERMANENT;
2943
      file_save($file);
2944
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2945
    }
2946
  }
2947
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2948
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2949
    // we first need to set the variable to persist the changes setting
2950
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
2951
    menu_rebuild();
2952
  }
2953
}
2954

    
2955
function cdm_settings_layout_search_submit($form, &$form_state){
2956
  // the visibility of media thumbnails also affects the ui of the search results
2957
  // so reset the according session variable
2958
  //    1. in order to give the user immediate
2959
  //       feedback on potential setting changes
2960
  //    2. let refresh the default if it has changed
2961
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2962
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
2963
  }
2964
}
2965

    
2966
/**
2967
 * Form validation handler for cdm_settings_general
2968
 *
2969
 * @param $form
2970
 * @param $form_state
2971
 */
2972
function cdm_settings_general_validate($form, &$form_state) {
2973

    
2974
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2975
    $form_state['values']['cdm_webservice_url'] .= '/';
2976
  }
2977

    
2978
}
2979

    
2980
/**
2981
 * Form submit handler for settings general.
2982
 *
2983
 * tasks performed:
2984
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2985
 *
2986
 * @param $form
2987
 * @param $form_state
2988
 */
2989
function cdm_settings_general_submit($form, &$form_state){
2990
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2991
  unset($_SESSION['cdm']['taxonomictree_uuid']);
2992
}
2993

    
2994
/**
2995
 * Form validation handler for cdm_settings_cache
2996
 */
2997
function cdm_settings_cache_validate($form, &$form_state) {
2998
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2999
    cache_clear_all(NULL, 'cache_cdm_ws');
3000
    // Better clear secref_cache since I can not be sure if the cache has not
3001
    // be used during this response.
3002
    cdm_api_secref_cache_clear();
3003
  }
3004

    
3005
}
3006

    
3007
/**
3008
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3009
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3010
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3011
 *  - version: the version, e.g.: v1.1
3012
 *
3013
 * @return array
3014
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3015
 */
3016
function get_edit_map_service_settings() {
3017

    
3018
  $settings = variable_get('edit_map_server', array(
3019
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3020
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3021
      )
3022
  );
3023

    
3024
  return $settings;
3025
}
3026

    
3027
/**
3028
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3029
 *
3030
 * @return string
3031
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3032
 */
3033
function get_edit_map_service_full_uri() {
3034
  $settings = get_edit_map_service_settings();
3035
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3036
}
3037

    
3038

    
3039
/**
3040
 * Returns the version number of the currently selected edit mapserver as a float
3041
 *
3042
 * @return float
3043
 *   The version number of the currently selected edit mapserver as a float.
3044
 *   Returns 0 on error.
3045
 */
3046
function get_edit_map_service_version_number() {
3047

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

    
3050
  $settings = get_edit_map_service_settings();
3051
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3052
  if (isset($matches[1])) {
3053
    // Convert string to float.
3054
    $version = 1 + $matches[1][0] - 1;
3055
    return $version;
3056
  }
3057
  else {
3058
    // Report error.
3059
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3060
        array(
3061
          '!version' => $settings['version'],
3062
          'warning')
3063
        )
3064
      );
3065
    return 0;
3066
  }
3067
}
3068

    
3069
/**
3070
 * Returns the array of selected items in a options array
3071
 *
3072
 * @param array $options
3073
 *   An options array as generated by a form element like checkoxes, select ...,
3074
 */
3075
function get_selection($options) {
3076
  $selection = array();
3077
  foreach ($options as $key=>$val) {
3078
    if (!empty($val)) {
3079
      $selection[] = $val;
3080
    }
3081
  }
3082
  return $selection;
3083
}
3084

    
3085

    
3086
/**
3087
 * Implements hook_element_info().
3088
 *
3089
 * Allows modules to declare their own Form API element types and specify their default values.
3090
 *
3091
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3092
 */
3093
function cdm_dataportal_element_info() {
3094
  $type['checkboxes_preferred'] = array(
3095
    '#input' => TRUE,
3096
    '#process' => array('checkboxes_preferred_expand'),
3097
    '#after_build' => array('checkboxes_preferred_after_build'),
3098
    '#theme' => array('checkboxes_preferred'),
3099
    // '#theme_wrapper' => array('form_element'),
3100
  );
3101
  return $type;
3102
}
3103

    
3104
/**
3105
 * #process callback function for the custom form element type 'checkbox_preferred'
3106
 *
3107
 *
3108
 */
3109
function checkboxes_preferred_expand($element, &$form_state, $form) {
3110

    
3111
  // First of all create checkboxes for each of the elements
3112
  $element = form_process_checkboxes($element);
3113

    
3114
  // compose the element name
3115
  $parents = array();
3116
  array_deep_copy($element['#parents'], $parents);
3117
  $parents[count($parents) -1 ] .= '_preferred';
3118
  $element_name = $parents[0];
3119
  for ($i=1; $i < count($parents); $i++){
3120
    $element_name .= '[' . $parents[$i] . ']';
3121
  }
3122

    
3123
  $children = element_children($element);
3124

    
3125
  $element['table_start'] = array(
3126
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3127
    '#weight' => -1,
3128
  );
3129

    
3130
  // prepare first part each of the table rows which contains the row label
3131
  $weight = 0;
3132
  foreach ($children as $key) {
3133
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3134
    $element[$key]['#weight'] = $weight;
3135
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
3136
    $element[$key]['#suffix'] = '</td>';
3137
    unset($element[$key]['#title']);
3138
    $weight += 2;
3139
  }
3140
  $weight = 0;
3141

    
3142
  // add a radio button to each of the checkboxes, the
3143
  // check boxes have already been created at the beginning
3144
  // of this function
3145
  if (count($element['#options']) > 0) {
3146
    foreach ($element['#options'] as $key => $choice) {
3147
      if (!isset($element[$key . '_preferred'])) {
3148
        $element[$key . '_preferred'] = array(
3149
          '#type' => 'radio',
3150
          '#name' => $element_name,
3151
          '#return_value' => check_plain($key),
3152
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3153
          '#attributes' => $element['#attributes'],
3154
          '#parents' => $element['#parents'],
3155
          // '#spawned' => TRUE,
3156
          '#weight' => $weight + 1,
3157
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3158
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3159
        );
3160
      }
3161
      $weight += 2;
3162
    }
3163
  }
3164

    
3165
  // end the table
3166
  $element['table_end'] = array(
3167
    '#markup' => '</table>',
3168
    '#weight' => $weight++,
3169
  );
3170

    
3171
  return $element;
3172
}
3173

    
3174
/**
3175
 * Theme function for the custom form field 'checkboxes_preferred'.
3176
 */
3177
function theme_checkboxes_preferred($variables) {
3178
  $element = $variables['element'];
3179
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3180
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3181
  $out .= drupal_render_children($element);
3182
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3183
  $out .= '</div>';
3184
  return $out;
3185
}
3186

    
3187
/**
3188
 * Callback for checkboxes preferred for widget which will
3189
 * be called after the form or element is built. The call
3190
 * back is configured in the form element by setting it as
3191
 * #after_build parameter.
3192
 *
3193
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3194
 *
3195
 * @param $element
3196
 *   Nested array of form elements that comprise the form.
3197
 * @param $form_state
3198
 *   A keyed array containing the current state of the form.
3199
 *   This includes the current persistent storage data for the form.
3200
 *   Additional information, like the sanitized $_POST data,
3201
 *   is also accumulated here in $form_state['input']
3202
 *
3203
 * @return the modified form array
3204
 */
3205
function checkboxes_preferred_after_build($element, &$form_state) {
3206

    
3207
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3208

    
3209
  if ($_POST && count($_POST) > 0) {
3210
    // TODO use  $form_state['input'] instead of POST !!!
3211
    // First pass of form processing.
3212
    $parents = array();
3213
    array_deep_copy($element['#parents'], $parents);
3214
    $parents[count($parents) - 1] .= '_preferred';
3215
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3216
    $element['#value']['PREFERRED'] = $preferred_layer;
3217
//     $form_state[$parent_id] = $element['#value'];
3218
//     $form_state['values']['baselayers'] = $element['#value'];
3219
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3220
    $form_state_element_values = $element['#value'];
3221
  }
3222
  else {
3223
    // Second pass of form processing.
3224
    $preferred_layer = $element['#value']['PREFERRED'];
3225
  }
3226

    
3227
  // Also set the chosen value (not sure if this is good Drupal style ....).
3228
  foreach ($children = element_children($element) as $key) {
3229
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3230
      $element[$key]['#value'] = $preferred_layer;
3231
    }
3232
  }
3233
  // The default layer must always be enabled.
3234
  $element[$preferred_layer]['#value'] = $preferred_layer;
3235

    
3236
  return $element;
3237
}
3238

    
3239
function radios_prepare_options_suffix(&$elements){
3240

    
3241
  $childrenKeys = element_children($elements);
3242
  foreach($childrenKeys as $key){
3243
    if(!is_array($elements[$key]['#theme_wrappers'])){
3244
      $elements[$key]['#theme_wrappers'] = array();
3245
    }
3246
    if(isset($elements['#options_suffixes'][$key])){
3247
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3248
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3249
    }
3250
  }
3251
  return $elements;
3252

    
3253
}
3254

    
3255
/**
3256
 * TODO
3257
 * @param unknown $variables
3258
 */
3259
function theme_radio_options_suffix($variables) {
3260
  $element = $variables['element'];
3261
  if(isset($element['#options_suffix'])) {
3262
    $element['#children'] .= $element['#options_suffix'];
3263
  }
3264
  return $element['#children'];
3265
}
3266

    
3267

    
3268
/**
3269
 * Element validate callback for text field and arrays containing json.
3270
 *
3271
 * @param $element
3272
 *   The form element to validate
3273
 * @param $form_state
3274
 *   A keyed array containing the current state of the form.
3275
 * @param $form
3276
 *   Nested array of form elements that comprise the form.
3277
 */
3278
function form_element_validate_json($element, &$form_state, $form) {
3279
   if (!empty($element['#value'])) {
3280
     json_decode($element['#value']);
3281
     if(json_last_error() != JSON_ERROR_NONE){
3282
       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/'));
3283
     }
3284
   }
3285
}
3286

    
3287
/**
3288
 * Form submission handler for textareas and textfields containing JSON.
3289
 *
3290
 * The contained JSON will be converted into an php array
3291
 * or object and will be stored in the variables as such.
3292
 *
3293
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3294
 *
3295
 * @param $form
3296
 *   Nested array of form elements that comprise the form.
3297
 * @param $form_state
3298
 *   A keyed array containing the current state of the form.
3299
 *
3300
 */
3301
function submit_json_as_php_array($form, &$form_state) {
3302
  if (is_array($form['#json_elements'])) {
3303
    foreach ($form['#json_elements'] as $element){
3304
      if (trim($form_state['values'][$element])) {
3305
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3306
      } else {
3307
        $form_state['values'][$element] = NULL;
3308
      }
3309
    }
3310
  }
3311
}
(15-15/15)