Project

General

Profile

Download (61 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
define('DEFAULT_TAXONTREE_RANKLIMIT', '1b11c34c-48a8-4efa-98d5-84f7f66ef43a');//TODO Genus UUID
4
define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
5

    
6
define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
7
define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
8
define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
9
define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
10
define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
11
define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 4);
12

    
13
/* annotationTypeKeys */
14
$annotationTypeKeys = array_keys( cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE) );
15
if(in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
16
  $annotationTypeKeys = array_flip($annotationTypeKeys);
17

    
18
  // technical annotation are off by default
19
  unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
20
  $annotationTypeKeys = array_flip($annotationTypeKeys);
21
}
22
define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
23

    
24
/* taxonRelationshipTypes */
25
define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
26

    
27

    
28
/* gallery variables */
29
$gallery_settings = array(
30
    "cdm_dataportal_show_taxon_thumbnails" => 1,
31
    "cdm_dataportal_show_synonym_thumbnails" => 0,
32
    "cdm_dataportal_show_thumbnail_captions" => 1,
33
    "cdm_dataportal_media_maxextend" => 120,
34
    "cdm_dataportal_media_cols" => 3,
35
    "cdm_dataportal_media_maxRows" => 1);
36

    
37

    
38
$taxon_tab_options = array(
39
  0 => 'General',
40
  1 => 'Synonymy',
41
  2 => 'Images',
42
  3 => 'Specimens',
43
  CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX => 'Last visited tab',
44
);
45

    
46
define('EDIT_MAPSERVER_V1_URI', 'http://edit.br.fgov.be/edit_wp5/v1');
47
define('EDIT_MAPSERVER_V11_URI', 'http://edit.br.fgov.be/edit_wp5/v1.1');
48
define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
49

    
50
// --- Taxon profile settings --- /
51
define (LAYOUT_SETTING_PREFIX, 'layout_');
52
define (FEATURE_TREE_LAYOUT_DEFAULTS, serialize(
53
    array(
54
    'enabled'=> false,
55
    'enclosingTag' => 'ul',
56
    'entryEnclosingTag' => 'li',
57
    'glue' => ' '
58
    )
59
  ));
60

    
61

    
62
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
63
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
64
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
65
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
66
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
67
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
68
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
69
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
70
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
71
//define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
72
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
73
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
74
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
75
define('CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
76
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
77

    
78
function getGallerySettings($gallery_config_form_name){
79
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
80
  return variable_get($gallery_config_form_name, $default_values);
81
}
82

    
83
function get_default_taxon_tab($index = false) {
84

    
85
  global $user;
86
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
87
  $user_tab_active = 'cdm_dataportal_' .$user->uid . '_default_tab_active';
88
  $user_tab = 'cdm_dataportal_' .$user->uid . '_default_tab';
89
  //get the user value
90
  $user_tab_on = variable_get($user_tab_active, false);
91
  if($user_tab_on){
92
    $user_value = variable_get($user_tab, 0);
93
    $index_value = $user_value;
94
  //get the system value
95
  }else{
96
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
97
    $index_value = $system_value;
98
  }
99
  if (!index){
100
     return ($values[$index_value]);
101
  }else{
102
     return $index_value;
103
  }
104

    
105

    
106
  switch ($value){
107
    case 0:
108
      $res = 'General';
109
      break;
110
    case 1:
111
      $res = 'Synonymy';
112
      break;
113
    case 2:
114
      $res = 'Images';
115
      break;
116
    case 3:
117
      $res = 'Specimens';
118
      break;
119
    case 4:
120
      $res = 'last_visited_tab';
121
      break;
122
    default:
123
      $res = 'General';
124
  }
125
  return $res;
126
}
127

    
128
function cdm_dataportal_menu_admin($may_cache, &$items){
129

    
130
  if (!$may_cache) {
131

    
132
    $items[] = array(
133
      'path' => 'admin/settings/cdm_dataportal',
134
      'title' => t('CDM Dataportal'),
135
      'description' => t('Setting for the CDM DataPortal'),
136
      'access' => user_access('administer cdm_dataportal'),
137
      'callback' => 'drupal_get_form',
138
      'callback arguments' => array('cdm_settings_general'),
139
      'type' => MENU_NORMAL_ITEM,
140
    );
141

    
142
    $items[] = array(
143
      'path' => 'admin/settings/cdm_dataportal/general',
144
      'title' => t('General'),
145
      'description' => t('Setting for the CDM DataPortal'),
146
      'access' => user_access('administer cdm_dataportal'),
147
      'callback' => 'drupal_get_form',
148
      'callback arguments' => array('cdm_settings_general'),
149
      'weight' => 0,
150
      'type' => MENU_LOCAL_TASK,
151
    );
152

    
153
    $items[] = array(
154
      'path' => 'admin/settings/cdm_dataportal/cachesite',
155
      'title' => t('Cache'),
156
      'description' => t('Cache'),
157
      'access' => user_access('administer cdm_dataportal'),
158
      'callback' => 'drupal_get_form',
159
      'callback arguments' => array('cdm_settings_cache'),
160
      'weight' => 10,
161
      'type' => MENU_LOCAL_TASK,
162
    );
163

    
164
    $items[] = array(
165
      'path' => 'admin/settings/cdm_dataportal/geo',
166
      'title' => t('Geo & Map'),
167
      'description' => t('Geo & Map'),
168
      'access' => user_access('administer cdm_dataportal'),
169
      'callback' => 'drupal_get_form',
170
      'callback arguments' => array('cdm_settings_geo'),
171
      'weight' => 1,
172
      'type' => MENU_LOCAL_TASK,
173
    );
174

    
175
    $items[] = array(
176
      'path' => 'admin/settings/cdm_dataportal/layout',
177
      'title' => t('Layout'),
178
      'description' => t('Configure and adjust the layout of your DataPortal '),
179
      'access' => user_access('administer cdm_dataportal'),
180
      'callback' => 'drupal_get_form',
181
      'callback arguments' => array('cdm_settings_layout'),
182
      'weight' => 2,
183
      'type' => MENU_LOCAL_TASK,
184
    );
185

    
186
    $items[] = array(
187
      'path' => 'admin/settings/cdm_dataportal/layout/taxon',
188
      'title' => t('Taxon'),
189
      'description' => t('Configure and adjust the layout of your DataPortal '),
190
      'access' => user_access('administer cdm_dataportal'),
191
      'callback' => 'drupal_get_form',
192
      'callback arguments' => array('cdm_settings_layout_taxon'),
193
      'weight' => 1,
194
      'type' => MENU_LOCAL_TASK,
195
    );
196
/*
197
    $items[] = array(
198
      'path' => 'admin/settings/cdm_dataportal/layout/synonymy',
199
      'title' => t('Synonymy'),
200
      'description' => t('Configure and adjust the layout of your DataPortal '),
201
      'access' => user_access('administer cdm_dataportal'),
202
      'callback' => 'drupal_get_form',
203
      'callback arguments' => array('cdm_settings_layout_synonymy'),
204
      'weight' => 1,
205
      'type' => MENU_LOCAL_TASK,
206
    );
207

    
208
    $items[] = array(
209
      'path' => 'admin/settings/cdm_dataportal/layout/specimens',
210
      'title' => t('Specimens'),
211
      'description' => t('Configure and adjust the layout of your DataPortal '),
212
      'access' => user_access('administer cdm_dataportal'),
213
      'callback' => 'drupal_get_form',
214
      'callback arguments' => array('cdm_settings_layout_specimens'),
215
      'weight' => 1,
216
      'type' => MENU_LOCAL_TASK,
217
    );
218
*/
219
    $items[] = array(
220
      'path' => 'admin/settings/cdm_dataportal/layout/search',
221
      'title' => t('Search'),
222
      'description' => t('Configure and adjust the layout of your DataPortal '),
223
      'access' => user_access('administer cdm_dataportal'),
224
      'callback' => 'drupal_get_form',
225
      'callback arguments' => array('cdm_settings_layout_search'),
226
      'weight' => 2,
227
      'type' => MENU_LOCAL_TASK,
228
    );
229

    
230
    $items[] = array(
231
      'path' => 'admin/settings/cdm_dataportal/layout/media',
232
      'title' => t('Media'),
233
      'description' => t('Configure and adjust the layout of your DataPortal '),
234
      'access' => user_access('administer cdm_dataportal'),
235
      'callback' => 'drupal_get_form',
236
      'callback arguments' => array('cdm_settings_layout_media'),
237
      'weight' => 3,
238
      'type' => MENU_LOCAL_TASK,
239
    );
240
/*   Path to banners configuration (DEFAULT THEME)
241
    $items[] = array(
242
      'path' => 'admin/settings/cdm_dataportal/layout/theme',
243
      'title' => t('Theme'),
244
      'description' => t('Configure the drupal theme of your DataPortal '),
245
      'access' => user_access('administer cdm_dataportal'),
246
      'callback' => 'drupal_get_form',
247
      'callback arguments' => array('cdm_dataportal_theming_form'),
248
      'weight' => 4,
249
      'type' => MENU_LOCAL_TASK,
250
        );
251
*/
252
  }
253

    
254

    
255
}
256

    
257
function cdm_help_general_cache(){
258
  $form = array();
259
  $form['cache_help'] = array(
260
    '#type' => 'fieldset',
261
  '#title' => t('Help'),
262
  '#collapsible' => TRUE,
263
  '#collapsed' => TRUE,
264
  );
265
  $form['cache_help']['test'] = array('#value' => t('probando'));
266
  return drupal_render($form);
267
  $res = array();
268
  $res['default'] = drupal_render($help);
269
  return $res;
270
}
271

    
272
/**
273
 * Configures the settings form for the CDM-API module.
274
 *
275
 * @return Array Drupal settings form
276
 */
277
function cdm_settings_general(){
278

    
279
  $form['cdm_webservice'] = array(
280
      '#type' => 'fieldset',
281
      '#title' => t('CDM Server'),
282
      '#collapsible' => FALSE,
283
      '#collapsed' => FALSE,
284
    '#description' => t('<em>CDM Server</em> makes possible the dialogue with
285
                         <em>CDM Data Portal</em> thanks to his web services.'),
286
  );
287

    
288
  $form['cdm_webservice']['cdm_webservice_url'] =  array(
289
    '#type' => 'textfield',
290
    '#title'         => t('CDM web service URL'),
291
    '#description'   => t('This is the ip address of the location of the CDM Web Server which contains
292
                           your collection database. The address must follow the format <em>"http://X:Y/Z"</em>
293
                           where "<em>X</em>" is the ip address of the machine where the server is running, "<em>Y</em>" is
294
                           the port number where the server is listening and "<em>Z</em>" the name of the database
295
                           where your collection is, e.g. <em>"http://160.45.63.201:8080/palmae"</em>'),
296
    '#default_value' => variable_get('cdm_webservice_url', NULL),
297
  );
298

    
299
  /** MOVED TO DATAPORTAL
300
  $form['cdm_webservice']['taxontree_ranklimit'] =  array(
301
    '#type'          => 'select',
302
    '#title'         => t('Rank of highest displayed taxon'),
303
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT), //before DEFAULT_TAXONTREE_RANKLIMIT_UUID
304
    '#options'       => cdm_rankVocabulary_as_option(),
305
    '#description'   => t('The rank of the highest displayed taxon in the <em>taxontree</em>. When you explore
306
                           your collection, you can navigate it through a tree structure (<em>taxontree</em>). You can
307
                           select here which rank should be at the top level of the tree structure.'),
308
  );
309
  */
310
/*
311
  $form['cdm_webservice']['cdm_webservice_cache'] =  array(
312
    '#type' => 'checkbox',
313
    '#title'         => t('<b>Enable caching</b>'),
314
  '#options'     => cdm_help_general_cache(),
315
    '#default_value' => variable_get('cdm_webservice_cache', 1),
316
    '#description'   => t('When caching is enabled all single taxon sites are stored in an internal drupal cache doing
317
                           the portal response of taxa sites faster. This is possible because the sites are loaded from
318
                           the cache and are not created from scratch.
319
                           You can manage and find more information about the cache at the <a href="./?q=admin/settings/cdm_dataportal/cachesite">cache configuration site</a>.<br>' .
320
                         '<b>Note:</b> If taxa are modified by the editor or any other application the changes will be not
321
                         visible till the cache is erased. Therefore developers should deactived this feature when they
322
                         are working on the CDM Dataportal Module')
323
    );
324
*/
325
    $form['cdm_webservice']['cdm_webservice_debug'] =  array(
326
    '#type' => 'checkbox',
327
    '#title'         => t('<b>Debug CDM Web Service</b>'),
328
    '#default_value' => variable_get('cdm_webservice_debug', 1),
329
    '#description'   => t('When enabled is possible to see which web services from CDM Server have been called and its
330
                           results. A black box will appear at the top of the web site with the information.<br>' .
331
                          '<b>Note:</b> this is meanly a feature for developers.')
332
    );
333

    
334
    $form['cdm_webservice']['proxy'] = array(
335
      '#type' => 'fieldset',
336
      '#title' => t('Proxy'),
337
      '#collapsible' => TRUE,
338
      '#collapsed' => TRUE
339
    );
340

    
341
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] =  array(
342
    '#type' => 'textfield',
343
    '#title'         => t('Proxy URL'),
344
    '#description'   => t('If this proxy url is set the cdm api tries
345
    to connect the web service over the given proxy server.
346
    Otherwise proxy usage is deactivated.'),
347
    '#default_value' => variable_get('cdm_webservice_proxy_url', false),
348
    );
349

    
350
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] =  array(
351
    '#type' => 'textfield',
352
    '#title'         => t('Proxy port'),
353
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
354
    );
355

    
356
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] =  array(
357
    '#type' => 'textfield',
358
    '#title'         => t('Login'),
359
    '#default_value' => variable_get('cdm_webservice_proxy_usr', false),
360
    );
361

    
362
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] =  array(
363
    '#type' => 'textfield',
364
    '#title'         => t('Password'),
365
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', false),
366
    );
367

    
368
    //TODO: settings are still incomplete, compare with trunk/dataportal/inc/config_default.php.inc
369
    $form['cdm_dataportal'] = array(
370
      '#type' => 'fieldset',
371
      '#title' => t('Taxon Tree'),
372
      '#collapsible' => FALSE,
373
      '#collapsed' => TRUE,
374
      '#description' => t('<p>When you explore your collection, you can navigate it through a
375
                           tree structure also called <em>Taxon Tree</em>.</p><p>To be able to navigate through
376
                           your collection the
377
                           <a href="http://drupal.org/handbook/blocks">drupal block</a>
378
                           <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
379
                           <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p>'),
380
    );
381

    
382
    $form['cdm_dataportal'][CDM_TAXONOMICTREE_UUID] = array(
383
      '#type' => 'select',
384
      '#title'         => t('Available classifications'),
385
      '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, false),
386
      '#options' => cdm_get_taxontrees_as_options(),
387
      '#description'   => t('Select the default taxa classification for your <em>taxon tree</em>,
388
                             the other classifications will be also available but with a manual user change.')
389
    );
390

    
391
    $form['cdm_dataportal']['taxontree_ranklimit'] =  array(
392
    '#type'          => 'select',
393
    '#title'         => t('Rank of highest displayed taxon'),
394
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT), //before DEFAULT_TAXONTREE_RANKLIMIT_UUID
395
    '#options'       => cdm_rankVocabulary_as_option(),
396
    '#description'   => t('This is the rank of the highest displayed taxon in the <em>taxon tree</em>. You can
397
                           select here which rank should be at the top level of the tree structure.'),
398
  );
399

    
400
    return system_settings_form($form);
401
}
402

    
403

    
404
/**
405
 * LAYOUT settings
406
 * @return unknown_type
407
 */
408
function cdm_settings_layout(){
409

    
410
  //drupal_goto('admin/settings/cdm_dataportal/layout/taxon');
411
  $form = array();
412
/*
413
  // -- tabbed pages -- //
414
  $form['cdm_dataportal_taxonpage_tabs'] = array(
415
    '#type' => 'checkbox',
416
    '#title' => t('Tabbed taxon page'),
417
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
418
    '#description' => t('If selected split the taxon page into individual tabs for description, images, synonymy. If not the taxon data is renderized as a long single page without tabs.')
419
  );
420
*/
421
  $form['gen_layout'] = array(
422
    '#type' => 'fieldset',
423
      '#title' => t('Portal Layout'),
424
        '#collapsible' => FALSE,
425
        '#collapsed' => FALSE,
426
      '#description' => t('This settings contains the general configurations layout. If you want to configure the specific sites layout visit the respective configuration site for taxon, search or media.'),
427
  );
428

    
429
  //---- footnotes ---//
430
  $form['gen_layout']['footnotes'] = array(
431
      '#type' => 'fieldset',
432
      '#title' => t('Footnotes'),
433
      '#collapsible' => FALSE,
434
      '#collapsed' => FALSE,
435
    '#description' => t('Taxa data such authors, synonyms names, descriptions, media or distribution areas may have annotations or footnotes. When the footnotes are enabled
436
                         they will be visible (if they exist).'),
437
  );
438

    
439
  $form['gen_layout']['footnotes']['cdm_dataportal_all_footnotes'] = array(
440
      '#type' => 'checkbox',
441
      '#title' => t('Do not show footnotes'),
442
      '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
443
      '#description' => t('Check this if you do not want to show any footnotes')
444
  );
445

    
446
  $form['gen_layout']['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
447
      '#type' => 'checkbox',
448
      '#title' => t('Do not show annotations footnotes'),
449
      '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
450
      '#description' => t('Check this if you do not want to show annotation footnotes')
451
  );
452

    
453
  $annotationTypeOptions = cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE);
454
  // additional option for the null case
455
  $annotationTypeOptions['NULL_VALUE']=t('unset (null)');
456
  $form['gen_layout']['footnotes']['annotations_types_as_footnotes'] = array(
457
      '#type' => 'checkboxes',
458
      '#title' => t('Annotation types as footnotes'),
459
      '#description' => t('Only annotations of the selected type will be displayed as footnotes. You may want to turn \'technical annotations\' off. Untyped annotations will always be displayed.'),
460
      '#options' => $annotationTypeOptions,
461
      '#default_value' => variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT))
462

    
463
  );
464

    
465
  //--- Advanced Search ---//
466
  $form['gen_layout']['asearch'] = array(
467
      '#type' => 'fieldset',
468
      '#title' => t('Advanced search'),
469
      '#collapsible' => FALSE,
470
      '#collapsed' => FALSE,
471
    );
472
    $form['gen_layout']['asearch']['cdm_dataportal_show_advanced_search'] = array(
473
      '#type' => 'checkbox',
474
      '#title' => t('Show advanced search link'),
475
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
476
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
477
    );
478

    
479
  return system_settings_form($form);
480
}
481

    
482
function cdm_dataportal_theming_form (){
483
    //--- Theme ---//
484
/*
485
    $form['cdm_dataportal_theming'] = array(
486
      '#type' => 'fieldset',
487
      '#title' => t('Theme Images'),
488
      '#collapsible' => FALSE,
489
      '#collapsed' => FALSE,
490
    );
491
*/
492
  $form = array('#attributes' => array('enctype' => 'multipart/form-data'));
493

    
494
    $form['cdm_dataportal_theming_right_image'] = array(
495
        '#type' => 'file',
496
        '#title' => t('Select top right image'),
497
        '#description' => t('Maximum dimensions are %dimensions and the maximum size is %size kB.',
498
                            array('%dimensions' =>  '250x250', '%size' => '30')),
499
    );
500
    $form['cdm_dataportal_theming_middle_image'] = array(
501
        '#type' => 'file',
502
        '#title' => t('Select top middle image'),
503
    );
504
    $form['test'] = array(
505
        '#type' => 'textfield',
506
        '#title' => t('test')
507
    );
508

    
509
    //$form['gen_layout']['theme']['#submit'][] = 'settings_validate_theme_pictures';
510
    $form['cdm_dataportal_theming']['submit'] = array(
511
      '#type' => 'submit',
512
      '#value' => t('Submit')
513
    );
514

    
515
    return $form;
516
}
517

    
518
function cdm_dataportal_theming_form_submit (&$form, &$form_values){
519
  $validators = array();
520
  //destination path where the files/banners will be saved
521
  $dest = absolute_path_to_drupal() . '/' . path_to_theme() . '/images/banners';
522
  $dest = str_replace('/', DIRECTORY_SEPARATOR, $dest);
523
  //drupal_set_message($dest);
524

    
525
  //check if directory exists
526
  if (!file_exists($dest)){
527
        if(!mkdir($dest, 0777, true)){//TODO: add rights, which rights should I add?
528
            drupal_set_message('Fail uploading the files; the directory '
529
                               . $dest . ' could not be created.',
530
                               'warning');
531
        }
532
  }
533
  //check if files already exist
534
  //if (file_exists($dest)) {
535
  //}
536

    
537
  //save the files
538
    $file = file_check_upload('cdm_dataportal_theming_middle_image');
539
    if ($file){
540
        $file = file_save_upload($file, 'files');
541
        drupal_set_message($file->filepath);
542
        file_move($file->filepath, $dest);
543
    }else{
544
      drupal_set_message('Fail uploading the file, the file is not accepted.', 'warning');
545
    }
546
  //use banners in the selected theme
547
    //if (!copy($file, $file.'.bak')) {
548
    //    print ("failed to copy $file...<br>\n");
549
    //}
550

    
551
    //use the banners as default theme
552
}
553
/*
554
function cdm_settings_layout_synonymy(){
555
  / * ====== SYNONYMY ====== * /
556
  $form['synonymy'] = array(
557
      '#type' => 'fieldset',
558
      '#title' => t('Synonymy'),
559
      '#collapsible' => TRUE,
560
      '#collapsed' => TRUE,
561
      '#description' => t('This section covers the settings related to the taxon <b>synonymy</b> tab.'),
562
  );
563

    
564
  $form['synonymy']['cdm_dataportal_nomref_in_title'] = array(
565
    '#type' => 'checkbox',
566
    '#title' => t('Show accepted taxon on top of the synonymy'),
567
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
568
    '#description' => t('If checked, the first homotypic taxon is a repetition of the accepted taxon most likely
569
                        with the full nomenclatural reference (depending on the currently chosen theme).')
570
  );
571

    
572
  $form['synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
573
    '#type' => 'checkbox',
574
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
575
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
576
    '#description' => t('Check this if after doing a search and clicking on a synonym you want to see the "accept of" text for the accepted synonym.')
577
  );
578

    
579
  $form['synonymy']['name_relationships']['name_relationships_to_show'] = array(
580
    '#type' => 'checkboxes',
581
    '#title' => t('Display name relationships'),
582
    '#default_value' => variable_get('name_relationships_to_show', 0),
583
    '#options' => $nameRelationshipTypeOptions,
584
    '#description' => t('Select the name relationships you want to show for the accepted taxa.'),
585
  );
586

    
587
  $form['synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
588
    '#type' => 'checkbox',
589
    '#title' => t('Show taxon relations ships of accepted taxon'),
590
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
591
    '#description' => t('If this option is enabled the synonymy will show the below selected taxon relationships of accepted taxa.')
592
  );
593

    
594
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE);
595
  $form['synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
596
      '#type' => 'checkboxes',
597
      '#title' => t('Taxon relationship types'),
598
      '#description' => t('Only taxon relationships of the selected type will be displayed'),
599
      '#options' => $taxonRelationshipTypeOptions,
600
      '#default_value' => variable_get('CDM_TAXON_RELATIONSHIP_TYPES', unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
601
      '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)
602
  );
603

    
604
  return system_settings_form($form);
605

    
606
}
607
*/
608

    
609
function cdm_settings_layout_taxon(){
610
  $collapsed = false;
611
  $form = array();
612

    
613
  //--------- TABBED TAXON -------//
614
  $form['taxon_tabs'] = array(
615
    '#type' => 'fieldset',
616
      '#title' => t('Taxon tabs'),
617
      '#collapsible' => TRUE,
618
      '#collapsed' => FALSE,
619
    '#description' => t('If tabbed taxon page is enabled the taxon profile will be splitted in four diferent tabs;
620
             General, Synonymy, Images and Specimens. If the taxon has no information for any of the tabs/sections such tab will be not displayed.'),
621
  );
622

    
623
    $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
624
    '#type' => 'checkbox',
625
    '#title' => t('Tabbed taxon page'),
626
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
627
    '#description' => t('<p>If selected split the taxon page into individual tabs for description, images, synonymy and specimens.
628
                            If not the taxon data is renderized as a long single page without tabs.</p>')
629
  );
630

    
631
  $form['taxon_tabs']['cdm_dataportal_detault_tab'] =  array(
632
      '#type'          => 'select',
633
      '#title'         => t('Default tab to display'),
634
      '#default_value' => variable_get('cdm_dataportal_detault_tab', 0),
635
      '#options'       => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
636
      '#description'   => t('<p>Select the default tab to display when visiting a taxon page. Only available if Tabbed Taxon Page is enable.</p>
637
              <strong>Note:</strong> After performing a search and clicking in any synonym, the taxon tab
638
              to be renderized will be the synonymy of the accepted taxon and not the above selected tab.'),
639
  );
640

    
641
  $form['cdm_dataportal_show_back_to_search_results'] = array(
642
      '#type' => 'checkbox',
643
        '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
644
        '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
645
        '#description' => t('<p>If checked the link to search results is rendererized at the top of the taxon site. Clicking on the link the last search performed is renderized again.</p>')
646
  );
647

    
648
  /* ======  TAXON_PROFILE ====== */
649

    
650
  $form['taxon_profile'] = array(
651
      '#type' => 'fieldset',
652
      '#title' => t('Taxon profile (tab)'),
653
      '#description' => t('<p>This section covers the setting related to the taxon profile tab, also known as the <strong>"General"</strong> tab.</p>'),
654
      '#collapsible' => TRUE,
655
      '#collapsed' => TRUE,
656
  );
657

    
658

    
659
  // ---- PROFILE PICTURE ----//
660
  $form['taxon_profile']['picture'] = array(
661
      '#type' => 'fieldset',
662
      '#title' => t('Profile Picture'),
663
      '#collapsible' => TRUE,
664
      '#collapsed' => FALSE,
665
    '#description' => t('Select a profile picture for taxa. Like a facebook of plants.'),
666
  );
667

    
668
  $form['taxon_profile']['picture']['cdm_dataportal_show_default_image'] = array(
669
      '#type' => 'checkbox',
670
      '#title' => t('Enable profil picture'),
671
      '#default_value' => variable_get('cdm_dataportal_show_default_image', false),
672
      '#description'   => t('Show the profil picture.')
673
  );
674

    
675
  $options = cdm_rankVocabulary_as_option();
676
  array_unshift($options, '-- DISABLED --');
677
  $form['taxon_profile']['picture']['image_hide_rank'] =  array(
678
      '#type'          => 'select',
679
      '#title'         => t('Hide picture for taxa above'),
680
      '#default_value' => variable_get('image_hide_rank', '0'),
681
      '#options'       => $options,
682
      '#description'   => t('Select which rank of pictures should not have a profil picture.'),
683
  );
684
  //show picture
685
  $selectShowMedia = array(0 => "Show only taxon pictures",
686
  1 => "Show taxon and child taxa pictures");
687

    
688
  $form['taxon_profile']['picture']['cdm_dataportal_show_media'] = array(
689
      '#type' => 'select',
690
      '#title' => t('Available picture files'),
691
      '#default_value' => variable_get('cdm_dataportal_show_media', false),
692
      '#options' => $selectShowMedia,
693
      '#description'   => t('Show the profil pictures current taxon\'s children.')
694
  );
695

    
696
  //-- MEDIA THUMBNAILS --//
697
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
698
  $form_title = 'Taxon Profile Images';
699
  $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>';
700
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
701

    
702
  // ---- FEATURE TREE ---- //
703
  $form['taxon_profile']['taxon_profile'] = array(
704
  '#type' => 'fieldset',
705
     '#title' => t('Features'),
706
     '#collapsible' => TRUE,
707
     '#collapsed' => FALSE,
708
  '#description' => t('This section covers settings related to the taxon\'s <em>Feature Tree</em>. The <em>feature tree</em> are the taxon\'s
709
                        features such description, distribution, common names, etc. that drupal will render at his taxon profile page.'),
710
  );
711

    
712
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID] = array(
713
      '#type' => 'radios',
714
      '#title'         => t('Taxon profile sections'),
715
      '#default_value' => variable_get(CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE),
716
      '#options' => cdm_get_featureTrees_as_options(TRUE),
717
      '#description'   => t('Select the Feature Tree to be displayed at the taxon profile. Click "Show Details" to see the Feature Tree elemets.'
718
      )
719
  );
720

    
721
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
722
    '#type' => 'radios',
723
    '#title'         => t('Natural language representation of structured descriptions'),
724
    '#default_value' => variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, null),
725
    '#options' => cdm_get_featureTrees_as_options(),
726
    '#description'   => t('Taxon descriptions can be stored in a highly structured form.'.
727
      ' The feature tree selected here will be used to generate textual representation in natural language.'
728
      //.' If there is no applicable FeatureTree you can create a new one using the <a href="">FeatureTreeManager</a>'
729
    )
730
  );
731

    
732
  //---- LAYOUT PER FEATURE ---- //
733
  $feature_tree = cdm_ws_get(CDM_WS_FEATURETREES, variable_get(CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE));
734

    
735
  if( isset($feature_tree->root->children) ){
736

    
737
    $form_feature_list_layout = array(
738
      '#title' => t('Taxon profile layout'),
739
      '#collapsible' => TRUE,
740
      '#collapsed' => FALSE,
741
      '#type' => 'fieldset',
742
      '#description' => t('Will be availbale in a future release.'),
743
    );
744

    
745
    $feature_list_layout_settings_disabled = true;
746
    foreach( $feature_tree->root->children as $featureNode ){
747

    
748

    
749
      if( !$feature_list_layout_settings_disabled && isset($featureNode->feature) ) {
750

    
751
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid; // must not exceed 45 characters !!!
752

    
753
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
754

    
755

    
756
        $form_feature_list_layout[$subform_id] = array(
757
          '#tree' => TRUE,
758
           '#title' => $featureNode->feature->representation_L10n,
759
          '#collapsible' => FALSE,
760
          '#collapsed' => FALSE,
761
          '#type' => 'fieldset',
762
          '#description' => t('')
763
        );
764

    
765
        $form_feature_list_layout[$subform_id]['enabled'] = array(
766
          '#type' => 'checkbox',
767
           '#title' => t('Enable'),
768
          '#default_value' => $settings['enabled'],
769
          '#description' => t('Enable user defined layout for this feature')
770
        );
771

    
772
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
773
          '#type' => 'textfield',
774
           '#title' => t('Enclosing tag'),
775
          '#disabled' => !$settings['enabled'],
776
          '#default_value' => $settings['enclosingTag'],
777
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'"
778
        );
779

    
780
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
781
          '#type' => 'textfield',
782
           '#title' => t('Entry enclosing tag'),
783
          '#disabled' => !$settings['enabled'],
784
          '#default_value' => $settings['entryEnclosingTag'],
785
          '#description' => t('Default is: ') . "'<code>". $systemDefaults['entryEnclosingTag'] ."</code>'"
786
        );
787

    
788
        $form_feature_list_layout[$subform_id]['glue'] = array(
789
          '#type' => 'textfield',
790
           '#title' => t('Glue'),
791
          '#disabled' => !$settings['enabled'],
792
          '#default_value' => $settings['glue'],
793
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'"
794
        );
795

    
796
      }
797

    
798
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
799
    }
800
  }
801

    
802

    
803
  //---- DISTRIBUTION LAYOUT ---- //
804

    
805
  $form['taxon_profile']['distribution_layout'] = array(
806
    '#title' => t('Distribution'),
807
    '#collapsible' => TRUE,
808
    '#collapsed' => FALSE,
809
    '#type' => 'fieldset',
810
    '#description' => t('Select if you want to sort or not the distribution text located below the distribution map.'),
811
  );
812

    
813
  $form['taxon_profile']['distribution_layout']['distribution_sort'] =  array(
814
  '#type'          => 'radios',
815
  '#title'         => t('Sort'),
816
  '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
817
  '#options' => array(
818
      'NO_SORT' => t('Standard (No sort)'),
819
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
820
    ));
821

    
822
   $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] =  array(
823
  '#type'          => 'checkbox',
824
  '#title'         => t('Show TextData elements on top of the map'),
825
  '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
826
  '#description' => t('Check this if you want to appear all <code>TextData</code> elements on top of the map.
827
    Otherwise all <code>TextData</code> distribution elements will be listed below the other area elements.
828
    This option is useful if you need to have descriptive texts for each distribution map.'),
829
  );
830

    
831

    
832
/* ====== SYNONYMY ====== */
833
  $form['taxon_synonymy'] = array(
834
      '#type' => 'fieldset',
835
      '#title' => t('Taxon synonymy (tab)'),
836
      '#collapsible' => TRUE,
837
      '#collapsed' => TRUE,
838
      '#description' => t('This section covers the settings related to the taxon <b>synonymy</b> tab.####'),
839
  );
840

    
841
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
842
    '#type' => 'checkbox',
843
    '#title' => t('Show accepted taxon on top of the synonymy'),
844
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
845
    '#description' => t('If checked, the first homotypic taxon is a repetition of the accepted taxon most likely
846
                        with the full nomenclatural reference (depending on the currently chosen theme).')
847
  );
848

    
849
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
850
    '#type' => 'checkbox',
851
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
852
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
853
    '#description' => t('Check this if after doing a search and clicking on a synonym you want to see the "accept of" text for the accepted synonym.')
854
  );
855

    
856
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
857
  $form['synonymy']['name_relationships']['name_relationships_to_show'] = array(
858
    '#type' => 'checkboxes',
859
    '#title' => t('Display name relationships'),
860
    '#default_value' => variable_get('name_relationships_to_show', 0),
861
    '#options' => $nameRelationshipTypeOptions,
862
    '#description' => t('Select the name relationships you want to show for the accepted taxa.'),
863
  );
864

    
865

    
866
 $form['synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
867
    '#type' => 'checkbox',
868
    '#title' => t('Show taxon relations ships of accepted taxon'),
869
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
870
    '#description' => t('If this option is enabled the synonymy will show the below selected taxon relationships of accepted taxa.')
871
  );
872

    
873
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, _cdm_relationship_type_term_label_callback);
874
  $form['synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
875
      '#type' => 'checkboxes',
876
      '#title' => t('Taxon relationship types'),
877
      '#description' => t('Only taxon relationships of the selected type will be displayed'),
878
      '#options' => $taxonRelationshipTypeOptions,
879
      '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
880
      '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)
881
  );
882

    
883
  // ====== SPECIMENS ====== //
884
  $form['taxon_specimens'] = array(
885
      '#type' => 'fieldset',
886
      '#title' => t('Taxon specimens (tab)'),
887
      '#collapsible' => TRUE,
888
      '#collapsed' => TRUE,
889
      '#description' => t('This section covers the settings related to the taxon <b>specimens</b> tab.'),
890
  );
891
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
892
  $form_title = 'Specimen media';
893
  $form_description = 'Specimens may have media which is displayed at the Specimen tab/section as a gallery.
894
   It is possible to configure the thumbnails gallery here, however for configuring how a single media should
895
   be displayed please go to <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>';
896
  $form['taxon_specimens'][] =
897
    cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
898

    
899

    
900
  // --- MEDIA GALLERY ---- //
901
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
902
  $form_title = 'Media gallery (tab)';
903
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
904
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
905
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
906
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
907
   <p><strong>Note:</strong> These settings are only taken into account when the standard
908
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
909
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
910

    
911

    
912
  return system_settings_form($form);
913
}
914

    
915
function cdm_settings_layout_search(){
916

    
917
  $form = array();
918

    
919
  $form['search_settings'] = array(
920
    '#type' => 'fieldset',
921
    '#title' => t('Taxa Search'),
922
    '#collapsible' => TRUE,
923
    '#collapsed' => TRUE,
924
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
925
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
926
         where they can write the text to be searched. You can find Drupal block configuration
927
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
928
  );
929

    
930
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
931
    '#type' => 'textfield',
932
    '#title' => t('Results per page'),
933
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
934
    '#description' => t('Number of results to display per page.')
935
  );
936

    
937
  // --- SEARCH TAXA GALLERY ---- //
938
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
939
  $collapsed = FALSE;
940
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
941
  $form_title = 'Taxa Search thumbnails';
942
  $form_description = 'Search results may show thumbnails. ';
943
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
944

    
945
  return system_settings_form($form);
946
}
947

    
948
function cdm_settings_layout_media(){
949

    
950
  $form = array();
951

    
952
  $form['media_settings'] = array(
953
      '#type' => 'fieldset',
954
      '#title' => t('Media display settings'),
955
      '#collapsible' => TRUE,
956
      '#collapsed' => FALSE,
957
    '#description' => t('This section covers the settings related to the taxa media, that is how each single media should be displayed.'),
958
      );
959

    
960
  $form['media_settings']['image_gallery_viewer'] =  array(
961
    '#type'          => 'select',
962
    '#title'         => t('Image viewer'),
963
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
964
    '#options' => array('default' => t('Standard image viewer'),
965
                        'fsi' => t('FSI viewer (requires FSI server!)')),
966
  );
967

    
968
  // --- MEDIA GALLERY ---- //
969
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
970
  $form_title = 'Standard viewer';
971
  $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>';
972
  //$form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
973
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
974

    
975

    
976
  return system_settings_form($form);
977
}
978

    
979

    
980
/**
981
 * GEOSERVICE and Map settings
982
 * @return unknown_type
983
 */
984
function cdm_settings_geo(){
985

    
986
  $form = array();
987

    
988
  /*
989
   * GEO SERVER
990
   */
991

    
992
  $form['geoserver'] = array(
993
    '#type' => 'fieldset',
994
    '#title' => t('Geo Server Settings'),
995
    '#collapsible' => TRUE,
996
    '#collapsed' => TRUE,
997
    '#description' => t('Configuration and selection of your geo server. The Geo Server is the responsible for generating the maps.'),
998
  );
999

    
1000
  $form['geoserver']['edit_map_server'] = array(
1001
    '#type' => 'select',
1002
    '#title' => t('Geoservice access point URL'),
1003
    '#default_value' => variable_get('edit_map_server', EDIT_MAPSERVER_V1_URI),
1004
    '#options' => array(
1005
        EDIT_MAPSERVER_V1_URI => 'EDIT Map Server v1',
1006
        EDIT_MAPSERVER_V11_URI => 'EDIT Map Server v1.1',
1007
        /*
1008
        'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server - Mirror 1',
1009
        'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server - Mirror 2',
1010
         */
1011
        'ALTERNATIVE' => '-- Alternative URL --'
1012
        ),
1013
    '#description' => t('Select the Map Server you want the data portal to connect.'
1014
         . 'If you want to introduce a custom address just select the Alternative URL value and fill the field Geoservice'
1015
         . 'Access Point - Alternative URL with the custem ip address.')
1016
    );
1017

    
1018
    $form['geoserver']['edit_map_server_alternative'] = array(
1019
      '#type' => 'textfield',
1020
      '#title' => t('Geoservice access point - alternative URL'),
1021
      '#default_value' => variable_get('edit_map_server_alternative', ''),
1022
      '#description' => t('Alternative URL of a EDIT Map Service to be used by this portal. You must choose the option <i>-- Alternative URL --</i> in the chooser abofe to enable this url.')
1023
    );
1024

    
1025

    
1026
  /*
1027
   *  MAP SETTINGS
1028
   */
1029

    
1030
    $form['map_settings'] = array(
1031
      '#type' => 'fieldset',
1032
      '#title' => t('Maps settings'),
1033
      '#collapsible' => TRUE,
1034
      '#collapsed' => TRUE,
1035
      '#description' => t('General configuration for all map types.'),
1036
     );
1037

    
1038
    $form['map_settings']['cdm_dataportal_geoservice_display_width'] = array(
1039
      '#type' => 'textfield',
1040
      '#title' => t('Maps width'),
1041
      '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
1042
      '#description' => t('Choose the width of your maps, the height will always be the half of the width. A value of 500 means the size will be 500 pixels witdh and 250 pixels height.')
1043
    );
1044

    
1045
    $form['map_settings']['cdm_dataportal_geoservice_bounding_box'] = array(
1046
      '#type' => 'textfield',
1047
      '#title' => t('Fixed bounding box'),
1048
      '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
1049
      '#description' => t('Define surrounding of area to be displayed in maps. Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong> to let the map <strong>automatically zoom</strong> to the distribution area.')
1050
    );
1051

    
1052
    $form['map_settings']['cdm_dataportal_geoservice_labels_on'] = array(
1053
      '#type' => 'checkbox',
1054
      '#title' => '<b>'.t('Display area labels').'</b>',
1055
      '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
1056
      '#description' => t('Check this if you like area names to be displayed in the maps. DOES IT WORKS???? ')
1057
    );
1058

    
1059
    $form['map_settings']['cdm_dataportal_geoservice_map_caption'] = array(
1060
      '#type' => 'textfield',
1061
      '#title' => t('Map caption'),
1062
      '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
1063
      '#description' => t('Define a caption for the map.')
1064
    );
1065

    
1066
    $form['map_settings']['cdm_dataportal_geoservice_distributionOpacity'] = array(
1067
      '#type' => 'textfield',
1068
      '#title' => t('Distribution layer opacity'),
1069
      '#default_value' => variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5'),
1070
      '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1071
                           fully visible, while a value near to 0.0 will be not much visible.')
1072
    );
1073

    
1074
    $form['map_settings']['cdm_dataportal_map_openlayers'] = array(
1075
      '#type' => 'radios',
1076
      '#title' => '<b>'.t('Map Viewer').'</b>',
1077
      '#options' => array(1 => "OpenLayers dynamic mapviewer", 0 => "Plain image" ),
1078
      '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1079
      '#description' => t('You can choose from two different map viewers:<ul><li><em>OpenLayers</em> displays the maps in an interactive viewer which allows zooming and panning. If not enabled the maps will consist
1080
                           on a static image. If enabled you can configure the default layer (background of your maps) below. Only one of
1081
                           them will be renderized.</li><li><em>Plain image</em> displays the map as a plain non interactive image</li></ul>')
1082
    );
1083

    
1084
    $openLayersEnabled = variable_get('cdm_dataportal_map_openlayers', 1) === 1;
1085

    
1086

    
1087
    // --- Plain Image Settings --- //
1088

    
1089
    $form['map_image'] = array(
1090
      '#type' => 'fieldset',
1091
      '#title' => t('Plain image map settings'),
1092
      '#collapsible' => TRUE,
1093
      '#collapsed' => $openLayersEnabled,
1094
      '#description' => 'The settings in this section are still expertimental '
1095
        .'and can onyl be used with the EDIT map service version 1.1 or above.'
1096
    );
1097

    
1098
    $edit_mapserver_version = getEDITMapServiceVersionNumber();
1099
    if ($edit_mapserver_version < 1.1) {
1100
      $form['map_image']['#description'] = '<div class="messages warning">' . t("The selected EDIT map service version has to small version number: $edit_mapserver_version") . '</div>'
1101
      . $form['map_image']['#description'];
1102
    }
1103

    
1104
    $form['map_image']['map_base_layer'] = array(
1105
      '#type' => 'textfield',
1106
      '#title' => t('Background layer'),
1107
      '#default_value' => variable_get('map_base_layer', 'cyprusdivs'),
1108
      '#description' => t('Background layer. for available layers inspect')
1109
        . l(" deegree-csw ",  "http://edit2.br.fgov.be:8080/deegree-csw/md_search.jsp") . t('or')
1110
        . l(" geoserver layers ", "http://edit.br.fgov.be:8080/geoserver/rest/layers")
1111
    );
1112

    
1113
    $form['map_image']['map_bg_color'] = array(
1114
      '#type' => 'textfield',
1115
      '#title' => t('Background color'),
1116
      '#default_value' => variable_get('map_bg_color', '1874CD')
1117
    );
1118

    
1119
    $form['map_image']['map_base_layer_style'] = array(
1120
      '#type' => 'textfield',
1121
      '#title' => t('Background layer area style'),
1122
      '#default_value' => variable_get('map_base_layer_style', 'ffffff,606060,,'), // only line color by now
1123
      '#description' => t('Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}')
1124
    );
1125

    
1126

    
1127
    // --- OpenLayers Settings --- //
1128

    
1129
    $form['openlayers'] = array(
1130
      '#type' => 'fieldset',
1131
      '#title' => t('OpenLayers settings'),
1132
      '#collapsible' => TRUE,
1133
      '#collapsed' => !$openLayersEnabled,
1134
      '#description' => ''
1135
    );
1136

    
1137
    if( !$openLayersEnabled ){
1138
      $form['openlayers']['#description'] = '<div class="messages warning">' . t("The Openlayers viewer is curretnly not enabled! (see section Maps settings above )") . '</div>'
1139
      . $form['openlayers']['#description'];
1140
    }
1141

    
1142
    $baselayer_options = array(
1143
      /*
1144
       * NOTICE: must correspond to the layers defined in js/openlayers_,ap.js#getLayersByName()
1145
       */
1146
      'osgeo_vmap0' => "OpenLayers World", // EPSG:4326
1147
      'metacarta_vmap0' => "Metacarta Vmap0" , // EPSG:4326, EPSG:900913
1148
       // all others EPSG:900913
1149
      'edit-vmap0_world_basic' => 'EDIT Vmap0',
1150
      'edit-etopo1' => "ETOPO1 Global Relief Model",
1151
      'osmarender' => 'OpenStreetMap',
1152
      //'oam' => 'OpenAerialMap', // currently unavailable
1153
      'gmap' => 'Google Streets',
1154
      'gsat' => 'Google Satellite',
1155
      'ghyb' => 'Google Hybrid',
1156
      'veroad' => 'Virtual Earth Roads',
1157
      'veaer' => 'Virtual Earth Aerial',
1158
      'vehyb' => 'Virtual Earth Hybrid'
1159
       //  ,
1160
       //    'yahoo' => 'Yahoo Street',
1161
       //    'yahoosat' => 'Yahoo Satellite',
1162
       //    'yahoohyb' => 'Yahoo Hybrid'
1163
    );
1164

    
1165
    $form['openlayers']['baselayers'] = array(
1166
      '#type' => 'checkboxes_preferred',
1167
      '#title' => t('Baser Layers'),
1168
      '#options' => $baselayer_options,
1169
      '#default_value' => variable_get('baselayers', array('metacarta_vmap0' => "metacarta_vmap0", 'PREFERRED' => 'metacarta_vmap0')),
1170
      '#description' => t('Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.')
1171
     );
1172

    
1173
  // cdm_dataportal_geoservice_showLayerSwitcher
1174
  $form['openlayers']['cdm_dataportal_geoservice_showLayerSwitcher'] = array(
1175
    '#type' => 'checkbox',
1176
    '#title' => '<b>'.t('Show Layer Switcher').'</b>',
1177
    '#default_value' => variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE),
1178
    '#description' => t('The Layer Switcher control displays a table of contents for the map.  This allows the user interface to switch between BaseLasyers and to show or hide Overlays.  By default the switcher is shown minimized on the right edge of the map, the user may expand it by clicking on the handle.')
1179
  );
1180

    
1181
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1182
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1183
  $form['openlayers']['gmap_api_key'] = array(
1184
    '#type' => 'textfield',
1185
    '#title' => t('Gogle maps API key'),
1186
    '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1187
    '#description' => t('If you want to use the Google Maps Layer a key is needed. If you need a key visit <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.<br>
1188
         <b>Note:</b> The following key: <code>'.$localhostkey.'</code> is the default key for the localhost (127.0.0.1). The key in use is the one above this text.')
1189
   );
1190

    
1191
  $form['cdm_dataportal_geoservice_map_legend'] = array(
1192
     '#type' => 'fieldset',
1193
     '#title' => t('Map legend'),
1194
     '#collapsible' => TRUE,
1195
     '#collapsed' => TRUE,
1196
     '#description' => t('Configure the maps legend.')
1197
  );
1198

    
1199
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
1200
    '#type' => 'checkbox',
1201
    '#title' => '<b>'.t('Display a map legend').'</b>',
1202
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
1203
    '#description' => t('Check this if you like a legend to be displayed with the maps.')
1204
  );
1205

    
1206
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legendOpacity'] = array(
1207
    '#type' => 'textfield',
1208
    '#title' => t('Legend opacity'),
1209
    '#default_value' => variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'),
1210
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
1211
                         to 0.0 will be not much visible.')
1212
  );
1213

    
1214
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
1215
    '#type' => 'textfield',
1216
    '#title' => t('Font size'),
1217
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
1218
    '#description' => t('Font size in pixels.')
1219
  );
1220

    
1221
  $fontStyles = array(0 => "plane", 1 => "italic");
1222
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
1223
    '#type' => 'select',
1224
    '#title' => t('Available font styles'),
1225
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', false),
1226
    '#options' => $fontStyles,
1227
    '#description'   => t('Select a font style for the map legend.')
1228
  );
1229

    
1230
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
1231
    '#type' => 'textfield',
1232
    '#title' => t('Legend icon width'),
1233
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
1234
    '#description' => t('Legend icon width in pixels.')
1235
  );
1236
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
1237
    '#type' => 'textfield',
1238
    '#title' => t('Legend icon height'),
1239
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
1240
    '#description' => t('Legend icon height in pixels.')
1241
  );
1242

    
1243
        return system_settings_form($form);
1244
}
1245

    
1246

    
1247
function cdm_settings_cache(){
1248

    
1249
  $form = array();
1250

    
1251
  $form['cache_settings'] = array(
1252
      '#type' => 'fieldset',
1253
      '#title' => t('Cache Settings'),
1254
      '#collapsible' => FALSE,
1255
      '#collapsed' => FALSE,
1256
    '#description' => t('<p>When caching is enabled all single taxon sites are stored in an internal drupal cache doing
1257
                           the portal response of taxa pages faster. This is possible because the sites are loaded from
1258
                           the cache and are not created from scratch.</p>'),
1259
      );
1260

    
1261
  $form['cache_settings']['cdm_webservice_cache'] =  array(
1262
    '#type'          => 'checkbox',
1263
    '#title'         => t('<strong>Enable caching</strong>'),
1264
  '#options'     => cdm_help_general_cache(),
1265
    '#default_value' => variable_get('cdm_webservice_cache', 1),
1266
    '#description'   => t('<p>Enable drupal to load taxa pages from the cache.</p>' .
1267
                         '<p><strong>Note:</strong> If taxa are modified by the editor or any other application the changes will be not
1268
                         visible till the cache is erased. Therefore developers should deactived this feature when they
1269
                         are working on the CDM Dataportal Module.</p>')
1270
    );
1271

    
1272
  $form['cache_settings']['cdm_run_cache'] = array(
1273
    '#value' => cdm_view_cache_site()
1274
  );
1275

    
1276
  return system_settings_form($form);
1277
}
1278

    
1279
/**
1280
 * @return walk and cache all taxon pages
1281
 */
1282
function cdm_view_cache_site(){
1283

    
1284
  $out = '';
1285

    
1286
  _add_js_progressbar();
1287
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cache_all_taxa.js');
1288

    
1289
  $request_params = array();
1290
  $request_params['query'] = '%';
1291
  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false); //cache only the dafault classification
1292
  $request_params['doTaxa'] = 1;
1293
  $request_params['doSynonyms'] = 0;
1294
  $request_params['doTaxaByCommonNames'] = 0;
1295

    
1296
  $search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND . ".json", null, queryString($request_params));
1297
  $search_url = uri_uriByProxy($search_url);
1298
  $taxon_page_url = url('cdm_dataportal/taxon/');
1299

    
1300

    
1301
  $out .= t('<p><strong>Cache all taxon pages</strong></p>');
1302
  $out .= '<p>When you lunch the cache process the cache is filled and ready to be enabled.<br/>
1303
  Remember that when you load the taxa from the cache last changes on taxa will be not visible till you erase
1304
  the cache and fill it again.</p>';
1305
  $out .= '<p>Before  running the cache bot you have to empty the cache manually</p>';
1306

    
1307
  $out .= '<form id="cache_site">';
1308
  $out .= '<div>'.t('This caching process may take long time and could cause heavy load on your server').'</div>';
1309
  $out .= '<div id="progress"></div>';
1310
  $out .= '<input type="hidden" name="searchTaxaUrl" value="'.$search_url.'"/>';
1311
  $out .= '<input type="hidden" name="taxonPageUrl" value="'.$taxon_page_url.'"/>';
1312
  $out .= '<input type="button" name="start" value="'.t('Start').'"/>';
1313
  $out .= '<input type="button" name="stop" value="'.t('Stop').'"/>';
1314
  $out .= '</form>';
1315
  $out .= '</div>';
1316
  //  foreach($taxonPager->records as $taxon){
1317
  //    cdm_dataportal_taxon_view($uuid);
1318
  //  }
1319

    
1320
  return $out;
1321
}
1322

    
1323

    
1324
/**
1325
 * Implementation of hook_validate()
1326
 *
1327
 * @param $element
1328
 */
1329
function cdm_settings_validate($form_id, $form_values){
1330

    
1331
  if (!str_endsWith($form_values['cdm_webservice_url'], '/')) {
1332
    //form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
1333
    $form_values['cdm_webservice_url'] .= '/';
1334
  }
1335

    
1336
  if($form_values['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)){
1337
    cache_clear_all(NULL, 'cache_cdm_ws');
1338
    // better clear secref_cache since i can not be sure if the cache has not be used during this response
1339
    cdm_api_secref_cache_clear();
1340
  }
1341

    
1342
}
1343

    
1344
function getEDITMapServiceURI(){
1345

    
1346
  if(variable_get('edit_map_server', false) == 'ALTERNATIVE'){
1347
    return (variable_get('edit_map_server_alternative', false));
1348
  } else if(variable_get('edit_map_server', false)) {
1349
    return variable_get('edit_map_server', false);
1350
  } else {
1351
    return EDIT_MAPSERVER_V1_URI;
1352
  }
1353

    
1354
}
1355

    
1356
/**
1357
 *
1358
 * @return float the version number of the currently selected edit mapserver as a float. Returns 0 on error
1359
 */
1360
function getEDITMapServiceVersionNumber() {
1361

    
1362
      $pattern = '/v(\d+\.\d+)/';
1363

    
1364
      $url = getEDITMapServiceURI();
1365
      preg_match($pattern, $url, $matches, PREG_OFFSET_CAPTURE, 3);
1366
      if( isset($matches[1]) ){
1367
        $version = 1 + $matches[1][0] -1; // convert string to float
1368
        return $version;
1369
      } else {
1370
        // report error
1371
        drupal_set_message(" Invalid version number in EDIT map service URL: '" + variable_get('edit_map_server', EDIT_MAPSERVER_V1_URI) + "'", "waring");
1372
        return 0;
1373
      }
1374
}
1375

    
1376
/**
1377
 * Implementation of hook_elements()
1378
 *
1379
 * see http://drupal.org/node/37862 for an example
1380
 */
1381
function cdm_dataportal_elements() {
1382
  $type['checkboxes_preferred'] = array(
1383
    '#input' => TRUE,
1384
    '#process' => array('expand_checkboxes_preferred' => array()),
1385
    '#after_build' => array('checkboxes_preferred_after_build')
1386
  );
1387
  return $type;
1388
}
1389

    
1390
/**
1391
 * #process function for the custom form element type 'checkbox_preferred'
1392
 */
1393
function expand_checkboxes_preferred($element){
1394

    
1395
  // first of all create the checkboxes
1396
  $element = expand_checkboxes($element);
1397

    
1398
  $children = element_children($element);
1399
  $element['table_start'] = array(
1400
    '#value' => '<table class="checkboxes_preferred"><tr><th></th><th>'.t('Enabled').'</th><th>'.t('Default').'</th></tr>',
1401
    '#weight'=>-1
1402
  );
1403
  $weight = 0;
1404
  foreach ($children as $key) {
1405
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
1406
    $element[$key]['#weight'] = $weight;
1407
    $element[$key]['#prefix'] = '<tr class="'.$odd_even.'"><td>'.t($element['#options'][$key]).'</td><td>';
1408
    $element[$key]['#suffix'] = '</td>';
1409
    unset($element[$key]['#title']);
1410
    $weight += 2;
1411
  }
1412
  $weight = 0;
1413

    
1414
  if (count($element['#options']) > 0) {
1415
    foreach ($element['#options'] as $key => $choice) {
1416
      if (!isset($element[$key.'_preferred'])) {
1417
        $element[$key.'_preferred'] = array(
1418
        '#type' => 'radio',
1419
        '#name' => $element['#parents'][0].'_preferred',
1420
        '#return_value' => check_plain($key),
1421
        '#default_value' => $element['#default_value_2'],
1422
        '#attributes' => $element['#attributes'],
1423
        '#parents' => $element['#parents'],
1424
        '#spawned' => TRUE,
1425
        '#weight' => $weight + 1,
1426
        '#prefix' => '<td>',
1427
        '#suffix' => '</td></tr>',
1428
        //'#submit' => 'submit_checkboxes_preferred'
1429
        );
1430
      }
1431
      $weight += 2;
1432
    }
1433
  }
1434

    
1435
  $element['table_end'] = array(
1436
  //'#type'=>'value',
1437
  '#value' => '</table>', '#weight'=>$weight++);
1438
  return $element;
1439
}
1440

    
1441

    
1442
function theme_checkboxes_preferred($element){
1443
  return theme('form_element',
1444
  array(
1445
      '#title' => $element['#title'],
1446
      '#description' => $element['#description'],
1447
      '#id' => $element['#id'],
1448
      '#required' => $element['#required'],
1449
      '#error' => $element['#error'],
1450
  ),
1451
  $element['#children']);
1452
}
1453

    
1454
function checkboxes_preferred_after_build($form, &$form_values){
1455

    
1456
  $parent_id = $form['#parents'][0];
1457

    
1458
  if($_POST && count($_POST) > 0){
1459
    // first pass of form processing
1460
    $preferred_layer = $_POST[$parent_id.'_preferred'];
1461
    $form['#value']['PREFERRED'] = $preferred_layer;
1462
    $form_values[$parent_id] = $form['#value'];
1463
  } else {
1464
    // second pass of form processing
1465
    $preferred_layer = $form['#value']['PREFERRED'];
1466
  }
1467

    
1468
  // also set the chosen value (not sure if this is good drupal style ....)
1469
  foreach( $children = element_children($form) as $key ){
1470
    if($form[$key]['#type'] == 'radio'){
1471
      $form[$key]['#value'] = $preferred_layer;
1472
    }
1473
  }
1474
  // the default layer mus always be enabled
1475
  $form[$preferred_layer]['#value'] = $preferred_layer;
1476

    
1477

    
1478
  return $form;
1479
}
1480

    
(12-12/12)