Project

General

Profile

Download (108 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

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

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

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

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

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

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

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

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

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

    
132
}
133

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

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

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

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

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

    
277

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

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

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

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

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

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

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

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

    
398
}
399

    
400
/**
401
 * returns the current setting for the original source bibliography
402
 *
403
 * Caches internally
404
 *
405
 * @return array
406
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
407
 *   - 'enabled': 1|0
408
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
409
 */
410
function get_bibliography_settings($clear_cache = false){
411
  static $bibliography_settings = null;
412
  if(!$bibliography_settings || $clear_cache){
413
    $bibliography_settings = get_array_variable_merged(BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE, BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT);
414
  }
415
  return $bibliography_settings;
416
}
417

    
418
/**
419
 * @todo Please document this function.
420
 * @see http://drupal.org/node/1354
421
 */
422
function cdm_dataportal_menu_admin(&$items) {
423
  // Display section on admin/config page.
424
  $items['admin/config/cdm_dataportal'] = array(
425
    'title' => 'CDM Dataportal',
426
    'description' => 'Settings for the CDM DataPortal.',
427
    'position' => 'right',
428
    'weight' => 10,
429
    'page callback' => 'system_admin_menu_block_page',
430
    'access arguments' => array('administer cdm_dataportal'),
431
    'file' => 'system.admin.inc',
432
    'file path' => drupal_get_path('module', 'system'),
433
  );
434
  $items['admin/config/cdm_dataportal/settings'] = array(
435
    'title' => 'Settings',
436
    'description' => 'Settings for the CDM DataPortal.',
437
    'weight' => 0,
438
    'page callback' => 'drupal_get_form',
439
    'page arguments' => array('cdm_settings_general'),
440
    'access arguments' => array('administer cdm_dataportal'),
441
    'type' => MENU_NORMAL_ITEM,
442
  );
443
  $items['admin/config/cdm_dataportal/settings/general'] = array(
444
    'title' => 'General',
445
    'description' => 'General',
446
    'weight' => 0,
447
    'page callback' => 'drupal_get_form',
448
    'page arguments' => array('cdm_settings_general'),
449
    'access arguments' => array('administer cdm_dataportal'),
450
    'type' => MENU_DEFAULT_LOCAL_TASK,
451
  );
452

    
453
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
454
    'title' => 'Cache',
455
    'description' => 'Cache',
456
    'access arguments' => array('administer cdm_dataportal'),
457
    'page callback' => 'drupal_get_form',
458
    'page arguments' => array('cdm_settings_cache'),
459
    'weight' => 10,
460
    'type' => MENU_LOCAL_TASK,
461
  );
462

    
463
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
464
    'title' => 'Geo & Map',
465
    'description' => 'Geo & Map',
466
    'access arguments' => array('administer cdm_dataportal'),
467
    'page callback' => 'drupal_get_form',
468
    'page arguments' => array('cdm_settings_geo'),
469
    'weight' => 1,
470
    'type' => MENU_LOCAL_TASK,
471
  );
472

    
473
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
474
    'title' => 'Layout',
475
    'description' => 'Configure and adjust the layout of your DataPortal ',
476
    'access arguments' => array('administer cdm_dataportal'),
477
    'page callback' => 'drupal_get_form',
478
    'page arguments' => array('cdm_settings_layout'),
479
    'weight' => 2,
480
    'type' => MENU_LOCAL_TASK,
481
  );
482

    
483
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
484
    'title' => 'Taxon',
485
    'description' => 'Configure and adjust the layout of your DataPortal ',
486
    'access arguments' => array('administer cdm_dataportal'),
487
    'page callback' => 'drupal_get_form',
488
    'page arguments' => array('cdm_settings_layout_taxon'),
489
    'weight' => 1,
490
    'type' => MENU_LOCAL_TASK,
491
  );
492
  /*
493
  $items[] = array(
494
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
495
  'title' => t('Synonymy'),
496
  'description' => t('Configure and adjust the layout of your DataPortal '),
497
  'access' => user_access('administer cdm_dataportal'),
498
  'callback' => 'drupal_get_form',
499
  'callback arguments' => array('cdm_settings_layout_synonymy'),
500
  'weight' => 1,
501
  'type' => MENU_LOCAL_TASK,
502
  );
503

    
504
  $items[] = array(
505
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
506
  'title' => t('Specimens'),
507
  'description' => t('Configure and adjust the layout of your DataPortal '),
508
  'access' => user_access('administer cdm_dataportal'),
509
  'callback' => 'drupal_get_form',
510
  'callback arguments' => array('cdm_settings_layout_specimens'),
511
  'weight' => 1,
512
  'type' => MENU_LOCAL_TASK,
513
  );
514
  */
515
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
516
    'title' => 'Search',
517
    'description' => 'Configure and adjust the layout of your DataPortal ',
518
    'access arguments' => array('administer cdm_dataportal'),
519
    'page callback' => 'drupal_get_form',
520
    'page arguments' => array('cdm_settings_layout_search'),
521
    'weight' => 2,
522
    'type' => MENU_LOCAL_TASK,
523
  );
524

    
525
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
526
    'title' => 'Media',
527
    'description' => 'Configure and adjust the layout of your DataPortal ',
528
    'access arguments' => array('administer cdm_dataportal'),
529
    'page callback' => 'drupal_get_form',
530
    'page arguments' => array('cdm_settings_layout_media'),
531
    'weight' => 3,
532
    'type' => MENU_LOCAL_TASK,
533
  );
534

    
535
}
536

    
537
/**
538
 * @todo document this function.
539
 */
540
function cdm_help_general_cache() {
541
  $form = array();
542
  $form['cache_help'] = array(
543
    '#type' => 'fieldset',
544
    '#title' => t('Help'),
545
    '#collapsible' => TRUE,
546
    '#collapsed' => TRUE,
547
  );
548
  $form['cache_help']['test'] = array('#value' => t('probando'));
549
  return drupal_render($form);
550
  $res = array();
551
  $res['default'] = drupal_render($help);
552
  return $res;
553
}
554

    
555
/**
556
 * Configures the settings form for the CDM-API module.
557
 *
558
 * @return array
559
 *   Drupal settings form.
560
 */
561
function cdm_settings_general() {
562

    
563
  $form['cdm_webservice'] = array(
564
    '#type' => 'fieldset',
565
    '#title' => t('CDM Server'),
566
    '#collapsible' => FALSE,
567
    '#collapsed' => FALSE,
568
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
569
        CDM data base to the web via RESTful web services and thus is the source of the data
570
        to be displayed by a CDM DataPotal.'),
571
  );
572

    
573
  $form['cdm_webservice']['cdm_webservice_url'] = array(
574
    '#type' => 'textfield',
575
    '#title' => t('CDM web service URL') . ':',
576
    '#description' => t('This is the URL to the CDM-Server exposing your data
577
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
578
    '#default_value' => variable_get('cdm_webservice_url', NULL),
579
  );
580

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

    
588
  $form['cdm_webservice']['freetext_index'] = array(
589
    '#type' => 'fieldset',
590
    '#title' => t('Freetext index'),
591
    '#collapsible' => FALSE,
592
    '#collapsed' => FALSE,
593
  );
594

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

    
607
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
608
  $trigger_link_options = array(
609
    'attributes' => array(
610
      'class' => 'index-trigger',
611
    ),
612
  );
613
  $form['cdm_webservice']['freetext_index']['operations'] = array(
614
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
615
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
616
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
617
      ))
618
    . '<div id="index-progress"></div></div>',
619
  );
620
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
621

    
622
  $form['cdm_webservice']['proxy'] = array(
623
    '#type' => 'fieldset',
624
    '#title' => t('Proxy'),
625
    '#collapsible' => TRUE,
626
    '#collapsed' => TRUE,
627
  );
628

    
629
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
630
    '#type' => 'textfield',
631
    '#title' => t('Proxy URL') . ':',
632
    '#description' => t('If this proxy url is set the cdm api tries
633
    to connect the web service over the given proxy server.
634
    Otherwise proxy usage is deactivated.'),
635
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
636
  );
637

    
638
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
639
    '#type' => 'textfield',
640
    '#title' => t('Proxy port') . ':',
641
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
642
  );
643

    
644
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
645
    '#type' => 'textfield',
646
    '#title' => t('Login') . ':',
647
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
648
  );
649

    
650
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
651
    '#type' => 'textfield',
652
    '#title' => t('Password') . ':',
653
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
654
  );
655

    
656
  // TODO: settings are still incomplete, compare with
657
  // trunk/dataportal/inc/config_default.php.inc.
658
  $form['taxon_tree'] = array(
659
    '#type' => 'fieldset',
660
    '#title' => t('Taxon Tree'),
661
    '#collapsible' => FALSE,
662
    '#collapsed' => TRUE,
663
    '#description' => t('<p>When you explore your collection, you can navigate
664
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
665
      able to navigate through your collection the
666
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
667
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
668
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
669
      </a></p>'),
670
  );
671

    
672
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
673
    '#type' => 'select',
674
    '#title' => t('Available classifications') . ':',
675
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
676
    '#options' => cdm_get_taxontrees_as_options(),
677
    '#description' => t('Select the default taxa classification for your
678
      <em>taxon tree</em>, the other classifications will be also available but
679
      with a manual user change.'),
680
  );
681

    
682
  $form['taxon_tree']['taxontree_ranklimit'] = array(
683
    '#type' => 'select',
684
    '#title' => t('Rank of highest displayed taxon') . ':',
685
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
686
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
687
    '#options' => cdm_rankVocabulary_as_option(),
688
    '#description' => t('This is the rank of the highest displayed taxon in the
689
      <em>taxon tree</em>. You can select here which rank should be at the top
690
      level of the tree structure.'),
691
  );
692

    
693
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
694
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
695
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
696
      '#type' => 'checkboxes',
697
      '#title' => t('Included Classifications') . ':',
698
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
699
      '#options' => cdm_get_taxontrees_as_options(),
700
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
701
  );
702

    
703
  $form['distribution'] = array(
704
      '#type' => 'fieldset',
705
      '#title' => t('Distributions'),
706
      '#collapsible' => FALSE,
707
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
708
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
709
          '<p>
710
          </p>',
711
  );
712

    
713
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
714
      '#type' => 'fieldset',
715
      '#title' => 'Distribution filter',
716
      '#collapsible' => FALSE,
717
      '#collapsed' => FALSE,
718
      '#tree' => TRUE,
719
      '#description' => 'The Distribution filter offers the following options
720
      <ul>
721
      <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>
722
      <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>
723
      <li><strong>Marked area filter:</strong>Skip distributions where the area has a Marker with one of the specified MarkerTypes</li>
724
      </ul>'
725
  );
726

    
727
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
728
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
729
      '#type' => 'checkboxes',
730
      '#title' => 'Filter rules',
731
      '#default_value' => $cdm_distribution_filter['filter_rules'],
732
      '#options' => array(
733
          'statusOrderPreference' => 'Status order preference rule',
734
          'subAreaPreference' => 'Sub area preference rule'
735
      ),
736
  );
737

    
738
  $marker_type_options = cdm_terms_as_options( cdm_ws_fetch_all('term', array('class' => 'MarkerType' )) );
739
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hideMarkedAreas'] = array(
740
      '#type' => 'checkboxes',
741
      '#title' => 'Hide marked area filter',
742
      '#default_value' => $cdm_distribution_filter['hideMarkedAreas'],
743
      '#options' => $marker_type_options,
744
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
745
  );
746

    
747
  $form['aggregation'] = array(
748
      '#type' => 'fieldset',
749
      '#title' => t('Aggregation of data'),
750
      '#collapsible' => FALSE,
751
      '#description' => 'This section covers the different aspects of aggregating information.
752
          <p>
753
          </p>',
754
  );
755

    
756
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
757
      '#type' => 'checkboxes',
758
      '#title' => 'Taxon media filter',
759
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
760
      '#options' => array(
761
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
762
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
763
          'includeOccurrences' => 'Media related to specimens and occurrences',
764
      ),
765
      '#description' => 'This filter configures which images should be taken into account.',
766
  );
767

    
768
  $form['aggregation']['notice'] = array(
769
      '#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
770
          want to make use of the caching capabilities of the dataportal.',
771
  );
772

    
773
  $form['aggregation']['media_aggregation'] = array(
774
      '#type' => 'fieldset',
775
      '#title' => t('Media aggregation'),
776
      '#collapsible' => FALSE,
777
      '#collapsed' => TRUE,
778
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
779

    
780
  );
781
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
782
      '#type' => 'select',
783
      '#title' => t('Aggregation of taxon pictures') . ':',
784
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
785
      '#options' => array(
786
          0 => "Show only pictures of the current taxon",
787
          1 => "Include pictures of taxonomic children",
788
      ),
789
      '#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."),
790
  );
791

    
792
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
793
      '#type' => 'fieldset',
794
      '#attributes' => array('class'=>array('clearfix')),
795
      '#title' => t('Aggregation via taxon relationsships'),
796
      '#collapsible' => TRUE,
797
      '#collapsed' => TRUE,
798
      '#tree' => TRUE,
799
      '#description' => t('Information on taxa will be aggregated along the below chosen
800
          taxon relation ships. This will affect images and occurrences (specimens).
801
          Taxon relation ships are directed and point form one taxon to another. The taxon
802
          relationships to be taken into accunt can therefore configured for the direct direction
803
          and for the inverse.'),
804
  );
805

    
806
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
807
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
808

    
809
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
810
      '#type' => 'checkboxes',
811
      '#title' => t('Direct'),
812
      '#options' => $taxonRelationshipTypeOptions,
813
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
814
  );
815
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
816
      '#type' => 'checkboxes',
817
      '#title' => t('Invers'),
818
      '#options' => $taxonRelationshipTypeOptions,
819
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
820
  );
821

    
822
  // ----------------------
823
  $form['cdm_js_devel_mode'] = array(
824
      '#type' => 'checkbox',
825
      '#title' => 'Java-script developer mode',
826
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
827
      '#description' => 'In production envirionments the java script libraries
828
      the cdm_dataportal is making use of are compressed and optimized. This
829
      is good for performance but a caveat if you need to debug java-script. When the
830
      java-script developer mode is enabled the uncompressed and commented developer
831
      versions of java-script libraries will be used where possible.
832
      <br/><strong>Do not use this option in production!</strong>'
833
  );
834
  // ----------------------
835
  $form['cdm_debug_mode'] = array(
836
      '#type' => 'checkbox',
837
      '#title' => 'CDM page debug mode',
838
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
839
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
840
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
841
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
842
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
843
      The log is written by the drupal devel module function <code>dd()</code>.
844
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
845
  );
846

    
847
  // Comment @WA: D7 form api does not support reset buttons,
848
  // so to mimic the D5 reset button we add one like this.
849
  $form['actions']['reset'] = array(
850
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
851
    '#weight' => 1000,
852
  );
853

    
854
  $form['#submit'][] = 'cdm_settings_general_submit';
855

    
856
  return system_settings_form($form);
857
}
858

    
859

    
860
/**
861
 * LAYOUT settings
862
 * @return unknown_type
863
 *   todo
864
 */
865
function cdm_settings_layout() {
866

    
867
  $form = array();
868

    
869
  $form['about'] = array(
870
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
871
      layout. If you want to configure the specific sites layout visit the
872
      respective configuration site for taxon, search or media.') . '</p>',
873
  );
874

    
875
  // ---- footnotes --- //
876
  $form['footnotes'] = array(
877
    '#type' => 'fieldset',
878
    '#title' => t('Footnotes'),
879
    '#collapsible' => FALSE,
880
    '#collapsed' => FALSE,
881
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
882
      media or distribution areas may have annotations or footnotes. When the
883
      footnotes are enabled they will be visible (if they exist).'),
884
  );
885

    
886
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
887
    '#type' => 'checkbox',
888
    '#title' => t('Do not show footnotes'),
889
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
890
    '#description' => t('Check this if you do not want to show any footnotes'),
891
  );
892

    
893
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
894
    '#type' => 'checkbox',
895
    '#title' => t('Do not show annotations footnotes'),
896
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
897
    '#description' => t('Check this if you do not want to show annotation footnotes'),
898
  );
899

    
900
  $annotationTypeOptions = cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE);
901
  // Additional option for the NULL case.
902
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
903
  $form['footnotes']['annotations_types_as_footnotes'] = array(
904
    '#type' => 'checkboxes',
905
    '#title' => t('Annotation types as footnotes'),
906
    '#description' => t("Only annotations of the selected type will be displayed
907
       as footnotes. You may want to turn 'technical annotations' off."),
908
    '#options' => $annotationTypeOptions,
909
  );
910
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
911
  if (!empty($annotationsTypesAsFootnotes)) {
912
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
913
  }
914

    
915
  // ---- original source --- //
916
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
917
      '#type' => 'fieldset',
918
      '#tree' => TRUE,
919
      '#title' => t('Source Citations'),
920
      '#collapsible' => FALSE,
921
      '#collapsed' => FALSE,
922
  );
923

    
924
  $bibliography_settings = get_bibliography_settings(true);
925

    
926
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
927
      '#type' => 'checkbox',
928
      '#title' => t('Original Source in bibliography'),
929
      '#default_value' => $bibliography_settings['enabled'],
930
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
931
       annotations in each feature block.'),
932
  );
933

    
934
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
935
    '#type' => 'select',
936
    '#title' => t('The format of the key numerals'),
937
    '#default_value' => $bibliography_settings['key_format'],
938
    '#options' => array('latin' => 'Latin',
939
      'ROMAN' => 'Roman (upper case)',
940
      'roman' => 'Roman (lower case)',
941
      'ALPHA'=> 'Alphabet (upper case)',
942
      'alpha' => 'Alphabet (lower case)')
943
  );
944

    
945
  // --- Advanced Search --- //
946
  $form['asearch'] = array(
947
    '#type' => 'fieldset',
948
    '#title' => t('Advanced search'),
949
    '#collapsible' => FALSE,
950
    '#collapsed' => FALSE,
951
  );
952

    
953
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
954
    '#type' => 'checkbox',
955
    '#title' => t('Show advanced search link'),
956
    '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
957
    '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
958
  );
959

    
960
  // ---- Taxon Name Rendering --- //
961
  $form['taxon_name'] = array(
962
      '#type' => 'fieldset',
963
      '#title' => t('Taxon name display'),
964
      '#collapsible' => TRUE,
965
      '#collapsed' => TRUE,
966
      '#description' => t('The display of taxon names is configured by two parts.'
967
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
968
          . 'The name parts are defined in the <stong>part definitions</strong>'),
969
  );
970

    
971
  drupal_add_js(
972
      'jQuery(document).ready( function( ) {
973
         // pretty print json
974
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
975
         var obj = JSON.parse(json_text);
976
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
977

    
978
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
979
         obj = JSON.parse(json_text);
980
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
981
       });'
982
      ,array(
983
          'type' => 'inline',
984
          'scope' => 'footer'
985
      )
986
  );
987

    
988
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
989

    
990
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
991
      '#type' => 'textarea',
992
      '#title' => t('Part definitions'),
993
      '#element_validate' => array('form_element_validate_json'),
994
      '#default_value' =>  json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions)),
995
      '#description' => '
996
          <p>
997
          (Clearing the text area will reset it to the default)
998
          </p>
999
          <p>
1000
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1001
          </p>
1002
          <p>
1003
           A full taxon name plus additional information can consist of the following elements:
1004
          <ul>
1005
             <li>name: the taxon name inclugin rank nbut without author</li>
1006
             <li>authors:  The authors of a reference, also used in taxon names</li>
1007
             <li>reference: the nomenclatural reference,</li>
1008
             <li>microreference:  Volume, page number etc.</li>
1009
             <li>status:  The nomenclatural status of a name</li>
1010
             <li>description: name descriptions like protologues etc ...</li>
1011
          </ul>
1012
          </p>
1013
          <p>
1014
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1015
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1016
           The following parts can be formed and are recognized by the system:
1017
          <ul>
1018
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1019
            <li>authorshipPart: the author (for example: "L.")</li>
1020
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1021
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1022
               be combined when a link to the taxon is rendered.</li>
1023
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1024
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1025
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1026
            <li>statusPart: the nomenclatorical status</li>
1027
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1028
          </ul>
1029
          </p>
1030
          <p>
1031
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1032
           specific parts part definitions:
1033
          <ul>
1034
            <li>BotanicalName</li>
1035
            <li>ZoologicalName</li>
1036
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1037
          </ul>
1038
           An example:
1039
          <pre>
1040
           {
1041
            "ZoologicalName": {
1042
              "namePart": {
1043
                "name": true
1044
              },
1045
              "referencePart": {
1046
                "authors": true
1047
              },
1048
              "microreferencePart": {
1049
                "microreference": true
1050
              },
1051
              "statusPart": {
1052
                "status": true
1053
              },
1054
              "descriptionPart": {
1055
                "description": true
1056
              }
1057
            },
1058
            "BotanicalName": {
1059
              "namePart": {
1060
                "name": true,
1061
                "authors": true
1062
              },
1063
              "referencePart": {
1064
                "reference": true,
1065
                "microreference": true
1066
              },
1067
              "statusPart": {
1068
                "status": true
1069
              },
1070
              "descriptionPart": {
1071
                "description": true
1072
              }
1073
            }
1074
          }
1075
           </pre>',
1076
  );
1077

    
1078
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1079

    
1080
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1081
      '#type' => 'textarea',
1082
      '#title' => t('Name render templates'),
1083
      '#element_validate' => array('form_element_validate_json'),
1084
      '#default_value' =>  json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates)),
1085
      '#description' => '
1086
          <p>
1087
          (Clearing the text area will reset it to the default)
1088
          </p>
1089
          <p>
1090
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1091
          render path. The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1092
          The following render Path keys are curretly recognized:
1093
          <ul>
1094
            <li>list_of_taxa</li>
1095
            <li>acceptedFor</li>
1096
            <li>homonym</li>
1097
            <li>taxon_page_synonymy</li>
1098
            <li>typedesignations</li>
1099
            <li>taxon_page_title</li>
1100
            <li>polytomousKey</li>
1101
            <li>na: name + authorship</li>
1102
            <li>nar:name + authorship + reference</li>
1103
            <li>#DEFAULT</li>
1104
          </ul>
1105
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1106
          array element should be a comma separated list of render paths, without any whitespace!.
1107
          </p>
1108
          <p>
1109
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1110
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1111
          <p>
1112
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1113
          The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
1114
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1115
          links if the paramters $nameLink or $refenceLink are given to the name render function
1116
          (this is hard coded and cannot be configured here).',
1117
  );
1118

    
1119
  // @WA: D7 form api does not support reset buttons,
1120
  // so to mimic the D5 reset button we add one like this.
1121
  $form['actions']['reset'] = array(
1122
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1123
    '#weight' => 1000,
1124
  );
1125

    
1126
  $form['#submit'] = array('submit_json_as_php_array');
1127
  // #json_elements especially defined for submit_json_as_php_array()
1128
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1129
  return system_settings_form($form);
1130
}
1131

    
1132

    
1133
/**
1134
 * @todo Please document this function.
1135
 * @see http://drupal.org/node/1354
1136
 */
1137
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1138
  $form[$form_name] = array(
1139
    '#type' => 'fieldset',
1140
    '#title' => t($form_title),
1141
    '#collapsible' => TRUE,
1142
    '#collapsed' => $collapsed,
1143
    '#tree' => TRUE,
1144
    '#description' => t($form_description),
1145
  );
1146

    
1147
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1148
  $gallery_settings = variable_get($form_name, $default_values);
1149
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1150
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1151
    /*
1152
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1153
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1154
    '#type' => 'textfield',
1155
    '#title' => t('Search Page Size'),
1156
    '#default_value' => $test,
1157
    '#description' => t('Number of Names to display per page in search results.')
1158
    );
1159
    */
1160
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1161
      '#type' => 'checkbox',
1162
      '#title' => t('Show media thumbnails for accepted taxa'),
1163
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1164
    );
1165

    
1166
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1167
      '#type' => 'checkbox',
1168
      '#title' => t('Show media thumbnails for synonyms'),
1169
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1170
      '#description' => '',
1171
    );
1172
  }
1173

    
1174
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1175
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1176
    '#type' => 'checkbox',
1177
    '#title' => t('Show captions under thumbnails'),
1178
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1179
    '#description' => '',
1180
  );
1181

    
1182
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1183
    '#type' => 'textfield',
1184
    '#title' => t('Thumbnail size') . ':',
1185
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1186
    '#description' => t('Select the size of each individual thumbnail.'),
1187
  );
1188

    
1189
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1190
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1191
      '#type' => 'textfield',
1192
      '#title' => t('Number of columns') . ':',
1193
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1194
      '#description' => t('Group the thumbnails in columns: select how many
1195
        columns the gallery should display.'),
1196
    );
1197
  }
1198

    
1199
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1200
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1201
      '#type' => 'textfield',
1202
      '#title' => t('Maximum number of rows') . ':',
1203
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1204
      '#description' => t('You can group the thumbnails in rows, select in how
1205
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1206
        If you want an unlimited number of rows please set to 0.'),
1207
    );
1208
  }
1209

    
1210
  return $form;
1211
}
1212

    
1213
/**
1214
 * @todo document this function.
1215
 */
1216
function cdm_settings_layout_taxon() {
1217
  $collapsed = FALSE;
1218
  $form = array();
1219

    
1220
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1221

    
1222
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1223
      '#type' => 'checkbox',
1224
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1225
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1226
      '#description' => t('<p>If checked the link to search results is rendered at
1227
       the top of the taxon site. Clicking on the link the last search performed
1228
       is rendered again.</p>'),
1229
  );
1230

    
1231
  // --------- TABBED TAXON ------- //
1232
  $form['taxon_tabs'] = array(
1233
    '#type' => 'fieldset',
1234
    '#title' => t('Taxon tabs'),
1235
    '#collapsible' => TRUE,
1236
    '#collapsed' => FALSE,
1237
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1238
      be splitted in four diferent tabs; General, Synonymy, Images and
1239
      Specimens. If the taxon has no information for any of the tabs/sections
1240
      such tab will be not displayed.'),
1241
  );
1242

    
1243
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1244
    '#type' => 'checkbox',
1245
    '#title' => t('Tabbed taxon page'),
1246
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1247
    '#description' => t('<p>If selected split the taxon page into individual
1248
      tabs for description, images, synonymy and specimens. If not the taxon
1249
      data is rendered as a long single page without tabs.</p>'),
1250
  );
1251

    
1252
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1253
    '#type' => 'checkboxes',
1254
    '#title' => t('Tabs visibility options') . ':',
1255
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1256
    '#options' => get_taxon_options_list(),
1257
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1258
  );
1259

    
1260
  // WEIGHT
1261
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1262
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1263
      '#tree' => true
1264
  );
1265
  // Weights range from -delta to +delta, so delta should be at least half
1266
  // of the amount of tabs present.
1267
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1268
  foreach (get_taxon_tabs_list() as $label) {
1269
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1270
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1271
        '#title' => $label,
1272
        '#type'  => 'weight',
1273
        '#default_value' => $taxontabs_weights[$key],
1274
        '#delta' => $tab_weight_delta
1275
    );
1276
  }
1277

    
1278
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1279
    '#type' => 'select',
1280
    '#title' => t('Default tab to display') . ':',
1281
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1282
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1283
    '#description' => t('<p>Select the default tab to display when visiting a
1284
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1285
      <strong>Note:</strong> After performing a search and clicking in any
1286
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1287
      taxon and not the above selected tab.'),
1288
  );
1289

    
1290
  /* ======  TAXON_PROFILE ====== */
1291
  $form['taxon_profile'] = array(
1292
    '#type' => 'fieldset',
1293
    '#title' => t('Taxon profile (tab)'),
1294
    '#description' => t('<p>This section covers the settings related to the taxon
1295
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1296
    '#collapsible' => TRUE,
1297
    '#collapsed' => TRUE,
1298
  );
1299

    
1300
  // ---- PROFILE PICTURE ----//
1301

    
1302
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1303
    '#type' => 'fieldset',
1304
    '#tree' => TRUE,
1305
    '#title' => t('Taxon profile picture'),
1306
    '#collapsible' => TRUE,
1307
    '#collapsed' => FALSE,
1308
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1309
  );
1310

    
1311
  //FIXME migrate variables:
1312
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1313
  // FIXME
1314
  //  eanable file modul in profile and in update
1315

    
1316
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1317
  /*
1318
   * 'show' => 1,
1319
   * 'maxextend' => 184,
1320
   * 'media_uri_query' => ''
1321
   * 'custom_placeholder_image_on' => 1,
1322
   * 'custom_placeholder_image_fid' => ''
1323
   */
1324
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1325
    '#type' => 'checkbox',
1326
    '#title' => t('Enable profil picture'),
1327
    '#description' => t('Show the profil picture.'),
1328
    '#default_value' => $taxon_profile_image_settings['show'],
1329
  );
1330

    
1331
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1332
      '#type' => 'textfield',
1333
      '#tree' => TRUE,
1334
      '#title' => t('Profil picture maximum extend'),
1335
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1336
      '#field_suffix' => 'px',
1337
      '#maxlength' => 4,
1338
      '#size' => 4,
1339
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1340
  );
1341

    
1342
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1343
      '#type' => 'textfield',
1344
      '#tree' => TRUE,
1345
      '#title' => t('Additional URI query parameter'),
1346
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1347
      '#maxlength' => 1024,
1348
      '#size' => 60,
1349
      '#description' => t('Additional query parameters to be used when requesting for the '
1350
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1351
          . 'The query parameters will be appendend to the uri of the media representation part'
1352
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1353
  );
1354

    
1355
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1356
      '#type' => 'checkbox',
1357
      '#title' => t('Use a custom placeholder image'),
1358
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1359
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1360
  );
1361

    
1362
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1363
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1364
        '#type' => 'managed_file',
1365
        '#title' => t('Custom placeholder image file'),
1366
        '#progress_indicator' => 'bar',
1367
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1368
    //       '#name' => 'custom_placeholder_image',
1369
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1370
    );
1371

    
1372
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1373
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1374
      $url = file_create_url($profile_image_file->uri);
1375
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1376
                '#type' => 'item',
1377
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1378
      );
1379
    }
1380
  } else {
1381
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1382
        '#type' => 'hidden',
1383
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1384
    );
1385
  }
1386

    
1387

    
1388

    
1389
  $options = cdm_rankVocabulary_as_option();
1390
  array_unshift($options, '-- DISABLED --');
1391
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1392
    '#type' => 'select',
1393
    '#title' => t('Hide profile picture for higher ranks') . ':',
1394
    '#default_value' => variable_get('image_hide_rank', '0'),
1395
    '#options' => $options,
1396
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1397
  );
1398

    
1399
  // -- MEDIA THUMBNAILS -- //
1400
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1401
  $form_title = 'Taxon Profile Images';
1402
  $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>';
1403
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1404

    
1405
  // ---- FEATURE TREE ---- //
1406
  $form['taxon_profile']['feature_trees'] = array(
1407
    '#type' => 'fieldset',
1408
    '#title' => t('Features'),
1409
    '#collapsible' => TRUE,
1410
    '#collapsed' => FALSE,
1411
    '#description' => t("This section covers settings related to the taxon's
1412
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1413
      features such as description, distribution, common names, etc. that Drupal
1414
      will render at the taxon profile page."),
1415
  );
1416
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1417
  $saved_uuid = variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1418
  if(!isset($featureTrees['options'][$saved_uuid])) {
1419
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1420
  }
1421
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
1422
    '#type' => 'radios',
1423
    '#title' => t('Taxon profile sections') . ':',
1424
    '#default_value' => $saved_uuid,
1425
    '#options' =>  $featureTrees['options'],
1426
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1427
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1428
    '#description' => t('Select the Feature Tree to be displayed at the taxon
1429
      profile. Click "Show Details" to see the Feature Tree elements.'
1430
    ),
1431
  );
1432
  $featureTrees = cdm_get_featureTrees_as_options();
1433
  $saved_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1434
  if(!isset($featureTrees['options'][$saved_uuid])) {
1435
    $saved_uuid = NULL;
1436
  }
1437
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
1438
    '#type' => 'radios',
1439
    '#title' => t('Natural language representation of structured descriptions') . ':',
1440
    '#default_value' => $saved_uuid,
1441
    '#options' => $featureTrees['options'],
1442
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1443
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1444
    '#description' => t('Taxon descriptions can be stored in a highly structured
1445
      form. The feature tree selected here will be used to generate textual
1446
      representation in natural language.'
1447
    ),
1448
  );
1449

    
1450
  // ---- LAYOUT PER FEATURE ---- //
1451
  $feature_tree = get_profile_featureTree();
1452
  if (isset($feature_tree->root->childNodes)) {
1453

    
1454
    $form_feature_list_layout = array(
1455
      '#title' => t('Taxon profile layout'),
1456
      '#collapsible' => TRUE,
1457
      '#collapsed' => FALSE,
1458
      '#type' => 'fieldset',
1459
      '#description' => t('Will be available in a future release.'),
1460
    );
1461

    
1462
    $feature_list_layout_settings_disabled = TRUE;
1463
    foreach ($feature_tree->root->childNodes as $featureNode) {
1464

    
1465
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1466
        // Must not exceed 45 characters !!!
1467
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1468

    
1469
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1470
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1471

    
1472
        $form_feature_list_layout[$subform_id] = array(
1473
          '#tree' => TRUE,
1474
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1475
          '#collapsible' => FALSE,
1476
          '#collapsed' => FALSE,
1477
          '#type' => 'fieldset',
1478
          '#description' => t(''),
1479
        );
1480

    
1481
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1482
          '#type' => 'checkbox',
1483
          '#title' => t('Enable'),
1484
          '#default_value' => $settings['enabled'],
1485
          '#description' => t('Enable user defined layout for this feature'),
1486
        );
1487

    
1488
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1489
          '#type' => 'textfield',
1490
          '#title' => t('Enclosing tag'),
1491
          '#disabled' => !$settings['enabled'],
1492
          '#default_value' => $settings['enclosingTag'],
1493
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1494
        );
1495

    
1496
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1497
          '#type' => 'textfield',
1498
          '#title' => t('Entry enclosing tag'),
1499
          '#disabled' => !$settings['enabled'],
1500
          '#default_value' => $settings['entryEnclosingTag'],
1501
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1502
        );
1503

    
1504
        $form_feature_list_layout[$subform_id]['glue'] = array(
1505
          '#type' => 'textfield',
1506
          '#title' => t('Glue'),
1507
          '#disabled' => !$settings['enabled'],
1508
          '#default_value' => $settings['glue'],
1509
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1510
        );
1511

    
1512
      }
1513

    
1514
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1515
    }
1516
  }
1517

    
1518
  // ---- DISTRIBUTION LAYOUT ---- //
1519
  $form['taxon_profile']['distribution_layout'] = array(
1520
    '#title' => t('Distribution'),
1521
    '#collapsible' => TRUE,
1522
    '#collapsed' => FALSE,
1523
    '#type' => 'fieldset',
1524
    '#description' => t('Select if you want to sort or not the distribution text
1525
      located below the distribution map.'),
1526
  );
1527

    
1528
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1529
    '#type' => 'radios',
1530
    '#title' => t('Sort') . ':',
1531
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1532
    '#options' => array(
1533
      'NO_SORT' => t('Standard (No sort)'),
1534
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1535
    ),
1536
  );
1537

    
1538
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1539
    '#type' => 'checkbox',
1540
    '#title' => t('Show TextData elements on top of the map'),
1541
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1542
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1543
      elements on top of the map. Otherwise all <code>TextData</code>
1544
      distribution elements will be listed below the other area elements.
1545
      This option is useful if you need to have descriptive texts for each
1546
      distribution map.'),
1547
  );
1548

    
1549
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
1550
      '#type' => 'textarea',
1551
      '#title' => t('Custom status colors'),
1552
      '#element_validate' => array('form_element_validate_json'),
1553
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
1554
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
1555
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
1556
          reference list of the idInVocabulary values of absence and presence terms:
1557
<pre>
1558
Presence Term
1559
p	present
1560
pd	present: doubtfully present
1561
n	native
1562
nq	native: presence questionable
1563
nd	native: doubtfully native
1564
c	cultivated
1565
i	introduced
1566
iq	introduced: presence questionable
1567
id	introduced: doubtfully introduced (perhaps cultivated only)
1568
ip	introduced: uncertain degree of naturalisation
1569
ia	introduced: adventitious (casual)
1570
in	introduced: naturalized
1571
ic	introduced: cultivated
1572
e	endemic for the relevant area
1573
na	naturalised
1574
iv	invasive
1575

    
1576
AbsenceTerm
1577
a	absent
1578
f	reported in error
1579
nf	native: reported in error
1580
if	introduced: reported in error
1581
cf	cultivated: reported in error
1582
ne	native: formerly native
1583
ie	introduced: formerly introduced
1584

    
1585
</pre>'),
1586
  );
1587

    
1588

    
1589
  /* ====== SYNONYMY ====== */
1590
  $form['taxon_synonymy'] = array(
1591
    '#type' => 'fieldset',
1592
    '#title' => t('Taxon synonymy (tab)'),
1593
    '#collapsible' => TRUE,
1594
    '#collapsed' => TRUE,
1595
    '#description' => t('This section covers the settings related to the taxon
1596
      <strong>synonymy</strong> tab.'),
1597
  );
1598

    
1599
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1600
    '#type' => 'checkbox',
1601
    '#title' => t('Show accepted taxon on top of the synonymy'),
1602
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1603
    '#description' => t('If checked, the first homotypic taxon is a repetition
1604
      of the accepted taxon most likely with the full nomenclatural reference
1605
      (depending on the currently chosen theme).'),
1606
  );
1607

    
1608
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1609
    '#type' => 'checkbox',
1610
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1611
      coming from a synonym link.'),
1612
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1613
    '#description' => t('Check this if after doing a search and clicking on a
1614
      synonym you want to see the "accept of" text for the accepted synonym.'),
1615
  );
1616

    
1617
  /* === currently unused ===
1618
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1619
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1620
    '#type' => 'checkboxes',
1621
    '#title' => t('Display name relationships') . ':',
1622
    '#default_value' => variable_get('name_relationships_to_show', 0),
1623
    '#options' => $nameRelationshipTypeOptions,
1624
    '#description' => t('Select the name relationships you want to show for the
1625
      accepted taxa.'),
1626
  );
1627
 */
1628

    
1629
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1630
    '#type' => 'checkbox',
1631
    '#title' => t('Show taxon relations ships of accepted taxon'),
1632
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1633
    '#description' => t('If this option is enabled the synonymy will show the
1634
      below selected taxon relationships of accepted taxa.'),
1635
  );
1636

    
1637
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1638
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1639
    '#type' => 'checkboxes',
1640
    '#title' => t('Taxon relationship types') . ':',
1641
    '#description' => t('Only taxon relationships of the selected type will be
1642
      displayed'),
1643
    '#options' => $taxonRelationshipTypeOptions,
1644
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1645
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1646
  );
1647

    
1648
  // ====== SPECIMENS ====== //
1649
  $form['taxon_specimens'] = array(
1650
    '#type' => 'fieldset',
1651
    '#title' => t('Taxon specimens (tab)'),
1652
    '#collapsible' => TRUE,
1653
    '#collapsed' => TRUE,
1654
    '#description' => t('This section covers the settings related to the taxon
1655
      <strong>specimens</strong> tab.'),
1656
  );
1657

    
1658
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1659
  $saved_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1660
  if(!isset($featureTrees['options'][$saved_uuid])) {
1661
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1662
  }
1663
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1664
      '#type' => 'radios',
1665
      '#title' => t('Specimen description feature tree') . ':',
1666
      '#default_value' => $saved_uuid,
1667
      '#options' =>  $featureTrees['options'],
1668
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1669
      '#options_suffixes' => $featureTrees['treeRepresentations'],
1670
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1671
      ),
1672
  );
1673

    
1674
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1675
  $form_title = t('Specimen media');
1676
  $form_description = t('Specimens may have media which is displayed at the
1677
     Specimen tab/section as a gallery. It is possible to configure the
1678
     thumbnails gallery here, however for configuring how a single media should
1679
     be displayed please go to !url.</p>',
1680
     array(
1681
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1682
     ));
1683
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1684

    
1685
  // --- MEDIA GALLERY ---- //
1686
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1687
  $form_title = 'Media gallery (tab)';
1688
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1689
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1690
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1691
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1692
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1693
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1694
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1695

    
1696
  // Comment @WA: D7 form api does not support reset buttons,
1697
  // so to mimic the D5 reset button we add one like this.
1698
  $form['actions']['reset'] = array(
1699
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1700
    '#weight' => 1000,
1701
  );
1702
  return system_settings_form($form);
1703
}
1704

    
1705
/**
1706
 * @todo document this function.
1707
 */
1708
function cdm_settings_layout_search() {
1709

    
1710
  $form = array();
1711

    
1712
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
1713

    
1714
  $form['search_settings'] = array(
1715
    '#type' => 'fieldset',
1716
    '#title' => t('Taxa Search'),
1717
    '#collapsible' => FALSE,
1718
    '#collapsed' => FALSE,
1719
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1720
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1721
         where they can write the text to be searched. You can find Drupal block configuration
1722
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1723
  );
1724

    
1725
  $form['search_settings']['simple_search_ignore_classification'] = array(
1726
      '#type' => 'checkbox',
1727
      '#title' => t('Ignore the chosen classification in simple search'),
1728
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
1729
      '#description' => t('The simple search, which can be executed via the search block,
1730
          will by default search on all classifications. Remove the tick if you want your
1731
          portal to search on the classification selected in the classification browser
1732
          selector.'),
1733
  );
1734

    
1735
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1736
    '#type' => 'textfield',
1737
    '#title' => t('Results per page') . ':',
1738
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1739
    '#description' => t('Number of results to display per page.'),
1740
  );
1741

    
1742
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
1743
  $form['search_settings']['cdm_search_taxa_mode'] = array(
1744
      '#type' => 'checkboxes',
1745
      '#title' => 'Search mode',
1746
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
1747
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
1748
          for the advance search form and the behaviour of the simple search form which always will behave according to the
1749
          defaults set here.',
1750
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
1751
      '#default_value' => $search_mode_default
1752
      );
1753

    
1754
  // --- SEARCH TAXA GALLERY ---- //
1755
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1756
  $collapsed = FALSE;
1757
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1758
  $form_title = 'Taxa Search thumbnails';
1759
  $form_description = 'Search results may show thumbnails. ';
1760
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1761

    
1762
  // Comment @WA: D7 form api does not support reset buttons,
1763
  // so to mimic the D5 reset button we add one like this.
1764
  $form['actions']['reset'] = array(
1765
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1766
    '#weight' => 1000,
1767
  );
1768
  return system_settings_form($form);
1769
}
1770

    
1771
/**
1772
 * @todo document this function.
1773
 */
1774
function cdm_settings_layout_media() {
1775

    
1776
  $form = array();
1777

    
1778
  $form['media_settings'] = array(
1779
    '#type' => 'fieldset',
1780
    '#title' => t('Media settings'),
1781
    '#collapsible' => FALSE,
1782
    '#collapsed' => FALSE,
1783
    '#description' => 'This section covers layout settings for media pages.'
1784
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
1785
  );
1786

    
1787
  $form['media_settings']['image_gallery_viewer'] = array(
1788
    '#type' => 'select',
1789
    '#title' => t('Image viewer') . ':',
1790
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1791
    '#options' => array(
1792
      'default' => t('Standard image viewer'),
1793
      'fsi' => t('FSI viewer (requires FSI server!)'),
1794
    ),
1795
  );
1796

    
1797
  // --- MEDIA GALLERY ---- //
1798
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1799
  $form_title = 'Standard viewer';
1800
  $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>';
1801
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1802
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1803

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

    
1813
/**
1814
 * GEOSERVICE and Map settings.
1815
 */
1816
function cdm_settings_geo($form, &$form_state) {
1817

    
1818
  $current_geoserver_settings = get_edit_map_service_settings();
1819
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
1820
  // The default layer must always be enabled
1821
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
1822
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
1823

    
1824
  $form = array();
1825

    
1826
  $dummy_distribution_query = NULL;
1827
  if($map_distribution['map_type'] != 1){
1828
    // we need to apply a dummy query since the map serice requires for image maps
1829
    // at least as and ad to be defined
1830
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
1831
  }
1832
  $form['map_preview'] = array(
1833
      '#type' => 'fieldset',
1834
      '#tree' => FALSE,
1835
      '#title' => t('Map preview'),
1836
      '#collapsible' => FALSE,
1837
      '#description' => 'The preview of the map'
1838
       . ($dummy_distribution_query != null ?
1839
           ' may not be accurate in case if image maps, please check the map display in the taxon pages.':
1840
           '.<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.')
1841
  );
1842
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL,
1843
      array(
1844
          'move' => "this.cdmOpenlayersMap.printInfo",
1845
          '#execute' => "this.cdmOpenlayersMap.printInfo"
1846
      )
1847
  );
1848

    
1849

    
1850
  /*
1851
   * GEO SERVER
1852
   */
1853
  $form['edit_map_server'] = array(
1854
    '#type' => 'fieldset',
1855
    '#tree' => true,
1856
    '#title' => t('EDIT map service'),
1857
    '#collapsible' => TRUE,
1858
    '#collapsed' => TRUE,
1859
    '#description' => t('Configuration and selection of your geo server.
1860
      The Geo Server is responsible for generating the maps.'),
1861
  );
1862

    
1863
  $form['edit_map_server']['base_uri'] = array(
1864
    '#type' => 'select',
1865
    '#title' => t('EDIT map service') . ':',
1866
    '#default_value' => $current_geoserver_settings['base_uri'],
1867
    '#options' => unserialize(EDIT_MAPSERVER_URI),
1868
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
1869
  );
1870
  $form['edit_map_server']['version'] = array(
1871
      '#type' => 'select',
1872
      '#title' => t('Version') . ':',
1873
      '#default_value' => $current_geoserver_settings['version'],
1874
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
1875
      '#description' => t('The version of the EDIT map services'),
1876
  );
1877

    
1878
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1879
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1880
  $form['gmap_api_key'] = array(
1881
      '#type' => 'textfield',
1882
      '#title' => t('Google maps API key') . ':',
1883
      '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1884
      '#description' => t('If you want to use the Google Maps Layer, a key is
1885
      needed. If you need a key, visit
1886
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
1887
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
1888
      is the default key for the localhost (127.0.0.1).',
1889
      array('!localhostkey' => $localhostkey)),
1890
  );
1891

    
1892

    
1893
  /*
1894
   * MAP SETTINGS
1895
   */
1896

    
1897
  $form[CDM_MAP_DISTRIBUTION] = array(
1898
    '#type' => 'fieldset',
1899
    '#tree' => TRUE,
1900
    '#title' => t('Maps settings'),
1901
    '#collapsible' => TRUE,
1902
    '#collapsed' => TRUE,
1903
    '#description' => t('General configuration for all map types.'),
1904
  );
1905

    
1906
  /*
1907
   * settings for the distribution map are used also for specimens map!!!!
1908
   */
1909

    
1910
  $form[CDM_MAP_DISTRIBUTION]['width'] = array(
1911
    '#type' => 'textfield',
1912
    '#title' => 'Width',
1913
    '#default_value' => $map_distribution['width'],
1914
    '#maxlength' => 4,
1915
    '#size' => 4,
1916
    '#description' => 'Width of the map. To allow OSM baselayers to zoom out to the full extend of the world the map width must be
1917
      a multiple of 256px since the osm tiles from tile.openstreetmap.org have a size of 256px x 256px and frational zoom
1918
      levels are not possible in this case.',
1919
  );
1920
  $form[CDM_MAP_DISTRIBUTION]['height'] = array(
1921
      '#type' => 'textfield',
1922
      '#title' => 'Height',
1923
      '#default_value' => $map_distribution['height'],
1924
      '#maxlength' => 4,
1925
      '#size' => 4,
1926
      '#description' => 'Height of the map. Depending on the chosen base layer you may want to choose the height equal
1927
      to the width or half of the width. Any other aspect ratio is also possible if desired.',
1928
  );
1929

    
1930
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
1931
    '#type' => 'textfield',
1932
    '#title' => 'Bounding box',
1933
    '#default_value' => $map_distribution['bbox'],
1934
    '#description' => t('The bounding box (left, bottom, right, top) defines the area to be initially displayed in maps.
1935
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
1936
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
1937
      <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.
1938
      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
1939
      below the map from where you can copy the bbox string.</p>'),
1940
  );
1941

    
1942
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
1943
    '#type' => 'checkbox',
1944
    '#title' => 'Display area labels',
1945
    '#default_value' => $map_distribution['show_labels'],
1946
    '#description' => t('The map will show name labels of the areas'),
1947
  );
1948

    
1949
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
1950
    '#type' => 'textfield',
1951
    '#title' => 'Map caption',
1952
    '#default_value' => $map_distribution['caption'],
1953
    '#description' => t('The caption will be shown below the map.'),
1954
  );
1955

    
1956
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
1957
    '#type' => 'textfield',
1958
    '#title' => 'Distribution layer opacity',
1959
    '#default_value' => $map_distribution['distribution_opacity'],
1960
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1961
                           fully visible, while a value near to 0.0 will be not much visible.'),
1962
  );
1963

    
1964
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
1965
    '#type' => 'radios',
1966
    '#title' => 'Map types',
1967
    '#options' => array(
1968
      1 => "OpenLayers dynamic map viewer",
1969
      0 => "Plain image",
1970
    ),
1971
    '#default_value' => $map_distribution['map_type'],
1972
    '#description' => 'Two different map types are available :
1973
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
1974
      which allows zooming and panning. If enabled you can configure the default layer
1975
      (background of your maps) below.</li>
1976
      <li><em>Plain image</em>: The map will be static non interactive
1977
      image.</li></ul>',
1978
  );
1979
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
1980

    
1981

    
1982
  // --- Plain Image Settings --- //
1983
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
1984
    '#type' => 'fieldset',
1985
    '#title' => 'Plain image map settings',
1986
    '#tree' => TRUE,
1987
    '#collapsible' => TRUE,
1988
    '#collapsed' => $open_layers_is_enabled,
1989
    '#description' => 'The settings in this section are still expertimental
1990
      and can only be used with the EDIT map service version 1.1 or above.',
1991
  );
1992
  $edit_mapserver_version = get_edit_map_service_version_number();
1993
  if ($edit_mapserver_version < 1.1) {
1994
    $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>'
1995
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
1996
  }
1997

    
1998
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
1999
    '#type' => 'textfield',
2000
    '#title' => 'Background layer',
2001
    '#default_value' => $map_distribution['image_map']['base_layer'],
2002
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2003
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2004
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2005
    )),
2006
  );
2007

    
2008
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2009
    '#type' => 'textfield',
2010
    '#title' => 'Background color',
2011
    '#default_value' => $map_distribution['image_map']['bg_color'],
2012
  );
2013

    
2014
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2015
    '#type' => 'textfield',
2016
    '#title' => 'Background layer style',
2017
     // Only line color by now.
2018
    '#default_value' => $map_distribution['image_map']['layer_style'],
2019
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2020
  );
2021

    
2022
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2023
      '#type' => 'textfield',
2024
      '#title' => 'Projection',
2025
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2026
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2027
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2028
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2029
  );
2030

    
2031

    
2032
  // --- OpenLayers Settings --- //
2033
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2034
    '#type' => 'fieldset',
2035
    '#title' => 'OpenLayers settings',
2036
    '#tree' => TRUE,
2037
    '#collapsible' => TRUE,
2038
    '#collapsed' => !$open_layers_is_enabled,
2039
    '#description' => '',
2040
  );
2041

    
2042

    
2043
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2044
      '#type' => 'checkbox',
2045
      '#title' => 'Display outside max extent',
2046
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2047
      '#description' => t('Allows the map to display parts of the layers which are outside
2048
         the max extent if the aspect ratio of the map and of the baselayer
2049
         are not equal.'),
2050
  );
2051

    
2052

    
2053
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2054
      '#type' => 'checkbox',
2055
      '#title' => 'Show Layer Switcher',
2056
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2057
      '#description' => 'The Layer Switcher control displays a table of contents
2058
      for the map.  This allows the user interface to switch between
2059
      base layers and to show or hide overlays.  By default the switcher is
2060
      shown minimized on the right edge of the map, the user may expand it
2061
      by clicking on the handle.',
2062
  );
2063

    
2064
  if (!$open_layers_is_enabled) {
2065
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2066
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2067
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2068
  }
2069

    
2070
  $baselayer_options = array(
2071
    /*
2072
   NOTICE: must correspond to the layers defined in
2073
   js/openlayers_,ap.js#getLayersByName()
2074
   */
2075
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
2076
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
2077
    // all others EPSG:900913
2078
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
2079
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2080
    'mapnik' => 'OpenStreetMap',
2081
    'mapquest_open' => "MapQuest",
2082
    'mapquest_sat' => "MapQuest Sattelite",
2083
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2084
    'gmap' => 'Google Streets',
2085
    'gsat' => 'Google Satellite',
2086
    'ghyb' => 'Google Hybrid',
2087
//     'veroad' => 'Virtual Earth Roads',
2088
//     'veaer' => 'Virtual Earth Aerial',
2089
//     'vehyb' => 'Virtual Earth Hybrid',
2090
    // 'yahoo' => 'Yahoo Street',
2091
    // 'yahoosat' => 'Yahoo Satellite',
2092
    // 'yahoohyb' => 'Yahoo Hybrid',
2093
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2094
  );
2095

    
2096
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2097
    '#type' => 'checkboxes_preferred',
2098
    '#title' => 'Base Layers',
2099
    '#options' => $baselayer_options,
2100
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2101
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2102
  );
2103

    
2104
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2105
      '#type' => 'fieldset',
2106
      '#title' => 'Custom WMS base layer',
2107
      '#tree' => TRUE,
2108
      '#collapsible' => FALSE,
2109
      '#collapsed' => FALSE,
2110
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2111
  );
2112

    
2113
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2114
      '#type' => 'textfield',
2115
      '#title' => 'Layer name',
2116
      // Only line color by now.
2117
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2118
      '#description' => 'A arbitrary name for the layer.',
2119
  );
2120
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2121
      '#type' => 'textfield',
2122
      '#title' => 'WMS url',
2123
      // Only line color by now.
2124
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2125
      '#description' => 'Base url for the WMS (e.g.  http://wms.jpl.nasa.gov/wms.cgi)'
2126
  );
2127
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2128
      '#type' => 'textarea',
2129
      '#title' => 'WMS parameters',
2130
      '#element_validate' => array('form_element_validate_json'),
2131
      // Only line color by now.
2132
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2133
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2134
<pre> {
2135
  "Layers": "topp:em_tiny_jan2003",
2136
  "Format": "image/png",
2137
  "BGCOLOR": "0xe0faff"
2138
}
2139
</pre>'
2140
  );
2141
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2142
      '#type' => 'textfield',
2143
      '#title' => 'Projection',
2144
      // Only line color by now.
2145
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2146
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2147
  );
2148
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2149
      '#type' => 'textfield',
2150
      '#maxlength' => 256,
2151
      '#title' => 'proj4js definition',
2152
      // Only line color by now.
2153
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2154
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2155
            The definitions for
2156
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2157
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2158
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2159
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2160
            choose to display the proj4js definition string.
2161
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2162
            <pre>
2163
+a         Semimajor radius of the ellipsoid axis
2164
+alpha     ? Used with Oblique Mercator and possibly a few others
2165
+axis      Axis orientation (new in 4.8.0)
2166
+b         Semiminor radius of the ellipsoid axis
2167
+datum     Datum name (see `proj -ld`)
2168
+ellps     Ellipsoid name (see `proj -le`)
2169
+k         Scaling factor (old name)
2170
+k_0       Scaling factor (new name)
2171
+lat_0     Latitude of origin
2172
+lat_1     Latitude of first standard parallel
2173
+lat_2     Latitude of second standard parallel
2174
+lat_ts    Latitude of true scale
2175
+lon_0     Central meridian
2176
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
2177
+lon_wrap  Center longitude to use for wrapping (see below)
2178
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
2179
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
2180
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
2181
+pm        Alternate prime meridian (typically a city name, see below)
2182
+proj      Projection name (see `proj -l`)
2183
+south     Denotes southern hemisphere UTM zone
2184
+to_meter  Multiplier to convert map units to 1.0m
2185
+towgs84   3 or 7 term datum transform parameters (see below)
2186
+units     meters, US survey feet, etc.
2187
+vto_meter vertical conversion to meters.
2188
+vunits    vertical units.
2189
+x_0       False easting
2190
+y_0       False northing
2191
+zone      UTM zone
2192
            </pre>
2193
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
2194
  );
2195
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
2196
      '#type' => 'textfield',
2197
      '#title' => 'Maximum extent',
2198
      // Only line color by now.
2199
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
2200
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
2201
  );
2202
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
2203
      '#type' => 'textfield',
2204
      '#title' => 'Units',
2205
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
2206
      '#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.'
2207
  );
2208

    
2209
  /*
2210
   * Map Legend
2211
   */
2212
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2213
    '#type' => 'fieldset',
2214
    '#title' => 'Map legend',
2215
    '#tree' => TRUE,
2216
    '#collapsible' => TRUE,
2217
    '#collapsed' => TRUE,
2218
    '#description' => 'Configure the maps legend.',
2219
  );
2220

    
2221
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2222
    '#type' => 'checkbox',
2223
    '#title' => 'Display a map legend',
2224
    '#default_value' => $map_distribution['legend']['show'],
2225
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2226
  );
2227

    
2228
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2229
    '#type' => 'textfield',
2230
    '#title' => 'Legend opacity',
2231
    '#default_value' => $map_distribution['legend']['opacity'],
2232
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2233
                         to 0.0 will be not much visible.',
2234
  );
2235

    
2236
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2237
    '#type' => 'textfield',
2238
    '#title' => 'Font size',
2239
    '#default_value' => $map_distribution['legend']['font_size'],
2240
    '#description' => 'Font size in pixels.',
2241
  );
2242

    
2243
  $fontStyles = array(
2244
    0 => "plane",
2245
    1 => "italic",
2246
  );
2247
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2248
    '#type' => 'select',
2249
    '#title' => 'Available font styles',
2250
    '#default_value' => $map_distribution['legend']['font_style'],
2251
    '#options' => $fontStyles,
2252
    '#description' => 'Select a font style for the map legend.',
2253
  );
2254

    
2255
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2256
    '#type' => 'textfield',
2257
    '#title' => 'Icon width',
2258
    '#default_value' => $map_distribution['legend']['icon_width'],
2259
    '#description' => 'Legend icon width in pixels.',
2260
  );
2261
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2262
    '#type' => 'textfield',
2263
    '#title' => 'Icon height',
2264
    '#default_value' => $map_distribution['legend']['icon_height'],
2265
    '#description' => 'Legend icon height in pixels.',
2266
  );
2267

    
2268
  // @WA: D7 form api does not support reset buttons,
2269
  // so to mimic the D5 reset button we add one like this.
2270
  $form['actions']['reset'] = array(
2271
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2272
    '#weight' => 1000,
2273
  );
2274

    
2275
  return system_settings_form($form);
2276
}
2277

    
2278
/**
2279
 * @todo document this function.
2280
 */
2281
function cdm_settings_cache() {
2282

    
2283
  $form = array();
2284

    
2285
  $form['cache_settings'] = array(
2286
    '#type' => 'fieldset',
2287
    '#title' => t('Cache Settings'),
2288
    '#collapsible' => FALSE,
2289
    '#collapsed' => FALSE,
2290
    '#description' => t('<p>When caching is enabled all single taxon sites are
2291
      stored in an internal drupal cache doing the portal response of taxa pages
2292
      faster. This is possible because the sites are loaded from the cache and
2293
      are not created from scratch.</p>'),
2294
  );
2295

    
2296
  $form['cache_settings']['cdm_webservice_cache'] = array(
2297
    '#type' => 'checkbox',
2298
    '#title' => t('<strong>Enable caching</strong>'),
2299
    '#options' => cdm_help_general_cache(),
2300
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2301
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2302
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2303
       application the changes will be not visible till the cache is erased.
2304
       Therefore developers should deactived this feature when they are working
2305
       on the CDM Dataportal Module.</p>'),
2306
  );
2307

    
2308
  $form['cache_settings']['cdm_run_cache'] = array(
2309
    '#markup' => cdm_view_cache_site(),
2310
  );
2311

    
2312
  // @WA: D7 form api does not support reset buttons,
2313
  // so to mimic the D5 reset button we add one like this.
2314
  $form['actions']['reset'] = array(
2315
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2316
    '#weight' => 1000,
2317
  );
2318
  return system_settings_form($form);
2319
}
2320

    
2321
/**
2322
 * Walk and cache all taxon pages.
2323
 */
2324
function cdm_view_cache_site() {
2325

    
2326
  $out = '';
2327

    
2328
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2329

    
2330
  $request_params = array();
2331
  $request_params['class'] = "Taxon";
2332

    
2333
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2334
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2335
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2336

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

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

    
2346
  // Comment @WA: A form within a form is not valid html and not needed here.
2347
  // Also, it would be recommended just to include this part of the form in the
2348
  // rest of the form array in cdm_settings_cache().
2349
  // $out .= '<form id="cache_site">';
2350
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2351
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2352
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2353
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2354
  // $out .= '</form>';
2355
  $out .= '</div>';
2356
  /*
2357
  foreach($taxonPager->records as $taxon){
2358
    cdm_dataportal_taxon_view($uuid);
2359
  }
2360
  */
2361
  return $out;
2362
}
2363

    
2364

    
2365
function cdm_settings_layout_taxon_submit($form, &$form_state){
2366
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2367
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2368
    if(is_object($file)){
2369
      $file->status = FILE_STATUS_PERMANENT;
2370
      file_save($file);
2371
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2372
    }
2373
  }
2374
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2375
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2376
    // we first need to set the variable to persist the changes setting
2377
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
2378
    menu_rebuild();
2379
  }
2380
}
2381

    
2382
function cdm_settings_layout_search_submit($form, &$form_state){
2383
  // the visibility of media thumbnails also affects the ui of the search results
2384
  // so reset the according session variable
2385
  //    1. in order to give the user immediate
2386
  //       feedback on potential setting changes
2387
  //    2. let refresh the default if it has changed
2388
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2389
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
2390
  }
2391
}
2392

    
2393
/**
2394
 * Form validation handler for cdm_settings_general
2395
 *
2396
 * @param $form
2397
 * @param $form_state
2398
 */
2399
function cdm_settings_general_validate($form, &$form_state) {
2400

    
2401
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2402
    $form_state['values']['cdm_webservice_url'] .= '/';
2403
  }
2404

    
2405
}
2406

    
2407
/**
2408
 * Form submit handler for settings general.
2409
 *
2410
 * tasks performed:
2411
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2412
 *
2413
 * @param $form
2414
 * @param $form_state
2415
 */
2416
function cdm_settings_general_submit($form, &$form_state){
2417
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2418
  unset($_SESSION['cdm']['taxonomictree_uuid']);
2419
}
2420

    
2421
/**
2422
 * Form validation handler for cdm_settings_cache
2423
 */
2424
function cdm_settings_cache_validate($form, &$form_state) {
2425
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2426
    cache_clear_all(NULL, 'cache_cdm_ws');
2427
    // Better clear secref_cache since I can not be sure if the cache has not
2428
    // be used during this response.
2429
    cdm_api_secref_cache_clear();
2430
  }
2431

    
2432
}
2433

    
2434
/**
2435
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
2436
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
2437
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
2438
 *  - version: the version, e.g.: v1.1
2439
 *
2440
 * @return array
2441
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
2442
 */
2443
function get_edit_map_service_settings() {
2444

    
2445
  $settings = variable_get('edit_map_server', array(
2446
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
2447
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
2448
      )
2449
  );
2450

    
2451
  return $settings;
2452
}
2453

    
2454
/**
2455
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2456
 *
2457
 * @return string
2458
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2459
 */
2460
function get_edit_map_service_full_uri() {
2461
  $settings = get_edit_map_service_settings();
2462
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
2463
}
2464

    
2465

    
2466
/**
2467
 * Returns the version number of the currently selected edit mapserver as a float
2468
 *
2469
 * @return float
2470
 *   The version number of the currently selected edit mapserver as a float.
2471
 *   Returns 0 on error.
2472
 */
2473
function get_edit_map_service_version_number() {
2474

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

    
2477
  $settings = get_edit_map_service_settings();
2478
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
2479
  if (isset($matches[1])) {
2480
    // Convert string to float.
2481
    $version = 1 + $matches[1][0] - 1;
2482
    return $version;
2483
  }
2484
  else {
2485
    // Report error.
2486
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
2487
        array(
2488
          '!version' => $settings['version'],
2489
          'warning')
2490
        )
2491
      );
2492
    return 0;
2493
  }
2494
}
2495

    
2496
/**
2497
 * Returns the array of selected items in a options array
2498
 *
2499
 * @param array $options
2500
 *   An options array as generated by a form element like checkoxes, select ...,
2501
 */
2502
function get_selection($options) {
2503
  $selection = array();
2504
  foreach ($options as $key=>$val) {
2505
    if (!empty($val)) {
2506
      $selection[] = $val;
2507
    }
2508
  }
2509
  return $selection;
2510
}
2511

    
2512

    
2513
/**
2514
 * Implements hook_element_info().
2515
 *
2516
 * Allows modules to declare their own Form API element types and specify their default values.
2517
 *
2518
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
2519
 */
2520
function cdm_dataportal_element_info() {
2521
  $type['checkboxes_preferred'] = array(
2522
    '#input' => TRUE,
2523
    '#process' => array('checkboxes_preferred_expand'),
2524
    '#after_build' => array('checkboxes_preferred_after_build'),
2525
    '#theme' => array('checkboxes_preferred'),
2526
    // '#theme_wrapper' => array('form_element'),
2527
  );
2528
  return $type;
2529
}
2530

    
2531
/**
2532
 * #process callback function for the custom form element type 'checkbox_preferred'
2533
 *
2534
 *
2535
 */
2536
function checkboxes_preferred_expand($element, &$form_state, $form) {
2537

    
2538
  // First of all create checkboxes for each of the elements
2539
  $element = form_process_checkboxes($element);
2540

    
2541
  // compose the element name
2542
  $parents = array();
2543
  array_deep_copy($element['#parents'], $parents);
2544
  $parents[count($parents) -1 ] .= '_preferred';
2545
  $element_name = $parents[0];
2546
  for ($i=1; $i < count($parents); $i++){
2547
    $element_name .= '[' . $parents[$i] . ']';
2548
  }
2549

    
2550
  $children = element_children($element);
2551

    
2552
  $element['table_start'] = array(
2553
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
2554
    '#weight' => -1,
2555
  );
2556

    
2557
  // prepare first part each of the table rows which contains the row label
2558
  $weight = 0;
2559
  foreach ($children as $key) {
2560
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
2561
    $element[$key]['#weight'] = $weight;
2562
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
2563
    $element[$key]['#suffix'] = '</td>';
2564
    unset($element[$key]['#title']);
2565
    $weight += 2;
2566
  }
2567
  $weight = 0;
2568

    
2569
  // add a radio button to each of the checkboxes, the
2570
  // check boxes have already been created at the beginning
2571
  // of this function
2572
  if (count($element['#options']) > 0) {
2573
    foreach ($element['#options'] as $key => $choice) {
2574
      if (!isset($element[$key . '_preferred'])) {
2575
        $element[$key . '_preferred'] = array(
2576
          '#type' => 'radio',
2577
          '#name' => $element_name,
2578
          '#return_value' => check_plain($key),
2579
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
2580
          '#attributes' => $element['#attributes'],
2581
          '#parents' => $element['#parents'],
2582
          // '#spawned' => TRUE,
2583
          '#weight' => $weight + 1,
2584
          '#prefix' => '<td>',        // add a prefix to start a new table cell
2585
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
2586
        );
2587
      }
2588
      $weight += 2;
2589
    }
2590
  }
2591

    
2592
  // end the table
2593
  $element['table_end'] = array(
2594
    '#markup' => '</table>',
2595
    '#weight' => $weight++,
2596
  );
2597

    
2598
  return $element;
2599
}
2600

    
2601
/**
2602
 * Theme function for the custom form field 'checkboxes_preferred'.
2603
 */
2604
function theme_checkboxes_preferred($variables) {
2605
  $element = $variables['element'];
2606
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
2607
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
2608
  $out .= drupal_render_children($element);
2609
  $out .= '<div class="description">' . $element['#description'] . '</div>';
2610
  $out .= '</div>';
2611
  return $out;
2612
}
2613

    
2614
/**
2615
 * Callback for checkboxes preferred for widget which will
2616
 * be called after the form or element is built. The call
2617
 * back is configured in the form element by setting it as
2618
 * #after_build parameter.
2619
 *
2620
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
2621
 *
2622
 * @param $element
2623
 *   Nested array of form elements that comprise the form.
2624
 * @param $form_state
2625
 *   A keyed array containing the current state of the form.
2626
 *   This includes the current persistent storage data for the form.
2627
 *   Additional information, like the sanitized $_POST data,
2628
 *   is also accumulated here in $form_state['input']
2629
 *
2630
 * @return the modified form array
2631
 */
2632
function checkboxes_preferred_after_build($element, &$form_state) {
2633

    
2634
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
2635

    
2636
  if ($_POST && count($_POST) > 0) {
2637
    // TODO use  $form_state['input'] instead of POST !!!
2638
    // First pass of form processing.
2639
    $parents = array();
2640
    array_deep_copy($element['#parents'], $parents);
2641
    $parents[count($parents) - 1] .= '_preferred';
2642
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
2643
    $element['#value']['PREFERRED'] = $preferred_layer;
2644
//     $form_state[$parent_id] = $element['#value'];
2645
//     $form_state['values']['baselayers'] = $element['#value'];
2646
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
2647
    $form_state_element_values = $element['#value'];
2648
  }
2649
  else {
2650
    // Second pass of form processing.
2651
    $preferred_layer = $element['#value']['PREFERRED'];
2652
  }
2653

    
2654
  // Also set the chosen value (not sure if this is good Drupal style ....).
2655
  foreach ($children = element_children($element) as $key) {
2656
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
2657
      $element[$key]['#value'] = $preferred_layer;
2658
    }
2659
  }
2660
  // The default layer must always be enabled.
2661
  $element[$preferred_layer]['#value'] = $preferred_layer;
2662

    
2663
  return $element;
2664
}
2665

    
2666
function radios_prepare_options_suffix(&$elements){
2667

    
2668
  $childrenKeys = element_children($elements);
2669
  foreach($childrenKeys as $key){
2670
    if(!is_array($elements[$key]['#theme_wrappers'])){
2671
      $elements[$key]['#theme_wrappers'] = array();
2672
    }
2673
    if(isset($elements['#options_suffixes'][$key])){
2674
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
2675
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
2676
    }
2677
  }
2678
  return $elements;
2679

    
2680
}
2681

    
2682
/**
2683
 * TODO
2684
 * @param unknown $variables
2685
 */
2686
function theme_radio_options_suffix($variables) {
2687
  $element = $variables['element'];
2688
  if(isset($element['#options_suffix'])) {
2689
    $element['#children'] .= $element['#options_suffix'];
2690
  }
2691
  return $element['#children'];
2692
}
2693

    
2694

    
2695
/**
2696
 * Element validate callback for text field and arrays containing json.
2697
 *
2698
 * @param $element
2699
 *   The form element to validate
2700
 * @param $form_state
2701
 *   A keyed array containing the current state of the form.
2702
 * @param $form
2703
 *   Nested array of form elements that comprise the form.
2704
 */
2705
function form_element_validate_json($element, &$form_state, $form) {
2706
   if (!empty($element['#value'])) {
2707
     json_decode($element['#value']);
2708
     if(json_last_error() != JSON_ERROR_NONE){
2709
       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/'));
2710
     }
2711
   }
2712
}
2713

    
2714
/**
2715
 * Form submission handler for textareas and textfields containing JSON.
2716
 *
2717
 * The contained JSON will be converted into an php array
2718
 * or object and will be stored in the variables as such.
2719
 *
2720
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2721
 *
2722
 * @param $form
2723
 *   Nested array of form elements that comprise the form.
2724
 * @param $form_state
2725
 *   A keyed array containing the current state of the form.
2726
 *
2727
 */
2728
function submit_json_as_php_array($form, &$form_state) {
2729
  if (is_array($form['#json_elements'])) {
2730
    foreach ($form['#json_elements'] as $element){
2731
      if (trim($form_state['values'][$element])) {
2732
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
2733
      } else {
2734
        $form_state['values'][$element] = NULL;
2735
      }
2736
    }
2737
  }
2738
}
(14-14/14)