Project

General

Profile

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