Project

General

Profile

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

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

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

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

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

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

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

    
41

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

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

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

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

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

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

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

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

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

    
131
}
132

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

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

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

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

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

    
276

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

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

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

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

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

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

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

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

    
396
  }
397
}
398

    
399
/**
400
 * preliminary mock implementation
401
 *
402
 * these settings only apply to feature blocks which do not have a special rendering
403
 * the specially handled features (e.g.: Distribution,CommonNames) may make use of the
404
 * 'special' element of the settings
405
 *
406
 *  "$feature uuid": {
407
 *    "as_list": div|ul|ol|dl,                       // div: not as list, ul: as bullet list, ol: as numbered list, dl:as definition list; will be used in compose_cdm_feature_block_elements() as $enclosing_tag
408
 *    "link_to_reference": boolean,                 // render the reference as link, ignored if the element is NOT a DescriptionElementSource
409
 *    "link_to_name_used_in_source": boolean
410
 *    // references_inline:
411
 *    // TRUE:
412
 *    //   1. if element has text (TextData) the source references will be appended in brackets like "text (source references)"
413
 *    //   2. otherwise they are the only content (e.g. use case CITATION) and afre not put into brackets
414
 *    // FALSE:
415
 *    //  they are put into the bibliography(=references) pseudo feature block
416
 *    "references_inline": boolean
417
 *    "sort_elements": SORT_ASC, SORT_DESC, NULL    // whether and how to sort the elements
418
 *    "element_tag": span | div                     // only applies if "as_list" == 'div'
419
 *    'special' => array()                          // can be used to extend with special settings for specialized rendering like for distributions
420
 *  }
421
 */
422
function get_feature_block_settings($feature_uuid = 'DEFAULT'){
423
  // the default must conform to the default parameter values of
424
  // compose_cdm_feature_block_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
425
  // theme_cdm_descriptionElementTextData() : asListElement = NULL
426

    
427
  // currently only element_tag is used.
428
  $default = array(
429
    'DEFAULT' => array(
430
      'as_list' => 'ul',
431
      'link_to_reference' => FALSE,
432
      'link_to_name_used_in_source' => TRUE,
433
      'references_inline' => TRUE,
434
      'sort_elements' => FALSE,
435
      'glue' => '',
436
      'element_tag'=> NULL
437
    )
438
  );
439

    
440
  $cichorieae_default = array(
441
    'DEFAULT' => array(
442
      'as_list' => 'div',
443
      'link_to_reference' => TRUE,
444
      'link_to_name_used_in_source' => TRUE,
445
      'references_inline' => TRUE,
446
      'sort_elements' => FALSE,
447
      'glue' => '',
448
      'element_tag'=> 'div'
449
    ),
450
    UUID_CITATION => array(
451
      'as_list' => 'div',
452
      'link_to_reference' => FALSE,
453
      'link_to_name_used_in_source' => FALSE,
454
      'references_inline' => TRUE,
455
      'sort_elements' => FALSE,
456
      'glue' => '',
457
      'element_tag'=> 'div'
458
    ),
459
    UUID_CHROMOSOMES_NUMBERS => array(
460
      'as_list' => 'ul',
461
      'link_to_reference' => TRUE,
462
      'link_to_name_used_in_source' => TRUE,
463
      'references_inline' => TRUE,
464
      'sort_elements' => FALSE,
465
      'glue' => '',
466
      'element_tag'=> 'div'
467
    ),
468
    UUID_CHROMOSOMES => array(
469
      'as_list' => 'ul',
470
      'link_to_reference' => FALSE,
471
      'link_to_name_used_in_source' => TRUE,
472
      'references_inline' => TRUE,
473
      'sort_elements' => FALSE,
474
      'glue' => '',
475
      'element_tag'=> 'div'
476
    ),
477
  );
478

    
479
  $default_theme = variable_get('theme_default', NULL);
480

    
481
  switch ($default_theme){
482
    case 'garland_cichorieae':
483
    case 'cyprus': // no longer used in production, but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
484
      $settings_for_theme = $cichorieae_default;
485
      break;
486
    case 'flore_afrique_centrale':
487
    case 'flora_malesiana':
488
    case 'flore_gabon':
489
      $settings_for_theme = $cichorieae_default;
490
      $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
491
      break;
492
    default:
493
      $settings_for_theme =  $default;
494
  }
495

    
496
  if(isset($settings_for_theme[$feature_uuid])){
497
    return $settings_for_theme[$feature_uuid];
498
  } else if(isset($settings_for_theme['DEFAULT'])){
499
    return $settings_for_theme['DEFAULT'];
500
  } else if(isset($settings_for_theme[$feature_uuid])){
501
    return $default[$feature_uuid];
502
  } else {
503
    return $default['DEFAULT'];
504
  }
505
}
506

    
507
  /**
508
 * returns the current setting for the original source bibliography
509
 *
510
 * Caches internally
511
 *
512
 * @return array
513
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
514
 *   - 'enabled': 1|0
515
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
516
 */
517
function get_bibliography_settings($clear_cache = false){
518
  static $bibliography_settings = null;
519
  if(!$bibliography_settings || $clear_cache){
520
    $bibliography_settings = get_array_variable_merged(BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE, BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT);
521
  }
522
  return $bibliography_settings;
523
}
524

    
525
/**
526
 * @todo Please document this function.
527
 * @see http://drupal.org/node/1354
528
 */
529
function cdm_dataportal_menu_admin(&$items) {
530
  // Display section on admin/config page.
531
  $items['admin/config/cdm_dataportal'] = array(
532
    'title' => 'CDM Dataportal',
533
    'description' => 'Settings for the CDM DataPortal.',
534
    'position' => 'right',
535
    'weight' => 10,
536
    'page callback' => 'system_admin_menu_block_page',
537
    'access arguments' => array('administer cdm_dataportal'),
538
    'file' => 'system.admin.inc',
539
    'file path' => drupal_get_path('module', 'system'),
540
  );
541
  $items['admin/config/cdm_dataportal/settings'] = array(
542
    'title' => 'Settings',
543
    'description' => 'Settings for the CDM DataPortal.',
544
    'weight' => 0,
545
    'page callback' => 'drupal_get_form',
546
    'page arguments' => array('cdm_settings_general'),
547
    'access arguments' => array('administer cdm_dataportal'),
548
    'type' => MENU_NORMAL_ITEM,
549
  );
550
  $items['admin/config/cdm_dataportal/settings/general'] = array(
551
    'title' => 'General',
552
    'description' => 'General',
553
    'weight' => 0,
554
    'page callback' => 'drupal_get_form',
555
    'page arguments' => array('cdm_settings_general'),
556
    'access arguments' => array('administer cdm_dataportal'),
557
    'type' => MENU_DEFAULT_LOCAL_TASK,
558
  );
559

    
560
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
561
    'title' => 'Cache',
562
    'description' => 'Cache',
563
    'access arguments' => array('administer cdm_dataportal'),
564
    'page callback' => 'drupal_get_form',
565
    'page arguments' => array('cdm_settings_cache'),
566
    'weight' => 10,
567
    'type' => MENU_LOCAL_TASK,
568
  );
569

    
570
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
571
    'title' => 'Geo & Map',
572
    'description' => 'Geo & Map',
573
    'access arguments' => array('administer cdm_dataportal'),
574
    'page callback' => 'drupal_get_form',
575
    'page arguments' => array('cdm_settings_geo'),
576
    'weight' => 1,
577
    'type' => MENU_LOCAL_TASK,
578
  );
579

    
580
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
581
    'title' => 'Layout',
582
    'description' => 'Configure and adjust the layout of your DataPortal ',
583
    'access arguments' => array('administer cdm_dataportal'),
584
    'page callback' => 'drupal_get_form',
585
    'page arguments' => array('cdm_settings_layout'),
586
    'weight' => 2,
587
    'type' => MENU_LOCAL_TASK,
588
  );
589

    
590
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
591
    'title' => 'Taxon',
592
    'description' => 'Configure and adjust the layout of your DataPortal ',
593
    'access arguments' => array('administer cdm_dataportal'),
594
    'page callback' => 'drupal_get_form',
595
    'page arguments' => array('cdm_settings_layout_taxon'),
596
    'weight' => 1,
597
    'type' => MENU_LOCAL_TASK,
598
  );
599
  /*
600
  $items[] = array(
601
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
602
  'title' => t('Synonymy'),
603
  'description' => t('Configure and adjust the layout of your DataPortal '),
604
  'access' => user_access('administer cdm_dataportal'),
605
  'callback' => 'drupal_get_form',
606
  'callback arguments' => array('cdm_settings_layout_synonymy'),
607
  'weight' => 1,
608
  'type' => MENU_LOCAL_TASK,
609
  );
610

    
611
  $items[] = array(
612
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
613
  'title' => t('Specimens'),
614
  'description' => t('Configure and adjust the layout of your DataPortal '),
615
  'access' => user_access('administer cdm_dataportal'),
616
  'callback' => 'drupal_get_form',
617
  'callback arguments' => array('cdm_settings_layout_specimens'),
618
  'weight' => 1,
619
  'type' => MENU_LOCAL_TASK,
620
  );
621
  */
622
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
623
    'title' => 'Search',
624
    'description' => 'Configure and adjust the layout of your DataPortal ',
625
    'access arguments' => array('administer cdm_dataportal'),
626
    'page callback' => 'drupal_get_form',
627
    'page arguments' => array('cdm_settings_layout_search'),
628
    'weight' => 2,
629
    'type' => MENU_LOCAL_TASK,
630
  );
631

    
632
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
633
    'title' => 'Media',
634
    'description' => 'Configure and adjust the layout of your DataPortal ',
635
    'access arguments' => array('administer cdm_dataportal'),
636
    'page callback' => 'drupal_get_form',
637
    'page arguments' => array('cdm_settings_layout_media'),
638
    'weight' => 3,
639
    'type' => MENU_LOCAL_TASK,
640
  );
641

    
642
}
643

    
644
/**
645
 * @todo document this function.
646
 */
647
function cdm_help_general_cache() {
648
  $form = array();
649
  $form['cache_help'] = array(
650
    '#type' => 'fieldset',
651
    '#title' => t('Help'),
652
    '#collapsible' => TRUE,
653
    '#collapsed' => TRUE,
654
  );
655
  $form['cache_help']['test'] = array('#value' => t('probando'));
656
  return drupal_render($form);
657
  $res = array();
658
  $res['default'] = drupal_render($help);
659
  return $res;
660
}
661

    
662
/**
663
 * Configures the settings form for the CDM-API module.
664
 *
665
 * @return array
666
 *   Drupal settings form.
667
 */
668
function cdm_settings_general() {
669

    
670
  $form['cdm_webservice'] = array(
671
    '#type' => 'fieldset',
672
    '#title' => t('CDM Server'),
673
    '#collapsible' => FALSE,
674
    '#collapsed' => FALSE,
675
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
676
        CDM data base to the web via RESTful web services and thus is the source of the data
677
        to be displayed by a CDM DataPotal.'),
678
  );
679

    
680
  $form['cdm_webservice']['cdm_webservice_url'] = array(
681
    '#type' => 'textfield',
682
    '#title' => t('CDM web service URL') . ':',
683
    '#description' => t('This is the URL to the CDM-Server exposing your data
684
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
685
    '#default_value' => variable_get('cdm_webservice_url', NULL),
686
  );
687

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

    
695
  $form['cdm_webservice']['freetext_index'] = array(
696
    '#type' => 'fieldset',
697
    '#title' => t('Freetext index'),
698
    '#collapsible' => FALSE,
699
    '#collapsed' => FALSE,
700
  );
701

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

    
714
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
715
  $trigger_link_options = array(
716
    'attributes' => array(
717
      'class' => 'index-trigger',
718
    ),
719
  );
720
  $form['cdm_webservice']['freetext_index']['operations'] = array(
721
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
722
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
723
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
724
      ))
725
    . '<div id="index-progress"></div></div>',
726
  );
727
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
728

    
729
  $form['cdm_webservice']['proxy'] = array(
730
    '#type' => 'fieldset',
731
    '#title' => t('Proxy'),
732
    '#collapsible' => TRUE,
733
    '#collapsed' => TRUE,
734
  );
735

    
736
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
737
    '#type' => 'textfield',
738
    '#title' => t('Proxy URL') . ':',
739
    '#description' => t('If this proxy url is set the cdm api tries
740
    to connect the web service over the given proxy server.
741
    Otherwise proxy usage is deactivated.'),
742
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
743
  );
744

    
745
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
746
    '#type' => 'textfield',
747
    '#title' => t('Proxy port') . ':',
748
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
749
  );
750

    
751
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
752
    '#type' => 'textfield',
753
    '#title' => t('Login') . ':',
754
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
755
  );
756

    
757
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
758
    '#type' => 'textfield',
759
    '#title' => t('Password') . ':',
760
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
761
  );
762

    
763
  // TODO: settings are still incomplete, compare with
764
  // trunk/dataportal/inc/config_default.php.inc.
765
  $form['taxon_tree'] = array(
766
    '#type' => 'fieldset',
767
    '#title' => t('Taxon Tree'),
768
    '#collapsible' => FALSE,
769
    '#collapsed' => TRUE,
770
    '#description' => t('<p>When you explore your collection, you can navigate
771
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
772
      able to navigate through your collection the
773
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
774
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
775
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
776
      </a></p>'),
777
  );
778

    
779
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
780
    '#type' => 'select',
781
    '#title' => t('Available classifications') . ':',
782
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
783
    '#options' => cdm_get_taxontrees_as_options(),
784
    '#description' => t('Select the default taxa classification for your
785
      <em>taxon tree</em>, the other classifications will be also available but
786
      with a manual user change.'),
787
  );
788

    
789
  $form['taxon_tree']['taxontree_ranklimit'] = array(
790
    '#type' => 'select',
791
    '#title' => t('Rank of highest displayed taxon') . ':',
792
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
793
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
794
    '#options' => cdm_rankVocabulary_as_option(),
795
    '#description' => t('This is the rank of the highest displayed taxon in the
796
      <em>taxon tree</em>. You can select here which rank should be at the top
797
      level of the tree structure.'),
798
  );
799

    
800
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
801
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
802
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
803
      '#type' => 'checkboxes',
804
      '#title' => t('Included Classifications') . ':',
805
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
806
      '#options' => cdm_get_taxontrees_as_options(),
807
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
808
  );
809

    
810
  $form['distribution'] = array(
811
      '#type' => 'fieldset',
812
      '#title' => t('Distributions'),
813
      '#collapsible' => FALSE,
814
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
815
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
816
          '<p>
817
          </p>',
818
  );
819

    
820
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
821
      '#type' => 'fieldset',
822
      '#title' => 'Distribution filter',
823
      '#collapsible' => FALSE,
824
      '#collapsed' => FALSE,
825
      '#tree' => TRUE,
826
      '#description' => 'The Distribution filter offers the following options
827
      <ul>
828
      <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>
829
      <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>
830
      <li><strong>Marked area filter:</strong>Skip distributions where the area has a Marker with one of the specified MarkerTypes</li>
831
      </ul>'
832
  );
833

    
834
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
835
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
836
      '#type' => 'checkboxes',
837
      '#title' => 'Filter rules',
838
      '#default_value' => $cdm_distribution_filter['filter_rules'],
839
      '#options' => array(
840
          'statusOrderPreference' => 'Status order preference rule',
841
          'subAreaPreference' => 'Sub area preference rule'
842
      ),
843
  );
844

    
845
  $marker_type_options = cdm_terms_as_options( cdm_ws_fetch_all('term', array('class' => 'MarkerType' )) );
846
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hideMarkedAreas'] = array(
847
      '#type' => 'checkboxes',
848
      '#title' => 'Hide marked area filter',
849
      '#default_value' => $cdm_distribution_filter['hideMarkedAreas'],
850
      '#options' => $marker_type_options,
851
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
852
  );
853

    
854
  $form['aggregation'] = array(
855
      '#type' => 'fieldset',
856
      '#title' => t('Aggregation of data'),
857
      '#collapsible' => FALSE,
858
      '#description' => 'This section covers the different aspects of aggregating information.
859
          <p>
860
          </p>',
861
  );
862

    
863
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
864
      '#type' => 'checkboxes',
865
      '#title' => 'Taxon media filter',
866
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
867
      '#options' => array(
868
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
869
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
870
          'includeOccurrences' => 'Media related to specimens and occurrences',
871
      ),
872
      '#description' => 'This filter configures which images should be taken into account.',
873
  );
874

    
875
  $form['aggregation']['notice'] = array(
876
      '#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
877
          want to make use of the caching capabilities of the dataportal.',
878
  );
879

    
880
  $form['aggregation']['media_aggregation'] = array(
881
      '#type' => 'fieldset',
882
      '#title' => t('Media aggregation'),
883
      '#collapsible' => FALSE,
884
      '#collapsed' => TRUE,
885
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
886

    
887
  );
888
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
889
      '#type' => 'select',
890
      '#title' => t('Aggregation of taxon pictures') . ':',
891
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
892
      '#options' => array(
893
          0 => "Show only pictures of the current taxon",
894
          1 => "Include pictures of taxonomic children",
895
      ),
896
      '#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."),
897
  );
898

    
899
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
900
      '#type' => 'fieldset',
901
      '#attributes' => array('class'=>array('clearfix')),
902
      '#title' => t('Aggregation via taxon relationsships'),
903
      '#collapsible' => TRUE,
904
      '#collapsed' => TRUE,
905
      '#tree' => TRUE,
906
      '#description' => t('Information on taxa will be aggregated along the below chosen
907
          taxon relation ships. This will affect images and occurrences (specimens).
908
          Taxon relation ships are directed and point form one taxon to another. The taxon
909
          relationships to be taken into accunt can therefore configured for the direct direction
910
          and for the inverse.'),
911
  );
912

    
913
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
914
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
915

    
916
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
917
      '#type' => 'checkboxes',
918
      '#title' => t('Direct'),
919
      '#options' => $taxonRelationshipTypeOptions,
920
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
921
  );
922
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
923
      '#type' => 'checkboxes',
924
      '#title' => t('Invers'),
925
      '#options' => $taxonRelationshipTypeOptions,
926
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
927
  );
928

    
929
  // ----------------------
930
  $form['cdm_js_devel_mode'] = array(
931
      '#type' => 'checkbox',
932
      '#title' => 'Java-script developer mode',
933
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
934
      '#description' => 'In production envirionments the java script libraries
935
      the cdm_dataportal is making use of are compressed and optimized. This
936
      is good for performance but a caveat if you need to debug java-script. When the
937
      java-script developer mode is enabled the uncompressed and commented developer
938
      versions of java-script libraries will be used where possible.
939
      <br/><strong>Do not use this option in production!</strong>'
940
  );
941
  // ----------------------
942
  $form['cdm_debug_mode'] = array(
943
      '#type' => 'checkbox',
944
      '#title' => 'CDM page debug mode',
945
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
946
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
947
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
948
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
949
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
950
      The log is written by the drupal devel module function <code>dd()</code>.
951
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
952
  );
953

    
954
  // Comment @WA: D7 form api does not support reset buttons,
955
  // so to mimic the D5 reset button we add one like this.
956
  $form['actions']['reset'] = array(
957
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
958
    '#weight' => 1000,
959
  );
960

    
961
  $form['#submit'][] = 'cdm_settings_general_submit';
962

    
963
  return system_settings_form($form);
964
}
965

    
966

    
967
/**
968
 * LAYOUT settings
969
 * @return
970
 *   todo
971
 */
972
function cdm_settings_layout() {
973

    
974
  $form = array();
975

    
976
  $form['about'] = array(
977
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
978
      layout. If you want to configure the specific sites layout visit the
979
      respective configuration site for taxon, search or media.') . '</p>',
980
  );
981

    
982
  // ---- footnotes --- //
983
  $form['footnotes'] = array(
984
    '#type' => 'fieldset',
985
    '#title' => t('Footnotes'),
986
    '#collapsible' => FALSE,
987
    '#collapsed' => FALSE,
988
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
989
      media or distribution areas may have annotations or footnotes. When the
990
      footnotes are enabled they will be visible (if they exist).'),
991
  );
992

    
993
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
994
    '#type' => 'checkbox',
995
    '#title' => t('Do not show footnotes'),
996
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
997
    '#description' => t('Check this if you do not want to show any footnotes'),
998
  );
999

    
1000
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1001
    '#type' => 'checkbox',
1002
    '#title' => t('Do not show annotations footnotes'),
1003
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1004
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1005
  );
1006

    
1007
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType', SORT_ASC);
1008
  // Additional option for the NULL case.
1009
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1010
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1011
    '#type' => 'checkboxes',
1012
    '#title' => t('Annotation types as footnotes'),
1013
    '#description' => t("Only annotations of the selected type will be displayed
1014
       as footnotes. You may want to turn 'technical annotations' off."),
1015
    '#options' => $annotationTypeOptions,
1016
  );
1017
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1018
  if (!empty($annotationsTypesAsFootnotes)) {
1019
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1020
  }
1021

    
1022
  // ---- original source --- //
1023
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1024
      '#type' => 'fieldset',
1025
      '#tree' => TRUE,
1026
      '#title' => t('Source Citations'),
1027
      '#collapsible' => FALSE,
1028
      '#collapsed' => FALSE,
1029
  );
1030

    
1031
  $bibliography_settings = get_bibliography_settings(true);
1032

    
1033
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1034
      '#type' => 'checkbox',
1035
      '#title' => t('Original Source in bibliography'),
1036
      '#default_value' => $bibliography_settings['enabled'],
1037
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1038
       annotations in each feature block.'),
1039
  );
1040

    
1041
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1042
    '#type' => 'select',
1043
    '#title' => t('The format of the key numerals'),
1044
    '#default_value' => $bibliography_settings['key_format'],
1045
    '#options' => array('latin' => 'Latin',
1046
      'ROMAN' => 'Roman (upper case)',
1047
      'roman' => 'Roman (lower case)',
1048
      'ALPHA'=> 'Alphabet (upper case)',
1049
      'alpha' => 'Alphabet (lower case)')
1050
  );
1051

    
1052
  // --- Advanced Search --- //
1053
  $form['asearch'] = array(
1054
    '#type' => 'fieldset',
1055
    '#title' => t('Advanced search'),
1056
    '#collapsible' => FALSE,
1057
    '#collapsed' => FALSE,
1058
  );
1059

    
1060
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1061
    '#type' => 'checkbox',
1062
    '#title' => t('Show advanced search link'),
1063
    '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1064
    '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1065
  );
1066

    
1067
  // ---- Taxon Name Rendering --- //
1068
  $form['taxon_name'] = array(
1069
      '#type' => 'fieldset',
1070
      '#title' => t('Taxon name display'),
1071
      '#collapsible' => TRUE,
1072
      '#collapsed' => TRUE,
1073
      '#description' => t('The display of taxon names is configured by two parts.'
1074
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
1075
          . 'The name parts are defined in the <stong>part definitions</strong>'),
1076
  );
1077

    
1078
  drupal_add_js(
1079
      'jQuery(document).ready( function( ) {
1080
         // pretty print json
1081
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
1082
         var obj = JSON.parse(json_text);
1083
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
1084

    
1085
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
1086
         obj = JSON.parse(json_text);
1087
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
1088
       });'
1089
      ,array(
1090
          'type' => 'inline',
1091
          'scope' => 'footer'
1092
      )
1093
  );
1094

    
1095
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1096

    
1097
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1098
      '#type' => 'textarea',
1099
      '#title' => t('Part definitions'),
1100
      '#element_validate' => array('form_element_validate_json'),
1101
      '#default_value' =>  json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions)),
1102
      '#description' => '
1103
          <p>
1104
          (Clearing the text area will reset it to the default)
1105
          </p>
1106
          <p>
1107
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1108
          </p>
1109
          <p>
1110
           A full taxon name plus additional information can consist of the following elements:
1111
          <ul>
1112
             <li>name: the taxon name inclugin rank nbut without author</li>
1113
             <li>authors:  The authors of a reference, also used in taxon names</li>
1114
             <li>reference: the nomenclatural reference,</li>
1115
             <li>microreference:  Volume, page number etc.</li>
1116
             <li>status:  The nomenclatural status of a name</li>
1117
             <li>description: name descriptions like protologues etc ...</li>
1118
          </ul>
1119
          </p>
1120
          <p>
1121
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1122
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1123
           The following parts can be formed and are recognized by the system:
1124
          <ul>
1125
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1126
            <li>authorshipPart: the author (for example: "L.")</li>
1127
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1128
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1129
               be combined when a link to the taxon is rendered.</li>
1130
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1131
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1132
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1133
            <li>statusPart: the nomenclatorical status</li>
1134
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1135
          </ul>
1136
          </p>
1137
          <p>
1138
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1139
           specific parts part definitions:
1140
          <ul>
1141
            <li>BotanicalName</li>
1142
            <li>ZoologicalName</li>
1143
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1144
          </ul>
1145
           An example:
1146
          <pre>
1147
           {
1148
            "ZoologicalName": {
1149
              "namePart": {
1150
                "name": true
1151
              },
1152
              "referencePart": {
1153
                "authors": true
1154
              },
1155
              "microreferencePart": {
1156
                "microreference": true
1157
              },
1158
              "statusPart": {
1159
                "status": true
1160
              },
1161
              "descriptionPart": {
1162
                "description": true
1163
              }
1164
            },
1165
            "BotanicalName": {
1166
              "namePart": {
1167
                "name": true,
1168
                "authors": true
1169
              },
1170
              "referencePart": {
1171
                "reference": true,
1172
                "microreference": true
1173
              },
1174
              "statusPart": {
1175
                "status": true
1176
              },
1177
              "descriptionPart": {
1178
                "description": true
1179
              }
1180
            }
1181
          }
1182
           </pre>',
1183
  );
1184

    
1185
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1186

    
1187
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1188
      '#type' => 'textarea',
1189
      '#title' => t('Name render templates'),
1190
      '#element_validate' => array('form_element_validate_json'),
1191
      '#default_value' =>  json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates)),
1192
      '#description' => '
1193
          <p>
1194
          (Clearing the text area will reset it to the default)
1195
          </p>
1196
          <p>
1197
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1198
          render path. The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1199
          The following render Path keys are curretly recognized:
1200
          <ul>
1201
            <li>list_of_taxa</li>
1202
            <li>acceptedFor</li>
1203
            <li>homonym</li>
1204
            <li>taxon_page_synonymy</li>
1205
            <li>typedesignations</li>
1206
            <li>taxon_page_title</li>
1207
            <li>polytomousKey</li>
1208
            <li>na: name + authorship</li>
1209
            <li>nar:name + authorship + reference</li>
1210
            <li>#DEFAULT</li>
1211
          </ul>
1212
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1213
          array element should be a comma separated list of render paths, without any whitespace!.
1214
          </p>
1215
          <p>
1216
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1217
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1218
          <p>
1219
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1220
          The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
1221
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1222
          links if the paramters $nameLink or $refenceLink are given to the name render function
1223
          (this is hard coded and cannot be configured here).',
1224
  );
1225

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

    
1233
  $form['#submit'] = array('submit_json_as_php_array');
1234
  // #json_elements especially defined for submit_json_as_php_array()
1235
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1236
  return system_settings_form($form);
1237
}
1238

    
1239

    
1240
/**
1241
 * @todo Please document this function.
1242
 * @see http://drupal.org/node/1354
1243
 */
1244
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1245
  $form[$form_name] = array(
1246
    '#type' => 'fieldset',
1247
    '#title' => t($form_title),
1248
    '#collapsible' => TRUE,
1249
    '#collapsed' => $collapsed,
1250
    '#tree' => TRUE,
1251
    '#description' => t($form_description),
1252
  );
1253

    
1254
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1255
  $gallery_settings = variable_get($form_name, $default_values);
1256
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1257
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1258
    /*
1259
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1260
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1261
    '#type' => 'textfield',
1262
    '#title' => t('Search Page Size'),
1263
    '#default_value' => $test,
1264
    '#description' => t('Number of Names to display per page in search results.')
1265
    );
1266
    */
1267
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1268
      '#type' => 'checkbox',
1269
      '#title' => t('Show media thumbnails for accepted taxa'),
1270
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1271
    );
1272

    
1273
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1274
      '#type' => 'checkbox',
1275
      '#title' => t('Show media thumbnails for synonyms'),
1276
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1277
      '#description' => '',
1278
    );
1279
  }
1280

    
1281
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1282
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1283
    '#type' => 'checkbox',
1284
    '#title' => t('Show captions under thumbnails'),
1285
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1286
    '#description' => '',
1287
  );
1288

    
1289
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1290
    '#type' => 'textfield',
1291
    '#title' => t('Thumbnail size') . ':',
1292
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1293
    '#description' => t('Select the size of each individual thumbnail.'),
1294
  );
1295

    
1296
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1297
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1298
      '#type' => 'textfield',
1299
      '#title' => t('Number of columns') . ':',
1300
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1301
      '#description' => t('Group the thumbnails in columns: select how many
1302
        columns the gallery should display.'),
1303
    );
1304
  }
1305

    
1306
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1307
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1308
      '#type' => 'textfield',
1309
      '#title' => t('Maximum number of rows') . ':',
1310
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1311
      '#description' => t('You can group the thumbnails in rows, select in how
1312
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1313
        If you want an unlimited number of rows please set to 0.'),
1314
    );
1315
  }
1316

    
1317
  return $form;
1318
}
1319

    
1320
/**
1321
 * @todo document this function.
1322
 */
1323
function cdm_settings_layout_taxon() {
1324
  $collapsed = FALSE;
1325
  $form = array();
1326

    
1327
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1328

    
1329
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1330
      '#type' => 'checkbox',
1331
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1332
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1333
      '#description' => t('<p>If checked the link to search results is rendered at
1334
       the top of the taxon site. Clicking on the link the last search performed
1335
       is rendered again.</p>'),
1336
  );
1337

    
1338
  // --------- TABBED TAXON ------- //
1339
  $form['taxon_tabs'] = array(
1340
    '#type' => 'fieldset',
1341
    '#title' => t('Taxon tabs'),
1342
    '#collapsible' => TRUE,
1343
    '#collapsed' => FALSE,
1344
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1345
      be splitted in four diferent tabs; General, Synonymy, Images and
1346
      Specimens. If the taxon has no information for any of the tabs/sections
1347
      such tab will be not displayed.'),
1348
  );
1349

    
1350
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1351
    '#type' => 'checkbox',
1352
    '#title' => t('Tabbed taxon page'),
1353
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1354
    '#description' => t('<p>If selected split the taxon page into individual
1355
      tabs for description, images, synonymy and specimens. If not the taxon
1356
      data is rendered as a long single page without tabs.</p>'),
1357
  );
1358

    
1359
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1360
    '#type' => 'checkboxes',
1361
    '#title' => t('Tabs visibility options') . ':',
1362
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1363
    '#options' => get_taxon_options_list(),
1364
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1365
  );
1366

    
1367
  // WEIGHT
1368
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1369
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1370
      '#tree' => true
1371
  );
1372
  // Weights range from -delta to +delta, so delta should be at least half
1373
  // of the amount of tabs present.
1374
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1375
  foreach (get_taxon_tabs_list() as $label) {
1376
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1377
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1378
        '#title' => $label,
1379
        '#type'  => 'weight',
1380
        '#default_value' => $taxontabs_weights[$key],
1381
        '#delta' => $tab_weight_delta
1382
    );
1383
  }
1384

    
1385
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1386
    '#type' => 'select',
1387
    '#title' => t('Default tab to display') . ':',
1388
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1389
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1390
    '#description' => t('<p>Select the default tab to display when visiting a
1391
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1392
      <strong>Note:</strong> After performing a search and clicking in any
1393
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1394
      taxon and not the above selected tab.'),
1395
  );
1396

    
1397
  /* ======  TAXON_PROFILE ====== */
1398
  $form['taxon_profile'] = array(
1399
    '#type' => 'fieldset',
1400
    '#title' => t('Taxon profile (tab)'),
1401
    '#description' => t('<p>This section covers the settings related to the taxon
1402
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1403
    '#collapsible' => TRUE,
1404
    '#collapsed' => TRUE,
1405
  );
1406

    
1407
  // ---- PROFILE PICTURE ----//
1408

    
1409
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1410
    '#type' => 'fieldset',
1411
    '#tree' => TRUE,
1412
    '#title' => t('Taxon profile picture'),
1413
    '#collapsible' => TRUE,
1414
    '#collapsed' => FALSE,
1415
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1416
  );
1417

    
1418
  //FIXME migrate variables:
1419
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1420
  // FIXME
1421
  //  eanable file modul in profile and in update
1422

    
1423
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1424
  /*
1425
   * 'show' => 1,
1426
   * 'maxextend' => 184,
1427
   * 'media_uri_query' => ''
1428
   * 'custom_placeholder_image_on' => 1,
1429
   * 'custom_placeholder_image_fid' => ''
1430
   */
1431
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1432
    '#type' => 'checkbox',
1433
    '#title' => t('Enable profil picture'),
1434
    '#description' => t('Show the profil picture.'),
1435
    '#default_value' => $taxon_profile_image_settings['show'],
1436
  );
1437

    
1438
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1439
      '#type' => 'textfield',
1440
      '#tree' => TRUE,
1441
      '#title' => t('Profil picture maximum extend'),
1442
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1443
      '#field_suffix' => 'px',
1444
      '#maxlength' => 4,
1445
      '#size' => 4,
1446
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1447
  );
1448

    
1449
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1450
      '#type' => 'textfield',
1451
      '#tree' => TRUE,
1452
      '#title' => t('Additional URI query parameter'),
1453
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1454
      '#maxlength' => 1024,
1455
      '#size' => 60,
1456
      '#description' => t('Additional query parameters to be used when requesting for the '
1457
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1458
          . 'The query parameters will be appendend to the uri of the media representation part'
1459
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1460
  );
1461

    
1462
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1463
      '#type' => 'checkbox',
1464
      '#title' => t('Use a custom placeholder image'),
1465
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1466
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1467
  );
1468

    
1469
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1470
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1471
        '#type' => 'managed_file',
1472
        '#title' => t('Custom placeholder image file'),
1473
        '#progress_indicator' => 'bar',
1474
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1475
    //       '#name' => 'custom_placeholder_image',
1476
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1477
    );
1478

    
1479
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1480
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1481
      $url = file_create_url($profile_image_file->uri);
1482
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1483
                '#type' => 'item',
1484
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1485
      );
1486
    }
1487
  } else {
1488
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1489
        '#type' => 'hidden',
1490
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1491
    );
1492
  }
1493

    
1494

    
1495

    
1496
  $options = cdm_rankVocabulary_as_option();
1497
  array_unshift($options, '-- DISABLED --');
1498
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1499
    '#type' => 'select',
1500
    '#title' => t('Hide profile picture for higher ranks') . ':',
1501
    '#default_value' => variable_get('image_hide_rank', '0'),
1502
    '#options' => $options,
1503
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1504
  );
1505

    
1506
  // -- MEDIA THUMBNAILS -- //
1507
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1508
  $form_title = 'Taxon Profile Images';
1509
  $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>';
1510
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1511

    
1512
  // ---- FEATURE TREE ---- //
1513
  $form['taxon_profile']['feature_trees'] = array(
1514
    '#type' => 'fieldset',
1515
    '#title' => t('Features'),
1516
    '#collapsible' => TRUE,
1517
    '#collapsed' => FALSE,
1518
    '#description' => t("This section covers settings related to the taxon's
1519
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1520
      features such as description, distribution, common names, etc. that Drupal
1521
      will render at the taxon profile page."),
1522
  );
1523
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1524
  $saved_uuid = variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1525
  if(!isset($featureTrees['options'][$saved_uuid])) {
1526
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1527
  }
1528
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
1529
    '#type' => 'radios',
1530
    '#title' => t('Taxon profile sections') . ':',
1531
    '#default_value' => $saved_uuid,
1532
    '#options' =>  $featureTrees['options'],
1533
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1534
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1535
    '#description' => t('Select the Feature Tree to be displayed at the taxon
1536
      profile. Click "Show Details" to see the Feature Tree elements.'
1537
    ),
1538
  );
1539
  $featureTrees = cdm_get_featureTrees_as_options();
1540
  $saved_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1541
  if(!isset($featureTrees['options'][$saved_uuid])) {
1542
    $saved_uuid = NULL;
1543
  }
1544
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
1545
    '#type' => 'radios',
1546
    '#title' => t('Natural language representation of structured descriptions') . ':',
1547
    '#default_value' => $saved_uuid,
1548
    '#options' => $featureTrees['options'],
1549
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1550
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1551
    '#description' => t('Taxon descriptions can be stored in a highly structured
1552
      form. The feature tree selected here will be used to generate textual
1553
      representation in natural language.'
1554
    ),
1555
  );
1556

    
1557
  // ---- LAYOUT PER FEATURE ---- //
1558
  $feature_tree = get_profile_featureTree();
1559
  if (isset($feature_tree->root->childNodes)) {
1560

    
1561
    $form_feature_list_layout = array(
1562
      '#title' => t('Taxon profile layout'),
1563
      '#collapsible' => TRUE,
1564
      '#collapsed' => FALSE,
1565
      '#type' => 'fieldset',
1566
      '#description' => t('Will be available in a future release.'),
1567
    );
1568

    
1569
    $feature_list_layout_settings_disabled = TRUE;
1570
    foreach ($feature_tree->root->childNodes as $featureNode) {
1571

    
1572
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1573
        // Must not exceed 45 characters !!!
1574
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1575

    
1576
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1577
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1578

    
1579
        $form_feature_list_layout[$subform_id] = array(
1580
          '#tree' => TRUE,
1581
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1582
          '#collapsible' => FALSE,
1583
          '#collapsed' => FALSE,
1584
          '#type' => 'fieldset',
1585
          '#description' => t(''),
1586
        );
1587

    
1588
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1589
          '#type' => 'checkbox',
1590
          '#title' => t('Enable'),
1591
          '#default_value' => $settings['enabled'],
1592
          '#description' => t('Enable user defined layout for this feature'),
1593
        );
1594

    
1595
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1596
          '#type' => 'textfield',
1597
          '#title' => t('Enclosing tag'),
1598
          '#disabled' => !$settings['enabled'],
1599
          '#default_value' => $settings['enclosingTag'],
1600
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1601
        );
1602

    
1603
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1604
          '#type' => 'textfield',
1605
          '#title' => t('Entry enclosing tag'),
1606
          '#disabled' => !$settings['enabled'],
1607
          '#default_value' => $settings['entryEnclosingTag'],
1608
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1609
        );
1610

    
1611
        $form_feature_list_layout[$subform_id]['glue'] = array(
1612
          '#type' => 'textfield',
1613
          '#title' => t('Glue'),
1614
          '#disabled' => !$settings['enabled'],
1615
          '#default_value' => $settings['glue'],
1616
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1617
        );
1618

    
1619
      }
1620

    
1621
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1622
    }
1623
  }
1624

    
1625
  // ---- DISTRIBUTION LAYOUT ---- //
1626
  $form['taxon_profile']['distribution_layout'] = array(
1627
    '#title' => t('Distribution'),
1628
    '#collapsible' => TRUE,
1629
    '#collapsed' => FALSE,
1630
    '#type' => 'fieldset',
1631
    '#description' => t('Select if you want to sort or not the distribution text
1632
      located below the distribution map.'),
1633
  );
1634

    
1635
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1636
    '#type' => 'radios',
1637
    '#title' => t('Sort') . ':',
1638
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1639
    '#options' => array(
1640
      'NO_SORT' => t('Standard (No sort)'),
1641
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1642
    ),
1643
  );
1644

    
1645
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1646
    '#type' => 'checkbox',
1647
    '#title' => t('Show TextData elements on top of the map'),
1648
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1649
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1650
      elements on top of the map. Otherwise all <code>TextData</code>
1651
      distribution elements will be listed below the other area elements.
1652
      This option is useful if you need to have descriptive texts for each
1653
      distribution map.'),
1654
  );
1655

    
1656
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
1657
      '#type' => 'textarea',
1658
      '#title' => t('Custom status colors'),
1659
      '#element_validate' => array('form_element_validate_json'),
1660
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
1661
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
1662
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
1663
          reference list of the idInVocabulary values of absence and presence terms:
1664
<pre>
1665
Presence Term
1666
p	present
1667
pd	present: doubtfully present
1668
n	native
1669
nq	native: presence questionable
1670
nd	native: doubtfully native
1671
c	cultivated
1672
i	introduced
1673
iq	introduced: presence questionable
1674
id	introduced: doubtfully introduced (perhaps cultivated only)
1675
ip	introduced: uncertain degree of naturalisation
1676
ia	introduced: adventitious (casual)
1677
in	introduced: naturalized
1678
ic	introduced: cultivated
1679
e	endemic for the relevant area
1680
na	naturalised
1681
iv	invasive
1682

    
1683
AbsenceTerm
1684
a	absent
1685
f	reported in error
1686
nf	native: reported in error
1687
if	introduced: reported in error
1688
cf	cultivated: reported in error
1689
ne	native: formerly native
1690
ie	introduced: formerly introduced
1691

    
1692
</pre>'),
1693
  );
1694

    
1695

    
1696
  /* ====== SYNONYMY ====== */
1697
  $form['taxon_synonymy'] = array(
1698
    '#type' => 'fieldset',
1699
    '#title' => t('Taxon synonymy (tab)'),
1700
    '#collapsible' => TRUE,
1701
    '#collapsed' => TRUE,
1702
    '#description' => t('This section covers the settings related to the taxon
1703
      <strong>synonymy</strong> tab.'),
1704
  );
1705

    
1706
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1707
    '#type' => 'checkbox',
1708
    '#title' => t('Show accepted taxon on top of the synonymy'),
1709
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1710
    '#description' => t('If checked, the first homotypic taxon is a repetition
1711
      of the accepted taxon most likely with the full nomenclatural reference
1712
      (depending on the currently chosen theme).'),
1713
  );
1714

    
1715
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1716
    '#type' => 'checkbox',
1717
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1718
      coming from a synonym link.'),
1719
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1720
    '#description' => t('Check this if after doing a search and clicking on a
1721
      synonym you want to see the "accept of" text for the accepted synonym.'),
1722
  );
1723

    
1724
  /* === currently unused ===
1725
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1726
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1727
    '#type' => 'checkboxes',
1728
    '#title' => t('Display name relationships') . ':',
1729
    '#default_value' => variable_get('name_relationships_to_show', 0),
1730
    '#options' => $nameRelationshipTypeOptions,
1731
    '#description' => t('Select the name relationships you want to show for the
1732
      accepted taxa.'),
1733
  );
1734
 */
1735

    
1736
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1737
    '#type' => 'checkbox',
1738
    '#title' => t('Show taxon relations ships of accepted taxon'),
1739
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1740
    '#description' => t('If this option is enabled the synonymy will show the
1741
      below selected taxon relationships of accepted taxa.'),
1742
  );
1743

    
1744
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1745
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1746
    '#type' => 'checkboxes',
1747
    '#title' => t('Taxon relationship types') . ':',
1748
    '#description' => t('Only taxon relationships of the selected type will be
1749
      displayed'),
1750
    '#options' => $taxonRelationshipTypeOptions,
1751
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1752
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1753
  );
1754

    
1755
  // ====== SPECIMENS ====== //
1756
  $form['taxon_specimens'] = array(
1757
    '#type' => 'fieldset',
1758
    '#title' => t('Taxon specimens (tab)'),
1759
    '#collapsible' => TRUE,
1760
    '#collapsed' => TRUE,
1761
    '#description' => t('This section covers the settings related to the taxon
1762
      <strong>specimens</strong> tab.'),
1763
  );
1764

    
1765
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1766
  $saved_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1767
  if(!isset($featureTrees['options'][$saved_uuid])) {
1768
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1769
  }
1770
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1771
      '#type' => 'radios',
1772
      '#title' => t('Specimen description feature tree') . ':',
1773
      '#default_value' => $saved_uuid,
1774
      '#options' =>  $featureTrees['options'],
1775
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1776
      '#options_suffixes' => $featureTrees['treeRepresentations'],
1777
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1778
      ),
1779
  );
1780

    
1781
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1782
  $form_title = t('Specimen media');
1783
  $form_description = t('Specimens may have media which is displayed at the
1784
     Specimen tab/section as a gallery. It is possible to configure the
1785
     thumbnails gallery here, however for configuring how a single media should
1786
     be displayed please go to !url.</p>',
1787
     array(
1788
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1789
     ));
1790
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1791

    
1792
  // --- MEDIA GALLERY ---- //
1793
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1794
  $form_title = 'Media gallery (tab)';
1795
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1796
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1797
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1798
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1799
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1800
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1801
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1802

    
1803
  // Comment @WA: D7 form api does not support reset buttons,
1804
  // so to mimic the D5 reset button we add one like this.
1805
  $form['actions']['reset'] = array(
1806
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1807
    '#weight' => 1000,
1808
  );
1809
  return system_settings_form($form);
1810
}
1811

    
1812
/**
1813
 * @todo document this function.
1814
 */
1815
function cdm_settings_layout_search() {
1816

    
1817
  $form = array();
1818

    
1819
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
1820

    
1821
  $form['search_settings'] = array(
1822
    '#type' => 'fieldset',
1823
    '#title' => t('Taxa Search'),
1824
    '#collapsible' => FALSE,
1825
    '#collapsed' => FALSE,
1826
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1827
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1828
         where they can write the text to be searched. You can find Drupal block configuration
1829
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1830
  );
1831

    
1832
  $form['search_settings']['simple_search_ignore_classification'] = array(
1833
      '#type' => 'checkbox',
1834
      '#title' => t('Ignore the chosen classification in simple search'),
1835
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
1836
      '#description' => t('The simple search, which can be executed via the search block,
1837
          will by default search on all classifications. Remove the tick if you want your
1838
          portal to search on the classification selected in the classification browser
1839
          selector.'),
1840
  );
1841

    
1842
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1843
    '#type' => 'textfield',
1844
    '#title' => t('Results per page') . ':',
1845
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1846
    '#description' => t('Number of results to display per page.'),
1847
  );
1848

    
1849
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
1850
  $form['search_settings']['cdm_search_taxa_mode'] = array(
1851
      '#type' => 'checkboxes',
1852
      '#title' => 'Search mode',
1853
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
1854
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
1855
          for the advance search form and the behaviour of the simple search form which always will behave according to the
1856
          defaults set here.',
1857
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
1858
      '#default_value' => $search_mode_default
1859
      );
1860

    
1861
  // --- SEARCH TAXA GALLERY ---- //
1862
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1863
  $collapsed = FALSE;
1864
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1865
  $form_title = 'Taxa Search thumbnails';
1866
  $form_description = 'Search results may show thumbnails. ';
1867
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1868

    
1869
  // Comment @WA: D7 form api does not support reset buttons,
1870
  // so to mimic the D5 reset button we add one like this.
1871
  $form['actions']['reset'] = array(
1872
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1873
    '#weight' => 1000,
1874
  );
1875
  return system_settings_form($form);
1876
}
1877

    
1878
/**
1879
 * @todo document this function.
1880
 */
1881
function cdm_settings_layout_media() {
1882

    
1883
  $form = array();
1884

    
1885
  $form['media_settings'] = array(
1886
    '#type' => 'fieldset',
1887
    '#title' => t('Media settings'),
1888
    '#collapsible' => FALSE,
1889
    '#collapsed' => FALSE,
1890
    '#description' => 'This section covers layout settings for media pages.'
1891
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
1892
  );
1893

    
1894
  $form['media_settings']['image_gallery_viewer'] = array(
1895
    '#type' => 'select',
1896
    '#title' => t('Image viewer') . ':',
1897
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1898
    '#options' => array(
1899
      'default' => t('Standard image viewer'),
1900
      'fsi' => t('FSI viewer (requires FSI server!)'),
1901
    ),
1902
  );
1903

    
1904
  // --- MEDIA GALLERY ---- //
1905
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1906
  $form_title = 'Standard viewer';
1907
  $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>';
1908
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1909
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1910

    
1911
  // @WA: D7 form api does not support reset buttons,
1912
  // so to mimic the D5 reset button we add one like this.
1913
  $form['actions']['reset'] = array(
1914
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1915
    '#weight' => 1000,
1916
  );
1917
  return system_settings_form($form);
1918
}
1919

    
1920
/**
1921
 * GEOSERVICE and Map settings.
1922
 */
1923
function cdm_settings_geo($form, &$form_state) {
1924

    
1925
  $current_geoserver_settings = get_edit_map_service_settings();
1926
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
1927
  // The default layer must always be enabled
1928
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
1929
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
1930

    
1931
  $form = array();
1932

    
1933
  $dummy_distribution_query = NULL;
1934
  if($map_distribution['map_type'] != 1){
1935
    // we need to apply a dummy query since the map serice requires for image maps
1936
    // at least as and ad to be defined
1937
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
1938
  }
1939
  $form['map_preview'] = array(
1940
      '#type' => 'fieldset',
1941
      '#tree' => FALSE,
1942
      '#title' => t('Map preview'),
1943
      '#collapsible' => FALSE,
1944
      '#description' => 'The preview of the map'
1945
       . ($dummy_distribution_query != null ?
1946
           ' may not be accurate in case if image maps, please check the map display in the taxon pages.':
1947
           '.<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.')
1948
  );
1949
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL,
1950
      array(
1951
          'move' => "this.cdmOpenlayersMap.printInfo",
1952
          '#execute' => "this.cdmOpenlayersMap.printInfo"
1953
      )
1954
  );
1955

    
1956

    
1957
  /*
1958
   * GEO SERVER
1959
   */
1960
  $form['edit_map_server'] = array(
1961
    '#type' => 'fieldset',
1962
    '#tree' => true,
1963
    '#title' => t('EDIT map service'),
1964
    '#collapsible' => TRUE,
1965
    '#collapsed' => TRUE,
1966
    '#description' => t('Configuration and selection of your geo server.
1967
      The Geo Server is responsible for generating the maps.'),
1968
  );
1969

    
1970
  $form['edit_map_server']['base_uri'] = array(
1971
    '#type' => 'select',
1972
    '#title' => t('EDIT map service') . ':',
1973
    '#default_value' => $current_geoserver_settings['base_uri'],
1974
    '#options' => unserialize(EDIT_MAPSERVER_URI),
1975
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
1976
  );
1977
  $form['edit_map_server']['version'] = array(
1978
      '#type' => 'select',
1979
      '#title' => t('Version') . ':',
1980
      '#default_value' => $current_geoserver_settings['version'],
1981
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
1982
      '#description' => t('The version of the EDIT map services'),
1983
  );
1984

    
1985
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1986
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1987
  $form['gmap_api_key'] = array(
1988
      '#type' => 'textfield',
1989
      '#title' => t('Google maps API key') . ':',
1990
      '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1991
      '#description' => t('If you want to use the Google Maps Layer, a key is
1992
      needed. If you need a key, visit
1993
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
1994
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
1995
      is the default key for the localhost (127.0.0.1).',
1996
      array('!localhostkey' => $localhostkey)),
1997
  );
1998

    
1999

    
2000
  /*
2001
   * MAP SETTINGS
2002
   */
2003

    
2004
  $form[CDM_MAP_DISTRIBUTION] = array(
2005
    '#type' => 'fieldset',
2006
    '#tree' => TRUE,
2007
    '#title' => t('Maps settings'),
2008
    '#collapsible' => TRUE,
2009
    '#collapsed' => TRUE,
2010
    '#description' => t('General configuration for all map types.'),
2011
  );
2012

    
2013
  /*
2014
   * settings for the distribution map are used also for specimens map!!!!
2015
   */
2016

    
2017
  $form[CDM_MAP_DISTRIBUTION]['width'] = array(
2018
    '#type' => 'textfield',
2019
    '#title' => 'Width',
2020
    '#default_value' => $map_distribution['width'],
2021
    '#maxlength' => 4,
2022
    '#size' => 4,
2023
    '#description' => 'Width of the map. To allow OSM baselayers to zoom out to the full extend of the world the map width must be
2024
      a multiple of 256px since the osm tiles from tile.openstreetmap.org have a size of 256px x 256px and frational zoom
2025
      levels are not possible in this case.',
2026
  );
2027
  $form[CDM_MAP_DISTRIBUTION]['height'] = array(
2028
      '#type' => 'textfield',
2029
      '#title' => 'Height',
2030
      '#default_value' => $map_distribution['height'],
2031
      '#maxlength' => 4,
2032
      '#size' => 4,
2033
      '#description' => 'Height of the map. Depending on the chosen base layer you may want to choose the height equal
2034
      to the width or half of the width. Any other aspect ratio is also possible if desired.',
2035
  );
2036

    
2037
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2038
    '#type' => 'textfield',
2039
    '#title' => 'Bounding box',
2040
    '#default_value' => $map_distribution['bbox'],
2041
    '#description' => t('The bounding box (left, bottom, right, top) defines the area to be initially displayed in maps.
2042
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2043
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2044
      <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.
2045
      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
2046
      below the map from where you can copy the bbox string.</p>'),
2047
  );
2048

    
2049
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2050
    '#type' => 'checkbox',
2051
    '#title' => 'Display area labels',
2052
    '#default_value' => $map_distribution['show_labels'],
2053
    '#description' => t('The map will show name labels of the areas'),
2054
  );
2055

    
2056
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2057
    '#type' => 'textfield',
2058
    '#title' => 'Map caption',
2059
    '#default_value' => $map_distribution['caption'],
2060
    '#description' => t('The caption will be shown below the map.'),
2061
  );
2062

    
2063
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2064
    '#type' => 'textfield',
2065
    '#title' => 'Distribution layer opacity',
2066
    '#default_value' => $map_distribution['distribution_opacity'],
2067
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
2068
                           fully visible, while a value near to 0.0 will be not much visible.'),
2069
  );
2070

    
2071
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2072
    '#type' => 'radios',
2073
    '#title' => 'Map types',
2074
    '#options' => array(
2075
      1 => "OpenLayers dynamic map viewer",
2076
      0 => "Plain image",
2077
    ),
2078
    '#default_value' => $map_distribution['map_type'],
2079
    '#description' => 'Two different map types are available :
2080
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2081
      which allows zooming and panning. If enabled you can configure the default layer
2082
      (background of your maps) below.</li>
2083
      <li><em>Plain image</em>: The map will be static non interactive
2084
      image.</li></ul>',
2085
  );
2086
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2087

    
2088

    
2089
  // --- Plain Image Settings --- //
2090
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2091
    '#type' => 'fieldset',
2092
    '#title' => 'Plain image map settings',
2093
    '#tree' => TRUE,
2094
    '#collapsible' => TRUE,
2095
    '#collapsed' => $open_layers_is_enabled,
2096
    '#description' => 'The settings in this section are still expertimental
2097
      and can only be used with the EDIT map service version 1.1 or above.',
2098
  );
2099
  $edit_mapserver_version = get_edit_map_service_version_number();
2100
  if ($edit_mapserver_version < 1.1) {
2101
    $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>'
2102
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2103
  }
2104

    
2105
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2106
    '#type' => 'textfield',
2107
    '#title' => 'Background layer',
2108
    '#default_value' => $map_distribution['image_map']['base_layer'],
2109
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2110
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2111
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2112
    )),
2113
  );
2114

    
2115
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2116
    '#type' => 'textfield',
2117
    '#title' => 'Background color',
2118
    '#default_value' => $map_distribution['image_map']['bg_color'],
2119
  );
2120

    
2121
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2122
    '#type' => 'textfield',
2123
    '#title' => 'Background layer style',
2124
     // Only line color by now.
2125
    '#default_value' => $map_distribution['image_map']['layer_style'],
2126
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2127
  );
2128

    
2129
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2130
      '#type' => 'textfield',
2131
      '#title' => 'Projection',
2132
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2133
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2134
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2135
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2136
  );
2137

    
2138

    
2139
  // --- OpenLayers Settings --- //
2140
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2141
    '#type' => 'fieldset',
2142
    '#title' => 'OpenLayers settings',
2143
    '#tree' => TRUE,
2144
    '#collapsible' => TRUE,
2145
    '#collapsed' => !$open_layers_is_enabled,
2146
    '#description' => '',
2147
  );
2148

    
2149

    
2150
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2151
      '#type' => 'checkbox',
2152
      '#title' => 'Display outside max extent',
2153
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2154
      '#description' => t('Allows the map to display parts of the layers which are outside
2155
         the max extent if the aspect ratio of the map and of the baselayer
2156
         are not equal.'),
2157
  );
2158

    
2159

    
2160
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2161
      '#type' => 'checkbox',
2162
      '#title' => 'Show Layer Switcher',
2163
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2164
      '#description' => 'The Layer Switcher control displays a table of contents
2165
      for the map.  This allows the user interface to switch between
2166
      base layers and to show or hide overlays.  By default the switcher is
2167
      shown minimized on the right edge of the map, the user may expand it
2168
      by clicking on the handle.',
2169
  );
2170

    
2171
  if (!$open_layers_is_enabled) {
2172
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2173
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2174
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2175
  }
2176

    
2177
  $baselayer_options = array(
2178
    /*
2179
   NOTICE: must correspond to the layers defined in
2180
   js/openlayers_,ap.js#getLayersByName()
2181
   */
2182
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
2183
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
2184
    // all others EPSG:900913
2185
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
2186
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2187
    'mapnik' => 'OpenStreetMap',
2188
    'mapquest_open' => "MapQuest",
2189
    'mapquest_sat' => "MapQuest Sattelite",
2190
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2191
    'gmap' => 'Google Streets',
2192
    'gsat' => 'Google Satellite',
2193
    'ghyb' => 'Google Hybrid',
2194
//     'veroad' => 'Virtual Earth Roads',
2195
//     'veaer' => 'Virtual Earth Aerial',
2196
//     'vehyb' => 'Virtual Earth Hybrid',
2197
    // 'yahoo' => 'Yahoo Street',
2198
    // 'yahoosat' => 'Yahoo Satellite',
2199
    // 'yahoohyb' => 'Yahoo Hybrid',
2200
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2201
  );
2202

    
2203
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2204
    '#type' => 'checkboxes_preferred',
2205
    '#title' => 'Base Layers',
2206
    '#options' => $baselayer_options,
2207
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2208
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2209
  );
2210

    
2211
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2212
      '#type' => 'fieldset',
2213
      '#title' => 'Custom WMS base layer',
2214
      '#tree' => TRUE,
2215
      '#collapsible' => FALSE,
2216
      '#collapsed' => FALSE,
2217
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2218
  );
2219

    
2220
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2221
      '#type' => 'textfield',
2222
      '#title' => 'Layer name',
2223
      // Only line color by now.
2224
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2225
      '#description' => 'A arbitrary name for the layer.',
2226
  );
2227
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2228
      '#type' => 'textfield',
2229
      '#title' => 'WMS url',
2230
      // Only line color by now.
2231
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2232
      '#description' => 'Base url for the WMS (e.g.  http://wms.jpl.nasa.gov/wms.cgi)'
2233
  );
2234
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2235
      '#type' => 'textarea',
2236
      '#title' => 'WMS parameters',
2237
      '#element_validate' => array('form_element_validate_json'),
2238
      // Only line color by now.
2239
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2240
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2241
<pre> {
2242
  "Layers": "topp:em_tiny_jan2003",
2243
  "Format": "image/png",
2244
  "BGCOLOR": "0xe0faff"
2245
}
2246
</pre>'
2247
  );
2248
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2249
      '#type' => 'textfield',
2250
      '#title' => 'Projection',
2251
      // Only line color by now.
2252
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2253
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2254
  );
2255
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2256
      '#type' => 'textfield',
2257
      '#maxlength' => 256,
2258
      '#title' => 'proj4js definition',
2259
      // Only line color by now.
2260
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2261
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2262
            The definitions for
2263
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2264
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2265
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2266
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2267
            choose to display the proj4js definition string.
2268
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2269
            <pre>
2270
+a         Semimajor radius of the ellipsoid axis
2271
+alpha     ? Used with Oblique Mercator and possibly a few others
2272
+axis      Axis orientation (new in 4.8.0)
2273
+b         Semiminor radius of the ellipsoid axis
2274
+datum     Datum name (see `proj -ld`)
2275
+ellps     Ellipsoid name (see `proj -le`)
2276
+k         Scaling factor (old name)
2277
+k_0       Scaling factor (new name)
2278
+lat_0     Latitude of origin
2279
+lat_1     Latitude of first standard parallel
2280
+lat_2     Latitude of second standard parallel
2281
+lat_ts    Latitude of true scale
2282
+lon_0     Central meridian
2283
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
2284
+lon_wrap  Center longitude to use for wrapping (see below)
2285
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
2286
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
2287
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
2288
+pm        Alternate prime meridian (typically a city name, see below)
2289
+proj      Projection name (see `proj -l`)
2290
+south     Denotes southern hemisphere UTM zone
2291
+to_meter  Multiplier to convert map units to 1.0m
2292
+towgs84   3 or 7 term datum transform parameters (see below)
2293
+units     meters, US survey feet, etc.
2294
+vto_meter vertical conversion to meters.
2295
+vunits    vertical units.
2296
+x_0       False easting
2297
+y_0       False northing
2298
+zone      UTM zone
2299
            </pre>
2300
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
2301
  );
2302
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
2303
      '#type' => 'textfield',
2304
      '#title' => 'Maximum extent',
2305
      // Only line color by now.
2306
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
2307
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
2308
  );
2309
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
2310
      '#type' => 'textfield',
2311
      '#title' => 'Units',
2312
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
2313
      '#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.'
2314
  );
2315

    
2316
  /*
2317
   * Map Legend
2318
   */
2319
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2320
    '#type' => 'fieldset',
2321
    '#title' => 'Map legend',
2322
    '#tree' => TRUE,
2323
    '#collapsible' => TRUE,
2324
    '#collapsed' => TRUE,
2325
    '#description' => 'Configure the maps legend.',
2326
  );
2327

    
2328
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2329
    '#type' => 'checkbox',
2330
    '#title' => 'Display a map legend',
2331
    '#default_value' => $map_distribution['legend']['show'],
2332
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2333
  );
2334

    
2335
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2336
    '#type' => 'textfield',
2337
    '#title' => 'Legend opacity',
2338
    '#default_value' => $map_distribution['legend']['opacity'],
2339
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2340
                         to 0.0 will be not much visible.',
2341
  );
2342

    
2343
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2344
    '#type' => 'textfield',
2345
    '#title' => 'Font size',
2346
    '#default_value' => $map_distribution['legend']['font_size'],
2347
    '#description' => 'Font size in pixels.',
2348
  );
2349

    
2350
  $fontStyles = array(
2351
    0 => "plane",
2352
    1 => "italic",
2353
  );
2354
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2355
    '#type' => 'select',
2356
    '#title' => 'Available font styles',
2357
    '#default_value' => $map_distribution['legend']['font_style'],
2358
    '#options' => $fontStyles,
2359
    '#description' => 'Select a font style for the map legend.',
2360
  );
2361

    
2362
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2363
    '#type' => 'textfield',
2364
    '#title' => 'Icon width',
2365
    '#default_value' => $map_distribution['legend']['icon_width'],
2366
    '#description' => 'Legend icon width in pixels.',
2367
  );
2368
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2369
    '#type' => 'textfield',
2370
    '#title' => 'Icon height',
2371
    '#default_value' => $map_distribution['legend']['icon_height'],
2372
    '#description' => 'Legend icon height in pixels.',
2373
  );
2374

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

    
2382
  return system_settings_form($form);
2383
}
2384

    
2385
/**
2386
 * @todo document this function.
2387
 */
2388
function cdm_settings_cache() {
2389

    
2390
  $form = array();
2391

    
2392
  $form['cache_settings'] = array(
2393
    '#type' => 'fieldset',
2394
    '#title' => t('Cache Settings'),
2395
    '#collapsible' => FALSE,
2396
    '#collapsed' => FALSE,
2397
    '#description' => t('<p>When caching is enabled all single taxon sites are
2398
      stored in an internal drupal cache doing the portal response of taxa pages
2399
      faster. This is possible because the sites are loaded from the cache and
2400
      are not created from scratch.</p>'),
2401
  );
2402

    
2403
  $form['cache_settings']['cdm_webservice_cache'] = array(
2404
    '#type' => 'checkbox',
2405
    '#title' => t('<strong>Enable caching</strong>'),
2406
    '#options' => cdm_help_general_cache(),
2407
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2408
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2409
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2410
       application the changes will be not visible till the cache is erased.
2411
       Therefore developers should deactived this feature when they are working
2412
       on the CDM Dataportal Module.</p>'),
2413
  );
2414

    
2415
  $form['cache_settings']['cdm_run_cache'] = array(
2416
    '#markup' => cdm_view_cache_site(),
2417
  );
2418

    
2419
  // @WA: D7 form api does not support reset buttons,
2420
  // so to mimic the D5 reset button we add one like this.
2421
  $form['actions']['reset'] = array(
2422
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2423
    '#weight' => 1000,
2424
  );
2425
  return system_settings_form($form);
2426
}
2427

    
2428
/**
2429
 * Walk and cache all taxon pages.
2430
 */
2431
function cdm_view_cache_site() {
2432

    
2433
  $out = '';
2434

    
2435
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2436

    
2437
  $request_params = array();
2438
  $request_params['class'] = "Taxon";
2439

    
2440
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2441
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2442
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2443

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

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

    
2453
  // Comment @WA: A form within a form is not valid html and not needed here.
2454
  // Also, it would be recommended just to include this part of the form in the
2455
  // rest of the form array in cdm_settings_cache().
2456
  // $out .= '<form id="cache_site">';
2457
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2458
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2459
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2460
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2461
  // $out .= '</form>';
2462
  $out .= '</div>';
2463
  /*
2464
  foreach($taxonPager->records as $taxon){
2465
    cdm_dataportal_taxon_view($uuid);
2466
  }
2467
  */
2468
  return $out;
2469
}
2470

    
2471

    
2472
function cdm_settings_layout_taxon_submit($form, &$form_state){
2473
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2474
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2475
    if(is_object($file)){
2476
      $file->status = FILE_STATUS_PERMANENT;
2477
      file_save($file);
2478
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2479
    }
2480
  }
2481
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2482
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2483
    // we first need to set the variable to persist the changes setting
2484
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
2485
    menu_rebuild();
2486
  }
2487
}
2488

    
2489
function cdm_settings_layout_search_submit($form, &$form_state){
2490
  // the visibility of media thumbnails also affects the ui of the search results
2491
  // so reset the according session variable
2492
  //    1. in order to give the user immediate
2493
  //       feedback on potential setting changes
2494
  //    2. let refresh the default if it has changed
2495
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2496
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
2497
  }
2498
}
2499

    
2500
/**
2501
 * Form validation handler for cdm_settings_general
2502
 *
2503
 * @param $form
2504
 * @param $form_state
2505
 */
2506
function cdm_settings_general_validate($form, &$form_state) {
2507

    
2508
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2509
    $form_state['values']['cdm_webservice_url'] .= '/';
2510
  }
2511

    
2512
}
2513

    
2514
/**
2515
 * Form submit handler for settings general.
2516
 *
2517
 * tasks performed:
2518
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2519
 *
2520
 * @param $form
2521
 * @param $form_state
2522
 */
2523
function cdm_settings_general_submit($form, &$form_state){
2524
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2525
  unset($_SESSION['cdm']['taxonomictree_uuid']);
2526
}
2527

    
2528
/**
2529
 * Form validation handler for cdm_settings_cache
2530
 */
2531
function cdm_settings_cache_validate($form, &$form_state) {
2532
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2533
    cache_clear_all(NULL, 'cache_cdm_ws');
2534
    // Better clear secref_cache since I can not be sure if the cache has not
2535
    // be used during this response.
2536
    cdm_api_secref_cache_clear();
2537
  }
2538

    
2539
}
2540

    
2541
/**
2542
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
2543
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
2544
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
2545
 *  - version: the version, e.g.: v1.1
2546
 *
2547
 * @return array
2548
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
2549
 */
2550
function get_edit_map_service_settings() {
2551

    
2552
  $settings = variable_get('edit_map_server', array(
2553
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
2554
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
2555
      )
2556
  );
2557

    
2558
  return $settings;
2559
}
2560

    
2561
/**
2562
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2563
 *
2564
 * @return string
2565
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2566
 */
2567
function get_edit_map_service_full_uri() {
2568
  $settings = get_edit_map_service_settings();
2569
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
2570
}
2571

    
2572

    
2573
/**
2574
 * Returns the version number of the currently selected edit mapserver as a float
2575
 *
2576
 * @return float
2577
 *   The version number of the currently selected edit mapserver as a float.
2578
 *   Returns 0 on error.
2579
 */
2580
function get_edit_map_service_version_number() {
2581

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

    
2584
  $settings = get_edit_map_service_settings();
2585
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
2586
  if (isset($matches[1])) {
2587
    // Convert string to float.
2588
    $version = 1 + $matches[1][0] - 1;
2589
    return $version;
2590
  }
2591
  else {
2592
    // Report error.
2593
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
2594
        array(
2595
          '!version' => $settings['version'],
2596
          'warning')
2597
        )
2598
      );
2599
    return 0;
2600
  }
2601
}
2602

    
2603
/**
2604
 * Returns the array of selected items in a options array
2605
 *
2606
 * @param array $options
2607
 *   An options array as generated by a form element like checkoxes, select ...,
2608
 */
2609
function get_selection($options) {
2610
  $selection = array();
2611
  foreach ($options as $key=>$val) {
2612
    if (!empty($val)) {
2613
      $selection[] = $val;
2614
    }
2615
  }
2616
  return $selection;
2617
}
2618

    
2619

    
2620
/**
2621
 * Implements hook_element_info().
2622
 *
2623
 * Allows modules to declare their own Form API element types and specify their default values.
2624
 *
2625
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
2626
 */
2627
function cdm_dataportal_element_info() {
2628
  $type['checkboxes_preferred'] = array(
2629
    '#input' => TRUE,
2630
    '#process' => array('checkboxes_preferred_expand'),
2631
    '#after_build' => array('checkboxes_preferred_after_build'),
2632
    '#theme' => array('checkboxes_preferred'),
2633
    // '#theme_wrapper' => array('form_element'),
2634
  );
2635
  return $type;
2636
}
2637

    
2638
/**
2639
 * #process callback function for the custom form element type 'checkbox_preferred'
2640
 *
2641
 *
2642
 */
2643
function checkboxes_preferred_expand($element, &$form_state, $form) {
2644

    
2645
  // First of all create checkboxes for each of the elements
2646
  $element = form_process_checkboxes($element);
2647

    
2648
  // compose the element name
2649
  $parents = array();
2650
  array_deep_copy($element['#parents'], $parents);
2651
  $parents[count($parents) -1 ] .= '_preferred';
2652
  $element_name = $parents[0];
2653
  for ($i=1; $i < count($parents); $i++){
2654
    $element_name .= '[' . $parents[$i] . ']';
2655
  }
2656

    
2657
  $children = element_children($element);
2658

    
2659
  $element['table_start'] = array(
2660
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
2661
    '#weight' => -1,
2662
  );
2663

    
2664
  // prepare first part each of the table rows which contains the row label
2665
  $weight = 0;
2666
  foreach ($children as $key) {
2667
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
2668
    $element[$key]['#weight'] = $weight;
2669
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
2670
    $element[$key]['#suffix'] = '</td>';
2671
    unset($element[$key]['#title']);
2672
    $weight += 2;
2673
  }
2674
  $weight = 0;
2675

    
2676
  // add a radio button to each of the checkboxes, the
2677
  // check boxes have already been created at the beginning
2678
  // of this function
2679
  if (count($element['#options']) > 0) {
2680
    foreach ($element['#options'] as $key => $choice) {
2681
      if (!isset($element[$key . '_preferred'])) {
2682
        $element[$key . '_preferred'] = array(
2683
          '#type' => 'radio',
2684
          '#name' => $element_name,
2685
          '#return_value' => check_plain($key),
2686
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
2687
          '#attributes' => $element['#attributes'],
2688
          '#parents' => $element['#parents'],
2689
          // '#spawned' => TRUE,
2690
          '#weight' => $weight + 1,
2691
          '#prefix' => '<td>',        // add a prefix to start a new table cell
2692
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
2693
        );
2694
      }
2695
      $weight += 2;
2696
    }
2697
  }
2698

    
2699
  // end the table
2700
  $element['table_end'] = array(
2701
    '#markup' => '</table>',
2702
    '#weight' => $weight++,
2703
  );
2704

    
2705
  return $element;
2706
}
2707

    
2708
/**
2709
 * Theme function for the custom form field 'checkboxes_preferred'.
2710
 */
2711
function theme_checkboxes_preferred($variables) {
2712
  $element = $variables['element'];
2713
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
2714
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
2715
  $out .= drupal_render_children($element);
2716
  $out .= '<div class="description">' . $element['#description'] . '</div>';
2717
  $out .= '</div>';
2718
  return $out;
2719
}
2720

    
2721
/**
2722
 * Callback for checkboxes preferred for widget which will
2723
 * be called after the form or element is built. The call
2724
 * back is configured in the form element by setting it as
2725
 * #after_build parameter.
2726
 *
2727
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
2728
 *
2729
 * @param $element
2730
 *   Nested array of form elements that comprise the form.
2731
 * @param $form_state
2732
 *   A keyed array containing the current state of the form.
2733
 *   This includes the current persistent storage data for the form.
2734
 *   Additional information, like the sanitized $_POST data,
2735
 *   is also accumulated here in $form_state['input']
2736
 *
2737
 * @return the modified form array
2738
 */
2739
function checkboxes_preferred_after_build($element, &$form_state) {
2740

    
2741
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
2742

    
2743
  if ($_POST && count($_POST) > 0) {
2744
    // TODO use  $form_state['input'] instead of POST !!!
2745
    // First pass of form processing.
2746
    $parents = array();
2747
    array_deep_copy($element['#parents'], $parents);
2748
    $parents[count($parents) - 1] .= '_preferred';
2749
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
2750
    $element['#value']['PREFERRED'] = $preferred_layer;
2751
//     $form_state[$parent_id] = $element['#value'];
2752
//     $form_state['values']['baselayers'] = $element['#value'];
2753
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
2754
    $form_state_element_values = $element['#value'];
2755
  }
2756
  else {
2757
    // Second pass of form processing.
2758
    $preferred_layer = $element['#value']['PREFERRED'];
2759
  }
2760

    
2761
  // Also set the chosen value (not sure if this is good Drupal style ....).
2762
  foreach ($children = element_children($element) as $key) {
2763
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
2764
      $element[$key]['#value'] = $preferred_layer;
2765
    }
2766
  }
2767
  // The default layer must always be enabled.
2768
  $element[$preferred_layer]['#value'] = $preferred_layer;
2769

    
2770
  return $element;
2771
}
2772

    
2773
function radios_prepare_options_suffix(&$elements){
2774

    
2775
  $childrenKeys = element_children($elements);
2776
  foreach($childrenKeys as $key){
2777
    if(!is_array($elements[$key]['#theme_wrappers'])){
2778
      $elements[$key]['#theme_wrappers'] = array();
2779
    }
2780
    if(isset($elements['#options_suffixes'][$key])){
2781
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
2782
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
2783
    }
2784
  }
2785
  return $elements;
2786

    
2787
}
2788

    
2789
/**
2790
 * TODO
2791
 * @param unknown $variables
2792
 */
2793
function theme_radio_options_suffix($variables) {
2794
  $element = $variables['element'];
2795
  if(isset($element['#options_suffix'])) {
2796
    $element['#children'] .= $element['#options_suffix'];
2797
  }
2798
  return $element['#children'];
2799
}
2800

    
2801

    
2802
/**
2803
 * Element validate callback for text field and arrays containing json.
2804
 *
2805
 * @param $element
2806
 *   The form element to validate
2807
 * @param $form_state
2808
 *   A keyed array containing the current state of the form.
2809
 * @param $form
2810
 *   Nested array of form elements that comprise the form.
2811
 */
2812
function form_element_validate_json($element, &$form_state, $form) {
2813
   if (!empty($element['#value'])) {
2814
     json_decode($element['#value']);
2815
     if(json_last_error() != JSON_ERROR_NONE){
2816
       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/'));
2817
     }
2818
   }
2819
}
2820

    
2821
/**
2822
 * Form submission handler for textareas and textfields containing JSON.
2823
 *
2824
 * The contained JSON will be converted into an php array
2825
 * or object and will be stored in the variables as such.
2826
 *
2827
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2828
 *
2829
 * @param $form
2830
 *   Nested array of form elements that comprise the form.
2831
 * @param $form_state
2832
 *   A keyed array containing the current state of the form.
2833
 *
2834
 */
2835
function submit_json_as_php_array($form, &$form_state) {
2836
  if (is_array($form['#json_elements'])) {
2837
    foreach ($form['#json_elements'] as $element){
2838
      if (trim($form_state['values'][$element])) {
2839
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
2840
      } else {
2841
        $form_state['values'][$element] = NULL;
2842
      }
2843
    }
2844
  }
2845
}
(14-14/14)