Project

General

Profile

Download (61.1 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
  //additional value for the null case
22
  $annotationTypeKeys[] = 'NULL_VALUE';
23
}
24
define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
25

    
26
/* taxonRelationshipTypes */
27
define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
28

    
29

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

    
39

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

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

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

    
63

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

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

    
85
function get_default_taxon_tab($index = false) {
86

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

    
107

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

    
130
function cdm_dataportal_menu_admin($may_cache, &$items){
131

    
132
  if (!$may_cache) {
133

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

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

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

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

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

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

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

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

    
256

    
257
}
258

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

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

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

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

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

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

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

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

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

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

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

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

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

    
402
    return system_settings_form($form);
403
}
404

    
405

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

    
412
  //drupal_goto('admin/settings/cdm_dataportal/layout/taxon');
413
  $form = array();
414
/*
415
  // -- tabbed pages -- //
416
  $form['cdm_dataportal_taxonpage_tabs'] = array(
417
    '#type' => 'checkbox',
418
    '#title' => t('Tabbed taxon page'),
419
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
420
    '#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.')
421
  );
422
*/
423
  $form['gen_layout'] = array(
424
    '#type' => 'fieldset',
425
      '#title' => t('Portal Layout'),
426
        '#collapsible' => FALSE,
427
        '#collapsed' => FALSE,
428
      '#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.'),
429
  );
430

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

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

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

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

    
465
  );
466

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

    
481
  return system_settings_form($form);
482
}
483

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

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

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

    
517
    return $form;
518
}
519

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

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

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

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

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

    
574
  $form['synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
575
    '#type' => 'checkbox',
576
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
577
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
578
    '#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.')
579
  );
580

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

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

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

    
606
  return system_settings_form($form);
607

    
608
}
609
*/
610

    
611
function cdm_settings_layout_taxon(){
612
  $collapsed = false;
613
  $form = array();
614

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

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

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

    
643
  $form['cdm_dataportal_show_back_to_search_results'] = array(
644
      '#type' => 'checkbox',
645
        '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
646
        '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
647
        '#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>')
648
  );
649

    
650
  /* ======  TAXON_PROFILE ====== */
651

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

    
660

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

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

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

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

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

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

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

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

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

    
737
  if( isset($feature_tree->root->children) ){
738

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

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

    
750

    
751
      if( !$feature_list_layout_settings_disabled && isset($featureNode->feature) ) {
752

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

    
755
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
756

    
757

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

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

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

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

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

    
798
      }
799

    
800
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
801
    }
802
  }
803

    
804

    
805
  //---- DISTRIBUTION LAYOUT ---- //
806

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

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

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

    
833

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

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

    
851
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
852
    '#type' => 'checkbox',
853
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
854
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
855
    '#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.')
856
  );
857

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

    
867

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

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

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

    
901

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

    
913

    
914
  return system_settings_form($form);
915
}
916

    
917
function cdm_settings_layout_search(){
918

    
919
  $form = array();
920

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

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

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

    
947
  return system_settings_form($form);
948
}
949

    
950
function cdm_settings_layout_media(){
951

    
952
  $form = array();
953

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

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

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

    
977

    
978
  return system_settings_form($form);
979
}
980

    
981

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

    
988
  $form = array();
989

    
990
  /*
991
   * GEO SERVER
992
   */
993

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

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

    
1020
    $form['geoserver']['edit_map_server_alternative'] = array(
1021
      '#type' => 'textfield',
1022
      '#title' => t('Geoservice access point - alternative URL'),
1023
      '#default_value' => variable_get('edit_map_server_alternative', ''),
1024
      '#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.')
1025
    );
1026

    
1027

    
1028
  /*
1029
   *  MAP SETTINGS
1030
   */
1031

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

    
1040
    $form['map_settings']['cdm_dataportal_geoservice_display_width'] = array(
1041
      '#type' => 'textfield',
1042
      '#title' => t('Maps width'),
1043
      '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
1044
      '#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.')
1045
    );
1046

    
1047
    $form['map_settings']['cdm_dataportal_geoservice_bounding_box'] = array(
1048
      '#type' => 'textfield',
1049
      '#title' => t('Fixed bounding box'),
1050
      '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
1051
      '#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.')
1052
    );
1053

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

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

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

    
1076
    $form['map_settings']['cdm_dataportal_map_openlayers'] = array(
1077
      '#type' => 'radios',
1078
      '#title' => '<b>'.t('Map Viewer').'</b>',
1079
      '#options' => array(1 => "OpenLayers dynamic mapviewer", 0 => "Plain image" ),
1080
      '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1081
      '#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
1082
                           on a static image. If enabled you can configure the default layer (background of your maps) below. Only one of
1083
                           them will be renderized.</li><li><em>Plain image</em> displays the map as a plain non interactive image</li></ul>')
1084
    );
1085

    
1086
    $openLayersEnabled = variable_get('cdm_dataportal_map_openlayers', 1) === 1;
1087

    
1088

    
1089
    // --- Plain Image Settings --- //
1090

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

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

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

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

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

    
1128

    
1129
    // --- OpenLayers Settings --- //
1130

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

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

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

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

    
1175
  // cdm_dataportal_geoservice_showLayerSwitcher
1176
  $form['openlayers']['cdm_dataportal_geoservice_showLayerSwitcher'] = array(
1177
    '#type' => 'checkbox',
1178
    '#title' => '<b>'.t('Show Layer Switcher').'</b>',
1179
    '#default_value' => variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE),
1180
    '#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.')
1181
  );
1182

    
1183
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1184
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1185
  $form['openlayers']['gmap_api_key'] = array(
1186
    '#type' => 'textfield',
1187
    '#title' => t('Gogle maps API key'),
1188
    '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1189
    '#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>
1190
         <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.')
1191
   );
1192

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

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

    
1208
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legendOpacity'] = array(
1209
    '#type' => 'textfield',
1210
    '#title' => t('Legend opacity'),
1211
    '#default_value' => variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'),
1212
    '#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
1213
                         to 0.0 will be not much visible.')
1214
  );
1215

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

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

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

    
1245
        return system_settings_form($form);
1246
}
1247

    
1248

    
1249
function cdm_settings_cache(){
1250

    
1251
  $form = array();
1252

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

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

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

    
1278
  return system_settings_form($form);
1279
}
1280

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

    
1286
  $out = '';
1287

    
1288
  _add_js_progressbar();
1289
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cache_all_taxa.js');
1290

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

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

    
1302

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

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

    
1322
  return $out;
1323
}
1324

    
1325

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

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

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

    
1344
}
1345

    
1346
function getEDITMapServiceURI(){
1347

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

    
1356
}
1357

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

    
1364
      $pattern = '/v(\d+\.\d+)/';
1365

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

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

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

    
1397
  // first of all create the checkboxes
1398
  $element = expand_checkboxes($element);
1399

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

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

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

    
1443

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

    
1456
function checkboxes_preferred_after_build($form, &$form_values){
1457

    
1458
  $parent_id = $form['#parents'][0];
1459

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

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

    
1479

    
1480
  return $form;
1481
}
1482

    
(12-12/12)