Project

General

Profile

Download (117 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?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 26fb3778 Andreas Kohlbecker
define ('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
11 6657531f Andreas Kohlbecker
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 f19f47fa Andreas Kohlbecker
define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
33 5611d467 Andreas Kohlbecker
define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
34
  'enabled' => 1,
35 800ff2b0 Andreas Kohlbecker
  'key_format' => 'ALPHA'
36 5611d467 Andreas Kohlbecker
)));
37 f19f47fa Andreas Kohlbecker
38 6657531f Andreas Kohlbecker
/* taxonRelationshipTypes */
39
define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
40
41 6280e639 Andreas Kohlbecker
42 ba706bf0 Andreas Kohlbecker
/* ---- MAP SETTING CONSTANTS ---- */
43 f19f47fa Andreas Kohlbecker
/**
44
 * @var array of URIs eg. http://edit.africamuseum.be"
45
 *   An options array
46 ba706bf0 Andreas Kohlbecker
 */
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 f19f47fa Andreas Kohlbecker
define('EDIT_MAPSERVER_VERSION', serialize(
60 ba706bf0 Andreas Kohlbecker
    array(
61
      'v1' => 'v1' ,
62
      'v1.1' => 'v1.1',
63 d7abe39c Andreas Kohlbecker
      'v1.2_dev' => 'v1.2_dev',
64
      'v1.2' => 'v1.2',
65 4bef194f Andreas Kohlbecker
      'v1.3_dev' => 'v1.3_dev',
66
      'v1.4_dev' => 'v1.4_dev'
67 f19f47fa Andreas Kohlbecker
    )
68 ba706bf0 Andreas Kohlbecker
  )
69
);
70
define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
71 d7abe39c Andreas Kohlbecker
define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
72 6657531f Andreas Kohlbecker
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 ba706bf0 Andreas Kohlbecker
define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
84 9c92cd84 Andreas Kohlbecker
define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
85
define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
86
    array(
87 0832bbb6 Andreas Kohlbecker
        'show' => 0,
88 9c92cd84 Andreas Kohlbecker
        'maxextend' => 184,
89 053a92ec Andreas Kohlbecker
        'media_uri_query' => '',
90 9c92cd84 Andreas Kohlbecker
        'custom_placeholder_image_on' => 0,
91
        'custom_placeholder_image_fid' => ''
92
    )
93
  )
94
);
95 ba706bf0 Andreas Kohlbecker
96 c6ee8193 Andreas Kohlbecker
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
97
98 6657531f Andreas Kohlbecker
/**
99 b54cbda1 Andreas Kohlbecker
 * Returns the array of implemented taxon page tabs.
100
 * The array has fixed integer keys which must not be changed.
101 6657531f Andreas Kohlbecker
 */
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 b54cbda1 Andreas Kohlbecker
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
113
  array('general' => '-3', 'synonymy' => '-2', 'images' => '0', 'specimens' => '1', 'keys' => '3')
114
));
115
116 6657531f Andreas Kohlbecker
$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 0f5f1c12 Andreas Kohlbecker
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
134
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
135 f19f47fa Andreas Kohlbecker
  array(
136
      'ZoologicalName' => array(
137 501347df Andreas Kohlbecker
        'namePart' => array('name' => TRUE),
138 f19f47fa Andreas Kohlbecker
        '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 0f5f1c12 Andreas Kohlbecker
      'BotanicalName'=> array(
145
        'namePart' => array('name' => TRUE),
146
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
147
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
148 51b04faf Andreas Kohlbecker
        'referenceYearPart' => array('reference.year' => TRUE),
149 0f5f1c12 Andreas Kohlbecker
        'statusPart' => array('status' => TRUE),
150
        'descriptionPart' => array('description' => TRUE),
151 f19f47fa Andreas Kohlbecker
      ),
152
     '#DEFAULT' => array(
153
        'namePart' => array(
154
            'name' => TRUE
155 501347df Andreas Kohlbecker
        ),
156
        'nameAuthorPart' => array(
157
            'name' => TRUE,
158
            'authors' => TRUE
159 f19f47fa Andreas Kohlbecker
        ),
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 0f5f1c12 Andreas Kohlbecker
    )
174
  )
175
);
176 f19f47fa Andreas Kohlbecker
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
177 0f5f1c12 Andreas Kohlbecker
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
178 f19f47fa Andreas Kohlbecker
   array (
179 5972ca1a Andreas Kohlbecker
     '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 51b04faf Andreas Kohlbecker
       'homonym'=> array(
189
            'nameAuthorPart' => array('#uri' => TRUE),
190
            'referenceYearPart' => TRUE,
191
        ),
192 5972ca1a Andreas Kohlbecker
      '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 f19f47fa Andreas Kohlbecker
       )
200 0f5f1c12 Andreas Kohlbecker
    )
201
));
202
203 6280e639 Andreas Kohlbecker
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 6657531f Andreas Kohlbecker
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 30f78c59 Andreas Kohlbecker
/**
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 6657531f Andreas Kohlbecker
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
244 30f78c59 Andreas Kohlbecker
/**
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 6657531f Andreas Kohlbecker
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
262 bfb2b81a Andreas Kohlbecker
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
263 6657531f Andreas Kohlbecker
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
264
265 aa63dfb4 Andreas Kohlbecker
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 a950f2f9 Andreas Kohlbecker
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 cc3c9807 Andreas Kohlbecker
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 2bbc28c8 Andreas Kohlbecker
     'custom_wms_base_layer' => array(
310
            'name' => NULL,
311
            'url' => NULL,
312
            'params' =>  NULL,
313
            'projection' => NULL,
314 e3026d72 Andreas Kohlbecker
            'proj4js_def' => NULL,
315 2bbc28c8 Andreas Kohlbecker
            'max_extent' => NULL,
316
            'units' => NULL
317
     ),
318
    'show_layer_switcher' => TRUE,
319
    'display_outside_max_extent' => FALSE
320 cc3c9807 Andreas Kohlbecker
  ),
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 5611d467 Andreas Kohlbecker
 * 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 b54cbda1 Andreas Kohlbecker
 * are just appended to the result array.
337
 *
338 cc3c9807 Andreas Kohlbecker
 * @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 5611d467 Andreas Kohlbecker
 *     Unserialization is cared for if necessary
343 cc3c9807 Andreas Kohlbecker
 * @return array
344 5611d467 Andreas Kohlbecker
 *     The merged array as returned by drupal_array_merge_deep()
345 cc3c9807 Andreas Kohlbecker
 */
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 b54cbda1 Andreas Kohlbecker
    $result = drupal_array_merge_deep($default, $variable);
354
    return $result;
355 cc3c9807 Andreas Kohlbecker
}
356
357 6657531f Andreas Kohlbecker
/**
358
 * @todo document this function.
359
 */
360
function getGallerySettings($gallery_config_form_name) {
361 cc3c9807 Andreas Kohlbecker
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
362 6657531f Andreas Kohlbecker
}
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 22f5e82d Andreas Kohlbecker
  }
397 6657531f Andreas Kohlbecker
}
398
399 22f5e82d Andreas Kohlbecker
400 f3a04cfa Andreas Kohlbecker
  /**
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 abacccbf Andreas Kohlbecker
   * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
408 f3a04cfa Andreas Kohlbecker
   * '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
   *    - link_to_reference: boolean,
423
   *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
424
   *    - link_to_name_used_in_source": boolean
425
   *        whether to show name is source information as link which will point to the according name page
426
   *    - sources_as_content (boolean)
427
   *        TRUE:
428 159cd9bb Andreas Kohlbecker
   *          1. If element is of the CDM type TextData and the text is not empty the source references will be
429 44d445c0 Andreas Kohlbecker
   *             appended in brackets like "text (source references)". If the original source has name in source
430
   *             information it will be appended to the citation string,
431
   *             like : "(citation, as name in source; citation, as name in source)"
432
   *          2. if the text of the TextData is empty, the original source citations are the only content
433
   *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
434
   *             prepended to the citation string like: "name in source: citation"
435 f3a04cfa Andreas Kohlbecker
   *        FALSE:
436 dcf17487 Andreas Kohlbecker
   *          Original sources are put into the bibliography(=references) pseudo feature block. If the original source
437 159cd9bb Andreas Kohlbecker
   *          citations are the only content, the resulting feature block content would only consist of footnotes.
438
   *          In this case the display of the respective feature block is suppressed.
439 dcf17487 Andreas Kohlbecker
   *          TODO if the bibliography is not enabled the sources will be treated as footnotes like annotations,
440
   *               in future however they will in this case be shown in a separate references section for each
441
   *               feature block.
442 f3a04cfa Andreas Kohlbecker
   *    - sources_as_content_to_bibliography  (boolean)
443
   *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
444 159cd9bb Andreas Kohlbecker
   *        in the bibliography.
445 f3a04cfa Andreas Kohlbecker
   *    - sort_elements
446
   *        whether and how to sort the elements
447 dcf17487 Andreas Kohlbecker
   *        possible values are the constants SORT_ASC, SORT_DESC, NULL,
448
   *        some feature types (Distribution) also support: SORT_HIERARCHICAL (TODO option to exclude levels)
449 f3a04cfa Andreas Kohlbecker
   *    - element_tag
450
   *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
451
   *        possible values are span | div
452
   *    - special: array()
453
   *        an array with further settings, this field can be used for special
454
   *        settings for specialized rendering like for distributions
455
   *  }
456
   *
457
   */
458
  function get_feature_block_settings($feature_uuid = 'DEFAULT'){
459
    // the default must conform to the default parameter values of
460
    // compose_cdm_feature_block_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
461
    // theme_cdm_descriptionElementTextData() : asListElement = NULL
462
463
    // see #3257 (implement means to define the features to show up in the taxonprofile and in the specimen descriptions)
464
465 6776a5bc Andreas Kohlbecker
    // only needed as final option, when the settings are not having a default
466 f3a04cfa Andreas Kohlbecker
    $default = array(
467 6776a5bc Andreas Kohlbecker
      'DEFAULT' => array(
468
        'as_list' => 'ul',
469
        'link_to_reference' => FALSE,
470
        'link_to_name_used_in_source' => TRUE,
471
        'sources_as_content' => TRUE,
472
        'sources_as_content_to_bibliography' => FALSE,
473
        'sort_elements' => NULL,
474
        'glue' => '',
475
        'element_tag'=> NULL
476
      )
477
    );
478
479
    // will be used as preset in the settings
480
    $other_themes_default = array(
481 f3a04cfa Andreas Kohlbecker
      'DEFAULT' => array(
482
        'as_list' => 'ul',
483
        'link_to_reference' => FALSE,
484
        'link_to_name_used_in_source' => TRUE,
485
        'sources_as_content' => TRUE,
486
        'sources_as_content_to_bibliography' => FALSE,
487 dcf17487 Andreas Kohlbecker
        'sort_elements' => NULL,
488 f3a04cfa Andreas Kohlbecker
        'glue' => '',
489
        'element_tag'=> NULL
490
      ),
491
      UUID_CITATION => array(
492
        'as_list' => 'div',
493
        'link_to_reference' => FALSE,
494
        'link_to_name_used_in_source' => FALSE,
495
        'sources_as_content' => TRUE,
496
        'sources_as_content_to_bibliography' => FALSE,
497 dcf17487 Andreas Kohlbecker
        'sort_elements' => SORT_ASC,
498 f3a04cfa Andreas Kohlbecker
        'glue' => '',
499
        'element_tag'=> 'div'
500 dcf17487 Andreas Kohlbecker
      ),
501
      UUID_DISTRIBUTION => array(
502
        'as_list' => 'div', // currently ignored
503
        'link_to_reference' => FALSE,
504
        'link_to_name_used_in_source' => FALSE,
505
        'sources_as_content' => FALSE,
506
        'sources_as_content_to_bibliography' => FALSE,
507 a009927b Andreas Kohlbecker
        'sort_elements' => NULL, // will cause ...
508 dcf17487 Andreas Kohlbecker
        'glue' => '',
509
        'element_tag'=> 'div'
510
      ),
511 f3a04cfa Andreas Kohlbecker
    );
512
513
    $cichorieae_default = array(
514
      'DEFAULT' => array(
515
        'as_list' => 'div',
516
        'link_to_reference' => TRUE,
517
        'link_to_name_used_in_source' => TRUE,
518
        'sources_as_content' => TRUE,
519
        'sources_as_content_to_bibliography' => FALSE,
520 dcf17487 Andreas Kohlbecker
        'sort_elements' => NULL,
521 f3a04cfa Andreas Kohlbecker
        'glue' => '',
522
        'element_tag'=> 'div'
523
      ),
524
      UUID_CITATION => array(
525
        'as_list' => 'div',
526
        'link_to_reference' => FALSE,
527
        'link_to_name_used_in_source' => FALSE,
528
        'sources_as_content' => TRUE,
529
        'sources_as_content_to_bibliography' => FALSE,
530 dcf17487 Andreas Kohlbecker
        'sort_elements' => SORT_ASC,
531 f3a04cfa Andreas Kohlbecker
        'glue' => '',
532
        'element_tag'=> 'div'
533
      ),
534
      UUID_CHROMOSOMES_NUMBERS => array(
535
        'as_list' => 'ul',
536
        'link_to_reference' => TRUE,
537
        'link_to_name_used_in_source' => TRUE,
538
        'sources_as_content' => TRUE,
539
        'sources_as_content_to_bibliography' => FALSE,
540 dcf17487 Andreas Kohlbecker
        'sort_elements' => NULL,
541 f3a04cfa Andreas Kohlbecker
        'glue' => '',
542
        'element_tag'=> 'div'
543
      ),
544
      UUID_CHROMOSOMES => array(
545
        'as_list' => 'ul',
546
        'link_to_reference' => FALSE,
547
        'link_to_name_used_in_source' => TRUE,
548
        'sources_as_content' => TRUE,
549
        'sources_as_content_to_bibliography' => FALSE,
550 dcf17487 Andreas Kohlbecker
        'sort_elements' => NULL,
551 f3a04cfa Andreas Kohlbecker
        'glue' => '',
552
        'element_tag'=> 'div'
553
      ),
554
    );
555
556
    $palmweb_default = array(
557
      'DEFAULT' => array(
558
        'as_list' => 'ul',
559
        'link_to_reference' => TRUE,
560
        'link_to_name_used_in_source' => TRUE,
561
        'sources_as_content' => TRUE,
562
        'sources_as_content_to_bibliography' => TRUE,
563 dcf17487 Andreas Kohlbecker
        'sort_elements' => NULL,
564 f3a04cfa Andreas Kohlbecker
        'glue' => '',
565
        'element_tag'=> NULL
566
      ),
567
      UUID_CITATION => array(
568
        'as_list' => 'ul',
569
        'link_to_reference' => TRUE,
570
        'link_to_name_used_in_source' => TRUE,
571 159cd9bb Andreas Kohlbecker
        'sources_as_content' => FALSE,
572 f3a04cfa Andreas Kohlbecker
        'sources_as_content_to_bibliography' => TRUE,
573 dcf17487 Andreas Kohlbecker
        'sort_elements' => SORT_ASC,
574 f3a04cfa Andreas Kohlbecker
        'glue' => '',
575
        'element_tag'=> 'div'
576 a009927b Andreas Kohlbecker
      ),
577
      UUID_DISTRIBUTION => array(
578
        'as_list' => 'div', // currently ignored
579
        'link_to_reference' => TRUE,
580
        'link_to_name_used_in_source' => TRUE,
581
        'sources_as_content' => TRUE, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
582
        'sources_as_content_to_bibliography' => TRUE,
583
        'sort_elements' => NULL, // will cause ...
584
        'glue' => '',
585
        'element_tag'=> 'div'
586
      ),
587 f3a04cfa Andreas Kohlbecker
    );
588
589 6776a5bc Andreas Kohlbecker
    $cyprus_default = $cichorieae_default;
590
    $cyprus_default[UUID_DISTRIBUTION ]  =  array(
591
      'as_list' => 'div', // currently ignored
592
      'link_to_reference' => FALSE,
593
      'link_to_name_used_in_source' => FALSE,
594
      'sources_as_content' => FALSE,
595
      'sources_as_content_to_bibliography' => FALSE,
596
      'sort_elements' => NULL, // will cause ...
597
      'glue' => '',
598
      'element_tag'=> 'div'
599
    );
600
601 f3a04cfa Andreas Kohlbecker
    $default_theme = variable_get('theme_default', NULL);
602
603
    switch ($default_theme){
604
      case 'garland_cichorieae':
605 6776a5bc Andreas Kohlbecker
        $settings_for_theme = $cichorieae_default;
606
        break;
607 f3a04cfa Andreas Kohlbecker
      case 'cyprus':
608
        // cyprus: no longer used in production,
609
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
610 6776a5bc Andreas Kohlbecker
        $settings_for_theme = $cyprus_default;
611 f3a04cfa Andreas Kohlbecker
        break;
612
      case 'flore_afrique_centrale':
613
      case 'flora_malesiana':
614
      case 'flore_gabon':
615
        $settings_for_theme = $cichorieae_default;
616
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
617
        break;
618
      case 'palmweb_2':
619
        $settings_for_theme = $palmweb_default;
620
        break;
621
      default:
622 6776a5bc Andreas Kohlbecker
        $settings_for_theme =  $other_themes_default;
623 f3a04cfa Andreas Kohlbecker
    }
624 c367b0ab Andreas Kohlbecker
625 f3a04cfa Andreas Kohlbecker
    if(isset($settings_for_theme[$feature_uuid])){
626
      return $settings_for_theme[$feature_uuid];
627
    } else if(isset($settings_for_theme['DEFAULT'])){
628 6776a5bc Andreas Kohlbecker
      return $settings_for_theme['DEFAULT']; // the fallback cascade will usually stop here since all settings should have a default
629 f3a04cfa Andreas Kohlbecker
    } else {
630
      return $default['DEFAULT'];
631
    }
632 22f5e82d Andreas Kohlbecker
  }
633
  /**
634 5611d467 Andreas Kohlbecker
 * returns the current setting for the original source bibliography
635
 *
636
 * Caches internally
637
 *
638
 * @return array
639
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
640
 *   - 'enabled': 1|0
641
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
642
 */
643 800ff2b0 Andreas Kohlbecker
function get_bibliography_settings($clear_cache = false){
644 5611d467 Andreas Kohlbecker
  static $bibliography_settings = null;
645 800ff2b0 Andreas Kohlbecker
  if(!$bibliography_settings || $clear_cache){
646 f3a04cfa Andreas Kohlbecker
    $bibliography_settings = get_array_variable_merged(
647
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
648
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
649
    );
650 5611d467 Andreas Kohlbecker
  }
651
  return $bibliography_settings;
652
}
653
654 6657531f Andreas Kohlbecker
/**
655
 * @todo Please document this function.
656
 * @see http://drupal.org/node/1354
657
 */
658
function cdm_dataportal_menu_admin(&$items) {
659
  // Display section on admin/config page.
660
  $items['admin/config/cdm_dataportal'] = array(
661
    'title' => 'CDM Dataportal',
662
    'description' => 'Settings for the CDM DataPortal.',
663
    'position' => 'right',
664
    'weight' => 10,
665
    'page callback' => 'system_admin_menu_block_page',
666 e014414c Andreas Kohlbecker
    'access arguments' => array('administer cdm_dataportal'),
667 6657531f Andreas Kohlbecker
    'file' => 'system.admin.inc',
668
    'file path' => drupal_get_path('module', 'system'),
669
  );
670
  $items['admin/config/cdm_dataportal/settings'] = array(
671
    'title' => 'Settings',
672
    'description' => 'Settings for the CDM DataPortal.',
673
    'weight' => 0,
674
    'page callback' => 'drupal_get_form',
675
    'page arguments' => array('cdm_settings_general'),
676
    'access arguments' => array('administer cdm_dataportal'),
677
    'type' => MENU_NORMAL_ITEM,
678
  );
679
  $items['admin/config/cdm_dataportal/settings/general'] = array(
680
    'title' => 'General',
681
    'description' => 'General',
682
    'weight' => 0,
683
    'page callback' => 'drupal_get_form',
684
    'page arguments' => array('cdm_settings_general'),
685
    'access arguments' => array('administer cdm_dataportal'),
686
    'type' => MENU_DEFAULT_LOCAL_TASK,
687
  );
688
689
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
690
    'title' => 'Cache',
691
    'description' => 'Cache',
692
    'access arguments' => array('administer cdm_dataportal'),
693
    'page callback' => 'drupal_get_form',
694
    'page arguments' => array('cdm_settings_cache'),
695
    'weight' => 10,
696
    'type' => MENU_LOCAL_TASK,
697
  );
698
699
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
700
    'title' => 'Geo & Map',
701
    'description' => 'Geo & Map',
702
    'access arguments' => array('administer cdm_dataportal'),
703
    'page callback' => 'drupal_get_form',
704
    'page arguments' => array('cdm_settings_geo'),
705
    'weight' => 1,
706
    'type' => MENU_LOCAL_TASK,
707
  );
708
709
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
710
    'title' => 'Layout',
711
    'description' => 'Configure and adjust the layout of your DataPortal ',
712
    'access arguments' => array('administer cdm_dataportal'),
713
    'page callback' => 'drupal_get_form',
714
    'page arguments' => array('cdm_settings_layout'),
715
    'weight' => 2,
716
    'type' => MENU_LOCAL_TASK,
717
  );
718
719
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
720
    'title' => 'Taxon',
721
    'description' => 'Configure and adjust the layout of your DataPortal ',
722
    'access arguments' => array('administer cdm_dataportal'),
723
    'page callback' => 'drupal_get_form',
724
    'page arguments' => array('cdm_settings_layout_taxon'),
725
    'weight' => 1,
726
    'type' => MENU_LOCAL_TASK,
727
  );
728
  /*
729
  $items[] = array(
730
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
731
  'title' => t('Synonymy'),
732
  'description' => t('Configure and adjust the layout of your DataPortal '),
733
  'access' => user_access('administer cdm_dataportal'),
734
  'callback' => 'drupal_get_form',
735
  'callback arguments' => array('cdm_settings_layout_synonymy'),
736
  'weight' => 1,
737
  'type' => MENU_LOCAL_TASK,
738
  );
739
740
  $items[] = array(
741
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
742
  'title' => t('Specimens'),
743
  'description' => t('Configure and adjust the layout of your DataPortal '),
744
  'access' => user_access('administer cdm_dataportal'),
745
  'callback' => 'drupal_get_form',
746
  'callback arguments' => array('cdm_settings_layout_specimens'),
747
  'weight' => 1,
748
  'type' => MENU_LOCAL_TASK,
749
  );
750
  */
751
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
752
    'title' => 'Search',
753
    'description' => 'Configure and adjust the layout of your DataPortal ',
754
    'access arguments' => array('administer cdm_dataportal'),
755
    'page callback' => 'drupal_get_form',
756
    'page arguments' => array('cdm_settings_layout_search'),
757
    'weight' => 2,
758
    'type' => MENU_LOCAL_TASK,
759
  );
760
761
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
762
    'title' => 'Media',
763
    'description' => 'Configure and adjust the layout of your DataPortal ',
764
    'access arguments' => array('administer cdm_dataportal'),
765
    'page callback' => 'drupal_get_form',
766
    'page arguments' => array('cdm_settings_layout_media'),
767
    'weight' => 3,
768
    'type' => MENU_LOCAL_TASK,
769
  );
770 947c6a8d Andreas Kohlbecker
771 6657531f Andreas Kohlbecker
}
772
773
/**
774
 * @todo document this function.
775
 */
776
function cdm_help_general_cache() {
777
  $form = array();
778
  $form['cache_help'] = array(
779
    '#type' => 'fieldset',
780
    '#title' => t('Help'),
781
    '#collapsible' => TRUE,
782
    '#collapsed' => TRUE,
783
  );
784
  $form['cache_help']['test'] = array('#value' => t('probando'));
785
  return drupal_render($form);
786
  $res = array();
787
  $res['default'] = drupal_render($help);
788
  return $res;
789
}
790
791
/**
792
 * Configures the settings form for the CDM-API module.
793
 *
794
 * @return array
795
 *   Drupal settings form.
796
 */
797
function cdm_settings_general() {
798
799
  $form['cdm_webservice'] = array(
800
    '#type' => 'fieldset',
801
    '#title' => t('CDM Server'),
802
    '#collapsible' => FALSE,
803
    '#collapsed' => FALSE,
804 9438ad3a Andreas Kohlbecker
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
805
        CDM data base to the web via RESTful web services and thus is the source of the data
806
        to be displayed by a CDM DataPotal.'),
807 6657531f Andreas Kohlbecker
  );
808
809
  $form['cdm_webservice']['cdm_webservice_url'] = array(
810
    '#type' => 'textfield',
811
    '#title' => t('CDM web service URL') . ':',
812
    '#description' => t('This is the URL to the CDM-Server exposing your data
813 d1eb0a8c Andreas Kohlbecker
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
814 6657531f Andreas Kohlbecker
    '#default_value' => variable_get('cdm_webservice_url', NULL),
815
  );
816
817
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
818 17c3d760 Andreas Kohlbecker
    '#type' => 'markup',
819 6ab41d7b Andreas Kohlbecker
    '#markup' => '<b>Debug CDM Web Service:</b> The web service debug box has completely been replaced '
820
      . 'by  the ' . l('CDM web service debug block', 'admin/structure/block/manage/cdm_api/cdm_ws_debug/configure')
821 17c3d760 Andreas Kohlbecker
      . '. It is usually only visible for administrative roles like <i>administrator</i> and <i>CDM admin</i>'
822 6657531f Andreas Kohlbecker
  );
823
824
  $form['cdm_webservice']['freetext_index'] = array(
825
    '#type' => 'fieldset',
826
    '#title' => t('Freetext index'),
827
    '#collapsible' => FALSE,
828
    '#collapsed' => FALSE,
829
  );
830
831
  // Check the cdmserver port number and display a waring if it is not port 80
832
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
833
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
834
    $form['cdm_webservice']['freetext_index']['message'] = array(
835
      '#markup' => "<div class=\"description\">"
836
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'."
837
      . " Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server."
838
      . " You may want to contact the maintainer of the according CDM Server in order to solve this problem.", array('!port' => $portNumberMatch[1][0]))
839
      . "</div>",
840
    );
841
  };
842
843
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
844
  $trigger_link_options = array(
845
    'attributes' => array(
846
      'class' => 'index-trigger',
847
    ),
848
  );
849
  $form['cdm_webservice']['freetext_index']['operations'] = array(
850
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
851
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
852
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
853
      ))
854
    . '<div id="index-progress"></div></div>',
855
  );
856
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
857
858
  $form['cdm_webservice']['proxy'] = array(
859
    '#type' => 'fieldset',
860
    '#title' => t('Proxy'),
861
    '#collapsible' => TRUE,
862
    '#collapsed' => TRUE,
863
  );
864
865
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
866
    '#type' => 'textfield',
867
    '#title' => t('Proxy URL') . ':',
868
    '#description' => t('If this proxy url is set the cdm api tries
869
    to connect the web service over the given proxy server.
870
    Otherwise proxy usage is deactivated.'),
871
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
872
  );
873
874
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
875
    '#type' => 'textfield',
876
    '#title' => t('Proxy port') . ':',
877
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
878
  );
879
880
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
881
    '#type' => 'textfield',
882
    '#title' => t('Login') . ':',
883
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
884
  );
885
886
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
887
    '#type' => 'textfield',
888
    '#title' => t('Password') . ':',
889
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
890
  );
891
892
  // TODO: settings are still incomplete, compare with
893
  // trunk/dataportal/inc/config_default.php.inc.
894 9438ad3a Andreas Kohlbecker
  $form['taxon_tree'] = array(
895 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
896
    '#title' => t('Taxon Tree'),
897
    '#collapsible' => FALSE,
898
    '#collapsed' => TRUE,
899
    '#description' => t('<p>When you explore your collection, you can navigate
900
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
901
      able to navigate through your collection the
902
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
903
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
904
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
905
      </a></p>'),
906
  );
907
908 9438ad3a Andreas Kohlbecker
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
909 6657531f Andreas Kohlbecker
    '#type' => 'select',
910
    '#title' => t('Available classifications') . ':',
911
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
912
    '#options' => cdm_get_taxontrees_as_options(),
913
    '#description' => t('Select the default taxa classification for your
914
      <em>taxon tree</em>, the other classifications will be also available but
915
      with a manual user change.'),
916
  );
917
918 9438ad3a Andreas Kohlbecker
  $form['taxon_tree']['taxontree_ranklimit'] = array(
919 6657531f Andreas Kohlbecker
    '#type' => 'select',
920
    '#title' => t('Rank of highest displayed taxon') . ':',
921
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
922
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
923
    '#options' => cdm_rankVocabulary_as_option(),
924
    '#description' => t('This is the rank of the highest displayed taxon in the
925
      <em>taxon tree</em>. You can select here which rank should be at the top
926
      level of the tree structure.'),
927
  );
928
929 26fb3778 Andreas Kohlbecker
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
930
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
931
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
932
      '#type' => 'checkboxes',
933
      '#title' => t('Included Classifications') . ':',
934
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
935
      '#options' => cdm_get_taxontrees_as_options(),
936
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
937
  );
938
939 aa63dfb4 Andreas Kohlbecker
  $form['distribution'] = array(
940
      '#type' => 'fieldset',
941
      '#title' => t('Distributions'),
942
      '#collapsible' => FALSE,
943
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
944
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
945
          '<p>
946
          </p>',
947
  );
948
949
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
950
      '#type' => 'fieldset',
951
      '#title' => 'Distribution filter',
952
      '#collapsible' => FALSE,
953
      '#collapsed' => FALSE,
954
      '#tree' => TRUE,
955
      '#description' => 'The Distribution filter offers the following options
956
      <ul>
957
      <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>
958
      <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>
959
      <li><strong>Marked area filter:</strong>Skip distributions where the area has a Marker with one of the specified MarkerTypes</li>
960
      </ul>'
961
  );
962
963
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
964
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
965
      '#type' => 'checkboxes',
966
      '#title' => 'Filter rules',
967
      '#default_value' => $cdm_distribution_filter['filter_rules'],
968
      '#options' => array(
969
          'statusOrderPreference' => 'Status order preference rule',
970
          'subAreaPreference' => 'Sub area preference rule'
971
      ),
972
  );
973
974
  $marker_type_options = cdm_terms_as_options( cdm_ws_fetch_all('term', array('class' => 'MarkerType' )) );
975
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hideMarkedAreas'] = array(
976
      '#type' => 'checkboxes',
977
      '#title' => 'Hide marked area filter',
978
      '#default_value' => $cdm_distribution_filter['hideMarkedAreas'],
979
      '#options' => $marker_type_options,
980
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
981
  );
982
983 f19f47fa Andreas Kohlbecker
  $form['aggregation'] = array(
984
      '#type' => 'fieldset',
985
      '#title' => t('Aggregation of data'),
986
      '#collapsible' => FALSE,
987 aa63dfb4 Andreas Kohlbecker
      '#description' => 'This section covers the different aspects of aggregating information.
988 9438ad3a Andreas Kohlbecker
          <p>
989 f19f47fa Andreas Kohlbecker
          </p>',
990 9438ad3a Andreas Kohlbecker
  );
991
992 ccde8251 Andreas Kohlbecker
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
993
      '#type' => 'checkboxes',
994
      '#title' => 'Taxon media filter',
995
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
996
      '#options' => array(
997
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
998
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
999
          'includeOccurrences' => 'Media related to specimens and occurrences',
1000
      ),
1001
      '#description' => 'This filter configures which images should be taken into account.',
1002
  );
1003
1004
  $form['aggregation']['notice'] = array(
1005 3a874294 Andreas Kohlbecker
      '#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
1006 ccde8251 Andreas Kohlbecker
          want to make use of the caching capabilities of the dataportal.',
1007
  );
1008
1009 f19f47fa Andreas Kohlbecker
  $form['aggregation']['media_aggregation'] = array(
1010
      '#type' => 'fieldset',
1011
      '#title' => t('Media aggregation'),
1012
      '#collapsible' => FALSE,
1013 9438ad3a Andreas Kohlbecker
      '#collapsed' => TRUE,
1014 f19f47fa Andreas Kohlbecker
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1015
1016 9438ad3a Andreas Kohlbecker
  );
1017 f19f47fa Andreas Kohlbecker
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1018
      '#type' => 'select',
1019
      '#title' => t('Aggregation of taxon pictures') . ':',
1020
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1021
      '#options' => array(
1022
          0 => "Show only pictures of the current taxon",
1023
          1 => "Include pictures of taxonomic children",
1024
      ),
1025
      '#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."),
1026 9438ad3a Andreas Kohlbecker
  );
1027
1028 f19f47fa Andreas Kohlbecker
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1029 30f78c59 Andreas Kohlbecker
      '#type' => 'fieldset',
1030
      '#attributes' => array('class'=>array('clearfix')),
1031 9438ad3a Andreas Kohlbecker
      '#title' => t('Aggregation via taxon relationsships'),
1032 30f78c59 Andreas Kohlbecker
      '#collapsible' => TRUE,
1033
      '#collapsed' => TRUE,
1034 f19f47fa Andreas Kohlbecker
      '#tree' => TRUE,
1035 30f78c59 Andreas Kohlbecker
      '#description' => t('Information on taxa will be aggregated along the below chosen
1036
          taxon relation ships. This will affect images and occurrences (specimens).
1037
          Taxon relation ships are directed and point form one taxon to another. The taxon
1038
          relationships to be taken into accunt can therefore configured for the direct direction
1039 f19f47fa Andreas Kohlbecker
          and for the inverse.'),
1040
  );
1041
1042 30f78c59 Andreas Kohlbecker
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1043
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1044 f19f47fa Andreas Kohlbecker
1045
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1046
      '#type' => 'checkboxes',
1047
      '#title' => t('Direct'),
1048
      '#options' => $taxonRelationshipTypeOptions,
1049
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1050 30f78c59 Andreas Kohlbecker
  );
1051 f19f47fa Andreas Kohlbecker
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1052
      '#type' => 'checkboxes',
1053
      '#title' => t('Invers'),
1054
      '#options' => $taxonRelationshipTypeOptions,
1055
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1056 30f78c59 Andreas Kohlbecker
  );
1057
1058 5ea8b301 Andreas Kohlbecker
  // ----------------------
1059
  $form['cdm_js_devel_mode'] = array(
1060
      '#type' => 'checkbox',
1061
      '#title' => 'Java-script developer mode',
1062
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1063
      '#description' => 'In production envirionments the java script libraries
1064
      the cdm_dataportal is making use of are compressed and optimized. This
1065
      is good for performance but a caveat if you need to debug java-script. When the
1066
      java-script developer mode is enabled the uncompressed and commented developer
1067
      versions of java-script libraries will be used where possible.
1068
      <br/><strong>Do not use this option in production!</strong>'
1069
  );
1070 2dd59bb5 Andreas Kohlbecker
  // ----------------------
1071
  $form['cdm_debug_mode'] = array(
1072
      '#type' => 'checkbox',
1073
      '#title' => 'CDM page debug mode',
1074
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1075
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1076 b5deb531 Andreas Kohlbecker
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1077
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1078
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1079 2dd59bb5 Andreas Kohlbecker
      The log is written by the drupal devel module function <code>dd()</code>.
1080 b5deb531 Andreas Kohlbecker
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1081 2dd59bb5 Andreas Kohlbecker
  );
1082 5ea8b301 Andreas Kohlbecker
1083 6657531f Andreas Kohlbecker
  // Comment @WA: D7 form api does not support reset buttons,
1084
  // so to mimic the D5 reset button we add one like this.
1085
  $form['actions']['reset'] = array(
1086
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1087
    '#weight' => 1000,
1088
  );
1089
1090 22eb20d7 Andreas Kohlbecker
  $form['#submit'][] = 'cdm_settings_general_submit';
1091
1092 6657531f Andreas Kohlbecker
  return system_settings_form($form);
1093
}
1094
1095
1096
/**
1097
 * LAYOUT settings
1098 cf839840 Andreas Kohlbecker
 * @return
1099 6657531f Andreas Kohlbecker
 *   todo
1100
 */
1101
function cdm_settings_layout() {
1102
1103
  $form = array();
1104 0f5f1c12 Andreas Kohlbecker
1105
  $form['about'] = array(
1106
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1107 6657531f Andreas Kohlbecker
      layout. If you want to configure the specific sites layout visit the
1108 0f5f1c12 Andreas Kohlbecker
      respective configuration site for taxon, search or media.') . '</p>',
1109 6657531f Andreas Kohlbecker
  );
1110
1111
  // ---- footnotes --- //
1112 0f5f1c12 Andreas Kohlbecker
  $form['footnotes'] = array(
1113 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1114
    '#title' => t('Footnotes'),
1115
    '#collapsible' => FALSE,
1116
    '#collapsed' => FALSE,
1117
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1118
      media or distribution areas may have annotations or footnotes. When the
1119
      footnotes are enabled they will be visible (if they exist).'),
1120
  );
1121
1122 0f5f1c12 Andreas Kohlbecker
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1123 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1124
    '#title' => t('Do not show footnotes'),
1125
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1126
    '#description' => t('Check this if you do not want to show any footnotes'),
1127
  );
1128
1129 0f5f1c12 Andreas Kohlbecker
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1130 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1131
    '#title' => t('Do not show annotations footnotes'),
1132
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1133
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1134
  );
1135
1136 cf839840 Andreas Kohlbecker
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType', SORT_ASC);
1137 6657531f Andreas Kohlbecker
  // Additional option for the NULL case.
1138
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1139 0f5f1c12 Andreas Kohlbecker
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1140 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
1141
    '#title' => t('Annotation types as footnotes'),
1142
    '#description' => t("Only annotations of the selected type will be displayed
1143
       as footnotes. You may want to turn 'technical annotations' off."),
1144
    '#options' => $annotationTypeOptions,
1145
  );
1146
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1147
  if (!empty($annotationsTypesAsFootnotes)) {
1148 0f5f1c12 Andreas Kohlbecker
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1149 6657531f Andreas Kohlbecker
  }
1150
1151 5611d467 Andreas Kohlbecker
  // ---- original source --- //
1152
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1153
      '#type' => 'fieldset',
1154
      '#tree' => TRUE,
1155
      '#title' => t('Source Citations'),
1156
      '#collapsible' => FALSE,
1157
      '#collapsed' => FALSE,
1158
  );
1159 f19f47fa Andreas Kohlbecker
1160 800ff2b0 Andreas Kohlbecker
  $bibliography_settings = get_bibliography_settings(true);
1161 5611d467 Andreas Kohlbecker
1162 800ff2b0 Andreas Kohlbecker
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1163 5611d467 Andreas Kohlbecker
      '#type' => 'checkbox',
1164
      '#title' => t('Original Source in bibliography'),
1165
      '#default_value' => $bibliography_settings['enabled'],
1166
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1167
       annotations in each feature block.'),
1168
  );
1169
1170
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1171
    '#type' => 'select',
1172
    '#title' => t('The format of the key numerals'),
1173
    '#default_value' => $bibliography_settings['key_format'],
1174
    '#options' => array('latin' => 'Latin',
1175
      'ROMAN' => 'Roman (upper case)',
1176
      'roman' => 'Roman (lower case)',
1177
      'ALPHA'=> 'Alphabet (upper case)',
1178
      'alpha' => 'Alphabet (lower case)')
1179
  );
1180 f19f47fa Andreas Kohlbecker
1181
  // --- Advanced Search --- //
1182
  $form['asearch'] = array(
1183 5611d467 Andreas Kohlbecker
    '#type' => 'fieldset',
1184
    '#title' => t('Advanced search'),
1185
    '#collapsible' => FALSE,
1186
    '#collapsed' => FALSE,
1187 f19f47fa Andreas Kohlbecker
  );
1188 5611d467 Andreas Kohlbecker
1189 f19f47fa Andreas Kohlbecker
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1190 5611d467 Andreas Kohlbecker
    '#type' => 'checkbox',
1191
    '#title' => t('Show advanced search link'),
1192
    '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1193
    '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1194 f19f47fa Andreas Kohlbecker
  );
1195
1196
  // ---- Taxon Name Rendering --- //
1197
  $form['taxon_name'] = array(
1198
      '#type' => 'fieldset',
1199
      '#title' => t('Taxon name display'),
1200
      '#collapsible' => TRUE,
1201
      '#collapsed' => TRUE,
1202 0f5f1c12 Andreas Kohlbecker
      '#description' => t('The display of taxon names is configured by two parts.'
1203
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
1204 f19f47fa Andreas Kohlbecker
          . 'The name parts are defined in the <stong>part definitions</strong>'),
1205 0f5f1c12 Andreas Kohlbecker
  );
1206
1207
  drupal_add_js(
1208
      'jQuery(document).ready( function( ) {
1209
         // pretty print json
1210
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
1211
         var obj = JSON.parse(json_text);
1212
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
1213
1214
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
1215
         obj = JSON.parse(json_text);
1216
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
1217
       });'
1218
      ,array(
1219
          'type' => 'inline',
1220
          'scope' => 'footer'
1221
      )
1222 6657531f Andreas Kohlbecker
  );
1223 f19f47fa Andreas Kohlbecker
1224 78292e72 Andreas Kohlbecker
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1225 0f5f1c12 Andreas Kohlbecker
1226
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1227
      '#type' => 'textarea',
1228
      '#title' => t('Part definitions'),
1229
      '#element_validate' => array('form_element_validate_json'),
1230
      '#default_value' =>  json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions)),
1231
      '#description' => '
1232
          <p>
1233
          (Clearing the text area will reset it to the default)
1234
          </p>
1235
          <p>
1236
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1237
          </p>
1238
          <p>
1239
           A full taxon name plus additional information can consist of the following elements:
1240
          <ul>
1241
             <li>name: the taxon name inclugin rank nbut without author</li>
1242
             <li>authors:  The authors of a reference, also used in taxon names</li>
1243
             <li>reference: the nomenclatural reference,</li>
1244
             <li>microreference:  Volume, page number etc.</li>
1245
             <li>status:  The nomenclatural status of a name</li>
1246
             <li>description: name descriptions like protologues etc ...</li>
1247
          </ul>
1248
          </p>
1249
          <p>
1250
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1251
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1252 51b04faf Andreas Kohlbecker
           The following parts can be formed and are recognized by the system:
1253 0f5f1c12 Andreas Kohlbecker
          <ul>
1254 51b04faf Andreas Kohlbecker
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1255
            <li>authorshipPart: the author (for example: "L.")</li>
1256
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1257 0f5f1c12 Andreas Kohlbecker
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1258
               be combined when a link to the taxon is rendered.</li>
1259 51b04faf Andreas Kohlbecker
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1260
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1261
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1262 0f5f1c12 Andreas Kohlbecker
            <li>statusPart: the nomenclatorical status</li>
1263
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1264
          </ul>
1265
          </p>
1266
          <p>
1267
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1268
           specific parts part definitions:
1269
          <ul>
1270
            <li>BotanicalName</li>
1271
            <li>ZoologicalName</li>
1272
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1273
          </ul>
1274
           An example:
1275
          <pre>
1276
           {
1277
            "ZoologicalName": {
1278
              "namePart": {
1279
                "name": true
1280
              },
1281
              "referencePart": {
1282 b5519d3a Andreas Kohlbecker
                "authors": true
1283 0f5f1c12 Andreas Kohlbecker
              },
1284
              "microreferencePart": {
1285
                "microreference": true
1286
              },
1287
              "statusPart": {
1288
                "status": true
1289
              },
1290
              "descriptionPart": {
1291
                "description": true
1292
              }
1293
            },
1294
            "BotanicalName": {
1295
              "namePart": {
1296
                "name": true,
1297
                "authors": true
1298
              },
1299
              "referencePart": {
1300
                "reference": true,
1301
                "microreference": true
1302
              },
1303
              "statusPart": {
1304
                "status": true
1305
              },
1306
              "descriptionPart": {
1307
                "description": true
1308
              }
1309
            }
1310
          }
1311
           </pre>',
1312
  );
1313
1314 78292e72 Andreas Kohlbecker
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1315 0f5f1c12 Andreas Kohlbecker
1316 f19f47fa Andreas Kohlbecker
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1317
      '#type' => 'textarea',
1318 0f5f1c12 Andreas Kohlbecker
      '#title' => t('Name render templates'),
1319 f19f47fa Andreas Kohlbecker
      '#element_validate' => array('form_element_validate_json'),
1320
      '#default_value' =>  json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates)),
1321 0f5f1c12 Andreas Kohlbecker
      '#description' => '
1322
          <p>
1323
          (Clearing the text area will reset it to the default)
1324
          </p>
1325
          <p>
1326
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1327
          render path. The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1328
          The following render Path keys are curretly recognized:
1329
          <ul>
1330 51b04faf Andreas Kohlbecker
            <li>list_of_taxa</li>
1331
            <li>acceptedFor</li>
1332
            <li>homonym</li>
1333 0f5f1c12 Andreas Kohlbecker
            <li>taxon_page_synonymy</li>
1334
            <li>typedesignations</li>
1335
            <li>taxon_page_title</li>
1336
            <li>polytomousKey</li>
1337
            <li>na: name + authorship</li>
1338
            <li>nar:name + authorship + reference</li>
1339
            <li>#DEFAULT</li>
1340
          </ul>
1341
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1342
          array element should be a comma separated list of render paths, without any whitespace!.
1343
          </p>
1344
          <p>
1345
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1346
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1347
          <p>
1348
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1349
          The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
1350
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1351
          links if the paramters $nameLink or $refenceLink are given to the name render function
1352 f19f47fa Andreas Kohlbecker
          (this is hard coded and cannot be configured here).',
1353 6657531f Andreas Kohlbecker
  );
1354
1355
  // @WA: D7 form api does not support reset buttons,
1356
  // so to mimic the D5 reset button we add one like this.
1357
  $form['actions']['reset'] = array(
1358
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1359
    '#weight' => 1000,
1360
  );
1361 f19f47fa Andreas Kohlbecker
1362 0f5f1c12 Andreas Kohlbecker
  $form['#submit'] = array('submit_json_as_php_array');
1363
  // #json_elements especially defined for submit_json_as_php_array()
1364
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1365 6657531f Andreas Kohlbecker
  return system_settings_form($form);
1366
}
1367
1368
1369
/**
1370
 * @todo Please document this function.
1371
 * @see http://drupal.org/node/1354
1372
 */
1373
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1374
  $form[$form_name] = array(
1375
    '#type' => 'fieldset',
1376
    '#title' => t($form_title),
1377
    '#collapsible' => TRUE,
1378
    '#collapsed' => $collapsed,
1379
    '#tree' => TRUE,
1380
    '#description' => t($form_description),
1381
  );
1382
1383
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1384
  $gallery_settings = variable_get($form_name, $default_values);
1385
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1386
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1387
    /*
1388
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1389
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1390
    '#type' => 'textfield',
1391
    '#title' => t('Search Page Size'),
1392
    '#default_value' => $test,
1393
    '#description' => t('Number of Names to display per page in search results.')
1394
    );
1395
    */
1396
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1397
      '#type' => 'checkbox',
1398
      '#title' => t('Show media thumbnails for accepted taxa'),
1399
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1400
    );
1401
1402
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1403
      '#type' => 'checkbox',
1404
      '#title' => t('Show media thumbnails for synonyms'),
1405
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1406
      '#description' => '',
1407
    );
1408
  }
1409
1410
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1411
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1412
    '#type' => 'checkbox',
1413
    '#title' => t('Show captions under thumbnails'),
1414
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1415
    '#description' => '',
1416
  );
1417
1418
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1419
    '#type' => 'textfield',
1420
    '#title' => t('Thumbnail size') . ':',
1421
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1422
    '#description' => t('Select the size of each individual thumbnail.'),
1423
  );
1424
1425
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1426
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1427
      '#type' => 'textfield',
1428
      '#title' => t('Number of columns') . ':',
1429
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1430
      '#description' => t('Group the thumbnails in columns: select how many
1431
        columns the gallery should display.'),
1432
    );
1433
  }
1434
1435
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1436
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1437
      '#type' => 'textfield',
1438
      '#title' => t('Maximum number of rows') . ':',
1439
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1440
      '#description' => t('You can group the thumbnails in rows, select in how
1441
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1442
        If you want an unlimited number of rows please set to 0.'),
1443
    );
1444
  }
1445
1446
  return $form;
1447
}
1448
1449
/**
1450
 * @todo document this function.
1451
 */
1452
function cdm_settings_layout_taxon() {
1453
  $collapsed = FALSE;
1454
  $form = array();
1455
1456 7df1be04 Andreas Kohlbecker
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1457
1458 d9c55e6c Andreas Kohlbecker
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1459
      '#type' => 'checkbox',
1460
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1461
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1462
      '#description' => t('<p>If checked the link to search results is rendered at
1463
       the top of the taxon site. Clicking on the link the last search performed
1464
       is rendered again.</p>'),
1465
  );
1466
1467 6657531f Andreas Kohlbecker
  // --------- TABBED TAXON ------- //
1468
  $form['taxon_tabs'] = array(
1469
    '#type' => 'fieldset',
1470
    '#title' => t('Taxon tabs'),
1471
    '#collapsible' => TRUE,
1472
    '#collapsed' => FALSE,
1473
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1474
      be splitted in four diferent tabs; General, Synonymy, Images and
1475
      Specimens. If the taxon has no information for any of the tabs/sections
1476
      such tab will be not displayed.'),
1477
  );
1478
1479
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1480
    '#type' => 'checkbox',
1481
    '#title' => t('Tabbed taxon page'),
1482
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1483
    '#description' => t('<p>If selected split the taxon page into individual
1484
      tabs for description, images, synonymy and specimens. If not the taxon
1485
      data is rendered as a long single page without tabs.</p>'),
1486
  );
1487
1488
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1489
    '#type' => 'checkboxes',
1490
    '#title' => t('Tabs visibility options') . ':',
1491
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1492
    '#options' => get_taxon_options_list(),
1493
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1494
  );
1495
1496 b54cbda1 Andreas Kohlbecker
  // WEIGHT
1497
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1498
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1499
      '#tree' => true
1500
  );
1501
  // Weights range from -delta to +delta, so delta should be at least half
1502
  // of the amount of tabs present.
1503
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1504
  foreach (get_taxon_tabs_list() as $label) {
1505
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1506
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1507
        '#title' => $label,
1508
        '#type'  => 'weight',
1509
        '#default_value' => $taxontabs_weights[$key],
1510
        '#delta' => $tab_weight_delta
1511
    );
1512
  }
1513
1514 6657531f Andreas Kohlbecker
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1515
    '#type' => 'select',
1516
    '#title' => t('Default tab to display') . ':',
1517
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1518
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1519
    '#description' => t('<p>Select the default tab to display when visiting a
1520
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1521
      <strong>Note:</strong> After performing a search and clicking in any
1522
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1523
      taxon and not the above selected tab.'),
1524
  );
1525
1526
  /* ======  TAXON_PROFILE ====== */
1527
  $form['taxon_profile'] = array(
1528
    '#type' => 'fieldset',
1529
    '#title' => t('Taxon profile (tab)'),
1530 9438ad3a Andreas Kohlbecker
    '#description' => t('<p>This section covers the settings related to the taxon
1531 6657531f Andreas Kohlbecker
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1532
    '#collapsible' => TRUE,
1533
    '#collapsed' => TRUE,
1534
  );
1535
1536
  // ---- PROFILE PICTURE ----//
1537 9c92cd84 Andreas Kohlbecker
1538
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1539 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1540 9c92cd84 Andreas Kohlbecker
    '#tree' => TRUE,
1541 9438ad3a Andreas Kohlbecker
    '#title' => t('Taxon profile picture'),
1542 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
1543
    '#collapsed' => FALSE,
1544 9438ad3a Andreas Kohlbecker
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1545 6657531f Andreas Kohlbecker
  );
1546
1547 9c92cd84 Andreas Kohlbecker
  //FIXME migrate variables:
1548
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1549
  // FIXME
1550 9aff46e4 Andreas Kohlbecker
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1551 9c92cd84 Andreas Kohlbecker
1552
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1553
  /*
1554
   * 'show' => 1,
1555
   * 'maxextend' => 184,
1556 053a92ec Andreas Kohlbecker
   * 'media_uri_query' => ''
1557 9c92cd84 Andreas Kohlbecker
   * 'custom_placeholder_image_on' => 1,
1558
   * 'custom_placeholder_image_fid' => ''
1559
   */
1560
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1561 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1562
    '#title' => t('Enable profil picture'),
1563
    '#description' => t('Show the profil picture.'),
1564 9c92cd84 Andreas Kohlbecker
    '#default_value' => $taxon_profile_image_settings['show'],
1565 6657531f Andreas Kohlbecker
  );
1566
1567 9c92cd84 Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1568 d9c55e6c Andreas Kohlbecker
      '#type' => 'textfield',
1569
      '#tree' => TRUE,
1570
      '#title' => t('Profil picture maximum extend'),
1571 9c92cd84 Andreas Kohlbecker
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1572 d9c55e6c Andreas Kohlbecker
      '#field_suffix' => 'px',
1573
      '#maxlength' => 4,
1574
      '#size' => 4,
1575
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1576
  );
1577
1578 053a92ec Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1579
      '#type' => 'textfield',
1580
      '#tree' => TRUE,
1581
      '#title' => t('Additional URI query parameter'),
1582
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1583
      '#maxlength' => 1024,
1584
      '#size' => 60,
1585
      '#description' => t('Additional query parameters to be used when requesting for the '
1586
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1587
          . 'The query parameters will be appendend to the uri of the media representation part'
1588
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1589
  );
1590
1591 9c92cd84 Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1592
      '#type' => 'checkbox',
1593
      '#title' => t('Use a custom placeholder image'),
1594 7df1be04 Andreas Kohlbecker
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1595 9c92cd84 Andreas Kohlbecker
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1596 7df1be04 Andreas Kohlbecker
  );
1597
1598 9c92cd84 Andreas Kohlbecker
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1599
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1600
        '#type' => 'managed_file',
1601
        '#title' => t('Custom placeholder image file'),
1602
        '#progress_indicator' => 'bar',
1603
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1604
    //       '#name' => 'custom_placeholder_image',
1605
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1606
    );
1607
1608
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1609
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1610
      $url = file_create_url($profile_image_file->uri);
1611
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1612
                '#type' => 'item',
1613
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1614
      );
1615
    }
1616
  } else {
1617
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1618
        '#type' => 'hidden',
1619
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1620
    );
1621
  }
1622
1623
1624
1625 6657531f Andreas Kohlbecker
  $options = cdm_rankVocabulary_as_option();
1626
  array_unshift($options, '-- DISABLED --');
1627
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1628
    '#type' => 'select',
1629 9438ad3a Andreas Kohlbecker
    '#title' => t('Hide profile picture for higher ranks') . ':',
1630 6657531f Andreas Kohlbecker
    '#default_value' => variable_get('image_hide_rank', '0'),
1631
    '#options' => $options,
1632 9438ad3a Andreas Kohlbecker
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1633 6657531f Andreas Kohlbecker
  );
1634
1635
  // -- MEDIA THUMBNAILS -- //
1636
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1637
  $form_title = 'Taxon Profile Images';
1638
  $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>';
1639
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1640
1641
  // ---- FEATURE TREE ---- //
1642 8127188a Alexander Oppermann
  $form['taxon_profile']['feature_trees'] = array(
1643 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1644
    '#title' => t('Features'),
1645
    '#collapsible' => TRUE,
1646
    '#collapsed' => FALSE,
1647
    '#description' => t("This section covers settings related to the taxon's
1648
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1649
      features such as description, distribution, common names, etc. that Drupal
1650
      will render at the taxon profile page."),
1651
  );
1652
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1653 854e1d99 Andreas Kohlbecker
  $saved_uuid = variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1654
  if(!isset($featureTrees['options'][$saved_uuid])) {
1655
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1656
  }
1657 6657531f Andreas Kohlbecker
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
1658
    '#type' => 'radios',
1659
    '#title' => t('Taxon profile sections') . ':',
1660 854e1d99 Andreas Kohlbecker
    '#default_value' => $saved_uuid,
1661 6657531f Andreas Kohlbecker
    '#options' =>  $featureTrees['options'],
1662 3f485c6d Andreas Kohlbecker
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1663
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1664 6657531f Andreas Kohlbecker
    '#description' => t('Select the Feature Tree to be displayed at the taxon
1665
      profile. Click "Show Details" to see the Feature Tree elements.'
1666
    ),
1667
  );
1668
  $featureTrees = cdm_get_featureTrees_as_options();
1669 854e1d99 Andreas Kohlbecker
  $saved_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1670
  if(!isset($featureTrees['options'][$saved_uuid])) {
1671
    $saved_uuid = NULL;
1672
  }
1673 6657531f Andreas Kohlbecker
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
1674
    '#type' => 'radios',
1675
    '#title' => t('Natural language representation of structured descriptions') . ':',
1676 854e1d99 Andreas Kohlbecker
    '#default_value' => $saved_uuid,
1677 6657531f Andreas Kohlbecker
    '#options' => $featureTrees['options'],
1678 3f485c6d Andreas Kohlbecker
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1679
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1680 6657531f Andreas Kohlbecker
    '#description' => t('Taxon descriptions can be stored in a highly structured
1681
      form. The feature tree selected here will be used to generate textual
1682
      representation in natural language.'
1683
    ),
1684
  );
1685
1686
  // ---- LAYOUT PER FEATURE ---- //
1687
  $feature_tree = get_profile_featureTree();
1688 fae36a2a Andreas Kohlbecker
  if (isset($feature_tree->root->childNodes)) {
1689 6657531f Andreas Kohlbecker
1690
    $form_feature_list_layout = array(
1691
      '#title' => t('Taxon profile layout'),
1692
      '#collapsible' => TRUE,
1693
      '#collapsed' => FALSE,
1694
      '#type' => 'fieldset',
1695
      '#description' => t('Will be available in a future release.'),
1696
    );
1697
1698
    $feature_list_layout_settings_disabled = TRUE;
1699 fae36a2a Andreas Kohlbecker
    foreach ($feature_tree->root->childNodes as $featureNode) {
1700 6657531f Andreas Kohlbecker
1701
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1702
        // Must not exceed 45 characters !!!
1703
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1704
1705
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1706
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1707
1708
        $form_feature_list_layout[$subform_id] = array(
1709
          '#tree' => TRUE,
1710
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1711
          '#collapsible' => FALSE,
1712
          '#collapsed' => FALSE,
1713
          '#type' => 'fieldset',
1714
          '#description' => t(''),
1715
        );
1716
1717
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1718
          '#type' => 'checkbox',
1719
          '#title' => t('Enable'),
1720
          '#default_value' => $settings['enabled'],
1721
          '#description' => t('Enable user defined layout for this feature'),
1722
        );
1723
1724
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1725
          '#type' => 'textfield',
1726
          '#title' => t('Enclosing tag'),
1727
          '#disabled' => !$settings['enabled'],
1728
          '#default_value' => $settings['enclosingTag'],
1729
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1730
        );
1731
1732
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1733
          '#type' => 'textfield',
1734
          '#title' => t('Entry enclosing tag'),
1735
          '#disabled' => !$settings['enabled'],
1736
          '#default_value' => $settings['entryEnclosingTag'],
1737
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1738
        );
1739
1740
        $form_feature_list_layout[$subform_id]['glue'] = array(
1741
          '#type' => 'textfield',
1742
          '#title' => t('Glue'),
1743
          '#disabled' => !$settings['enabled'],
1744
          '#default_value' => $settings['glue'],
1745
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1746
        );
1747
1748
      }
1749
1750
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1751
    }
1752
  }
1753
1754
  // ---- DISTRIBUTION LAYOUT ---- //
1755
  $form['taxon_profile']['distribution_layout'] = array(
1756
    '#title' => t('Distribution'),
1757
    '#collapsible' => TRUE,
1758
    '#collapsed' => FALSE,
1759
    '#type' => 'fieldset',
1760
    '#description' => t('Select if you want to sort or not the distribution text
1761
      located below the distribution map.'),
1762
  );
1763
1764
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1765
    '#type' => 'radios',
1766
    '#title' => t('Sort') . ':',
1767
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1768
    '#options' => array(
1769
      'NO_SORT' => t('Standard (No sort)'),
1770
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1771
    ),
1772
  );
1773
1774
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1775
    '#type' => 'checkbox',
1776
    '#title' => t('Show TextData elements on top of the map'),
1777
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1778
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1779
      elements on top of the map. Otherwise all <code>TextData</code>
1780
      distribution elements will be listed below the other area elements.
1781
      This option is useful if you need to have descriptive texts for each
1782
      distribution map.'),
1783
  );
1784
1785 c6ee8193 Andreas Kohlbecker
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
1786
      '#type' => 'textarea',
1787
      '#title' => t('Custom status colors'),
1788
      '#element_validate' => array('form_element_validate_json'),
1789
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
1790
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
1791
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
1792 eb961cb9 Andreas Kohlbecker
          reference list of the idInVocabulary values of absence and presence terms:
1793 c6ee8193 Andreas Kohlbecker
<pre>
1794 eb961cb9 Andreas Kohlbecker
Presence Term
1795
p	present
1796
pd	present: doubtfully present
1797
n	native
1798
nq	native: presence questionable
1799
nd	native: doubtfully native
1800
c	cultivated
1801
i	introduced
1802
iq	introduced: presence questionable
1803
id	introduced: doubtfully introduced (perhaps cultivated only)
1804
ip	introduced: uncertain degree of naturalisation
1805
ia	introduced: adventitious (casual)
1806
in	introduced: naturalized
1807
ic	introduced: cultivated
1808
e	endemic for the relevant area
1809
na	naturalised
1810
iv	invasive
1811
1812
AbsenceTerm
1813
a	absent
1814
f	reported in error
1815
nf	native: reported in error
1816
if	introduced: reported in error
1817
cf	cultivated: reported in error
1818
ne	native: formerly native
1819
ie	introduced: formerly introduced
1820
1821 c6ee8193 Andreas Kohlbecker
</pre>'),
1822
  );
1823
1824 6657531f Andreas Kohlbecker
1825
  /* ====== SYNONYMY ====== */
1826
  $form['taxon_synonymy'] = array(
1827
    '#type' => 'fieldset',
1828
    '#title' => t('Taxon synonymy (tab)'),
1829
    '#collapsible' => TRUE,
1830
    '#collapsed' => TRUE,
1831
    '#description' => t('This section covers the settings related to the taxon
1832 501347df Andreas Kohlbecker
      <strong>synonymy</strong> tab.'),
1833 6657531f Andreas Kohlbecker
  );
1834
1835
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1836
    '#type' => 'checkbox',
1837
    '#title' => t('Show accepted taxon on top of the synonymy'),
1838
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1839
    '#description' => t('If checked, the first homotypic taxon is a repetition
1840
      of the accepted taxon most likely with the full nomenclatural reference
1841
      (depending on the currently chosen theme).'),
1842
  );
1843
1844
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1845
    '#type' => 'checkbox',
1846
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1847
      coming from a synonym link.'),
1848
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1849
    '#description' => t('Check this if after doing a search and clicking on a
1850
      synonym you want to see the "accept of" text for the accepted synonym.'),
1851
  );
1852
1853 24058570 Andreas Kohlbecker
  /* === currently unused ===
1854 6657531f Andreas Kohlbecker
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1855 5014bf09 Andreas Kohlbecker
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1856 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
1857
    '#title' => t('Display name relationships') . ':',
1858
    '#default_value' => variable_get('name_relationships_to_show', 0),
1859
    '#options' => $nameRelationshipTypeOptions,
1860
    '#description' => t('Select the name relationships you want to show for the
1861
      accepted taxa.'),
1862
  );
1863 24058570 Andreas Kohlbecker
 */
1864 6657531f Andreas Kohlbecker
1865 5014bf09 Andreas Kohlbecker
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1866 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1867
    '#title' => t('Show taxon relations ships of accepted taxon'),
1868
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1869
    '#description' => t('If this option is enabled the synonymy will show the
1870
      below selected taxon relationships of accepted taxa.'),
1871
  );
1872
1873
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1874 5014bf09 Andreas Kohlbecker
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1875 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
1876
    '#title' => t('Taxon relationship types') . ':',
1877
    '#description' => t('Only taxon relationships of the selected type will be
1878
      displayed'),
1879
    '#options' => $taxonRelationshipTypeOptions,
1880
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1881
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1882
  );
1883
1884
  // ====== SPECIMENS ====== //
1885
  $form['taxon_specimens'] = array(
1886
    '#type' => 'fieldset',
1887
    '#title' => t('Taxon specimens (tab)'),
1888
    '#collapsible' => TRUE,
1889
    '#collapsed' => TRUE,
1890
    '#description' => t('This section covers the settings related to the taxon
1891
      <strong>specimens</strong> tab.'),
1892
  );
1893
1894 854e1d99 Andreas Kohlbecker
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1895
  $saved_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1896
  if(!isset($featureTrees['options'][$saved_uuid])) {
1897
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1898 f19f47fa Andreas Kohlbecker
  }
1899
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1900
      '#type' => 'radios',
1901
      '#title' => t('Specimen description feature tree') . ':',
1902
      '#default_value' => $saved_uuid,
1903
      '#options' =>  $featureTrees['options'],
1904 3f485c6d Andreas Kohlbecker
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1905 f19f47fa Andreas Kohlbecker
      '#options_suffixes' => $featureTrees['treeRepresentations'],
1906
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1907
      ),
1908 bfb2b81a Andreas Kohlbecker
  );
1909
1910 6657531f Andreas Kohlbecker
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1911
  $form_title = t('Specimen media');
1912
  $form_description = t('Specimens may have media which is displayed at the
1913
     Specimen tab/section as a gallery. It is possible to configure the
1914
     thumbnails gallery here, however for configuring how a single media should
1915
     be displayed please go to !url.</p>',
1916
     array(
1917
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1918
     ));
1919
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1920
1921
  // --- MEDIA GALLERY ---- //
1922
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1923
  $form_title = 'Media gallery (tab)';
1924
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1925
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1926
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1927
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1928
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1929
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1930
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1931
1932
  // Comment @WA: D7 form api does not support reset buttons,
1933
  // so to mimic the D5 reset button we add one like this.
1934
  $form['actions']['reset'] = array(
1935
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1936
    '#weight' => 1000,
1937
  );
1938
  return system_settings_form($form);
1939
}
1940
1941
/**
1942
 * @todo document this function.
1943
 */
1944
function cdm_settings_layout_search() {
1945
1946
  $form = array();
1947
1948 c5ed6357 Andreas Kohlbecker
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
1949
1950 6657531f Andreas Kohlbecker
  $form['search_settings'] = array(
1951
    '#type' => 'fieldset',
1952
    '#title' => t('Taxa Search'),
1953 61b6ee11 Andreas Kohlbecker
    '#collapsible' => FALSE,
1954
    '#collapsed' => FALSE,
1955 6657531f Andreas Kohlbecker
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1956
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1957
         where they can write the text to be searched. You can find Drupal block configuration
1958
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1959
  );
1960
1961 f19f47fa Andreas Kohlbecker
  $form['search_settings']['simple_search_ignore_classification'] = array(
1962
      '#type' => 'checkbox',
1963
      '#title' => t('Ignore the chosen classification in simple search'),
1964
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
1965 61b6ee11 Andreas Kohlbecker
      '#description' => t('The simple search, which can be executed via the search block,
1966
          will by default search on all classifications. Remove the tick if you want your
1967
          portal to search on the classification selected in the classification browser
1968 f19f47fa Andreas Kohlbecker
          selector.'),
1969 61b6ee11 Andreas Kohlbecker
  );
1970
1971 6657531f Andreas Kohlbecker
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1972
    '#type' => 'textfield',
1973
    '#title' => t('Results per page') . ':',
1974
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1975
    '#description' => t('Number of results to display per page.'),
1976
  );
1977
1978 6280e639 Andreas Kohlbecker
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
1979
  $form['search_settings']['cdm_search_taxa_mode'] = array(
1980
      '#type' => 'checkboxes',
1981
      '#title' => 'Search mode',
1982
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
1983
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
1984
          for the advance search form and the behaviour of the simple search form which always will behave according to the
1985
          defaults set here.',
1986
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
1987
      '#default_value' => $search_mode_default
1988
      );
1989 6657531f Andreas Kohlbecker
1990
  // --- SEARCH TAXA GALLERY ---- //
1991
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1992
  $collapsed = FALSE;
1993
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1994
  $form_title = 'Taxa Search thumbnails';
1995
  $form_description = 'Search results may show thumbnails. ';
1996
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1997
1998
  // Comment @WA: D7 form api does not support reset buttons,
1999
  // so to mimic the D5 reset button we add one like this.
2000
  $form['actions']['reset'] = array(
2001
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2002
    '#weight' => 1000,
2003
  );
2004
  return system_settings_form($form);
2005
}
2006
2007
/**
2008
 * @todo document this function.
2009
 */
2010
function cdm_settings_layout_media() {
2011
2012
  $form = array();
2013
2014
  $form['media_settings'] = array(
2015
    '#type' => 'fieldset',
2016 a950f2f9 Andreas Kohlbecker
    '#title' => t('Media settings'),
2017
    '#collapsible' => FALSE,
2018 6657531f Andreas Kohlbecker
    '#collapsed' => FALSE,
2019 ccde8251 Andreas Kohlbecker
    '#description' => 'This section covers layout settings for media pages.'
2020
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2021 6657531f Andreas Kohlbecker
  );
2022
2023
  $form['media_settings']['image_gallery_viewer'] = array(
2024
    '#type' => 'select',
2025
    '#title' => t('Image viewer') . ':',
2026
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2027
    '#options' => array(
2028
      'default' => t('Standard image viewer'),
2029
      'fsi' => t('FSI viewer (requires FSI server!)'),
2030
    ),
2031
  );
2032
2033
  // --- MEDIA GALLERY ---- //
2034
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2035
  $form_title = 'Standard viewer';
2036
  $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>';
2037
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2038
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2039
2040
  // @WA: D7 form api does not support reset buttons,
2041
  // so to mimic the D5 reset button we add one like this.
2042
  $form['actions']['reset'] = array(
2043
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2044
    '#weight' => 1000,
2045
  );
2046
  return system_settings_form($form);
2047
}
2048
2049
/**
2050
 * GEOSERVICE and Map settings.
2051
 */
2052 1d39ec64 w.addink
function cdm_settings_geo($form, &$form_state) {
2053 6657531f Andreas Kohlbecker
2054 cc3c9807 Andreas Kohlbecker
  $current_geoserver_settings = get_edit_map_service_settings();
2055
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2056 d5661a4c Andreas Kohlbecker
  // The default layer must always be enabled
2057
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2058
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2059 cc3c9807 Andreas Kohlbecker
2060 6657531f Andreas Kohlbecker
  $form = array();
2061
2062 cc3c9807 Andreas Kohlbecker
  $dummy_distribution_query = NULL;
2063
  if($map_distribution['map_type'] != 1){
2064
    // we need to apply a dummy query since the map serice requires for image maps
2065
    // at least as and ad to be defined
2066
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2067
  }
2068 d2fd2a4c Andreas Kohlbecker
  $form['map_preview'] = array(
2069
      '#type' => 'fieldset',
2070
      '#tree' => FALSE,
2071
      '#title' => t('Map preview'),
2072
      '#collapsible' => FALSE,
2073 cc3c9807 Andreas Kohlbecker
      '#description' => 'The preview of the map'
2074 2bbc28c8 Andreas Kohlbecker
       . ($dummy_distribution_query != null ?
2075
           ' may not be accurate in case if image maps, please check the map display in the taxon pages.':
2076 d5661a4c Andreas Kohlbecker
           '.<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.')
2077 d2fd2a4c Andreas Kohlbecker
  );
2078 cc3c9807 Andreas Kohlbecker
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL,
2079 d2fd2a4c Andreas Kohlbecker
      array(
2080
          'move' => "this.cdmOpenlayersMap.printInfo",
2081
          '#execute' => "this.cdmOpenlayersMap.printInfo"
2082
      )
2083
  );
2084
2085 cc3c9807 Andreas Kohlbecker
2086 6657531f Andreas Kohlbecker
  /*
2087 d2fd2a4c Andreas Kohlbecker
   * GEO SERVER
2088
   */
2089 ba706bf0 Andreas Kohlbecker
  $form['edit_map_server'] = array(
2090 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2091 ba706bf0 Andreas Kohlbecker
    '#tree' => true,
2092
    '#title' => t('EDIT map service'),
2093 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
2094
    '#collapsed' => TRUE,
2095
    '#description' => t('Configuration and selection of your geo server.
2096
      The Geo Server is responsible for generating the maps.'),
2097
  );
2098
2099 f19f47fa Andreas Kohlbecker
  $form['edit_map_server']['base_uri'] = array(
2100 6657531f Andreas Kohlbecker
    '#type' => 'select',
2101 ba706bf0 Andreas Kohlbecker
    '#title' => t('EDIT map service') . ':',
2102
    '#default_value' => $current_geoserver_settings['base_uri'],
2103
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2104
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2105 6657531f Andreas Kohlbecker
  );
2106 f19f47fa Andreas Kohlbecker
  $form['edit_map_server']['version'] = array(
2107
      '#type' => 'select',
2108
      '#title' => t('Version') . ':',
2109
      '#default_value' => $current_geoserver_settings['version'],
2110
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2111
      '#description' => t('The version of the EDIT map services'),
2112 6657531f Andreas Kohlbecker
  );
2113
2114 cc3c9807 Andreas Kohlbecker
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
2115
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
2116
  $form['gmap_api_key'] = array(
2117
      '#type' => 'textfield',
2118
      '#title' => t('Google maps API key') . ':',
2119
      '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
2120
      '#description' => t('If you want to use the Google Maps Layer, a key is
2121
      needed. If you need a key, visit
2122
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
2123
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
2124
      is the default key for the localhost (127.0.0.1).',
2125
      array('!localhostkey' => $localhostkey)),
2126
  );
2127
2128
2129 6657531f Andreas Kohlbecker
  /*
2130 d2fd2a4c Andreas Kohlbecker
   * MAP SETTINGS
2131
   */
2132 cc3c9807 Andreas Kohlbecker
2133
  $form[CDM_MAP_DISTRIBUTION] = array(
2134 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2135 cc3c9807 Andreas Kohlbecker
    '#tree' => TRUE,
2136 6657531f Andreas Kohlbecker
    '#title' => t('Maps settings'),
2137
    '#collapsible' => TRUE,
2138
    '#collapsed' => TRUE,
2139
    '#description' => t('General configuration for all map types.'),
2140
  );
2141
2142 cc3c9807 Andreas Kohlbecker
  /*
2143
   * settings for the distribution map are used also for specimens map!!!!
2144
   */
2145
2146
  $form[CDM_MAP_DISTRIBUTION]['width'] = array(
2147 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2148 cc3c9807 Andreas Kohlbecker
    '#title' => 'Width',
2149
    '#default_value' => $map_distribution['width'],
2150
    '#maxlength' => 4,
2151
    '#size' => 4,
2152
    '#description' => 'Width of the map. To allow OSM baselayers to zoom out to the full extend of the world the map width must be
2153 d2fd2a4c Andreas Kohlbecker
      a multiple of 256px since the osm tiles from tile.openstreetmap.org have a size of 256px x 256px and frational zoom
2154
      levels are not possible in this case.',
2155 6657531f Andreas Kohlbecker
  );
2156 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['height'] = array(
2157
      '#type' => 'textfield',
2158
      '#title' => 'Height',
2159
      '#default_value' => $map_distribution['height'],
2160
      '#maxlength' => 4,
2161
      '#size' => 4,
2162
      '#description' => 'Height of the map. Depending on the chosen base layer you may want to choose the height equal
2163
      to the width or half of the width. Any other aspect ratio is also possible if desired.',
2164
  );
2165 6657531f Andreas Kohlbecker
2166 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2167 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2168 cc3c9807 Andreas Kohlbecker
    '#title' => 'Bounding box',
2169
    '#default_value' => $map_distribution['bbox'],
2170 14339c2a Andreas Kohlbecker
    '#description' => t('The bounding box (left, bottom, right, top) defines the area to be initially displayed in maps.
2171 6657531f Andreas Kohlbecker
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2172 2bbc28c8 Andreas Kohlbecker
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2173
      <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.
2174 d5661a4c Andreas Kohlbecker
      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
2175 2bbc28c8 Andreas Kohlbecker
      below the map from where you can copy the bbox string.</p>'),
2176 6657531f Andreas Kohlbecker
  );
2177
2178 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2179 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
2180 cc3c9807 Andreas Kohlbecker
    '#title' => 'Display area labels',
2181
    '#default_value' => $map_distribution['show_labels'],
2182
    '#description' => t('The map will show name labels of the areas'),
2183 6657531f Andreas Kohlbecker
  );
2184
2185 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2186 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2187 cc3c9807 Andreas Kohlbecker
    '#title' => 'Map caption',
2188
    '#default_value' => $map_distribution['caption'],
2189
    '#description' => t('The caption will be shown below the map.'),
2190 6657531f Andreas Kohlbecker
  );
2191
2192 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2193 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2194 cc3c9807 Andreas Kohlbecker
    '#title' => 'Distribution layer opacity',
2195
    '#default_value' => $map_distribution['distribution_opacity'],
2196 6657531f Andreas Kohlbecker
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
2197
                           fully visible, while a value near to 0.0 will be not much visible.'),
2198
  );
2199
2200 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2201 6657531f Andreas Kohlbecker
    '#type' => 'radios',
2202 cc3c9807 Andreas Kohlbecker
    '#title' => 'Map types',
2203 6657531f Andreas Kohlbecker
    '#options' => array(
2204 cc3c9807 Andreas Kohlbecker
      1 => "OpenLayers dynamic map viewer",
2205 6657531f Andreas Kohlbecker
      0 => "Plain image",
2206
    ),
2207 cc3c9807 Andreas Kohlbecker
    '#default_value' => $map_distribution['map_type'],
2208
    '#description' => 'Two different map types are available :
2209
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2210
      which allows zooming and panning. If enabled you can configure the default layer
2211
      (background of your maps) below.</li>
2212
      <li><em>Plain image</em>: The map will be static non interactive
2213
      image.</li></ul>',
2214 6657531f Andreas Kohlbecker
  );
2215 cc3c9807 Andreas Kohlbecker
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2216 6657531f Andreas Kohlbecker
2217
2218
  // --- Plain Image Settings --- //
2219 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2220 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2221 cc3c9807 Andreas Kohlbecker
    '#title' => 'Plain image map settings',
2222
    '#tree' => TRUE,
2223 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
2224 cc3c9807 Andreas Kohlbecker
    '#collapsed' => $open_layers_is_enabled,
2225
    '#description' => 'The settings in this section are still expertimental
2226
      and can only be used with the EDIT map service version 1.1 or above.',
2227 6657531f Andreas Kohlbecker
  );
2228 ba706bf0 Andreas Kohlbecker
  $edit_mapserver_version = get_edit_map_service_version_number();
2229 6657531f Andreas Kohlbecker
  if ($edit_mapserver_version < 1.1) {
2230 cc3c9807 Andreas Kohlbecker
    $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>'
2231
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2232 6657531f Andreas Kohlbecker
  }
2233
2234 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2235 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2236 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background layer',
2237
    '#default_value' => $map_distribution['image_map']['base_layer'],
2238 6657531f Andreas Kohlbecker
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2239 cc3c9807 Andreas Kohlbecker
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2240
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2241 6657531f Andreas Kohlbecker
    )),
2242
  );
2243
2244 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2245 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2246 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background color',
2247
    '#default_value' => $map_distribution['image_map']['bg_color'],
2248 6657531f Andreas Kohlbecker
  );
2249
2250 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2251 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2252 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background layer style',
2253 6657531f Andreas Kohlbecker
     // Only line color by now.
2254 cc3c9807 Andreas Kohlbecker
    '#default_value' => $map_distribution['image_map']['layer_style'],
2255
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2256 6657531f Andreas Kohlbecker
  );
2257
2258 4bef194f Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2259
      '#type' => 'textfield',
2260
      '#title' => 'Projection',
2261
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2262
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2263
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2264
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2265
  );
2266
2267 6657531f Andreas Kohlbecker
2268
  // --- OpenLayers Settings --- //
2269 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2270 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2271 cc3c9807 Andreas Kohlbecker
    '#title' => 'OpenLayers settings',
2272
    '#tree' => TRUE,
2273 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
2274 cc3c9807 Andreas Kohlbecker
    '#collapsed' => !$open_layers_is_enabled,
2275 6657531f Andreas Kohlbecker
    '#description' => '',
2276
  );
2277
2278 2bbc28c8 Andreas Kohlbecker
2279
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2280
      '#type' => 'checkbox',
2281
      '#title' => 'Display outside max extent',
2282
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2283
      '#description' => t('Allows the map to display parts of the layers which are outside
2284
         the max extent if the aspect ratio of the map and of the baselayer
2285
         are not equal.'),
2286
  );
2287
2288 570f0e73 Andreas Kohlbecker
2289 2bbc28c8 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2290
      '#type' => 'checkbox',
2291
      '#title' => 'Show Layer Switcher',
2292
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2293
      '#description' => 'The Layer Switcher control displays a table of contents
2294
      for the map.  This allows the user interface to switch between
2295
      base layers and to show or hide overlays.  By default the switcher is
2296
      shown minimized on the right edge of the map, the user may expand it
2297
      by clicking on the handle.',
2298
  );
2299
2300 cc3c9807 Andreas Kohlbecker
  if (!$open_layers_is_enabled) {
2301
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2302
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2303
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2304 6657531f Andreas Kohlbecker
  }
2305
2306
  $baselayer_options = array(
2307
    /*
2308
   NOTICE: must correspond to the layers defined in
2309
   js/openlayers_,ap.js#getLayersByName()
2310
   */
2311 1d39ec64 w.addink
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
2312
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
2313 6657531f Andreas Kohlbecker
    // all others EPSG:900913
2314
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
2315
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2316
    'mapnik' => 'OpenStreetMap',
2317 2bbc28c8 Andreas Kohlbecker
    'mapquest_open' => "MapQuest",
2318
    'mapquest_sat' => "MapQuest Sattelite",
2319
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2320 6657531f Andreas Kohlbecker
    'gmap' => 'Google Streets',
2321
    'gsat' => 'Google Satellite',
2322
    'ghyb' => 'Google Hybrid',
2323 cc3c9807 Andreas Kohlbecker
//     'veroad' => 'Virtual Earth Roads',
2324
//     'veaer' => 'Virtual Earth Aerial',
2325
//     'vehyb' => 'Virtual Earth Hybrid',
2326 6657531f Andreas Kohlbecker
    // 'yahoo' => 'Yahoo Street',
2327
    // 'yahoosat' => 'Yahoo Satellite',
2328
    // 'yahoohyb' => 'Yahoo Hybrid',
2329 2bbc28c8 Andreas Kohlbecker
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2330 6657531f Andreas Kohlbecker
  );
2331
2332 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2333 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes_preferred',
2334 cc3c9807 Andreas Kohlbecker
    '#title' => 'Base Layers',
2335 6657531f Andreas Kohlbecker
    '#options' => $baselayer_options,
2336 cc3c9807 Andreas Kohlbecker
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2337
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2338 6657531f Andreas Kohlbecker
  );
2339
2340 2bbc28c8 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2341
      '#type' => 'fieldset',
2342
      '#title' => 'Custom WMS base layer',
2343
      '#tree' => TRUE,
2344
      '#collapsible' => FALSE,
2345
      '#collapsed' => FALSE,
2346
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2347
  );
2348
2349
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2350
      '#type' => 'textfield',
2351
      '#title' => 'Layer name',
2352
      // Only line color by now.
2353
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2354
      '#description' => 'A arbitrary name for the layer.',
2355
  );
2356
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2357
      '#type' => 'textfield',
2358
      '#title' => 'WMS url',
2359
      // Only line color by now.
2360
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2361
      '#description' => 'Base url for the WMS (e.g.  http://wms.jpl.nasa.gov/wms.cgi)'
2362
  );
2363
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2364
      '#type' => 'textarea',
2365
      '#title' => 'WMS parameters',
2366
      '#element_validate' => array('form_element_validate_json'),
2367
      // Only line color by now.
2368
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2369 570f0e73 Andreas Kohlbecker
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2370
<pre> {
2371
  "Layers": "topp:em_tiny_jan2003",
2372
  "Format": "image/png",
2373
  "BGCOLOR": "0xe0faff"
2374
}
2375
</pre>'
2376 2bbc28c8 Andreas Kohlbecker
  );
2377
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2378
      '#type' => 'textfield',
2379
      '#title' => 'Projection',
2380
      // Only line color by now.
2381
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2382
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2383
  );
2384 e3026d72 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2385
      '#type' => 'textfield',
2386 14339c2a Andreas Kohlbecker
      '#maxlength' => 256,
2387 e3026d72 Andreas Kohlbecker
      '#title' => 'proj4js definition',
2388
      // Only line color by now.
2389
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2390
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2391
            The definitions for
2392
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2393
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2394
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2395
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2396
            choose to display the proj4js definition string.
2397 7f71136d Andreas Kohlbecker
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2398
            <pre>
2399
+a         Semimajor radius of the ellipsoid axis
2400
+alpha     ? Used with Oblique Mercator and possibly a few others
2401
+axis      Axis orientation (new in 4.8.0)
2402
+b         Semiminor radius of the ellipsoid axis
2403
+datum     Datum name (see `proj -ld`)
2404
+ellps     Ellipsoid name (see `proj -le`)
2405
+k         Scaling factor (old name)
2406
+k_0       Scaling factor (new name)
2407
+lat_0     Latitude of origin
2408
+lat_1     Latitude of first standard parallel
2409
+lat_2     Latitude of second standard parallel
2410
+lat_ts    Latitude of true scale
2411
+lon_0     Central meridian
2412
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
2413
+lon_wrap  Center longitude to use for wrapping (see below)
2414
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
2415
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
2416
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
2417
+pm        Alternate prime meridian (typically a city name, see below)
2418
+proj      Projection name (see `proj -l`)
2419
+south     Denotes southern hemisphere UTM zone
2420
+to_meter  Multiplier to convert map units to 1.0m
2421
+towgs84   3 or 7 term datum transform parameters (see below)
2422
+units     meters, US survey feet, etc.
2423
+vto_meter vertical conversion to meters.
2424
+vunits    vertical units.
2425
+x_0       False easting
2426
+y_0       False northing
2427
+zone      UTM zone
2428
            </pre>
2429
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
2430 e3026d72 Andreas Kohlbecker
  );
2431 2bbc28c8 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
2432
      '#type' => 'textfield',
2433
      '#title' => 'Maximum extent',
2434
      // Only line color by now.
2435
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
2436 14339c2a Andreas Kohlbecker
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
2437 2bbc28c8 Andreas Kohlbecker
  );
2438
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
2439
      '#type' => 'textfield',
2440
      '#title' => 'Units',
2441
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
2442
      '#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.'
2443 6657531f Andreas Kohlbecker
  );
2444
2445 cc3c9807 Andreas Kohlbecker
  /*
2446
   * Map Legend
2447
   */
2448
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2449 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2450 cc3c9807 Andreas Kohlbecker
    '#title' => 'Map legend',
2451
    '#tree' => TRUE,
2452 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
2453
    '#collapsed' => TRUE,
2454 cc3c9807 Andreas Kohlbecker
    '#description' => 'Configure the maps legend.',
2455 6657531f Andreas Kohlbecker
  );
2456
2457 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2458 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
2459 cc3c9807 Andreas Kohlbecker
    '#title' => 'Display a map legend',
2460
    '#default_value' => $map_distribution['legend']['show'],
2461
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2462 6657531f Andreas Kohlbecker
  );
2463
2464 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2465 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2466 cc3c9807 Andreas Kohlbecker
    '#title' => 'Legend opacity',
2467
    '#default_value' => $map_distribution['legend']['opacity'],
2468
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2469
                         to 0.0 will be not much visible.',
2470 6657531f Andreas Kohlbecker
  );
2471
2472 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2473 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2474 cc3c9807 Andreas Kohlbecker
    '#title' => 'Font size',
2475
    '#default_value' => $map_distribution['legend']['font_size'],
2476
    '#description' => 'Font size in pixels.',
2477 6657531f Andreas Kohlbecker
  );
2478
2479
  $fontStyles = array(
2480
    0 => "plane",
2481
    1 => "italic",
2482
  );
2483 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2484 6657531f Andreas Kohlbecker
    '#type' => 'select',
2485 cc3c9807 Andreas Kohlbecker
    '#title' => 'Available font styles',
2486
    '#default_value' => $map_distribution['legend']['font_style'],
2487 6657531f Andreas Kohlbecker
    '#options' => $fontStyles,
2488 cc3c9807 Andreas Kohlbecker
    '#description' => 'Select a font style for the map legend.',
2489 6657531f Andreas Kohlbecker
  );
2490
2491 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2492 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2493 cc3c9807 Andreas Kohlbecker
    '#title' => 'Icon width',
2494
    '#default_value' => $map_distribution['legend']['icon_width'],
2495
    '#description' => 'Legend icon width in pixels.',
2496 6657531f Andreas Kohlbecker
  );
2497 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2498 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2499 cc3c9807 Andreas Kohlbecker
    '#title' => 'Icon height',
2500
    '#default_value' => $map_distribution['legend']['icon_height'],
2501
    '#description' => 'Legend icon height in pixels.',
2502 6657531f Andreas Kohlbecker
  );
2503
2504
  // @WA: D7 form api does not support reset buttons,
2505
  // so to mimic the D5 reset button we add one like this.
2506
  $form['actions']['reset'] = array(
2507
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2508
    '#weight' => 1000,
2509
  );
2510 1d39ec64 w.addink
2511 6657531f Andreas Kohlbecker
  return system_settings_form($form);
2512
}
2513
2514
/**
2515
 * @todo document this function.
2516
 */
2517
function cdm_settings_cache() {
2518
2519
  $form = array();
2520
2521
  $form['cache_settings'] = array(
2522
    '#type' => 'fieldset',
2523
    '#title' => t('Cache Settings'),
2524
    '#collapsible' => FALSE,
2525
    '#collapsed' => FALSE,
2526
    '#description' => t('<p>When caching is enabled all single taxon sites are
2527
      stored in an internal drupal cache doing the portal response of taxa pages
2528
      faster. This is possible because the sites are loaded from the cache and
2529
      are not created from scratch.</p>'),
2530
  );
2531
2532
  $form['cache_settings']['cdm_webservice_cache'] = array(
2533
    '#type' => 'checkbox',
2534
    '#title' => t('<strong>Enable caching</strong>'),
2535
    '#options' => cdm_help_general_cache(),
2536
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2537
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2538
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2539
       application the changes will be not visible till the cache is erased.
2540
       Therefore developers should deactived this feature when they are working
2541
       on the CDM Dataportal Module.</p>'),
2542
  );
2543
2544
  $form['cache_settings']['cdm_run_cache'] = array(
2545
    '#markup' => cdm_view_cache_site(),
2546
  );
2547
2548
  // @WA: D7 form api does not support reset buttons,
2549
  // so to mimic the D5 reset button we add one like this.
2550
  $form['actions']['reset'] = array(
2551
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2552
    '#weight' => 1000,
2553
  );
2554
  return system_settings_form($form);
2555
}
2556
2557
/**
2558
 * Walk and cache all taxon pages.
2559
 */
2560
function cdm_view_cache_site() {
2561
2562
  $out = '';
2563
2564
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2565
2566
  $request_params = array();
2567 7d828d59 Andreas Kohlbecker
  $request_params['class'] = "Taxon";
2568 6657531f Andreas Kohlbecker
2569 7d828d59 Andreas Kohlbecker
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2570
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2571
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2572 6657531f Andreas Kohlbecker
2573
  $out .= t('<p><strong>Cache all taxon pages</strong></p>');
2574
  $out .= '<p>When you launch the cache process the cache is filled and ready to be enabled.<br/>
2575
  Remember that when you load the taxa from the cache last changes on taxa will be not visible till you erase
2576
  the cache and fill it again.</p>';
2577
  $out .= '<p>Before  running the cache bot you have to empty the cache manually.</p>';
2578
2579
  $out .= '<div>' . t('This caching process may take long time and could cause heavy load on your server') . '</div>';
2580
  $out .= '<div id="progress"></div>';
2581
2582
  // Comment @WA: A form within a form is not valid html and not needed here.
2583
  // Also, it would be recommended just to include this part of the form in the
2584
  // rest of the form array in cdm_settings_cache().
2585
  // $out .= '<form id="cache_site">';
2586 0516e3d0 Andreas Kohlbecker
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2587 7d828d59 Andreas Kohlbecker
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2588 6657531f Andreas Kohlbecker
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2589
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2590
  // $out .= '</form>';
2591
  $out .= '</div>';
2592
  /*
2593
  foreach($taxonPager->records as $taxon){
2594
    cdm_dataportal_taxon_view($uuid);
2595
  }
2596
  */
2597
  return $out;
2598
}
2599
2600 7df1be04 Andreas Kohlbecker
2601
function cdm_settings_layout_taxon_submit($form, &$form_state){
2602 9c92cd84 Andreas Kohlbecker
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2603
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2604
    if(is_object($file)){
2605
      $file->status = FILE_STATUS_PERMANENT;
2606
      file_save($file);
2607
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2608
    }
2609 7df1be04 Andreas Kohlbecker
  }
2610 d5403dc4 Andreas Kohlbecker
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2611
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2612
    // we first need to set the variable to persist the changes setting
2613
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
2614
    menu_rebuild();
2615
  }
2616 7df1be04 Andreas Kohlbecker
}
2617
2618 c5ed6357 Andreas Kohlbecker
function cdm_settings_layout_search_submit($form, &$form_state){
2619
  // the visibility of media thumbnails also affects the ui of the search results
2620
  // so reset the according session variable
2621
  //    1. in order to give the user immediate
2622
  //       feedback on potential setting changes
2623
  //    2. let refresh the default if it has changed
2624
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2625
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
2626
  }
2627
}
2628
2629 6657531f Andreas Kohlbecker
/**
2630 d1eb0a8c Andreas Kohlbecker
 * Form validation handler for cdm_settings_general
2631 6657531f Andreas Kohlbecker
 *
2632 22eb20d7 Andreas Kohlbecker
 * @param $form
2633
 * @param $form_state
2634 6657531f Andreas Kohlbecker
 */
2635 d1eb0a8c Andreas Kohlbecker
function cdm_settings_general_validate($form, &$form_state) {
2636 6657531f Andreas Kohlbecker
2637
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2638
    $form_state['values']['cdm_webservice_url'] .= '/';
2639
  }
2640
2641 d1eb0a8c Andreas Kohlbecker
}
2642
2643 22eb20d7 Andreas Kohlbecker
/**
2644
 * Form submit handler for settings general.
2645
 *
2646
 * tasks performed:
2647
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2648
 *
2649
 * @param $form
2650
 * @param $form_state
2651
 */
2652
function cdm_settings_general_submit($form, &$form_state){
2653
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2654
  unset($_SESSION['cdm']['taxonomictree_uuid']);
2655
}
2656
2657 d1eb0a8c Andreas Kohlbecker
/**
2658
 * Form validation handler for cdm_settings_cache
2659
 */
2660 847bb49e Andreas Kohlbecker
function cdm_settings_cache_validate($form, &$form_state) {
2661 6657531f Andreas Kohlbecker
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2662
    cache_clear_all(NULL, 'cache_cdm_ws');
2663
    // Better clear secref_cache since I can not be sure if the cache has not
2664
    // be used during this response.
2665
    cdm_api_secref_cache_clear();
2666
  }
2667 d1eb0a8c Andreas Kohlbecker
2668 6657531f Andreas Kohlbecker
}
2669
2670
/**
2671 ba706bf0 Andreas Kohlbecker
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
2672
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
2673
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
2674
 *  - version: the version, e.g.: v1.1
2675
 *
2676
 * @return array
2677
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
2678 6657531f Andreas Kohlbecker
 */
2679 ba706bf0 Andreas Kohlbecker
function get_edit_map_service_settings() {
2680
2681
  $settings = variable_get('edit_map_server', array(
2682
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
2683
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
2684
      )
2685
  );
2686 6657531f Andreas Kohlbecker
2687 ba706bf0 Andreas Kohlbecker
  return $settings;
2688 6657531f Andreas Kohlbecker
}
2689
2690
/**
2691 ba706bf0 Andreas Kohlbecker
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2692
 *
2693
 * @return string
2694
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2695
 */
2696
function get_edit_map_service_full_uri() {
2697
  $settings = get_edit_map_service_settings();
2698
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
2699
}
2700
2701
2702
/**
2703
 * Returns the version number of the currently selected edit mapserver as a float
2704 6657531f Andreas Kohlbecker
 *
2705
 * @return float
2706
 *   The version number of the currently selected edit mapserver as a float.
2707
 *   Returns 0 on error.
2708
 */
2709 ba706bf0 Andreas Kohlbecker
function get_edit_map_service_version_number() {
2710 6657531f Andreas Kohlbecker
2711 ba706bf0 Andreas Kohlbecker
  $pattern = '/v([\d\.]+).*$/';
2712 6657531f Andreas Kohlbecker
2713 ba706bf0 Andreas Kohlbecker
  $settings = get_edit_map_service_settings();
2714
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
2715 6657531f Andreas Kohlbecker
  if (isset($matches[1])) {
2716
    // Convert string to float.
2717
    $version = 1 + $matches[1][0] - 1;
2718
    return $version;
2719
  }
2720
  else {
2721
    // Report error.
2722 ba706bf0 Andreas Kohlbecker
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
2723
        array(
2724
          '!version' => $settings['version'],
2725
          'warning')
2726
        )
2727
      );
2728 6657531f Andreas Kohlbecker
    return 0;
2729
  }
2730
}
2731
2732 30f78c59 Andreas Kohlbecker
/**
2733 ba706bf0 Andreas Kohlbecker
 * Returns the array of selected items in a options array
2734 30f78c59 Andreas Kohlbecker
 *
2735
 * @param array $options
2736
 *   An options array as generated by a form element like checkoxes, select ...,
2737
 */
2738
function get_selection($options) {
2739
  $selection = array();
2740
  foreach ($options as $key=>$val) {
2741
    if (!empty($val)) {
2742
      $selection[] = $val;
2743
    }
2744
  }
2745
  return $selection;
2746
}
2747
2748 bfb2b81a Andreas Kohlbecker
2749 6657531f Andreas Kohlbecker
/**
2750
 * Implements hook_element_info().
2751
 *
2752 14feebe9 Andreas Kohlbecker
 * Allows modules to declare their own Form API element types and specify their default values.
2753
 *
2754
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
2755 6657531f Andreas Kohlbecker
 */
2756
function cdm_dataportal_element_info() {
2757
  $type['checkboxes_preferred'] = array(
2758
    '#input' => TRUE,
2759 14feebe9 Andreas Kohlbecker
    '#process' => array('checkboxes_preferred_expand'),
2760 6657531f Andreas Kohlbecker
    '#after_build' => array('checkboxes_preferred_after_build'),
2761
    '#theme' => array('checkboxes_preferred'),
2762
    // '#theme_wrapper' => array('form_element'),
2763
  );
2764
  return $type;
2765
}
2766
2767
/**
2768 14feebe9 Andreas Kohlbecker
 * #process callback function for the custom form element type 'checkbox_preferred'
2769
 *
2770
 *
2771 6657531f Andreas Kohlbecker
 */
2772 14feebe9 Andreas Kohlbecker
function checkboxes_preferred_expand($element, &$form_state, $form) {
2773
2774
  // First of all create checkboxes for each of the elements
2775 6657531f Andreas Kohlbecker
  $element = form_process_checkboxes($element);
2776
2777 cc3c9807 Andreas Kohlbecker
  // compose the element name
2778
  $parents = array();
2779
  array_deep_copy($element['#parents'], $parents);
2780
  $parents[count($parents) -1 ] .= '_preferred';
2781
  $element_name = $parents[0];
2782
  for ($i=1; $i < count($parents); $i++){
2783
    $element_name .= '[' . $parents[$i] . ']';
2784
  }
2785
2786 6657531f Andreas Kohlbecker
  $children = element_children($element);
2787
2788
  $element['table_start'] = array(
2789
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
2790
    '#weight' => -1,
2791
  );
2792
2793 14feebe9 Andreas Kohlbecker
  // prepare first part each of the table rows which contains the row label
2794 6657531f Andreas Kohlbecker
  $weight = 0;
2795
  foreach ($children as $key) {
2796
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
2797
    $element[$key]['#weight'] = $weight;
2798
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
2799
    $element[$key]['#suffix'] = '</td>';
2800
    unset($element[$key]['#title']);
2801
    $weight += 2;
2802
  }
2803
  $weight = 0;
2804
2805 14feebe9 Andreas Kohlbecker
  // add a radio button to each of the checkboxes, the
2806
  // check boxes have already been created at the beginning
2807
  // of this function
2808 6657531f Andreas Kohlbecker
  if (count($element['#options']) > 0) {
2809
    foreach ($element['#options'] as $key => $choice) {
2810
      if (!isset($element[$key . '_preferred'])) {
2811
        $element[$key . '_preferred'] = array(
2812
          '#type' => 'radio',
2813 cc3c9807 Andreas Kohlbecker
          '#name' => $element_name,
2814 6657531f Andreas Kohlbecker
          '#return_value' => check_plain($key),
2815
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
2816
          '#attributes' => $element['#attributes'],
2817 1d39ec64 w.addink
          '#parents' => $element['#parents'],
2818 6657531f Andreas Kohlbecker
          // '#spawned' => TRUE,
2819
          '#weight' => $weight + 1,
2820 14feebe9 Andreas Kohlbecker
          '#prefix' => '<td>',        // add a prefix to start a new table cell
2821
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
2822 6657531f Andreas Kohlbecker
        );
2823
      }
2824
      $weight += 2;
2825
    }
2826
  }
2827
2828 14feebe9 Andreas Kohlbecker
  // end the table
2829 6657531f Andreas Kohlbecker
  $element['table_end'] = array(
2830
    '#markup' => '</table>',
2831
    '#weight' => $weight++,
2832
  );
2833
2834
  return $element;
2835
}
2836
2837
/**
2838
 * Theme function for the custom form field 'checkboxes_preferred'.
2839
 */
2840
function theme_checkboxes_preferred($variables) {
2841
  $element = $variables['element'];
2842
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
2843
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
2844
  $out .= drupal_render_children($element);
2845
  $out .= '<div class="description">' . $element['#description'] . '</div>';
2846
  $out .= '</div>';
2847
  return $out;
2848
}
2849
2850
/**
2851 14feebe9 Andreas Kohlbecker
 * Callback for checkboxes preferred for widget which will
2852
 * be called after the form or element is built. The call
2853
 * back is configured in the form element by setting it as
2854
 * #after_build parameter.
2855
 *
2856
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
2857
 *
2858 cc3c9807 Andreas Kohlbecker
 * @param $element
2859 14feebe9 Andreas Kohlbecker
 *   Nested array of form elements that comprise the form.
2860
 * @param $form_state
2861
 *   A keyed array containing the current state of the form.
2862 cc3c9807 Andreas Kohlbecker
 *   This includes the current persistent storage data for the form.
2863
 *   Additional information, like the sanitized $_POST data,
2864
 *   is also accumulated here in $form_state['input']
2865 14feebe9 Andreas Kohlbecker
 *
2866
 * @return the modified form array
2867 6657531f Andreas Kohlbecker
 */
2868 cc3c9807 Andreas Kohlbecker
function checkboxes_preferred_after_build($element, &$form_state) {
2869 6657531f Andreas Kohlbecker
2870 cc3c9807 Andreas Kohlbecker
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
2871 6657531f Andreas Kohlbecker
2872
  if ($_POST && count($_POST) > 0) {
2873 cc3c9807 Andreas Kohlbecker
    // TODO use  $form_state['input'] instead of POST !!!
2874 6657531f Andreas Kohlbecker
    // First pass of form processing.
2875 cc3c9807 Andreas Kohlbecker
    $parents = array();
2876
    array_deep_copy($element['#parents'], $parents);
2877
    $parents[count($parents) - 1] .= '_preferred';
2878
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
2879
    $element['#value']['PREFERRED'] = $preferred_layer;
2880
//     $form_state[$parent_id] = $element['#value'];
2881
//     $form_state['values']['baselayers'] = $element['#value'];
2882
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
2883
    $form_state_element_values = $element['#value'];
2884 6657531f Andreas Kohlbecker
  }
2885
  else {
2886
    // Second pass of form processing.
2887 cc3c9807 Andreas Kohlbecker
    $preferred_layer = $element['#value']['PREFERRED'];
2888 6657531f Andreas Kohlbecker
  }
2889
2890
  // Also set the chosen value (not sure if this is good Drupal style ....).
2891 cc3c9807 Andreas Kohlbecker
  foreach ($children = element_children($element) as $key) {
2892
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
2893
      $element[$key]['#value'] = $preferred_layer;
2894 6657531f Andreas Kohlbecker
    }
2895
  }
2896
  // The default layer must always be enabled.
2897 cc3c9807 Andreas Kohlbecker
  $element[$preferred_layer]['#value'] = $preferred_layer;
2898 6657531f Andreas Kohlbecker
2899 cc3c9807 Andreas Kohlbecker
  return $element;
2900 6657531f Andreas Kohlbecker
}
2901 0f5f1c12 Andreas Kohlbecker
2902 3f485c6d Andreas Kohlbecker
function radios_prepare_options_suffix(&$elements){
2903
2904
  $childrenKeys = element_children($elements);
2905
  foreach($childrenKeys as $key){
2906
    if(!is_array($elements[$key]['#theme_wrappers'])){
2907
      $elements[$key]['#theme_wrappers'] = array();
2908
    }
2909
    if(isset($elements['#options_suffixes'][$key])){
2910
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
2911
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
2912
    }
2913
  }
2914
  return $elements;
2915
2916
}
2917
2918
/**
2919
 * TODO
2920
 * @param unknown $variables
2921
 */
2922
function theme_radio_options_suffix($variables) {
2923
  $element = $variables['element'];
2924
  if(isset($element['#options_suffix'])) {
2925
    $element['#children'] .= $element['#options_suffix'];
2926
  }
2927
  return $element['#children'];
2928
}
2929
2930
2931 0f5f1c12 Andreas Kohlbecker
/**
2932
 * Element validate callback for text field and arrays containing json.
2933
 *
2934
 * @param $element
2935
 *   The form element to validate
2936
 * @param $form_state
2937
 *   A keyed array containing the current state of the form.
2938 cc3c9807 Andreas Kohlbecker
 * @param $form
2939
 *   Nested array of form elements that comprise the form.
2940 0f5f1c12 Andreas Kohlbecker
 */
2941
function form_element_validate_json($element, &$form_state, $form) {
2942
   if (!empty($element['#value'])) {
2943
     json_decode($element['#value']);
2944
     if(json_last_error() != JSON_ERROR_NONE){
2945
       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/'));
2946
     }
2947
   }
2948
}
2949
2950
/**
2951
 * Form submission handler for textareas and textfields containing JSON.
2952
 *
2953
 * The contained JSON will be converted into an php array
2954 2bbc28c8 Andreas Kohlbecker
 * or object and will be stored in the variables as such.
2955 0f5f1c12 Andreas Kohlbecker
 *
2956
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2957
 *
2958
 * @param $form
2959
 *   Nested array of form elements that comprise the form.
2960
 * @param $form_state
2961
 *   A keyed array containing the current state of the form.
2962
 *
2963
 */
2964
function submit_json_as_php_array($form, &$form_state) {
2965
  if (is_array($form['#json_elements'])) {
2966
    foreach ($form['#json_elements'] as $element){
2967 80370786 Andreas Kohlbecker
      if (trim($form_state['values'][$element])) {
2968
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
2969
      } else {
2970
        $form_state['values'][$element] = NULL;
2971
      }
2972 0f5f1c12 Andreas Kohlbecker
    }
2973
  }
2974
}