Project

General

Profile

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

    
7
// TODO Genus UUID.
8
define('DEFAULT_TAXONTREE_RANKLIMIT', '1b11c34c-48a8-4efa-98d5-84f7f66ef43a');
9
define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
10
define ('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
11

    
12
define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
13
define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
14
define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
15
define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
16
define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
17
define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
18

    
19
/* annotationTypeKeys */
20
$annotationTypeKeys = array_keys(cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE));
21
if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
22
  $annotationTypeKeys = array_flip($annotationTypeKeys);
23

    
24
  // Technical annotation are off by default.
25
  unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
26
  $annotationTypeKeys = array_flip($annotationTypeKeys);
27
  // Additional value for the NULL case.
28
  $annotationTypeKeys[] = 'NULL_VALUE';
29
}
30
define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
31

    
32
define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
33
define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
34
  'enabled' => 1,
35
  'key_format' => 'ALPHA'
36
)));
37

    
38
/* taxonRelationshipTypes */
39
define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
40

    
41

    
42
/* ---- MAP SETTING CONSTANTS ---- */
43
/**
44
 * @var array of URIs eg. http://edit.africamuseum.be"
45
 *   An options array
46
 */
47
define('EDIT_MAPSERVER_URI', serialize(
48
    array(
49
      'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)',
50
      'http://edit.br.fgov.be'=>'Secondary (http://edit.br.fgov.be)',
51
    )
52
  )
53
);
54
define('EDIT_MAPSERVER_PATH', '/edit_wp5');
55
/**
56
 * @var array of versions eg. "v1.2"
57
 *   An options array
58
 */
59
define('EDIT_MAPSERVER_VERSION', serialize(
60
    array(
61
      'v1' => 'v1' ,
62
      'v1.1' => 'v1.1',
63
      'v1.2_dev' => 'v1.2_dev',
64
      'v1.2' => 'v1.2',
65
      'v1.3_dev' => 'v1.3_dev',
66
      'v1.4_dev' => 'v1.4_dev'
67
    )
68
  )
69
);
70
define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
71
define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
72

    
73
// --- Taxon profile settings --- /
74
define('LAYOUT_SETTING_PREFIX', 'layout_');
75
define('FEATURE_TREE_LAYOUT_DEFAULTS', serialize(
76
  array(
77
    'enabled' => FALSE,
78
    'enclosingTag' => 'ul',
79
    'entryEnclosingTag' => 'li',
80
    'glue' => ' ',
81
  )));
82

    
83
define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
84
define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
85
define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
86
    array(
87
        'show' => 0,
88
        'maxextend' => 184,
89
        'media_uri_query' => '',
90
        'custom_placeholder_image_on' => 0,
91
        'custom_placeholder_image_fid' => ''
92
    )
93
  )
94
);
95

    
96
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
97

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

    
112
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
113
  array('general' => '-3', 'synonymy' => '-2', 'images' => '0', 'specimens' => '1', 'keys' => '3')
114
));
115

    
116
$taxon_tab_options = get_taxon_tabs_list();
117
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
118

    
119
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
120

    
121
/**
122
 * @todo document this function.
123
 */
124
function get_taxon_options_list() {
125
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
126
  foreach ($taxon_tab_options as $key => $value) {
127
    $taxon_tab_options[$key] = t($key);
128
  }
129
  return $taxon_tab_options;
130

    
131
}
132

    
133
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
134
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
135
  array(
136
      'ZoologicalName' => array(
137
        'namePart' => array('name' => TRUE),
138
        'nameAuthorPart' => array('name' => TRUE),
139
        'referencePart' => array('authors' => TRUE),
140
        'microreferencePart' => array('microreference' => TRUE),
141
        'statusPart' => array('status' => TRUE),
142
        'descriptionPart' => array('description' => TRUE),
143
      ),
144
      'BotanicalName'=> array(
145
        'namePart' => array('name' => TRUE),
146
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
147
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
148
        'referenceYearPart' => array('reference.year' => TRUE),
149
        'statusPart' => array('status' => TRUE),
150
        'descriptionPart' => array('description' => TRUE),
151
      ),
152
     '#DEFAULT' => array(
153
        'namePart' => array(
154
            'name' => TRUE
155
        ),
156
        'nameAuthorPart' => array(
157
            'name' => TRUE,
158
            'authors' => TRUE
159
        ),
160
        'referencePart' => array(
161
            'reference' => TRUE
162
        ),
163
        'microreferencePart' => array(
164
            'microreference' => TRUE,
165
        ),
166
        'statusPart' => array(
167
            'status' => TRUE,
168
        ),
169
        'descriptionPart' => array(
170
            'description' => TRUE,
171
        ),
172
      )
173
    )
174
  )
175
);
176
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
177
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
178
   array (
179
     'taxon_page_title,polytomousKey'=> array(
180
          'namePart' => array('#uri' => TRUE),
181
        ),
182
      'taxon_page_synonymy,related_taxon'=> array(
183
          'nameAuthorPart' => array('#uri' => TRUE),
184
          'referencePart' => TRUE,
185
          'statusPart' => TRUE,
186
          'descriptionPart' => TRUE,
187
        ),
188
       'homonym'=> array(
189
            'nameAuthorPart' => array('#uri' => TRUE),
190
            'referenceYearPart' => TRUE,
191
        ),
192
      'acceptedFor,typedesignations,list_of_taxa' => array(
193
          'nameAuthorPart' => array('#uri' => TRUE),
194
          'referencePart' => TRUE,
195
        ),
196
      '#DEFAULT' => array(
197
          'nameAuthorPart' => array('#uri' => TRUE),
198
          'referencePart' => TRUE,
199
       )
200
    )
201
));
202

    
203
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
204
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
205
    // to unset a default enntry set the value to 0
206
    array(
207
      'doTaxa'=>'doTaxa',
208
      'doSynonyms' => 'doSynonyms',
209
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
210
      'doMisappliedNames' => 'doMisappliedNames'
211
    )
212
  )
213
);
214

    
215
/* Gallery variables. */
216
$gallery_settings = array(
217
    "cdm_dataportal_show_taxon_thumbnails" => 1,
218
    "cdm_dataportal_show_synonym_thumbnails" => 0,
219
    "cdm_dataportal_show_thumbnail_captions" => 1,
220
    "cdm_dataportal_media_maxextend" => 120,
221
    "cdm_dataportal_media_cols" => 3,
222
    "cdm_dataportal_media_maxRows" => 1,
223
);
224

    
225
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
226
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
227
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
228
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
229
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
230
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
231
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
232
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
233
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
234
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
235
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
236
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
237
/**
238
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
239
 * the snonymy.
240
 *
241
 * @var string
242
 */
243
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
244
/**
245
 * The drupal variable for the configuration of the information aggregation along
246
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
247
 *    - direct: the uuids of the taxon relationship types to take into account in invers
248
 *      direction.
249
 *    - invers: the uuids of the taxon relationship types to take into account in direct
250
 *      direction.
251
 *
252
 * @var String
253
 */
254
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
255
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
256
    array(
257
        'direct'=>array(),
258
        'invers'=>array()
259
     )
260
   ));
261
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
262
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
263
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
264

    
265
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
266
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
267
      array(
268
      'filter_rules' => array(
269
        'statusOrderPreference' => 0,
270
        'subAreaPreference' => 0,
271
      ),
272
      'hideMarkedAreas' => array()
273
     )
274
));
275

    
276

    
277
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
278
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
279
    array(
280
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
281
        'includeOccurrences' => 0,
282
        'includeTaxonNameDescriptions' => 0
283
     )
284
  ));
285

    
286
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
287
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
288
  // needs to be merged with user setting by drupal_array_merge_deep()
289
  'width' => 512, // optimum size for OSM layers is 512
290
  'height' => 512 / 2, // optimum size for OSM layers 256
291
  'bbox' => '', // empty to allow automatic zooming to extend
292
  'show_labels' => FALSE,
293
  'caption' => '',
294
  'distribution_opacity' => '0.5',
295
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
296
  'image_map' => array(
297
    'base_layer' => '', // none, formerly this was cyprusdivs
298
    'bg_color' => '1874CD',
299
    'layer_style' => 'ffffff,606060,,',
300
  ),
301
  'openlayers' => array(
302
    'base_layers' =>  array(
303
      // A layer MUST NOT BE SET in the defaults,
304
      // otherwise it can not be overidden by the user settings:
305
      // 'osgeo_vmap0' => 'osgeo_vmap0',
306
      // it is sufficient to define the preferred layer,
307
      // since it will automatically be enabled:
308
      'PREFERRED' => 'osgeo_vmap0'),
309
     'custom_wms_base_layer' => array(
310
            'name' => NULL,
311
            'url' => NULL,
312
            'params' =>  NULL,
313
            'projection' => NULL,
314
            'proj4js_def' => NULL,
315
            'max_extent' => NULL,
316
            'units' => NULL
317
     ),
318
    'show_layer_switcher' => TRUE,
319
    'display_outside_max_extent' => FALSE
320
  ),
321
  'legend' => array(
322
    'show' => TRUE,
323
    'opacity' => '0.5',
324
    'font_size' => 10,
325
    'font_style' => FALSE,
326
    'icon_width' => 35,
327
    'icon_height' => 15
328
  )
329
)));
330

    
331
/**
332
 * Merges the named array variable with the array of defaults.
333
 *
334
 * IMPORTANT: The array keys must be strings. When the keys are integers
335
 * the merging will not take place for these entities. Number keyed entities
336
 * are just appended to the result array.
337
 *
338
 * @param string $variable_name
339
 *     The variable name
340
 * @param string | array $default
341
 *     The array containing the default values either as array or serialized as string.
342
 *     Unserialization is cared for if necessary
343
 * @return array
344
 *     The merged array as returned by drupal_array_merge_deep()
345
 */
346
function get_array_variable_merged($variable_name, $default){
347

    
348
    // unserialize if nessecary
349
    if(!is_array($default)){
350
      $default = unserialize($default);
351
    }
352
    $variable = variable_get($variable_name, array());
353
    $result = drupal_array_merge_deep($default, $variable);
354
    return $result;
355
}
356

    
357
/**
358
 * @todo document this function.
359
 */
360
function getGallerySettings($gallery_config_form_name) {
361
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
362
}
363

    
364
/**
365
 * Returns the string representation of the default tab.
366
 *
367
 * @param bool $returnTabIndex
368
 *   Defaults to FALSE, if set true this function will return the index number
369
 *   of the default tab. (used to supply default values to form elements).
370
 */
371
function get_default_taxon_tab($returnTabIndex = FALSE) {
372

    
373
  global $user;
374
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
375
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
376
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
377
  // Get the user value if the used has chosen to overwrite the system settings.
378
  $user_tab_on = variable_get($user_tab_active, FALSE);
379
  if ($user_tab_on) {
380
    $user_value = variable_get($user_tab, 0);
381
    $index_value = $user_value;
382
    // Get the system value.
383
  }
384
  else {
385
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
386
    $index_value = $system_value;
387
  }
388

    
389
  // Return the index value or the string representation.
390
  if ($returnTabIndex) {
391
    return $index_value;
392
  }
393
  else {
394
    return ($values[$index_value]);
395

    
396
  }
397
}
398

    
399

    
400
  /**
401
   * preliminary mock implementation
402
   *
403
   * Provides the feature block settings for a specific feature it is is provides as $feature_uuid parameter.
404
   *
405
   *
406
   * Note: These settings only apply to feature blocks which do not have a special rendering
407
   * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
408
   * 'special' element of the settings
409
   *
410
   * @param $feature_uuid
411
   *   The uuid string representation of the feature to return the settings for
412
   *
413
   * @return array
414
   *  an associative array of settings, with the following fields:
415
   *    - as_list: string
416
   *        this setting will be used in compose_cdm_feature_block_elements() as $enclosing_tag
417
   *        possible values are:
418
   *          div: not as list,
419
   *          ul: as bullet list,
420
   *          ol: as numbered list,
421
   *          dl: as definition list
422
   *        The tag used for the inner element, thus depends on the value of this field. The
423
   *        inner tag name can be retrieved by the function cdm_feature_block_element_tag_name()
424
   *    - link_to_reference: boolean,
425
   *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
426
   *    - link_to_name_used_in_source": boolean
427
   *        whether to show name is source information as link which will point to the according name page
428
   *    - sources_as_content (boolean)
429
   *        TRUE:
430
   *          1. If element is of the CDM type TextData and the text is not empty the source references will be
431
   *             appended in brackets like "text (source references)". If the original source has name in source
432
   *             information it will be appended to the citation string,
433
   *             like : "(citation, as name in source; citation, as name in source)"
434
   *          2. if the text of the TextData is empty, the original source citations are the only content
435
   *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
436
   *             prepended to the citation string like: "name in source: citation"
437
   *        FALSE:
438
   *          Original sources are put into the bibliography(=references) pseudo feature block. If the original source
439
   *          citations are the only content, the resulting feature block content would only consist of footnotes.
440
   *          In this case the display of the respective feature block is suppressed.
441
   *          TODO if the bibliography is not enabled the sources will be treated as footnotes like annotations,
442
   *               in future however they will in this case be shown in a separate references section for each
443
   *               feature block.
444
   *    - sources_as_content_to_bibliography  (boolean)
445
   *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
446
   *        in the bibliography.
447
   *    - sort_elements
448
   *        whether and how to sort the elements
449
   *        possible values are the constants SORT_ASC, SORT_DESC, NULL,
450
   *        some feature types (Distribution) also support: SORT_HIERARCHICAL (TODO option to exclude levels)
451
   *    - element_tag
452
   *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
453
   *        possible values are span | div
454
   *    - special: array()
455
   *        an array with further settings, this field can be used for special
456
   *        settings for specialized rendering like for distributions
457
   *  }
458
   *
459
   */
460
  function get_feature_block_settings($feature_uuid = 'DEFAULT'){
461
    // the default must conform to the default parameter values of
462
    // compose_cdm_feature_block_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
463
    // theme_cdm_descriptionElementTextData() : asListElement = NULL
464

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

    
467
    // only needed as final option, when the settings are not having a default
468
    $default = array(
469
      'DEFAULT' => array(
470
        'as_list' => 'ul',
471
        'link_to_reference' => FALSE,
472
        'link_to_name_used_in_source' => TRUE,
473
        'sources_as_content' => TRUE,
474
        'sources_as_content_to_bibliography' => FALSE,
475
        'sort_elements' => NULL,
476
        'glue' => '',
477
        'element_tag'=> NULL
478
      )
479
    );
480

    
481
    // will be used as preset in the settings
482
    $other_themes_default = array(
483
      'DEFAULT' => array(
484
        'as_list' => 'ul',
485
        'link_to_reference' => FALSE,
486
        'link_to_name_used_in_source' => TRUE,
487
        'sources_as_content' => TRUE,
488
        'sources_as_content_to_bibliography' => FALSE,
489
        'sort_elements' => NULL,
490
        'glue' => '',
491
        'element_tag'=> NULL
492
      ),
493
      UUID_CITATION => array(
494
        'as_list' => 'div',
495
        'link_to_reference' => FALSE,
496
        'link_to_name_used_in_source' => FALSE,
497
        'sources_as_content' => TRUE,
498
        'sources_as_content_to_bibliography' => FALSE,
499
        'sort_elements' => SORT_ASC,
500
        'glue' => '',
501
        'element_tag'=> 'div'
502
      ),
503
      UUID_DISTRIBUTION => array(
504
        'as_list' => 'div', // currently ignored
505
        'link_to_reference' => FALSE,
506
        'link_to_name_used_in_source' => FALSE,
507
        'sources_as_content' => FALSE,
508
        'sources_as_content_to_bibliography' => FALSE,
509
        'sort_elements' => NULL, // will cause ...
510
        'glue' => '',
511
        'element_tag'=> 'div'
512
      ),
513
    );
514

    
515
    $cichorieae_default = array(
516
      'DEFAULT' => array(
517
        'as_list' => 'div',
518
        'link_to_reference' => TRUE,
519
        'link_to_name_used_in_source' => TRUE,
520
        'sources_as_content' => TRUE,
521
        'sources_as_content_to_bibliography' => FALSE,
522
        'sort_elements' => NULL,
523
        'glue' => '',
524
        'element_tag'=> 'div'
525
      ),
526
      UUID_CITATION => array(
527
        'as_list' => 'div',
528
        'link_to_reference' => FALSE,
529
        'link_to_name_used_in_source' => FALSE,
530
        'sources_as_content' => TRUE,
531
        'sources_as_content_to_bibliography' => FALSE,
532
        'sort_elements' => SORT_ASC,
533
        'glue' => '',
534
        'element_tag'=> 'div'
535
      ),
536
      UUID_CHROMOSOMES_NUMBERS => array(
537
        'as_list' => 'ul',
538
        'link_to_reference' => TRUE,
539
        'link_to_name_used_in_source' => TRUE,
540
        'sources_as_content' => TRUE,
541
        'sources_as_content_to_bibliography' => FALSE,
542
        'sort_elements' => NULL,
543
        'glue' => '',
544
        'element_tag'=> 'div'
545
      ),
546
      UUID_CHROMOSOMES => array(
547
        'as_list' => 'ul',
548
        'link_to_reference' => FALSE,
549
        'link_to_name_used_in_source' => TRUE,
550
        'sources_as_content' => TRUE,
551
        'sources_as_content_to_bibliography' => FALSE,
552
        'sort_elements' => NULL,
553
        'glue' => '',
554
        'element_tag'=> 'div'
555
      ),
556
    );
557

    
558
    $palmweb_default = array(
559
      'DEFAULT' => array(
560
        'as_list' => 'ul',
561
        'link_to_reference' => TRUE,
562
        'link_to_name_used_in_source' => TRUE,
563
        'sources_as_content' => TRUE,
564
        'sources_as_content_to_bibliography' => TRUE,
565
        'sort_elements' => NULL,
566
        'glue' => '',
567
        'element_tag'=> NULL
568
      ),
569
      UUID_CITATION => array(
570
        'as_list' => 'ul',
571
        'link_to_reference' => TRUE,
572
        'link_to_name_used_in_source' => TRUE,
573
        'sources_as_content' => FALSE,
574
        'sources_as_content_to_bibliography' => TRUE,
575
        'sort_elements' => SORT_ASC,
576
        'glue' => '',
577
        'element_tag'=> 'div'
578
      ),
579
      UUID_DISTRIBUTION => array(
580
        'as_list' => 'div', // currently ignored
581
        'link_to_reference' => TRUE,
582
        'link_to_name_used_in_source' => TRUE,
583
        'sources_as_content' => TRUE, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
584
        'sources_as_content_to_bibliography' => TRUE,
585
        'sort_elements' => NULL, // will cause ...
586
        'glue' => '',
587
        'element_tag'=> 'div'
588
      ),
589
    );
590

    
591
    $cyprus_default = $cichorieae_default;
592
    $cyprus_default[UUID_DISTRIBUTION ]  =  array(
593
      'as_list' => 'div', // currently ignored
594
      'link_to_reference' => FALSE,
595
      'link_to_name_used_in_source' => FALSE,
596
      'sources_as_content' => FALSE,
597
      'sources_as_content_to_bibliography' => FALSE,
598
      'sort_elements' => NULL, // will cause ...
599
      'glue' => '',
600
      'element_tag'=> 'div'
601
    );
602

    
603
    $default_theme = variable_get('theme_default', NULL);
604

    
605
    switch ($default_theme){
606
      case 'garland_cichorieae':
607
        $settings_for_theme = $cichorieae_default;
608
        break;
609
      case 'cyprus':
610
        // cyprus: no longer used in production,
611
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
612
        $settings_for_theme = $cyprus_default;
613
        break;
614
      case 'flore_afrique_centrale':
615
      case 'flora_malesiana':
616
      case 'flore_gabon':
617
        $settings_for_theme = $cichorieae_default;
618
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
619
        break;
620
      case 'palmweb_2':
621
        $settings_for_theme = $palmweb_default;
622
        break;
623
      default:
624
        $settings_for_theme =  $other_themes_default;
625
    }
626

    
627
    if(isset($settings_for_theme[$feature_uuid])){
628
      return $settings_for_theme[$feature_uuid];
629
    } else if(isset($settings_for_theme['DEFAULT'])){
630
      return $settings_for_theme['DEFAULT']; // the fallback cascade will usually stop here since all settings should have a default
631
    } else {
632
      return $default['DEFAULT'];
633
    }
634
  }
635
  /**
636
 * returns the current setting for the original source bibliography
637
 *
638
 * Caches internally
639
 *
640
 * @return array
641
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
642
 *   - 'enabled': 1|0
643
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
644
 */
645
function get_bibliography_settings($clear_cache = false){
646
  static $bibliography_settings = null;
647
  if(!$bibliography_settings || $clear_cache){
648
    $bibliography_settings = get_array_variable_merged(
649
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
650
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
651
    );
652
  }
653
  return $bibliography_settings;
654
}
655

    
656
/**
657
 * @todo Please document this function.
658
 * @see http://drupal.org/node/1354
659
 */
660
function cdm_dataportal_menu_admin(&$items) {
661
  // Display section on admin/config page.
662
  $items['admin/config/cdm_dataportal'] = array(
663
    'title' => 'CDM Dataportal',
664
    'description' => 'Settings for the CDM DataPortal.',
665
    'position' => 'right',
666
    'weight' => 10,
667
    'page callback' => 'system_admin_menu_block_page',
668
    'access arguments' => array('administer cdm_dataportal'),
669
    'file' => 'system.admin.inc',
670
    'file path' => drupal_get_path('module', 'system'),
671
  );
672
  $items['admin/config/cdm_dataportal/settings'] = array(
673
    'title' => 'Settings',
674
    'description' => 'Settings for the CDM DataPortal.',
675
    'weight' => 0,
676
    'page callback' => 'drupal_get_form',
677
    'page arguments' => array('cdm_settings_general'),
678
    'access arguments' => array('administer cdm_dataportal'),
679
    'type' => MENU_NORMAL_ITEM,
680
  );
681
  $items['admin/config/cdm_dataportal/settings/general'] = array(
682
    'title' => 'General',
683
    'description' => 'General',
684
    'weight' => 0,
685
    'page callback' => 'drupal_get_form',
686
    'page arguments' => array('cdm_settings_general'),
687
    'access arguments' => array('administer cdm_dataportal'),
688
    'type' => MENU_DEFAULT_LOCAL_TASK,
689
  );
690

    
691
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
692
    'title' => 'Cache',
693
    'description' => 'Cache',
694
    'access arguments' => array('administer cdm_dataportal'),
695
    'page callback' => 'drupal_get_form',
696
    'page arguments' => array('cdm_settings_cache'),
697
    'weight' => 10,
698
    'type' => MENU_LOCAL_TASK,
699
  );
700

    
701
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
702
    'title' => 'Geo & Map',
703
    'description' => 'Geo & Map',
704
    'access arguments' => array('administer cdm_dataportal'),
705
    'page callback' => 'drupal_get_form',
706
    'page arguments' => array('cdm_settings_geo'),
707
    'weight' => 1,
708
    'type' => MENU_LOCAL_TASK,
709
  );
710

    
711
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
712
    'title' => 'Layout',
713
    'description' => 'Configure and adjust the layout of your DataPortal ',
714
    'access arguments' => array('administer cdm_dataportal'),
715
    'page callback' => 'drupal_get_form',
716
    'page arguments' => array('cdm_settings_layout'),
717
    'weight' => 2,
718
    'type' => MENU_LOCAL_TASK,
719
  );
720

    
721
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
722
    'title' => 'Taxon',
723
    'description' => 'Configure and adjust the layout of your DataPortal ',
724
    'access arguments' => array('administer cdm_dataportal'),
725
    'page callback' => 'drupal_get_form',
726
    'page arguments' => array('cdm_settings_layout_taxon'),
727
    'weight' => 1,
728
    'type' => MENU_LOCAL_TASK,
729
  );
730
  /*
731
  $items[] = array(
732
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
733
  'title' => t('Synonymy'),
734
  'description' => t('Configure and adjust the layout of your DataPortal '),
735
  'access' => user_access('administer cdm_dataportal'),
736
  'callback' => 'drupal_get_form',
737
  'callback arguments' => array('cdm_settings_layout_synonymy'),
738
  'weight' => 1,
739
  'type' => MENU_LOCAL_TASK,
740
  );
741

    
742
  $items[] = array(
743
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
744
  'title' => t('Specimens'),
745
  'description' => t('Configure and adjust the layout of your DataPortal '),
746
  'access' => user_access('administer cdm_dataportal'),
747
  'callback' => 'drupal_get_form',
748
  'callback arguments' => array('cdm_settings_layout_specimens'),
749
  'weight' => 1,
750
  'type' => MENU_LOCAL_TASK,
751
  );
752
  */
753
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
754
    'title' => 'Search',
755
    'description' => 'Configure and adjust the layout of your DataPortal ',
756
    'access arguments' => array('administer cdm_dataportal'),
757
    'page callback' => 'drupal_get_form',
758
    'page arguments' => array('cdm_settings_layout_search'),
759
    'weight' => 2,
760
    'type' => MENU_LOCAL_TASK,
761
  );
762

    
763
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
764
    'title' => 'Media',
765
    'description' => 'Configure and adjust the layout of your DataPortal ',
766
    'access arguments' => array('administer cdm_dataportal'),
767
    'page callback' => 'drupal_get_form',
768
    'page arguments' => array('cdm_settings_layout_media'),
769
    'weight' => 3,
770
    'type' => MENU_LOCAL_TASK,
771
  );
772

    
773
}
774

    
775
/**
776
 * @todo document this function.
777
 */
778
function cdm_help_general_cache() {
779
  $form = array();
780
  $form['cache_help'] = array(
781
    '#type' => 'fieldset',
782
    '#title' => t('Help'),
783
    '#collapsible' => TRUE,
784
    '#collapsed' => TRUE,
785
  );
786
  $form['cache_help']['test'] = array('#value' => t('probando'));
787
  return drupal_render($form);
788
  $res = array();
789
  $res['default'] = drupal_render($help);
790
  return $res;
791
}
792

    
793
/**
794
 * Configures the settings form for the CDM-API module.
795
 *
796
 * @return array
797
 *   Drupal settings form.
798
 */
799
function cdm_settings_general() {
800

    
801
  $form['cdm_webservice'] = array(
802
    '#type' => 'fieldset',
803
    '#title' => t('CDM Server'),
804
    '#collapsible' => FALSE,
805
    '#collapsed' => FALSE,
806
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
807
        CDM data base to the web via RESTful web services and thus is the source of the data
808
        to be displayed by a CDM DataPotal.'),
809
  );
810

    
811
  $form['cdm_webservice']['cdm_webservice_url'] = array(
812
    '#type' => 'textfield',
813
    '#title' => t('CDM web service URL') . ':',
814
    '#description' => t('This is the URL to the CDM-Server exposing your data
815
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
816
    '#default_value' => variable_get('cdm_webservice_url', NULL),
817
  );
818

    
819
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
820
    '#type' => 'markup',
821
    '#markup' => '<b>Debug CDM Web Service:</b> The web service debug box has completely been replaced '
822
      . 'by  the ' . l('CDM web service debug block', 'admin/structure/block/manage/cdm_api/cdm_ws_debug/configure')
823
      . '. It is usually only visible for administrative roles like <i>administrator</i> and <i>CDM admin</i>'
824
  );
825

    
826
  $form['cdm_webservice']['freetext_index'] = array(
827
    '#type' => 'fieldset',
828
    '#title' => t('Freetext index'),
829
    '#collapsible' => FALSE,
830
    '#collapsed' => FALSE,
831
  );
832

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

    
845
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
846
  $trigger_link_options = array(
847
    'attributes' => array(
848
      'class' => 'index-trigger',
849
    ),
850
  );
851
  $form['cdm_webservice']['freetext_index']['operations'] = array(
852
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
853
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
854
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
855
      ))
856
    . '<div id="index-progress"></div></div>',
857
  );
858
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
859

    
860
  $form['cdm_webservice']['proxy'] = array(
861
    '#type' => 'fieldset',
862
    '#title' => t('Proxy'),
863
    '#collapsible' => TRUE,
864
    '#collapsed' => TRUE,
865
  );
866

    
867
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
868
    '#type' => 'textfield',
869
    '#title' => t('Proxy URL') . ':',
870
    '#description' => t('If this proxy url is set the cdm api tries
871
    to connect the web service over the given proxy server.
872
    Otherwise proxy usage is deactivated.'),
873
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
874
  );
875

    
876
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
877
    '#type' => 'textfield',
878
    '#title' => t('Proxy port') . ':',
879
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
880
  );
881

    
882
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
883
    '#type' => 'textfield',
884
    '#title' => t('Login') . ':',
885
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
886
  );
887

    
888
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
889
    '#type' => 'textfield',
890
    '#title' => t('Password') . ':',
891
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
892
  );
893

    
894
  // TODO: settings are still incomplete, compare with
895
  // trunk/dataportal/inc/config_default.php.inc.
896
  $form['taxon_tree'] = array(
897
    '#type' => 'fieldset',
898
    '#title' => t('Taxon Tree'),
899
    '#collapsible' => FALSE,
900
    '#collapsed' => TRUE,
901
    '#description' => t('<p>When you explore your collection, you can navigate
902
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
903
      able to navigate through your collection the
904
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
905
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
906
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
907
      </a></p>'),
908
  );
909

    
910
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
911
    '#type' => 'select',
912
    '#title' => t('Available classifications') . ':',
913
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
914
    '#options' => cdm_get_taxontrees_as_options(),
915
    '#description' => t('Select the default taxa classification for your
916
      <em>taxon tree</em>, the other classifications will be also available but
917
      with a manual user change.'),
918
  );
919

    
920
  $form['taxon_tree']['taxontree_ranklimit'] = array(
921
    '#type' => 'select',
922
    '#title' => t('Rank of highest displayed taxon') . ':',
923
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
924
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
925
    '#options' => cdm_rankVocabulary_as_option(),
926
    '#description' => t('This is the rank of the highest displayed taxon in the
927
      <em>taxon tree</em>. You can select here which rank should be at the top
928
      level of the tree structure.'),
929
  );
930

    
931
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
932
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
933
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
934
      '#type' => 'checkboxes',
935
      '#title' => t('Included Classifications') . ':',
936
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
937
      '#options' => cdm_get_taxontrees_as_options(),
938
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
939
  );
940

    
941
  $form['distribution'] = array(
942
      '#type' => 'fieldset',
943
      '#title' => t('Distributions'),
944
      '#collapsible' => FALSE,
945
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
946
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
947
          '<p>
948
          </p>',
949
  );
950

    
951
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
952
      '#type' => 'fieldset',
953
      '#title' => 'Distribution filter',
954
      '#collapsible' => FALSE,
955
      '#collapsed' => FALSE,
956
      '#tree' => TRUE,
957
      '#description' => 'The Distribution filter offers the following options
958
      <ul>
959
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
960
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
961
      <li><strong>Marked area filter:</strong>Skip distributions where the area has a Marker with one of the specified MarkerTypes</li>
962
      </ul>'
963
  );
964

    
965
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
966
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
967
      '#type' => 'checkboxes',
968
      '#title' => 'Filter rules',
969
      '#default_value' => $cdm_distribution_filter['filter_rules'],
970
      '#options' => array(
971
          'statusOrderPreference' => 'Status order preference rule',
972
          'subAreaPreference' => 'Sub area preference rule'
973
      ),
974
  );
975

    
976
  $marker_type_options = cdm_terms_as_options( cdm_ws_fetch_all('term', array('class' => 'MarkerType' )) );
977
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hideMarkedAreas'] = array(
978
      '#type' => 'checkboxes',
979
      '#title' => 'Hide marked area filter',
980
      '#default_value' => $cdm_distribution_filter['hideMarkedAreas'],
981
      '#options' => $marker_type_options,
982
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
983
  );
984

    
985
  $form['aggregation'] = array(
986
      '#type' => 'fieldset',
987
      '#title' => t('Aggregation of data'),
988
      '#collapsible' => FALSE,
989
      '#description' => 'This section covers the different aspects of aggregating information.
990
          <p>
991
          </p>',
992
  );
993

    
994
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
995
      '#type' => 'checkboxes',
996
      '#title' => 'Taxon media filter',
997
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
998
      '#options' => array(
999
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1000
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1001
          'includeOccurrences' => 'Media related to specimens and occurrences',
1002
      ),
1003
      '#description' => 'This filter configures which images should be taken into account.',
1004
  );
1005

    
1006
  $form['aggregation']['notice'] = array(
1007
      '#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
1008
          want to make use of the caching capabilities of the dataportal.',
1009
  );
1010

    
1011
  $form['aggregation']['media_aggregation'] = array(
1012
      '#type' => 'fieldset',
1013
      '#title' => t('Media aggregation'),
1014
      '#collapsible' => FALSE,
1015
      '#collapsed' => TRUE,
1016
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1017

    
1018
  );
1019
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1020
      '#type' => 'select',
1021
      '#title' => t('Aggregation of taxon pictures') . ':',
1022
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1023
      '#options' => array(
1024
          0 => "Show only pictures of the current taxon",
1025
          1 => "Include pictures of taxonomic children",
1026
      ),
1027
      '#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."),
1028
  );
1029

    
1030
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1031
      '#type' => 'fieldset',
1032
      '#attributes' => array('class'=>array('clearfix')),
1033
      '#title' => t('Aggregation via taxon relationsships'),
1034
      '#collapsible' => TRUE,
1035
      '#collapsed' => TRUE,
1036
      '#tree' => TRUE,
1037
      '#description' => t('Information on taxa will be aggregated along the below chosen
1038
          taxon relation ships. This will affect images and occurrences (specimens).
1039
          Taxon relation ships are directed and point form one taxon to another. The taxon
1040
          relationships to be taken into accunt can therefore configured for the direct direction
1041
          and for the inverse.'),
1042
  );
1043

    
1044
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1045
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1046

    
1047
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1048
      '#type' => 'checkboxes',
1049
      '#title' => t('Direct'),
1050
      '#options' => $taxonRelationshipTypeOptions,
1051
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1052
  );
1053
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1054
      '#type' => 'checkboxes',
1055
      '#title' => t('Invers'),
1056
      '#options' => $taxonRelationshipTypeOptions,
1057
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1058
  );
1059

    
1060
  // ----------------------
1061
  $form['cdm_js_devel_mode'] = array(
1062
      '#type' => 'checkbox',
1063
      '#title' => 'Java-script developer mode',
1064
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1065
      '#description' => 'In production envirionments the java script libraries
1066
      the cdm_dataportal is making use of are compressed and optimized. This
1067
      is good for performance but a caveat if you need to debug java-script. When the
1068
      java-script developer mode is enabled the uncompressed and commented developer
1069
      versions of java-script libraries will be used where possible.
1070
      <br/><strong>Do not use this option in production!</strong>'
1071
  );
1072
  // ----------------------
1073
  $form['cdm_debug_mode'] = array(
1074
      '#type' => 'checkbox',
1075
      '#title' => 'CDM page debug mode',
1076
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1077
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1078
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1079
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1080
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1081
      The log is written by the drupal devel module function <code>dd()</code>.
1082
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1083
  );
1084

    
1085
  // Comment @WA: D7 form api does not support reset buttons,
1086
  // so to mimic the D5 reset button we add one like this.
1087
  $form['actions']['reset'] = array(
1088
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1089
    '#weight' => 1000,
1090
  );
1091

    
1092
  $form['#submit'][] = 'cdm_settings_general_submit';
1093

    
1094
  return system_settings_form($form);
1095
}
1096

    
1097

    
1098
/**
1099
 * LAYOUT settings
1100
 * @return
1101
 *   todo
1102
 */
1103
function cdm_settings_layout() {
1104

    
1105
  $form = array();
1106

    
1107
  $form['about'] = array(
1108
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1109
      layout. If you want to configure the specific sites layout visit the
1110
      respective configuration site for taxon, search or media.') . '</p>',
1111
  );
1112

    
1113
  // ---- footnotes --- //
1114
  $form['footnotes'] = array(
1115
    '#type' => 'fieldset',
1116
    '#title' => t('Footnotes'),
1117
    '#collapsible' => FALSE,
1118
    '#collapsed' => FALSE,
1119
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1120
      media or distribution areas may have annotations or footnotes. When the
1121
      footnotes are enabled they will be visible (if they exist).'),
1122
  );
1123

    
1124
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1125
    '#type' => 'checkbox',
1126
    '#title' => t('Do not show footnotes'),
1127
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1128
    '#description' => t('Check this if you do not want to show any footnotes'),
1129
  );
1130

    
1131
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1132
    '#type' => 'checkbox',
1133
    '#title' => t('Do not show annotations footnotes'),
1134
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1135
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1136
  );
1137

    
1138
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType', SORT_ASC);
1139
  // Additional option for the NULL case.
1140
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1141
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1142
    '#type' => 'checkboxes',
1143
    '#title' => t('Annotation types as footnotes'),
1144
    '#description' => t("Only annotations of the selected type will be displayed
1145
       as footnotes. You may want to turn 'technical annotations' off."),
1146
    '#options' => $annotationTypeOptions,
1147
  );
1148
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1149
  if (!empty($annotationsTypesAsFootnotes)) {
1150
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1151
  }
1152

    
1153
  // ---- original source --- //
1154
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1155
      '#type' => 'fieldset',
1156
      '#tree' => TRUE,
1157
      '#title' => t('Source Citations'),
1158
      '#collapsible' => FALSE,
1159
      '#collapsed' => FALSE,
1160
  );
1161

    
1162
  $bibliography_settings = get_bibliography_settings(true);
1163

    
1164
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1165
      '#type' => 'checkbox',
1166
      '#title' => t('Original Source in bibliography'),
1167
      '#default_value' => $bibliography_settings['enabled'],
1168
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1169
       annotations in each feature block.'),
1170
  );
1171

    
1172
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1173
    '#type' => 'select',
1174
    '#title' => t('The format of the key numerals'),
1175
    '#default_value' => $bibliography_settings['key_format'],
1176
    '#options' => array('latin' => 'Latin',
1177
      'ROMAN' => 'Roman (upper case)',
1178
      'roman' => 'Roman (lower case)',
1179
      'ALPHA'=> 'Alphabet (upper case)',
1180
      'alpha' => 'Alphabet (lower case)')
1181
  );
1182

    
1183
  // --- Advanced Search --- //
1184
  $form['asearch'] = array(
1185
    '#type' => 'fieldset',
1186
    '#title' => t('Advanced search'),
1187
    '#collapsible' => FALSE,
1188
    '#collapsed' => FALSE,
1189
  );
1190

    
1191
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1192
    '#type' => 'checkbox',
1193
    '#title' => t('Show advanced search link'),
1194
    '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1195
    '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1196
  );
1197

    
1198
  // ---- Taxon Name Rendering --- //
1199
  $form['taxon_name'] = array(
1200
      '#type' => 'fieldset',
1201
      '#title' => t('Taxon name display'),
1202
      '#collapsible' => TRUE,
1203
      '#collapsed' => TRUE,
1204
      '#description' => t('The display of taxon names is configured by two parts.'
1205
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
1206
          . 'The name parts are defined in the <stong>part definitions</strong>'),
1207
  );
1208

    
1209
  drupal_add_js(
1210
      'jQuery(document).ready( function( ) {
1211
         // pretty print json
1212
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
1213
         var obj = JSON.parse(json_text);
1214
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
1215

    
1216
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
1217
         obj = JSON.parse(json_text);
1218
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
1219
       });'
1220
      ,array(
1221
          'type' => 'inline',
1222
          'scope' => 'footer'
1223
      )
1224
  );
1225

    
1226
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1227

    
1228
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1229
      '#type' => 'textarea',
1230
      '#title' => t('Part definitions'),
1231
      '#element_validate' => array('form_element_validate_json'),
1232
      '#default_value' =>  json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions)),
1233
      '#description' => '
1234
          <p>
1235
          (Clearing the text area will reset it to the default)
1236
          </p>
1237
          <p>
1238
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1239
          </p>
1240
          <p>
1241
           A full taxon name plus additional information can consist of the following elements:
1242
          <ul>
1243
             <li>name: the taxon name inclugin rank nbut without author</li>
1244
             <li>authors:  The authors of a reference, also used in taxon names</li>
1245
             <li>reference: the nomenclatural reference,</li>
1246
             <li>microreference:  Volume, page number etc.</li>
1247
             <li>status:  The nomenclatural status of a name</li>
1248
             <li>description: name descriptions like protologues etc ...</li>
1249
          </ul>
1250
          </p>
1251
          <p>
1252
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1253
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1254
           The following parts can be formed and are recognized by the system:
1255
          <ul>
1256
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1257
            <li>authorshipPart: the author (for example: "L.")</li>
1258
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1259
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1260
               be combined when a link to the taxon is rendered.</li>
1261
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1262
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1263
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1264
            <li>statusPart: the nomenclatorical status</li>
1265
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1266
          </ul>
1267
          </p>
1268
          <p>
1269
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1270
           specific parts part definitions:
1271
          <ul>
1272
            <li>BotanicalName</li>
1273
            <li>ZoologicalName</li>
1274
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1275
          </ul>
1276
           An example:
1277
          <pre>
1278
           {
1279
            "ZoologicalName": {
1280
              "namePart": {
1281
                "name": true
1282
              },
1283
              "referencePart": {
1284
                "authors": true
1285
              },
1286
              "microreferencePart": {
1287
                "microreference": true
1288
              },
1289
              "statusPart": {
1290
                "status": true
1291
              },
1292
              "descriptionPart": {
1293
                "description": true
1294
              }
1295
            },
1296
            "BotanicalName": {
1297
              "namePart": {
1298
                "name": true,
1299
                "authors": true
1300
              },
1301
              "referencePart": {
1302
                "reference": true,
1303
                "microreference": true
1304
              },
1305
              "statusPart": {
1306
                "status": true
1307
              },
1308
              "descriptionPart": {
1309
                "description": true
1310
              }
1311
            }
1312
          }
1313
           </pre>',
1314
  );
1315

    
1316
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1317

    
1318
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1319
      '#type' => 'textarea',
1320
      '#title' => t('Name render templates'),
1321
      '#element_validate' => array('form_element_validate_json'),
1322
      '#default_value' =>  json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates)),
1323
      '#description' => '
1324
          <p>
1325
          (Clearing the text area will reset it to the default)
1326
          </p>
1327
          <p>
1328
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1329
          render path. The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1330
          The following render Path keys are curretly recognized:
1331
          <ul>
1332
            <li>list_of_taxa</li>
1333
            <li>acceptedFor</li>
1334
            <li>homonym</li>
1335
            <li>taxon_page_synonymy</li>
1336
            <li>typedesignations</li>
1337
            <li>taxon_page_title</li>
1338
            <li>polytomousKey</li>
1339
            <li>na: name + authorship</li>
1340
            <li>nar:name + authorship + reference</li>
1341
            <li>#DEFAULT</li>
1342
          </ul>
1343
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1344
          array element should be a comma separated list of render paths, without any whitespace!.
1345
          </p>
1346
          <p>
1347
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1348
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1349
          <p>
1350
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1351
          The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
1352
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1353
          links if the paramters $nameLink or $refenceLink are given to the name render function
1354
          (this is hard coded and cannot be configured here).',
1355
  );
1356

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

    
1364
  $form['#submit'] = array('submit_json_as_php_array');
1365
  // #json_elements especially defined for submit_json_as_php_array()
1366
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1367
  return system_settings_form($form);
1368
}
1369

    
1370

    
1371
/**
1372
 * @todo Please document this function.
1373
 * @see http://drupal.org/node/1354
1374
 */
1375
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1376
  $form[$form_name] = array(
1377
    '#type' => 'fieldset',
1378
    '#title' => t($form_title),
1379
    '#collapsible' => TRUE,
1380
    '#collapsed' => $collapsed,
1381
    '#tree' => TRUE,
1382
    '#description' => t($form_description),
1383
  );
1384

    
1385
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1386
  $gallery_settings = variable_get($form_name, $default_values);
1387
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1388
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1389
    /*
1390
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1391
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1392
    '#type' => 'textfield',
1393
    '#title' => t('Search Page Size'),
1394
    '#default_value' => $test,
1395
    '#description' => t('Number of Names to display per page in search results.')
1396
    );
1397
    */
1398
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1399
      '#type' => 'checkbox',
1400
      '#title' => t('Show media thumbnails for accepted taxa'),
1401
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1402
    );
1403

    
1404
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1405
      '#type' => 'checkbox',
1406
      '#title' => t('Show media thumbnails for synonyms'),
1407
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1408
      '#description' => '',
1409
    );
1410
  }
1411

    
1412
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1413
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1414
    '#type' => 'checkbox',
1415
    '#title' => t('Show captions under thumbnails'),
1416
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1417
    '#description' => '',
1418
  );
1419

    
1420
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1421
    '#type' => 'textfield',
1422
    '#title' => t('Thumbnail size') . ':',
1423
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1424
    '#description' => t('Select the size of each individual thumbnail.'),
1425
  );
1426

    
1427
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1428
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1429
      '#type' => 'textfield',
1430
      '#title' => t('Number of columns') . ':',
1431
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1432
      '#description' => t('Group the thumbnails in columns: select how many
1433
        columns the gallery should display.'),
1434
    );
1435
  }
1436

    
1437
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1438
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1439
      '#type' => 'textfield',
1440
      '#title' => t('Maximum number of rows') . ':',
1441
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1442
      '#description' => t('You can group the thumbnails in rows, select in how
1443
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1444
        If you want an unlimited number of rows please set to 0.'),
1445
    );
1446
  }
1447

    
1448
  return $form;
1449
}
1450

    
1451
/**
1452
 * @todo document this function.
1453
 */
1454
function cdm_settings_layout_taxon() {
1455
  $collapsed = FALSE;
1456
  $form = array();
1457

    
1458
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1459

    
1460
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1461
      '#type' => 'checkbox',
1462
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1463
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1464
      '#description' => t('<p>If checked the link to search results is rendered at
1465
       the top of the taxon site. Clicking on the link the last search performed
1466
       is rendered again.</p>'),
1467
  );
1468

    
1469
  // --------- TABBED TAXON ------- //
1470
  $form['taxon_tabs'] = array(
1471
    '#type' => 'fieldset',
1472
    '#title' => t('Taxon tabs'),
1473
    '#collapsible' => TRUE,
1474
    '#collapsed' => FALSE,
1475
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1476
      be splitted in four diferent tabs; General, Synonymy, Images and
1477
      Specimens. If the taxon has no information for any of the tabs/sections
1478
      such tab will be not displayed.'),
1479
  );
1480

    
1481
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1482
    '#type' => 'checkbox',
1483
    '#title' => t('Tabbed taxon page'),
1484
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1485
    '#description' => t('<p>If selected split the taxon page into individual
1486
      tabs for description, images, synonymy and specimens. If not the taxon
1487
      data is rendered as a long single page without tabs.</p>'),
1488
  );
1489

    
1490
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1491
    '#type' => 'checkboxes',
1492
    '#title' => t('Tabs visibility options') . ':',
1493
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1494
    '#options' => get_taxon_options_list(),
1495
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1496
  );
1497

    
1498
  // WEIGHT
1499
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1500
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1501
      '#tree' => true
1502
  );
1503
  // Weights range from -delta to +delta, so delta should be at least half
1504
  // of the amount of tabs present.
1505
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1506
  foreach (get_taxon_tabs_list() as $label) {
1507
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1508
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1509
        '#title' => $label,
1510
        '#type'  => 'weight',
1511
        '#default_value' => $taxontabs_weights[$key],
1512
        '#delta' => $tab_weight_delta
1513
    );
1514
  }
1515

    
1516
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1517
    '#type' => 'select',
1518
    '#title' => t('Default tab to display') . ':',
1519
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1520
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1521
    '#description' => t('<p>Select the default tab to display when visiting a
1522
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1523
      <strong>Note:</strong> After performing a search and clicking in any
1524
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1525
      taxon and not the above selected tab.'),
1526
  );
1527

    
1528
  /* ======  TAXON_PROFILE ====== */
1529
  $form['taxon_profile'] = array(
1530
    '#type' => 'fieldset',
1531
    '#title' => t('Taxon profile (tab)'),
1532
    '#description' => t('<p>This section covers the settings related to the taxon
1533
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1534
    '#collapsible' => TRUE,
1535
    '#collapsed' => TRUE,
1536
  );
1537

    
1538
  // ---- PROFILE PICTURE ----//
1539

    
1540
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1541
    '#type' => 'fieldset',
1542
    '#tree' => TRUE,
1543
    '#title' => t('Taxon profile picture'),
1544
    '#collapsible' => TRUE,
1545
    '#collapsed' => FALSE,
1546
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1547
  );
1548

    
1549
  //FIXME migrate variables:
1550
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1551
  // FIXME
1552
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1553

    
1554
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1555
  /*
1556
   * 'show' => 1,
1557
   * 'maxextend' => 184,
1558
   * 'media_uri_query' => ''
1559
   * 'custom_placeholder_image_on' => 1,
1560
   * 'custom_placeholder_image_fid' => ''
1561
   */
1562
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1563
    '#type' => 'checkbox',
1564
    '#title' => t('Enable profil picture'),
1565
    '#description' => t('Show the profil picture.'),
1566
    '#default_value' => $taxon_profile_image_settings['show'],
1567
  );
1568

    
1569
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1570
      '#type' => 'textfield',
1571
      '#tree' => TRUE,
1572
      '#title' => t('Profil picture maximum extend'),
1573
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1574
      '#field_suffix' => 'px',
1575
      '#maxlength' => 4,
1576
      '#size' => 4,
1577
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1578
  );
1579

    
1580
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1581
      '#type' => 'textfield',
1582
      '#tree' => TRUE,
1583
      '#title' => t('Additional URI query parameter'),
1584
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1585
      '#maxlength' => 1024,
1586
      '#size' => 60,
1587
      '#description' => t('Additional query parameters to be used when requesting for the '
1588
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1589
          . 'The query parameters will be appendend to the uri of the media representation part'
1590
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1591
  );
1592

    
1593
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1594
      '#type' => 'checkbox',
1595
      '#title' => t('Use a custom placeholder image'),
1596
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1597
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1598
  );
1599

    
1600
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1601
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1602
        '#type' => 'managed_file',
1603
        '#title' => t('Custom placeholder image file'),
1604
        '#progress_indicator' => 'bar',
1605
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1606
    //       '#name' => 'custom_placeholder_image',
1607
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1608
    );
1609

    
1610
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1611
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1612
      $url = file_create_url($profile_image_file->uri);
1613
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1614
                '#type' => 'item',
1615
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1616
      );
1617
    }
1618
  } else {
1619
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1620
        '#type' => 'hidden',
1621
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1622
    );
1623
  }
1624

    
1625

    
1626

    
1627
  $options = cdm_rankVocabulary_as_option();
1628
  array_unshift($options, '-- DISABLED --');
1629
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1630
    '#type' => 'select',
1631
    '#title' => t('Hide profile picture for higher ranks') . ':',
1632
    '#default_value' => variable_get('image_hide_rank', '0'),
1633
    '#options' => $options,
1634
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1635
  );
1636

    
1637
  // -- MEDIA THUMBNAILS -- //
1638
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1639
  $form_title = 'Taxon Profile Images';
1640
  $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>';
1641
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1642

    
1643
  // ---- FEATURE TREE ---- //
1644
  $form['taxon_profile']['feature_trees'] = array(
1645
    '#type' => 'fieldset',
1646
    '#title' => t('Features'),
1647
    '#collapsible' => TRUE,
1648
    '#collapsed' => FALSE,
1649
    '#description' => t("This section covers settings related to the taxon's
1650
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1651
      features such as description, distribution, common names, etc. that Drupal
1652
      will render at the taxon profile page."),
1653
  );
1654
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1655
  $saved_uuid = variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1656
  if(!isset($featureTrees['options'][$saved_uuid])) {
1657
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1658
  }
1659
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
1660
    '#type' => 'radios',
1661
    '#title' => t('Taxon profile sections') . ':',
1662
    '#default_value' => $saved_uuid,
1663
    '#options' =>  $featureTrees['options'],
1664
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1665
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1666
    '#description' => t('Select the Feature Tree to be displayed at the taxon
1667
      profile. Click "Show Details" to see the Feature Tree elements.'
1668
    ),
1669
  );
1670
  $featureTrees = cdm_get_featureTrees_as_options();
1671
  $saved_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1672
  if(!isset($featureTrees['options'][$saved_uuid])) {
1673
    $saved_uuid = NULL;
1674
  }
1675
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
1676
    '#type' => 'radios',
1677
    '#title' => t('Natural language representation of structured descriptions') . ':',
1678
    '#default_value' => $saved_uuid,
1679
    '#options' => $featureTrees['options'],
1680
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1681
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1682
    '#description' => t('Taxon descriptions can be stored in a highly structured
1683
      form. The feature tree selected here will be used to generate textual
1684
      representation in natural language.'
1685
    ),
1686
  );
1687

    
1688
  // ---- LAYOUT PER FEATURE ---- //
1689
  $feature_tree = get_profile_featureTree();
1690
  if (isset($feature_tree->root->childNodes)) {
1691

    
1692
    $form_feature_list_layout = array(
1693
      '#title' => t('Taxon profile layout'),
1694
      '#collapsible' => TRUE,
1695
      '#collapsed' => FALSE,
1696
      '#type' => 'fieldset',
1697
      '#description' => t('Will be available in a future release.'),
1698
    );
1699

    
1700
    $feature_list_layout_settings_disabled = TRUE;
1701
    foreach ($feature_tree->root->childNodes as $featureNode) {
1702

    
1703
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1704
        // Must not exceed 45 characters !!!
1705
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1706

    
1707
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1708
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1709

    
1710
        $form_feature_list_layout[$subform_id] = array(
1711
          '#tree' => TRUE,
1712
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1713
          '#collapsible' => FALSE,
1714
          '#collapsed' => FALSE,
1715
          '#type' => 'fieldset',
1716
          '#description' => t(''),
1717
        );
1718

    
1719
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1720
          '#type' => 'checkbox',
1721
          '#title' => t('Enable'),
1722
          '#default_value' => $settings['enabled'],
1723
          '#description' => t('Enable user defined layout for this feature'),
1724
        );
1725

    
1726
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1727
          '#type' => 'textfield',
1728
          '#title' => t('Enclosing tag'),
1729
          '#disabled' => !$settings['enabled'],
1730
          '#default_value' => $settings['enclosingTag'],
1731
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1732
        );
1733

    
1734
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1735
          '#type' => 'textfield',
1736
          '#title' => t('Entry enclosing tag'),
1737
          '#disabled' => !$settings['enabled'],
1738
          '#default_value' => $settings['entryEnclosingTag'],
1739
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1740
        );
1741

    
1742
        $form_feature_list_layout[$subform_id]['glue'] = array(
1743
          '#type' => 'textfield',
1744
          '#title' => t('Glue'),
1745
          '#disabled' => !$settings['enabled'],
1746
          '#default_value' => $settings['glue'],
1747
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1748
        );
1749

    
1750
      }
1751

    
1752
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1753
    }
1754
  }
1755

    
1756
  // ---- DISTRIBUTION LAYOUT ---- //
1757
  $form['taxon_profile']['distribution_layout'] = array(
1758
    '#title' => t('Distribution'),
1759
    '#collapsible' => TRUE,
1760
    '#collapsed' => FALSE,
1761
    '#type' => 'fieldset',
1762
    '#description' => t('Select if you want to sort or not the distribution text
1763
      located below the distribution map.'),
1764
  );
1765

    
1766
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1767
    '#type' => 'radios',
1768
    '#title' => t('Sort') . ':',
1769
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1770
    '#options' => array(
1771
      'NO_SORT' => t('Standard (No sort)'),
1772
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1773
    ),
1774
  );
1775

    
1776
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1777
    '#type' => 'checkbox',
1778
    '#title' => t('Show TextData elements on top of the map'),
1779
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1780
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1781
      elements on top of the map. Otherwise all <code>TextData</code>
1782
      distribution elements will be listed below the other area elements.
1783
      This option is useful if you need to have descriptive texts for each
1784
      distribution map.'),
1785
  );
1786

    
1787
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
1788
      '#type' => 'textarea',
1789
      '#title' => t('Custom status colors'),
1790
      '#element_validate' => array('form_element_validate_json'),
1791
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
1792
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
1793
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
1794
          reference list of the idInVocabulary values of absence and presence terms:
1795
<pre>
1796
Presence Term
1797
p	present
1798
pd	present: doubtfully present
1799
n	native
1800
nq	native: presence questionable
1801
nd	native: doubtfully native
1802
c	cultivated
1803
i	introduced
1804
iq	introduced: presence questionable
1805
id	introduced: doubtfully introduced (perhaps cultivated only)
1806
ip	introduced: uncertain degree of naturalisation
1807
ia	introduced: adventitious (casual)
1808
in	introduced: naturalized
1809
ic	introduced: cultivated
1810
e	endemic for the relevant area
1811
na	naturalised
1812
iv	invasive
1813

    
1814
AbsenceTerm
1815
a	absent
1816
f	reported in error
1817
nf	native: reported in error
1818
if	introduced: reported in error
1819
cf	cultivated: reported in error
1820
ne	native: formerly native
1821
ie	introduced: formerly introduced
1822

    
1823
</pre>'),
1824
  );
1825

    
1826

    
1827
  /* ====== SYNONYMY ====== */
1828
  $form['taxon_synonymy'] = array(
1829
    '#type' => 'fieldset',
1830
    '#title' => t('Taxon synonymy (tab)'),
1831
    '#collapsible' => TRUE,
1832
    '#collapsed' => TRUE,
1833
    '#description' => t('This section covers the settings related to the taxon
1834
      <strong>synonymy</strong> tab.'),
1835
  );
1836

    
1837
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1838
    '#type' => 'checkbox',
1839
    '#title' => t('Show accepted taxon on top of the synonymy'),
1840
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1841
    '#description' => t('If checked, the first homotypic taxon is a repetition
1842
      of the accepted taxon most likely with the full nomenclatural reference
1843
      (depending on the currently chosen theme).'),
1844
  );
1845

    
1846
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1847
    '#type' => 'checkbox',
1848
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1849
      coming from a synonym link.'),
1850
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1851
    '#description' => t('Check this if after doing a search and clicking on a
1852
      synonym you want to see the "accept of" text for the accepted synonym.'),
1853
  );
1854

    
1855
  /* === currently unused ===
1856
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1857
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1858
    '#type' => 'checkboxes',
1859
    '#title' => t('Display name relationships') . ':',
1860
    '#default_value' => variable_get('name_relationships_to_show', 0),
1861
    '#options' => $nameRelationshipTypeOptions,
1862
    '#description' => t('Select the name relationships you want to show for the
1863
      accepted taxa.'),
1864
  );
1865
 */
1866

    
1867
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1868
    '#type' => 'checkbox',
1869
    '#title' => t('Show taxon relations ships of accepted taxon'),
1870
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1871
    '#description' => t('If this option is enabled the synonymy will show the
1872
      below selected taxon relationships of accepted taxa.'),
1873
  );
1874

    
1875
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1876
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1877
    '#type' => 'checkboxes',
1878
    '#title' => t('Taxon relationship types') . ':',
1879
    '#description' => t('Only taxon relationships of the selected type will be
1880
      displayed'),
1881
    '#options' => $taxonRelationshipTypeOptions,
1882
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1883
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1884
  );
1885

    
1886
  // ====== SPECIMENS ====== //
1887
  $form['taxon_specimens'] = array(
1888
    '#type' => 'fieldset',
1889
    '#title' => t('Taxon specimens (tab)'),
1890
    '#collapsible' => TRUE,
1891
    '#collapsed' => TRUE,
1892
    '#description' => t('This section covers the settings related to the taxon
1893
      <strong>specimens</strong> tab.'),
1894
  );
1895

    
1896
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1897
  $saved_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1898
  if(!isset($featureTrees['options'][$saved_uuid])) {
1899
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1900
  }
1901
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1902
      '#type' => 'radios',
1903
      '#title' => t('Specimen description feature tree') . ':',
1904
      '#default_value' => $saved_uuid,
1905
      '#options' =>  $featureTrees['options'],
1906
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1907
      '#options_suffixes' => $featureTrees['treeRepresentations'],
1908
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1909
      ),
1910
  );
1911

    
1912
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1913
  $form_title = t('Specimen media');
1914
  $form_description = t('Specimens may have media which is displayed at the
1915
     Specimen tab/section as a gallery. It is possible to configure the
1916
     thumbnails gallery here, however for configuring how a single media should
1917
     be displayed please go to !url.</p>',
1918
     array(
1919
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1920
     ));
1921
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1922

    
1923
  // --- MEDIA GALLERY ---- //
1924
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1925
  $form_title = 'Media gallery (tab)';
1926
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1927
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1928
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1929
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1930
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1931
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1932
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1933

    
1934
  // Comment @WA: D7 form api does not support reset buttons,
1935
  // so to mimic the D5 reset button we add one like this.
1936
  $form['actions']['reset'] = array(
1937
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1938
    '#weight' => 1000,
1939
  );
1940
  return system_settings_form($form);
1941
}
1942

    
1943
/**
1944
 * @todo document this function.
1945
 */
1946
function cdm_settings_layout_search() {
1947

    
1948
  $form = array();
1949

    
1950
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
1951

    
1952
  $form['search_settings'] = array(
1953
    '#type' => 'fieldset',
1954
    '#title' => t('Taxa Search'),
1955
    '#collapsible' => FALSE,
1956
    '#collapsed' => FALSE,
1957
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1958
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1959
         where they can write the text to be searched. You can find Drupal block configuration
1960
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1961
  );
1962

    
1963
  $form['search_settings']['simple_search_ignore_classification'] = array(
1964
      '#type' => 'checkbox',
1965
      '#title' => t('Ignore the chosen classification in simple search'),
1966
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
1967
      '#description' => t('The simple search, which can be executed via the search block,
1968
          will by default search on all classifications. Remove the tick if you want your
1969
          portal to search on the classification selected in the classification browser
1970
          selector.'),
1971
  );
1972

    
1973
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1974
    '#type' => 'textfield',
1975
    '#title' => t('Results per page') . ':',
1976
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1977
    '#description' => t('Number of results to display per page.'),
1978
  );
1979

    
1980
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
1981
  $form['search_settings']['cdm_search_taxa_mode'] = array(
1982
      '#type' => 'checkboxes',
1983
      '#title' => 'Search mode',
1984
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
1985
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
1986
          for the advance search form and the behaviour of the simple search form which always will behave according to the
1987
          defaults set here.',
1988
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
1989
      '#default_value' => $search_mode_default
1990
      );
1991

    
1992
  // --- SEARCH TAXA GALLERY ---- //
1993
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1994
  $collapsed = FALSE;
1995
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1996
  $form_title = 'Taxa Search thumbnails';
1997
  $form_description = 'Search results may show thumbnails. ';
1998
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1999

    
2000
  // Comment @WA: D7 form api does not support reset buttons,
2001
  // so to mimic the D5 reset button we add one like this.
2002
  $form['actions']['reset'] = array(
2003
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2004
    '#weight' => 1000,
2005
  );
2006
  return system_settings_form($form);
2007
}
2008

    
2009
/**
2010
 * @todo document this function.
2011
 */
2012
function cdm_settings_layout_media() {
2013

    
2014
  $form = array();
2015

    
2016
  $form['media_settings'] = array(
2017
    '#type' => 'fieldset',
2018
    '#title' => t('Media settings'),
2019
    '#collapsible' => FALSE,
2020
    '#collapsed' => FALSE,
2021
    '#description' => 'This section covers layout settings for media pages.'
2022
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2023
  );
2024

    
2025
  $form['media_settings']['image_gallery_viewer'] = array(
2026
    '#type' => 'select',
2027
    '#title' => t('Image viewer') . ':',
2028
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2029
    '#options' => array(
2030
      'default' => t('Standard image viewer'),
2031
      'fsi' => t('FSI viewer (requires FSI server!)'),
2032
    ),
2033
  );
2034

    
2035
  // --- MEDIA GALLERY ---- //
2036
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2037
  $form_title = 'Standard viewer';
2038
  $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>';
2039
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2040
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2041

    
2042
  // @WA: D7 form api does not support reset buttons,
2043
  // so to mimic the D5 reset button we add one like this.
2044
  $form['actions']['reset'] = array(
2045
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2046
    '#weight' => 1000,
2047
  );
2048
  return system_settings_form($form);
2049
}
2050

    
2051
/**
2052
 * GEOSERVICE and Map settings.
2053
 */
2054
function cdm_settings_geo($form, &$form_state) {
2055

    
2056
  $current_geoserver_settings = get_edit_map_service_settings();
2057
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2058
  // The default layer must always be enabled
2059
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2060
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2061

    
2062
  $form = array();
2063

    
2064
  $dummy_distribution_query = NULL;
2065
  if($map_distribution['map_type'] != 1){
2066
    // we need to apply a dummy query since the map serice requires for image maps
2067
    // at least as and ad to be defined
2068
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2069
  }
2070
  $form['map_preview'] = array(
2071
      '#type' => 'fieldset',
2072
      '#tree' => FALSE,
2073
      '#title' => t('Map preview'),
2074
      '#collapsible' => FALSE,
2075
      '#description' => 'The preview of the map'
2076
       . ($dummy_distribution_query != null ?
2077
           ' may not be accurate in case if image maps, please check the map display in the taxon pages.':
2078
           '.<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.')
2079
  );
2080
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL,
2081
      array(
2082
          'move' => "this.cdmOpenlayersMap.printInfo",
2083
          '#execute' => "this.cdmOpenlayersMap.printInfo"
2084
      )
2085
  );
2086

    
2087

    
2088
  /*
2089
   * GEO SERVER
2090
   */
2091
  $form['edit_map_server'] = array(
2092
    '#type' => 'fieldset',
2093
    '#tree' => true,
2094
    '#title' => t('EDIT map service'),
2095
    '#collapsible' => TRUE,
2096
    '#collapsed' => TRUE,
2097
    '#description' => t('Configuration and selection of your geo server.
2098
      The Geo Server is responsible for generating the maps.'),
2099
  );
2100

    
2101
  $form['edit_map_server']['base_uri'] = array(
2102
    '#type' => 'select',
2103
    '#title' => t('EDIT map service') . ':',
2104
    '#default_value' => $current_geoserver_settings['base_uri'],
2105
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2106
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2107
  );
2108
  $form['edit_map_server']['version'] = array(
2109
      '#type' => 'select',
2110
      '#title' => t('Version') . ':',
2111
      '#default_value' => $current_geoserver_settings['version'],
2112
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2113
      '#description' => t('The version of the EDIT map services'),
2114
  );
2115

    
2116
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
2117
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
2118
  $form['gmap_api_key'] = array(
2119
      '#type' => 'textfield',
2120
      '#title' => t('Google maps API key') . ':',
2121
      '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
2122
      '#description' => t('If you want to use the Google Maps Layer, a key is
2123
      needed. If you need a key, visit
2124
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
2125
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
2126
      is the default key for the localhost (127.0.0.1).',
2127
      array('!localhostkey' => $localhostkey)),
2128
  );
2129

    
2130

    
2131
  /*
2132
   * MAP SETTINGS
2133
   */
2134

    
2135
  $form[CDM_MAP_DISTRIBUTION] = array(
2136
    '#type' => 'fieldset',
2137
    '#tree' => TRUE,
2138
    '#title' => t('Maps settings'),
2139
    '#collapsible' => TRUE,
2140
    '#collapsed' => TRUE,
2141
    '#description' => t('General configuration for all map types.'),
2142
  );
2143

    
2144
  /*
2145
   * settings for the distribution map are used also for specimens map!!!!
2146
   */
2147

    
2148
  $form[CDM_MAP_DISTRIBUTION]['width'] = array(
2149
    '#type' => 'textfield',
2150
    '#title' => 'Width',
2151
    '#default_value' => $map_distribution['width'],
2152
    '#maxlength' => 4,
2153
    '#size' => 4,
2154
    '#description' => 'Width of the map. To allow OSM baselayers to zoom out to the full extend of the world the map width must be
2155
      a multiple of 256px since the osm tiles from tile.openstreetmap.org have a size of 256px x 256px and frational zoom
2156
      levels are not possible in this case.',
2157
  );
2158
  $form[CDM_MAP_DISTRIBUTION]['height'] = array(
2159
      '#type' => 'textfield',
2160
      '#title' => 'Height',
2161
      '#default_value' => $map_distribution['height'],
2162
      '#maxlength' => 4,
2163
      '#size' => 4,
2164
      '#description' => 'Height of the map. Depending on the chosen base layer you may want to choose the height equal
2165
      to the width or half of the width. Any other aspect ratio is also possible if desired.',
2166
  );
2167

    
2168
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2169
    '#type' => 'textfield',
2170
    '#title' => 'Bounding box',
2171
    '#default_value' => $map_distribution['bbox'],
2172
    '#description' => t('The bounding box (left, bottom, right, top) defines the area to be initially displayed in maps.
2173
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2174
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2175
      <strong>TIP: </strong>You can use the map preview above to choose a bbox from the map. Maybe you need to change the map type to OpeLayers.
2176
      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
2177
      below the map from where you can copy the bbox string.</p>'),
2178
  );
2179

    
2180
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2181
    '#type' => 'checkbox',
2182
    '#title' => 'Display area labels',
2183
    '#default_value' => $map_distribution['show_labels'],
2184
    '#description' => t('The map will show name labels of the areas'),
2185
  );
2186

    
2187
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2188
    '#type' => 'textfield',
2189
    '#title' => 'Map caption',
2190
    '#default_value' => $map_distribution['caption'],
2191
    '#description' => t('The caption will be shown below the map.'),
2192
  );
2193

    
2194
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2195
    '#type' => 'textfield',
2196
    '#title' => 'Distribution layer opacity',
2197
    '#default_value' => $map_distribution['distribution_opacity'],
2198
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
2199
                           fully visible, while a value near to 0.0 will be not much visible.'),
2200
  );
2201

    
2202
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2203
    '#type' => 'radios',
2204
    '#title' => 'Map types',
2205
    '#options' => array(
2206
      1 => "OpenLayers dynamic map viewer",
2207
      0 => "Plain image",
2208
    ),
2209
    '#default_value' => $map_distribution['map_type'],
2210
    '#description' => 'Two different map types are available :
2211
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2212
      which allows zooming and panning. If enabled you can configure the default layer
2213
      (background of your maps) below.</li>
2214
      <li><em>Plain image</em>: The map will be static non interactive
2215
      image.</li></ul>',
2216
  );
2217
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2218

    
2219

    
2220
  // --- Plain Image Settings --- //
2221
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2222
    '#type' => 'fieldset',
2223
    '#title' => 'Plain image map settings',
2224
    '#tree' => TRUE,
2225
    '#collapsible' => TRUE,
2226
    '#collapsed' => $open_layers_is_enabled,
2227
    '#description' => 'The settings in this section are still expertimental
2228
      and can only be used with the EDIT map service version 1.1 or above.',
2229
  );
2230
  $edit_mapserver_version = get_edit_map_service_version_number();
2231
  if ($edit_mapserver_version < 1.1) {
2232
    $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>'
2233
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2234
  }
2235

    
2236
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2237
    '#type' => 'textfield',
2238
    '#title' => 'Background layer',
2239
    '#default_value' => $map_distribution['image_map']['base_layer'],
2240
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2241
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2242
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2243
    )),
2244
  );
2245

    
2246
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2247
    '#type' => 'textfield',
2248
    '#title' => 'Background color',
2249
    '#default_value' => $map_distribution['image_map']['bg_color'],
2250
  );
2251

    
2252
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2253
    '#type' => 'textfield',
2254
    '#title' => 'Background layer style',
2255
     // Only line color by now.
2256
    '#default_value' => $map_distribution['image_map']['layer_style'],
2257
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2258
  );
2259

    
2260
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2261
      '#type' => 'textfield',
2262
      '#title' => 'Projection',
2263
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2264
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2265
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2266
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2267
  );
2268

    
2269

    
2270
  // --- OpenLayers Settings --- //
2271
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2272
    '#type' => 'fieldset',
2273
    '#title' => 'OpenLayers settings',
2274
    '#tree' => TRUE,
2275
    '#collapsible' => TRUE,
2276
    '#collapsed' => !$open_layers_is_enabled,
2277
    '#description' => '',
2278
  );
2279

    
2280

    
2281
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2282
      '#type' => 'checkbox',
2283
      '#title' => 'Display outside max extent',
2284
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2285
      '#description' => t('Allows the map to display parts of the layers which are outside
2286
         the max extent if the aspect ratio of the map and of the baselayer
2287
         are not equal.'),
2288
  );
2289

    
2290

    
2291
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2292
      '#type' => 'checkbox',
2293
      '#title' => 'Show Layer Switcher',
2294
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2295
      '#description' => 'The Layer Switcher control displays a table of contents
2296
      for the map.  This allows the user interface to switch between
2297
      base layers and to show or hide overlays.  By default the switcher is
2298
      shown minimized on the right edge of the map, the user may expand it
2299
      by clicking on the handle.',
2300
  );
2301

    
2302
  if (!$open_layers_is_enabled) {
2303
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2304
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2305
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2306
  }
2307

    
2308
  $baselayer_options = array(
2309
    /*
2310
   NOTICE: must correspond to the layers defined in
2311
   js/openlayers_,ap.js#getLayersByName()
2312
   */
2313
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
2314
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
2315
    // all others EPSG:900913
2316
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
2317
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2318
    'mapnik' => 'OpenStreetMap',
2319
    'mapquest_open' => "MapQuest",
2320
    'mapquest_sat' => "MapQuest Sattelite",
2321
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2322
    'gmap' => 'Google Streets',
2323
    'gsat' => 'Google Satellite',
2324
    'ghyb' => 'Google Hybrid',
2325
//     'veroad' => 'Virtual Earth Roads',
2326
//     'veaer' => 'Virtual Earth Aerial',
2327
//     'vehyb' => 'Virtual Earth Hybrid',
2328
    // 'yahoo' => 'Yahoo Street',
2329
    // 'yahoosat' => 'Yahoo Satellite',
2330
    // 'yahoohyb' => 'Yahoo Hybrid',
2331
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2332
  );
2333

    
2334
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2335
    '#type' => 'checkboxes_preferred',
2336
    '#title' => 'Base Layers',
2337
    '#options' => $baselayer_options,
2338
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2339
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2340
  );
2341

    
2342
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2343
      '#type' => 'fieldset',
2344
      '#title' => 'Custom WMS base layer',
2345
      '#tree' => TRUE,
2346
      '#collapsible' => FALSE,
2347
      '#collapsed' => FALSE,
2348
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2349
  );
2350

    
2351
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2352
      '#type' => 'textfield',
2353
      '#title' => 'Layer name',
2354
      // Only line color by now.
2355
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2356
      '#description' => 'A arbitrary name for the layer.',
2357
  );
2358
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2359
      '#type' => 'textfield',
2360
      '#title' => 'WMS url',
2361
      // Only line color by now.
2362
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2363
      '#description' => 'Base url for the WMS (e.g.  http://wms.jpl.nasa.gov/wms.cgi)'
2364
  );
2365
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2366
      '#type' => 'textarea',
2367
      '#title' => 'WMS parameters',
2368
      '#element_validate' => array('form_element_validate_json'),
2369
      // Only line color by now.
2370
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2371
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2372
<pre> {
2373
  "Layers": "topp:em_tiny_jan2003",
2374
  "Format": "image/png",
2375
  "BGCOLOR": "0xe0faff"
2376
}
2377
</pre>'
2378
  );
2379
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2380
      '#type' => 'textfield',
2381
      '#title' => 'Projection',
2382
      // Only line color by now.
2383
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2384
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2385
  );
2386
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2387
      '#type' => 'textfield',
2388
      '#maxlength' => 256,
2389
      '#title' => 'proj4js definition',
2390
      // Only line color by now.
2391
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2392
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2393
            The definitions for
2394
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2395
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2396
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2397
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2398
            choose to display the proj4js definition string.
2399
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2400
            <pre>
2401
+a         Semimajor radius of the ellipsoid axis
2402
+alpha     ? Used with Oblique Mercator and possibly a few others
2403
+axis      Axis orientation (new in 4.8.0)
2404
+b         Semiminor radius of the ellipsoid axis
2405
+datum     Datum name (see `proj -ld`)
2406
+ellps     Ellipsoid name (see `proj -le`)
2407
+k         Scaling factor (old name)
2408
+k_0       Scaling factor (new name)
2409
+lat_0     Latitude of origin
2410
+lat_1     Latitude of first standard parallel
2411
+lat_2     Latitude of second standard parallel
2412
+lat_ts    Latitude of true scale
2413
+lon_0     Central meridian
2414
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
2415
+lon_wrap  Center longitude to use for wrapping (see below)
2416
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
2417
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
2418
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
2419
+pm        Alternate prime meridian (typically a city name, see below)
2420
+proj      Projection name (see `proj -l`)
2421
+south     Denotes southern hemisphere UTM zone
2422
+to_meter  Multiplier to convert map units to 1.0m
2423
+towgs84   3 or 7 term datum transform parameters (see below)
2424
+units     meters, US survey feet, etc.
2425
+vto_meter vertical conversion to meters.
2426
+vunits    vertical units.
2427
+x_0       False easting
2428
+y_0       False northing
2429
+zone      UTM zone
2430
            </pre>
2431
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
2432
  );
2433
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
2434
      '#type' => 'textfield',
2435
      '#title' => 'Maximum extent',
2436
      // Only line color by now.
2437
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
2438
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
2439
  );
2440
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
2441
      '#type' => 'textfield',
2442
      '#title' => 'Units',
2443
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
2444
      '#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.'
2445
  );
2446

    
2447
  /*
2448
   * Map Legend
2449
   */
2450
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2451
    '#type' => 'fieldset',
2452
    '#title' => 'Map legend',
2453
    '#tree' => TRUE,
2454
    '#collapsible' => TRUE,
2455
    '#collapsed' => TRUE,
2456
    '#description' => 'Configure the maps legend.',
2457
  );
2458

    
2459
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2460
    '#type' => 'checkbox',
2461
    '#title' => 'Display a map legend',
2462
    '#default_value' => $map_distribution['legend']['show'],
2463
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2464
  );
2465

    
2466
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2467
    '#type' => 'textfield',
2468
    '#title' => 'Legend opacity',
2469
    '#default_value' => $map_distribution['legend']['opacity'],
2470
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2471
                         to 0.0 will be not much visible.',
2472
  );
2473

    
2474
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2475
    '#type' => 'textfield',
2476
    '#title' => 'Font size',
2477
    '#default_value' => $map_distribution['legend']['font_size'],
2478
    '#description' => 'Font size in pixels.',
2479
  );
2480

    
2481
  $fontStyles = array(
2482
    0 => "plane",
2483
    1 => "italic",
2484
  );
2485
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2486
    '#type' => 'select',
2487
    '#title' => 'Available font styles',
2488
    '#default_value' => $map_distribution['legend']['font_style'],
2489
    '#options' => $fontStyles,
2490
    '#description' => 'Select a font style for the map legend.',
2491
  );
2492

    
2493
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2494
    '#type' => 'textfield',
2495
    '#title' => 'Icon width',
2496
    '#default_value' => $map_distribution['legend']['icon_width'],
2497
    '#description' => 'Legend icon width in pixels.',
2498
  );
2499
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2500
    '#type' => 'textfield',
2501
    '#title' => 'Icon height',
2502
    '#default_value' => $map_distribution['legend']['icon_height'],
2503
    '#description' => 'Legend icon height in pixels.',
2504
  );
2505

    
2506
  // @WA: D7 form api does not support reset buttons,
2507
  // so to mimic the D5 reset button we add one like this.
2508
  $form['actions']['reset'] = array(
2509
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2510
    '#weight' => 1000,
2511
  );
2512

    
2513
  return system_settings_form($form);
2514
}
2515

    
2516
/**
2517
 * @todo document this function.
2518
 */
2519
function cdm_settings_cache() {
2520

    
2521
  $form = array();
2522

    
2523
  $form['cache_settings'] = array(
2524
    '#type' => 'fieldset',
2525
    '#title' => t('Cache Settings'),
2526
    '#collapsible' => FALSE,
2527
    '#collapsed' => FALSE,
2528
    '#description' => t('<p>When caching is enabled all single taxon sites are
2529
      stored in an internal drupal cache doing the portal response of taxa pages
2530
      faster. This is possible because the sites are loaded from the cache and
2531
      are not created from scratch.</p>'),
2532
  );
2533

    
2534
  $form['cache_settings']['cdm_webservice_cache'] = array(
2535
    '#type' => 'checkbox',
2536
    '#title' => t('<strong>Enable caching</strong>'),
2537
    '#options' => cdm_help_general_cache(),
2538
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2539
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2540
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2541
       application the changes will be not visible till the cache is erased.
2542
       Therefore developers should deactived this feature when they are working
2543
       on the CDM Dataportal Module.</p>'),
2544
  );
2545

    
2546
  $form['cache_settings']['cdm_run_cache'] = array(
2547
    '#markup' => cdm_view_cache_site(),
2548
  );
2549

    
2550
  // @WA: D7 form api does not support reset buttons,
2551
  // so to mimic the D5 reset button we add one like this.
2552
  $form['actions']['reset'] = array(
2553
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2554
    '#weight' => 1000,
2555
  );
2556
  return system_settings_form($form);
2557
}
2558

    
2559
/**
2560
 * Walk and cache all taxon pages.
2561
 */
2562
function cdm_view_cache_site() {
2563

    
2564
  $out = '';
2565

    
2566
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2567

    
2568
  $request_params = array();
2569
  $request_params['class'] = "Taxon";
2570

    
2571
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2572
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2573
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2574

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

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

    
2584
  // Comment @WA: A form within a form is not valid html and not needed here.
2585
  // Also, it would be recommended just to include this part of the form in the
2586
  // rest of the form array in cdm_settings_cache().
2587
  // $out .= '<form id="cache_site">';
2588
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2589
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2590
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2591
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2592
  // $out .= '</form>';
2593
  $out .= '</div>';
2594
  /*
2595
  foreach($taxonPager->records as $taxon){
2596
    cdm_dataportal_taxon_view($uuid);
2597
  }
2598
  */
2599
  return $out;
2600
}
2601

    
2602

    
2603
function cdm_settings_layout_taxon_submit($form, &$form_state){
2604
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2605
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2606
    if(is_object($file)){
2607
      $file->status = FILE_STATUS_PERMANENT;
2608
      file_save($file);
2609
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2610
    }
2611
  }
2612
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2613
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2614
    // we first need to set the variable to persist the changes setting
2615
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
2616
    menu_rebuild();
2617
  }
2618
}
2619

    
2620
function cdm_settings_layout_search_submit($form, &$form_state){
2621
  // the visibility of media thumbnails also affects the ui of the search results
2622
  // so reset the according session variable
2623
  //    1. in order to give the user immediate
2624
  //       feedback on potential setting changes
2625
  //    2. let refresh the default if it has changed
2626
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2627
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
2628
  }
2629
}
2630

    
2631
/**
2632
 * Form validation handler for cdm_settings_general
2633
 *
2634
 * @param $form
2635
 * @param $form_state
2636
 */
2637
function cdm_settings_general_validate($form, &$form_state) {
2638

    
2639
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2640
    $form_state['values']['cdm_webservice_url'] .= '/';
2641
  }
2642

    
2643
}
2644

    
2645
/**
2646
 * Form submit handler for settings general.
2647
 *
2648
 * tasks performed:
2649
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2650
 *
2651
 * @param $form
2652
 * @param $form_state
2653
 */
2654
function cdm_settings_general_submit($form, &$form_state){
2655
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2656
  unset($_SESSION['cdm']['taxonomictree_uuid']);
2657
}
2658

    
2659
/**
2660
 * Form validation handler for cdm_settings_cache
2661
 */
2662
function cdm_settings_cache_validate($form, &$form_state) {
2663
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2664
    cache_clear_all(NULL, 'cache_cdm_ws');
2665
    // Better clear secref_cache since I can not be sure if the cache has not
2666
    // be used during this response.
2667
    cdm_api_secref_cache_clear();
2668
  }
2669

    
2670
}
2671

    
2672
/**
2673
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
2674
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
2675
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
2676
 *  - version: the version, e.g.: v1.1
2677
 *
2678
 * @return array
2679
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
2680
 */
2681
function get_edit_map_service_settings() {
2682

    
2683
  $settings = variable_get('edit_map_server', array(
2684
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
2685
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
2686
      )
2687
  );
2688

    
2689
  return $settings;
2690
}
2691

    
2692
/**
2693
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2694
 *
2695
 * @return string
2696
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2697
 */
2698
function get_edit_map_service_full_uri() {
2699
  $settings = get_edit_map_service_settings();
2700
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
2701
}
2702

    
2703

    
2704
/**
2705
 * Returns the version number of the currently selected edit mapserver as a float
2706
 *
2707
 * @return float
2708
 *   The version number of the currently selected edit mapserver as a float.
2709
 *   Returns 0 on error.
2710
 */
2711
function get_edit_map_service_version_number() {
2712

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

    
2715
  $settings = get_edit_map_service_settings();
2716
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
2717
  if (isset($matches[1])) {
2718
    // Convert string to float.
2719
    $version = 1 + $matches[1][0] - 1;
2720
    return $version;
2721
  }
2722
  else {
2723
    // Report error.
2724
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
2725
        array(
2726
          '!version' => $settings['version'],
2727
          'warning')
2728
        )
2729
      );
2730
    return 0;
2731
  }
2732
}
2733

    
2734
/**
2735
 * Returns the array of selected items in a options array
2736
 *
2737
 * @param array $options
2738
 *   An options array as generated by a form element like checkoxes, select ...,
2739
 */
2740
function get_selection($options) {
2741
  $selection = array();
2742
  foreach ($options as $key=>$val) {
2743
    if (!empty($val)) {
2744
      $selection[] = $val;
2745
    }
2746
  }
2747
  return $selection;
2748
}
2749

    
2750

    
2751
/**
2752
 * Implements hook_element_info().
2753
 *
2754
 * Allows modules to declare their own Form API element types and specify their default values.
2755
 *
2756
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
2757
 */
2758
function cdm_dataportal_element_info() {
2759
  $type['checkboxes_preferred'] = array(
2760
    '#input' => TRUE,
2761
    '#process' => array('checkboxes_preferred_expand'),
2762
    '#after_build' => array('checkboxes_preferred_after_build'),
2763
    '#theme' => array('checkboxes_preferred'),
2764
    // '#theme_wrapper' => array('form_element'),
2765
  );
2766
  return $type;
2767
}
2768

    
2769
/**
2770
 * #process callback function for the custom form element type 'checkbox_preferred'
2771
 *
2772
 *
2773
 */
2774
function checkboxes_preferred_expand($element, &$form_state, $form) {
2775

    
2776
  // First of all create checkboxes for each of the elements
2777
  $element = form_process_checkboxes($element);
2778

    
2779
  // compose the element name
2780
  $parents = array();
2781
  array_deep_copy($element['#parents'], $parents);
2782
  $parents[count($parents) -1 ] .= '_preferred';
2783
  $element_name = $parents[0];
2784
  for ($i=1; $i < count($parents); $i++){
2785
    $element_name .= '[' . $parents[$i] . ']';
2786
  }
2787

    
2788
  $children = element_children($element);
2789

    
2790
  $element['table_start'] = array(
2791
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
2792
    '#weight' => -1,
2793
  );
2794

    
2795
  // prepare first part each of the table rows which contains the row label
2796
  $weight = 0;
2797
  foreach ($children as $key) {
2798
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
2799
    $element[$key]['#weight'] = $weight;
2800
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
2801
    $element[$key]['#suffix'] = '</td>';
2802
    unset($element[$key]['#title']);
2803
    $weight += 2;
2804
  }
2805
  $weight = 0;
2806

    
2807
  // add a radio button to each of the checkboxes, the
2808
  // check boxes have already been created at the beginning
2809
  // of this function
2810
  if (count($element['#options']) > 0) {
2811
    foreach ($element['#options'] as $key => $choice) {
2812
      if (!isset($element[$key . '_preferred'])) {
2813
        $element[$key . '_preferred'] = array(
2814
          '#type' => 'radio',
2815
          '#name' => $element_name,
2816
          '#return_value' => check_plain($key),
2817
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
2818
          '#attributes' => $element['#attributes'],
2819
          '#parents' => $element['#parents'],
2820
          // '#spawned' => TRUE,
2821
          '#weight' => $weight + 1,
2822
          '#prefix' => '<td>',        // add a prefix to start a new table cell
2823
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
2824
        );
2825
      }
2826
      $weight += 2;
2827
    }
2828
  }
2829

    
2830
  // end the table
2831
  $element['table_end'] = array(
2832
    '#markup' => '</table>',
2833
    '#weight' => $weight++,
2834
  );
2835

    
2836
  return $element;
2837
}
2838

    
2839
/**
2840
 * Theme function for the custom form field 'checkboxes_preferred'.
2841
 */
2842
function theme_checkboxes_preferred($variables) {
2843
  $element = $variables['element'];
2844
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
2845
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
2846
  $out .= drupal_render_children($element);
2847
  $out .= '<div class="description">' . $element['#description'] . '</div>';
2848
  $out .= '</div>';
2849
  return $out;
2850
}
2851

    
2852
/**
2853
 * Callback for checkboxes preferred for widget which will
2854
 * be called after the form or element is built. The call
2855
 * back is configured in the form element by setting it as
2856
 * #after_build parameter.
2857
 *
2858
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
2859
 *
2860
 * @param $element
2861
 *   Nested array of form elements that comprise the form.
2862
 * @param $form_state
2863
 *   A keyed array containing the current state of the form.
2864
 *   This includes the current persistent storage data for the form.
2865
 *   Additional information, like the sanitized $_POST data,
2866
 *   is also accumulated here in $form_state['input']
2867
 *
2868
 * @return the modified form array
2869
 */
2870
function checkboxes_preferred_after_build($element, &$form_state) {
2871

    
2872
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
2873

    
2874
  if ($_POST && count($_POST) > 0) {
2875
    // TODO use  $form_state['input'] instead of POST !!!
2876
    // First pass of form processing.
2877
    $parents = array();
2878
    array_deep_copy($element['#parents'], $parents);
2879
    $parents[count($parents) - 1] .= '_preferred';
2880
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
2881
    $element['#value']['PREFERRED'] = $preferred_layer;
2882
//     $form_state[$parent_id] = $element['#value'];
2883
//     $form_state['values']['baselayers'] = $element['#value'];
2884
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
2885
    $form_state_element_values = $element['#value'];
2886
  }
2887
  else {
2888
    // Second pass of form processing.
2889
    $preferred_layer = $element['#value']['PREFERRED'];
2890
  }
2891

    
2892
  // Also set the chosen value (not sure if this is good Drupal style ....).
2893
  foreach ($children = element_children($element) as $key) {
2894
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
2895
      $element[$key]['#value'] = $preferred_layer;
2896
    }
2897
  }
2898
  // The default layer must always be enabled.
2899
  $element[$preferred_layer]['#value'] = $preferred_layer;
2900

    
2901
  return $element;
2902
}
2903

    
2904
function radios_prepare_options_suffix(&$elements){
2905

    
2906
  $childrenKeys = element_children($elements);
2907
  foreach($childrenKeys as $key){
2908
    if(!is_array($elements[$key]['#theme_wrappers'])){
2909
      $elements[$key]['#theme_wrappers'] = array();
2910
    }
2911
    if(isset($elements['#options_suffixes'][$key])){
2912
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
2913
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
2914
    }
2915
  }
2916
  return $elements;
2917

    
2918
}
2919

    
2920
/**
2921
 * TODO
2922
 * @param unknown $variables
2923
 */
2924
function theme_radio_options_suffix($variables) {
2925
  $element = $variables['element'];
2926
  if(isset($element['#options_suffix'])) {
2927
    $element['#children'] .= $element['#options_suffix'];
2928
  }
2929
  return $element['#children'];
2930
}
2931

    
2932

    
2933
/**
2934
 * Element validate callback for text field and arrays containing json.
2935
 *
2936
 * @param $element
2937
 *   The form element to validate
2938
 * @param $form_state
2939
 *   A keyed array containing the current state of the form.
2940
 * @param $form
2941
 *   Nested array of form elements that comprise the form.
2942
 */
2943
function form_element_validate_json($element, &$form_state, $form) {
2944
   if (!empty($element['#value'])) {
2945
     json_decode($element['#value']);
2946
     if(json_last_error() != JSON_ERROR_NONE){
2947
       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/'));
2948
     }
2949
   }
2950
}
2951

    
2952
/**
2953
 * Form submission handler for textareas and textfields containing JSON.
2954
 *
2955
 * The contained JSON will be converted into an php array
2956
 * or object and will be stored in the variables as such.
2957
 *
2958
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2959
 *
2960
 * @param $form
2961
 *   Nested array of form elements that comprise the form.
2962
 * @param $form_state
2963
 *   A keyed array containing the current state of the form.
2964
 *
2965
 */
2966
function submit_json_as_php_array($form, &$form_state) {
2967
  if (is_array($form['#json_elements'])) {
2968
    foreach ($form['#json_elements'] as $element){
2969
      if (trim($form_state['values'][$element])) {
2970
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
2971
      } else {
2972
        $form_state['values'][$element] = NULL;
2973
      }
2974
    }
2975
  }
2976
}
(14-14/14)