Project

General

Profile

Download (63.3 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 = array_keys( cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE) );
14
if(in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
15
  $annotationTypeKeys = array_flip($annotationTypeKeys);
16
  // technical annotation are off by default
17
  unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
18
  $annotationTypeKeys = array_flip($annotationTypeKeys);
19
}
20
define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
21

    
22

    
23
/* gallery variables */
24
$gallery_settings = array(
25
    "cdm_dataportal_show_taxon_thumbnails" => 1,
26
    "cdm_dataportal_show_synonym_thumbnails" => 0,
27
    "cdm_dataportal_show_thumbnail_captions" => 1,
28
    "cdm_dataportal_media_maxextend" => 120,
29
    "cdm_dataportal_media_cols" => 3,
30
    "cdm_dataportal_media_maxRows" => 1);
31

    
32

    
33
$taxon_tab_options = array(
34
  0 => 'General',
35
  1 => 'Synonymy',
36
  2 => 'Images',
37
  3 => 'Specimens',
38
  CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX => 'Last visited tab',
39
);
40

    
41
define('EDIT_MAPSERVER_V1_URI', 'http://edit.br.fgov.be/edit_wp5/v1');
42
define('EDIT_MAPSERVER_V11_URI', 'http://edit.br.fgov.be/edit_wp5/v1.1');
43
define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
44

    
45
// --- Taxon profile settings --- /
46
define (LAYOUT_SETTING_PREFIX, 'layout_');
47
define (FEATURE_TREE_LAYOUT_DEFAULTS, serialize(
48
    array(
49
    'enabled'=> false,
50
    'enclosingTag' => 'ul',
51
    'entryEnclosingTag' => 'li',
52
    'glue' => ' '
53
    )
54
  ));
55

    
56
/**
57
 * default settings for all gallerys
58
 * @var unknown_type
59
 */
60
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
61
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
62
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
63
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
64
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
65
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
66
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
67
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
68
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
69
//define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
70
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
71
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
72
define('CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
73
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
74

    
75
function getGallerySettings($gallery_config_form_name){
76
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
77
  return variable_get($gallery_config_form_name, $default_values);
78
}
79

    
80
function get_default_taxon_tab($index = false) {
81

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

    
102

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

    
125
function cdm_dataportal_menu_admin($may_cache, &$items){
126

    
127
  if (!$may_cache) {
128

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

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

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

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

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

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

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

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

    
251

    
252
}
253

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

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

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

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

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

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

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

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

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

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

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

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

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

    
397
    return system_settings_form($form);
398
}
399

    
400

    
401
/**
402
 * LAYOUT settings
403
 * @return unknown_type
404
 */
405
function cdm_settings_layout(){
406

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

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

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

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

    
450
  $annotationTypeOptions = cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE);
451
  $form['gen_layout']['footnotes']['annotations_types_as_footnotes'] = array(
452
      '#type' => 'checkboxes',
453
      '#title' => t('Annotation types as footnotes'),
454
      '#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.'),
455
      '#options' => $annotationTypeOptions,
456
      '#default_value' => variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT))
457

    
458
  );
459

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

    
474
  return system_settings_form($form);
475
}
476

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

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

    
504
    //$form['gen_layout']['theme']['#submit'][] = 'settings_validate_theme_pictures';
505
    $form['cdm_dataportal_theming']['submit'] = array(
506
      '#type' => 'submit',
507
      '#value' => t('Submit')
508
    );
509

    
510
    return $form;
511
}
512

    
513
function cdm_dataportal_theming_form_submit (&$form, &$form_values){
514
  $validators = array();
515
  //destination path where the files/banners will be saved
516
  $dest = absolute_path_to_drupal() . '/' . path_to_theme() . '/images/banners';
517
  $dest = str_replace('/', DIRECTORY_SEPARATOR, $dest);
518
  //drupal_set_message($dest);
519

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

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

    
546
    //use the banners as default theme
547
}
548

    
549
function cdm_settings_layout_synonymy(){
550
  /* ====== SYNONYMY ====== */
551
  $form['synonymy'] = array(
552
      '#type' => 'fieldset',
553
      '#title' => t('Synonymy'),
554
      '#collapsible' => TRUE,
555
      '#collapsed' => TRUE,
556
      '#description' => t('This section covers the settings related to the taxon <b>synonymy</b> tab.'),
557
  );
558

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

    
567
  $form['synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
568
    '#type' => 'checkbox',
569
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
570
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
571
    '#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.')
572
  );
573

    
574
  $name_relationships_terms = cdm_ws_get(CDM_WS_TERMVOCABULARY, UUID_NAME_RELATIONSHIP_TYPE);
575
  $name_rel_options = array();
576
  //$name_rel_options['default'] = 'Show all';
577
  foreach ($name_relationships_terms->terms as $element){
578
    $name_rel_options[$element->uuid] = t('Show "' . $element->representation_L10n_abbreviated . '" relationships');
579
  }
580

    
581
  $name_relationships_form['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' => $name_rel_options,
586
    '#description' => t('Select the name relationships you want to show for the accepted taxa.'),
587
  );
588

    
589
  $form['synonymy']['name_relationships'] = $name_relationships_form;
590
      /*
591
       $form['synonymy'][CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS] = array(
592
       '#type' => 'checkbox',
593
       '#title' => t('Show name relations of accepted taxa on taxon page'),
594
       '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT),
595
       //'#description' => t('Check this if you want the synonymy list to show all the name relationships where other names implies the accepted taxa.')
596
       '#description' => t('Check this if you want the synonymy list to show all the name relationships of accepted taxa.')
597
       );
598
     */
599
  $form['synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
600
    '#type' => 'checkbox',
601
    '#title' => t('Show taxon relations of accepted taxa on taxon page'),
602
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
603
    '#description' => t('Check this if you want the synonymy list to show the <em>"Misapplied Name for"</em> and <em>"Invalid Designation for"</em> relationships of accepted taxa.')
604
  );
605

    
606
  return system_settings_form($form);
607
      /*
608
       $form['synonymy']['cdm_dataportal_name_relations_skiptype_basionym'] = array(
609
       '#type' => 'checkbox',
610
       '#title' => t('Exclude the basionym relationship type from the taxon page'),
611
       '#default_value' => variable_get('cdm_dataportal_name_relations_skiptype_basionym', 1),
612
       '#description' => t('')
613
       );
614
       */
615
}
616

    
617
function cdm_settings_layout_taxon(){
618
  $collapsed = false;
619
  $form = array();
620

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

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

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

    
649
  $form['cdm_dataportal_show_back_to_search_results'] = array(
650
      '#type' => 'checkbox',
651
        '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
652
        '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
653
        '#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>')
654
  );
655

    
656
  /* ======  TAXON_PROFILE ====== */
657

    
658
  $form['taxon_profile'] = array(
659
      '#type' => 'fieldset',
660
      '#title' => t('Taxon profile (tab)'),
661
      '#description' => t('<p>This section covers the setting related to the taxon profile tab, also known as the <strong>"General"</strong> tab.</p>'),
662
      '#collapsible' => TRUE,
663
      '#collapsed' => TRUE,
664
  );
665

    
666

    
667
  // ---- PROFILE PICTURE ----//
668
  $form['taxon_profile']['picture'] = array(
669
      '#type' => 'fieldset',
670
      '#title' => t('Profile Picture'),
671
      '#collapsible' => TRUE,
672
      '#collapsed' => FALSE,
673
    '#description' => t('Select a profile picture for taxa. Like a facebook of plants.'),
674
  );
675

    
676
  $form['taxon_profile']['picture']['cdm_dataportal_show_default_image'] = array(
677
      '#type' => 'checkbox',
678
      '#title' => t('Enable profil picture'),
679
      '#default_value' => variable_get('cdm_dataportal_show_default_image', false),
680
      '#description'   => t('Show the profil picture.')
681
  );
682

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

    
696
  $form['taxon_profile']['picture']['cdm_dataportal_show_media'] = array(
697
      '#type' => 'select',
698
      '#title' => t('Available picture files'),
699
      '#default_value' => variable_get('cdm_dataportal_show_media', false),
700
      '#options' => $selectShowMedia,
701
      '#description'   => t('Show the profil pictures current taxon\'s children.')
702
  );
703

    
704
  //-- MEDIA THUMBNAILS --//
705
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
706
  $form_title = 'Taxon Profile Images';
707
  $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>';
708
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
709

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

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

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

    
740
  //---- LAYOUT PER FEATURE ---- //
741
  $feature_tree = cdm_ws_get(CDM_WS_FEATURETREES, variable_get(CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE));
742

    
743
  if( isset($feature_tree->root->children) ){
744

    
745
    $form_feature_list_layout = array(
746
      '#title' => t('Taxon profile layout'),
747
      '#collapsible' => TRUE,
748
      '#collapsed' => FALSE,
749
      '#type' => 'fieldset',
750
      '#description' => t('Will be availbale in a future release.'),
751
    );
752

    
753
    $feature_list_layout_settings_disabled = true;
754
    foreach( $feature_tree->root->children as $featureNode ){
755

    
756

    
757
      if( !$feature_list_layout_settings_disabled && isset($featureNode->feature) ) {
758

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

    
761
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
762

    
763

    
764
        $form_feature_list_layout[$subform_id] = array(
765
          '#tree' => TRUE,
766
           '#title' => $featureNode->feature->representation_L10n,
767
          '#collapsible' => FALSE,
768
          '#collapsed' => FALSE,
769
          '#type' => 'fieldset',
770
          '#description' => t('')
771
        );
772

    
773
        $form_feature_list_layout[$subform_id]['enabled'] = array(
774
          '#type' => 'checkbox',
775
           '#title' => t('Enable'),
776
          '#default_value' => $settings['enabled'],
777
          '#description' => t('Enable user defined layout for this feature')
778
        );
779

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

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

    
796
        $form_feature_list_layout[$subform_id]['glue'] = array(
797
          '#type' => 'textfield',
798
           '#title' => t('Glue'),
799
          '#disabled' => !$settings['enabled'],
800
          '#default_value' => $settings['glue'],
801
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'"
802
        );
803

    
804
      }
805

    
806
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
807
    }
808
  }
809

    
810

    
811
  //---- DISTRIBUTION LAYOUT ---- //
812

    
813
  $form['taxon_profile']['distribution_layout'] = array(
814
    '#title' => t('Distribution'),
815
    '#collapsible' => TRUE,
816
    '#collapsed' => FALSE,
817
    '#type' => 'fieldset',
818
    '#description' => t('Select if you want to sort or not the distribution text located below the distribution map.'),
819
  );
820

    
821
  $form['taxon_profile']['distribution_layout']['distribution_sort'] =  array(
822
  '#type'          => 'radios',
823
  '#title'         => t('Sort'),
824
  '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
825
  '#options' => array(
826
      'NO_SORT' => t('Standard (No sort)'),
827
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
828
    ));
829

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

    
839

    
840
/* ====== SYNONYMY ====== */
841
  $form['taxon_synonymy'] = array(
842
      '#type' => 'fieldset',
843
      '#title' => t('Taxon synonymy (tab)'),
844
      '#collapsible' => TRUE,
845
      '#collapsed' => TRUE,
846
      '#description' => t('This section covers the settings related to the taxon <b>synonymy</b> tab.'),
847
  );
848

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

    
857
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
858
    '#type' => 'checkbox',
859
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
860
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
861
    '#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.')
862
  );
863

    
864
  $name_relationships_terms = cdm_ws_get(CDM_WS_TERMVOCABULARY, UUID_NAME_RELATIONSHIP_TYPE);
865
  $name_rel_options = array();
866
  //$name_rel_options['default'] = 'Show all';
867
  foreach ($name_relationships_terms->terms as $element){
868
    $name_rel_options[$element->uuid] = t('Show "' . $element->representation_L10n_abbreviated . '" relationships');
869
  }
870

    
871
  $name_relationships_form['name_relationships_to_show']= array(
872
    '#type' => 'checkboxes',
873
    '#title' => t('Display name relationships'),
874
    '#default_value' => variable_get('name_relationships_to_show', 0),
875
    '#options' => $name_rel_options,
876
    '#description' => t('Select the name relationships you want to show for the accepted taxa.'),
877
  );
878

    
879
  $form['taxon_synonymy']['name_relationships'] = $name_relationships_form;
880
      /*
881
       $form['synonymy'][CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS] = array(
882
       '#type' => 'checkbox',
883
       '#title' => t('Show name relations of accepted taxa on taxon page'),
884
       '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT),
885
       //'#description' => t('Check this if you want the synonymy list to show all the name relationships where other names implies the accepted taxa.')
886
       '#description' => t('Check this if you want the synonymy list to show all the name relationships of accepted taxa.')
887
       );
888
     */
889
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
890
    '#type' => 'checkbox',
891
    '#title' => t('Show taxon relations of accepted taxa on taxon page'),
892
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
893
    '#description' => t('Check this if you want the synonymy list to show the <em>"Misapplied Name for"</em> and <em>"Invalid Designation for"</em> relationships of accepted taxa.')
894
  );
895

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

    
912

    
913
  // --- MEDIA GALLERY ---- //
914
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
915
  $form_title = 'Media gallery (tab)';
916
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
917
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
918
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
919
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
920
   <p><strong>Note:</strong> These settings are only taken into account when the standard
921
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
922
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
923

    
924

    
925
  return system_settings_form($form);
926
}
927

    
928
function cdm_settings_layout_search(){
929

    
930
  $form = array();
931

    
932
  $form['search_settings'] = array(
933
    '#type' => 'fieldset',
934
    '#title' => t('Taxa Search'),
935
    '#collapsible' => TRUE,
936
    '#collapsed' => TRUE,
937
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
938
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
939
         where they can write the text to be searched. You can find Drupal block configuration
940
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
941
  );
942

    
943
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
944
    '#type' => 'textfield',
945
    '#title' => t('Results per page'),
946
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
947
    '#description' => t('Number of results to display per page.')
948
  );
949

    
950
  // --- SEARCH TAXA GALLERY ---- //
951
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
952
  $collapsed = FALSE;
953
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
954
  $form_title = 'Taxa Search thumbnails';
955
  $form_description = 'Search results may show thumbnails. ';
956
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
957

    
958
  return system_settings_form($form);
959
}
960

    
961
function cdm_settings_layout_media(){
962

    
963
  $form = array();
964

    
965
  $form['media_settings'] = array(
966
      '#type' => 'fieldset',
967
      '#title' => t('Media display settings'),
968
      '#collapsible' => TRUE,
969
      '#collapsed' => FALSE,
970
    '#description' => t('This section covers the settings related to the taxa media, that is how each single media should be displayed.'),
971
      );
972

    
973
  $form['media_settings']['image_gallery_viewer'] =  array(
974
    '#type'          => 'select',
975
    '#title'         => t('Image viewer'),
976
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
977
    '#options' => array('default' => t('Standard image viewer'),
978
                        'fsi' => t('FSI viewer (requires FSI server!)')),
979
  );
980

    
981
  // --- MEDIA GALLERY ---- //
982
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
983
  $form_title = 'Standard viewer';
984
  $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>';
985
  //$form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
986
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
987

    
988

    
989
  return system_settings_form($form);
990
}
991

    
992

    
993
/**
994
 * GEOSERVICE and Map settings
995
 * @return unknown_type
996
 */
997
function cdm_settings_geo(){
998

    
999
  $form = array();
1000

    
1001
  /*
1002
   * GEO SERVER
1003
   */
1004

    
1005
  $form['geoserver'] = array(
1006
    '#type' => 'fieldset',
1007
    '#title' => t('Geo Server Settings'),
1008
    '#collapsible' => TRUE,
1009
    '#collapsed' => TRUE,
1010
    '#description' => t('Configuration and selection of your geo server. The Geo Server is the responsible for generating the maps.'),
1011
  );
1012

    
1013
  $form['geoserver']['edit_map_server'] = array(
1014
    '#type' => 'select',
1015
    '#title' => t('Geoservice access point URL'),
1016
    '#default_value' => variable_get('edit_map_server', EDIT_MAPSERVER_V1_URI),
1017
    '#options' => array(
1018
        EDIT_MAPSERVER_V1_URI => 'EDIT Map Server v1',
1019
        EDIT_MAPSERVER_V11_URI => 'EDIT Map Server v1.1',
1020
        /*
1021
        'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server - Mirror 1',
1022
        'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server - Mirror 2',
1023
         */
1024
        'ALTERNATIVE' => '-- Alternative URL --'
1025
        ),
1026
    '#description' => t('Select the Map Server you want the data portal to connect.'
1027
         . 'If you want to introduce a custom address just select the Alternative URL value and fill the field Geoservice'
1028
         . 'Access Point - Alternative URL with the custem ip address.')
1029
    );
1030

    
1031
    $form['geoserver']['edit_map_server_alternative'] = array(
1032
      '#type' => 'textfield',
1033
      '#title' => t('Geoservice access point - alternative URL'),
1034
      '#default_value' => variable_get('edit_map_server_alternative', ''),
1035
      '#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.')
1036
    );
1037

    
1038

    
1039
  /*
1040
   *  MAP SETTINGS
1041
   */
1042

    
1043
    $form['map_settings'] = array(
1044
      '#type' => 'fieldset',
1045
      '#title' => t('Maps settings'),
1046
      '#collapsible' => TRUE,
1047
      '#collapsed' => TRUE,
1048
      '#description' => t('Configuration of the renderized maps.'),
1049
     );
1050

    
1051
    $form['map_settings']['cdm_dataportal_geoservice_display_width'] = array(
1052
      '#type' => 'textfield',
1053
      '#title' => t('Maps size'),
1054
      '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
1055
      '#description' => t('Choose the size of your Maps. A value of 500 means the size will be 500x500, a value of 300 means the size will be 300x300.')
1056
    );
1057

    
1058
    $form['map_settings']['cdm_dataportal_geoservice_bounding_box'] = array(
1059
      '#type' => 'textfield',
1060
      '#title' => t('Fixed bounding box'),
1061
      '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
1062
      '#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.')
1063
    );
1064

    
1065
    $form['map_settings']['cdm_dataportal_geoservice_labels_on'] = array(
1066
      '#type' => 'checkbox',
1067
      '#title' => '<b>'.t('Display area labels').'</b>',
1068
      '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
1069
      '#description' => t('Check this if you like area names to be displayed in the maps. DOES IT WORKS???? ')
1070
    );
1071

    
1072
    $form['map_settings']['cdm_dataportal_geoservice_map_caption'] = array(
1073
      '#type' => 'textfield',
1074
      '#title' => t('Map caption'),
1075
      '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
1076
      '#description' => t('Define a caption for the map.')
1077
    );
1078

    
1079
    $form['map_settings']['cdm_dataportal_geoservice_distributionOpacity'] = array(
1080
      '#type' => 'textfield',
1081
      '#title' => t('Distribution layer opacity'),
1082
      '#default_value' => variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5'),
1083
      '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1084
                           fully visible, while a value near to 0.0 will be not much visible.')
1085
    );
1086

    
1087
    $form['map_settings']['cdm_dataportal_map_openlayers'] = array(
1088
      '#type' => 'radios',
1089
      '#title' => '<b>'.t('Map Viewer').'</b>',
1090
      '#options' => array(1 => "OpenLayers dynamic mapviewer", 0 => "Plain image" ),
1091
      '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1092
      '#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
1093
                           on a static image. If enabled you can configure the default layer (background of your maps) below. Only one of
1094
                           them will be renderized.</li><li><em>Plain image</em> displays the map as a plain non interactive image</li></ul>')
1095
    );
1096

    
1097
    $openLayersEnabled = variable_get('cdm_dataportal_map_openlayers', 1) === 1;
1098

    
1099

    
1100
    // --- Plain Image Settings --- //
1101

    
1102
    $form['map_image'] = array(
1103
      '#type' => 'fieldset',
1104
      '#title' => t('Plain image map settings'),
1105
      '#collapsible' => TRUE,
1106
      '#collapsed' => $openLayersEnabled,
1107
      '#description' => 'The settings in this section are still expertimental '
1108
        .'and can onyl be used with the EDIT map service version 1.1 or above.'
1109
    );
1110

    
1111
    $edit_mapserver_version = getEDITMapServiceVersionNumber();
1112
    if ($edit_mapserver_version < 1.1) {
1113
      $form['map_image']['#description'] = '<div class="messages warning">' . t("The selected EDIT map service version has to small version number: $edit_mapserver_version") . '</div>'
1114
      . $form['map_image']['#description'];
1115
    }
1116

    
1117
    $form['map_image']['map_base_layer'] = array(
1118
      '#type' => 'textfield',
1119
      '#title' => t('Background layer'),
1120
      '#default_value' => variable_get('map_base_layer', 'cyprusdivs'),
1121
      '#description' => t('Background layer. for available layers inspect')
1122
        . l(" deegree-csw ",  "http://edit2.br.fgov.be:8080/deegree-csw/md_search.jsp") . t('or')
1123
        . l(" geoserver layers ", "http://edit.br.fgov.be:8080/geoserver/rest/layers")
1124
    );
1125

    
1126
    $form['map_image']['map_bg_color'] = array(
1127
      '#type' => 'textfield',
1128
      '#title' => t('Background color'),
1129
      '#default_value' => variable_get('map_bg_color', '1874CD')
1130
    );
1131

    
1132
    $form['map_image']['map_base_layer_style'] = array(
1133
      '#type' => 'textfield',
1134
      '#title' => t('Background layer area style'),
1135
      '#default_value' => variable_get('map_base_layer_style', 'ffffff,606060,,'), // only line color by now
1136
      '#description' => t('Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}')
1137
    );
1138

    
1139

    
1140
    // --- OpenLayers Settings --- //
1141

    
1142
    $form['openlayers'] = array(
1143
      '#type' => 'fieldset',
1144
      '#title' => t('OpenLayers settings'),
1145
      '#collapsible' => TRUE,
1146
      '#collapsed' => !$openLayersEnabled,
1147
      '#description' => ''
1148
    );
1149

    
1150
    if( !$openLayersEnabled ){
1151
      $form['openlayers']['#description'] = '<div class="messages warning">' . t("The Openlayers viewer is curretnly not enabled! (see section Maps settings above )") . '</div>'
1152
      . $form['openlayers']['#description'];
1153
    }
1154

    
1155
    $baselayer_options = array(
1156
      /*
1157
       * NOTICE: must correspond to the layers defined in js/openlayers_,ap.js#getLayersByName()
1158
       */
1159
      'osgeo_vmap0' => "OpenLayers World", // EPSG:4326
1160
      'metacarta_vmap0' => "Metacarta Vmap0" , // EPSG:4326, EPSG:900913
1161
       // all others EPSG:900913
1162
      'edit-vmap0_world_basic' => 'EDIT Vmap0',
1163
      'edit-etopo1' => "ETOPO1 Global Relief Model",
1164
      'osmarender' => 'OpenStreetMap',
1165
      //'oam' => 'OpenAerialMap', // currently unavailable
1166
      'gmap' => 'Google Streets',
1167
      'gsat' => 'Google Satellite',
1168
      'ghyb' => 'Google Hybrid',
1169
      'veroad' => 'Virtual Earth Roads',
1170
      'veaer' => 'Virtual Earth Aerial',
1171
      'vehyb' => 'Virtual Earth Hybrid'
1172
       //  ,
1173
       //    'yahoo' => 'Yahoo Street',
1174
       //    'yahoosat' => 'Yahoo Satellite',
1175
       //    'yahoohyb' => 'Yahoo Hybrid'
1176
    );
1177

    
1178
    $form['openlayers']['baselayers'] = array(
1179
      '#type' => 'checkboxes_preferred',
1180
      '#title' => t('Baser Layers'),
1181
      '#options' => $baselayer_options,
1182
      '#default_value' => variable_get('baselayers', array('metacarta_vmap0' => "metacarta_vmap0", 'PREFERRED' => 'metacarta_vmap0')),
1183
      '#description' => t('Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.')
1184
     );
1185

    
1186
  // cdm_dataportal_geoservice_showLayerSwitcher
1187
  $form['openlayers']['cdm_dataportal_geoservice_showLayerSwitcher'] = array(
1188
    '#type' => 'checkbox',
1189
    '#title' => '<b>'.t('Show Layer Switcher').'</b>',
1190
    '#default_value' => variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE),
1191
    '#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.')
1192
  );
1193

    
1194
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1195
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1196
  $form['openlayers']['gmap_api_key'] = array(
1197
    '#type' => 'textfield',
1198
    '#title' => t('Gogle maps API key'),
1199
    '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1200
    '#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>
1201
         <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.')
1202
   );
1203

    
1204
  $form['cdm_dataportal_geoservice_map_legend'] = array(
1205
     '#type' => 'fieldset',
1206
     '#title' => t('Map legend'),
1207
     '#collapsible' => TRUE,
1208
     '#collapsed' => TRUE,
1209
     '#description' => t('Configure the maps legend.')
1210
  );
1211

    
1212
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
1213
    '#type' => 'checkbox',
1214
    '#title' => '<b>'.t('Display a map legend').'</b>',
1215
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
1216
    '#description' => t('Check this if you like a legend to be displayed with the maps.')
1217
  );
1218

    
1219
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legendOpacity'] = array(
1220
    '#type' => 'textfield',
1221
    '#title' => t('Legend opacity'),
1222
    '#default_value' => variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'),
1223
    '#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
1224
                         to 0.0 will be not much visible.')
1225
  );
1226

    
1227
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
1228
    '#type' => 'textfield',
1229
    '#title' => t('Font size'),
1230
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
1231
    '#description' => t('Font size in pixels.')
1232
  );
1233

    
1234
  $fontStyles = array(0 => "plane", 1 => "italic");
1235
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
1236
    '#type' => 'select',
1237
    '#title' => t('Available font styles'),
1238
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', false),
1239
    '#options' => $fontStyles,
1240
    '#description'   => t('Select a font style for the map legend.')
1241
  );
1242

    
1243
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
1244
    '#type' => 'textfield',
1245
    '#title' => t('Legend icon width'),
1246
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
1247
    '#description' => t('Legend icon width in pixels.')
1248
  );
1249
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
1250
    '#type' => 'textfield',
1251
    '#title' => t('Legend icon height'),
1252
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
1253
    '#description' => t('Legend icon height in pixels.')
1254
  );
1255

    
1256
        return system_settings_form($form);
1257
}
1258

    
1259

    
1260
function cdm_settings_cache(){
1261

    
1262
  $form = array();
1263

    
1264
  $form['cache_settings'] = array(
1265
      '#type' => 'fieldset',
1266
      '#title' => t('Cache Settings'),
1267
      '#collapsible' => FALSE,
1268
      '#collapsed' => FALSE,
1269
    '#description' => t('<p>When caching is enabled all single taxon sites are stored in an internal drupal cache doing
1270
                           the portal response of taxa pages faster. This is possible because the sites are loaded from
1271
                           the cache and are not created from scratch.</p>'),
1272
      );
1273

    
1274
  $form['cache_settings']['cdm_webservice_cache'] =  array(
1275
    '#type'          => 'checkbox',
1276
    '#title'         => t('<strong>Enable caching</strong>'),
1277
  '#options'		 => cdm_help_general_cache(),
1278
    '#default_value' => variable_get('cdm_webservice_cache', 1),
1279
    '#description'   => t('<p>Enable drupal to load taxa pages from the cache.</p>' .
1280
                         '<p><strong>Note:</strong> If taxa are modified by the editor or any other application the changes will be not
1281
                         visible till the cache is erased. Therefore developers should deactived this feature when they
1282
                         are working on the CDM Dataportal Module.</p>')
1283
    );
1284

    
1285
  $form['cache_settings']['cdm_run_cache'] = array(
1286
    '#value' => cdm_view_cache_site()
1287
  );
1288

    
1289
  return system_settings_form($form);
1290
}
1291

    
1292
/**
1293
 * @return walk and cache all taxon pages
1294
 */
1295
function cdm_view_cache_site(){
1296

    
1297
  $out = '';
1298

    
1299
  _add_js_progressbar();
1300
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cache_all_taxa.js');
1301

    
1302
  $request_params = array();
1303
  $request_params['query'] = '%';
1304
  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false); //cache only the dafault classification
1305
  $request_params['doTaxa'] = 1;
1306
  $request_params['doSynonyms'] = 0;
1307
  $request_params['doTaxaByCommonNames'] = 0;
1308

    
1309
  $search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND . ".json", null, queryString($request_params));
1310
  $search_url = uri_uriByProxy($search_url);
1311
  $taxon_page_url = url('cdm_dataportal/taxon/');
1312

    
1313

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

    
1320
  $out .= '<form id="cache_site">';
1321
  $out .= '<div>'.t('This caching process may take long time and could cause heavy load on your server').'</div>';
1322
  $out .= '<div id="progress"></div>';
1323
  $out .= '<input type="hidden" name="searchTaxaUrl" value="'.$search_url.'"/>';
1324
  $out .= '<input type="hidden" name="taxonPageUrl" value="'.$taxon_page_url.'"/>';
1325
  $out .= '<input type="button" name="start" value="'.t('Start').'"/>';
1326
  $out .= '<input type="button" name="stop" value="'.t('Stop').'"/>';
1327
  $out .= '</form>';
1328
  $out .= '</div>';
1329
  //  foreach($taxonPager->records as $taxon){
1330
  //    cdm_dataportal_taxon_view($uuid);
1331
  //  }
1332

    
1333
  return $out;
1334
}
1335

    
1336

    
1337
/**
1338
 * Implementation of hook_validate()
1339
 *
1340
 * @param $element
1341
 */
1342
function cdm_settings_validate($form_id, $form_values){
1343

    
1344
  if (!str_endsWith($form_values['cdm_webservice_url'], '/')) {
1345
    //form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
1346
    $form_values['cdm_webservice_url'] .= '/';
1347
  }
1348

    
1349
  if($form_values['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)){
1350
    cache_clear_all(NULL, 'cache_cdm_ws');
1351
    // better clear secref_cache since i can not be sure if the cache has not be used during this response
1352
    cdm_api_secref_cache_clear();
1353
  }
1354

    
1355
}
1356

    
1357
function getEDITMapServiceURI(){
1358

    
1359
  if(variable_get('edit_map_server', false) == 'ALTERNATIVE'){
1360
    return (variable_get('edit_map_server_alternative', false));
1361
  } else if(variable_get('edit_map_server', false)) {
1362
    return variable_get('edit_map_server', false);
1363
  } else {
1364
    return EDIT_MAPSERVER_V1_URI;
1365
  }
1366

    
1367
}
1368

    
1369
/**
1370
 *
1371
 * @return float the version number of the currently selected edit mapserver as a float. Returns 0 on error
1372
 */
1373
function getEDITMapServiceVersionNumber() {
1374

    
1375
      $pattern = '/v(\d+\.\d+)/';
1376

    
1377
      $url = getEDITMapServiceURI();
1378
      preg_match($pattern, $url, $matches, PREG_OFFSET_CAPTURE, 3);
1379
      if( isset($matches[1]) ){
1380
        $version = 1 + $matches[1][0] -1; // convert string to float
1381
        return $version;
1382
      } else {
1383
        // report error
1384
        drupal_set_message(" Invalid version number in EDIT map service URL: '" + variable_get('edit_map_server', EDIT_MAPSERVER_V1_URI) + "'", "waring");
1385
        return 0;
1386
      }
1387
}
1388

    
1389
/**
1390
 * Implementation of hook_elements()
1391
 *
1392
 * see http://drupal.org/node/37862 for an example
1393
 */
1394
function cdm_dataportal_elements() {
1395
  $type['checkboxes_preferred'] = array(
1396
    '#input' => TRUE,
1397
    '#process' => array('expand_checkboxes_preferred' => array()),
1398
    '#after_build' => array('checkboxes_preferred_after_build')
1399
  );
1400
  return $type;
1401
}
1402

    
1403
/**
1404
 * #process function for the custom form element type 'checkbox_preferred'
1405
 */
1406
function expand_checkboxes_preferred($element){
1407

    
1408
  // first of all create the checkboxes
1409
  $element = expand_checkboxes($element);
1410

    
1411
  $children = element_children($element);
1412
  $element['table_start'] = array(
1413
    '#value' => '<table class="checkboxes_preferred"><tr><th></th><th>'.t('Enabled').'</th><th>'.t('Default').'</th></tr>',
1414
    '#weight'=>-1
1415
  );
1416
  $weight = 0;
1417
  foreach ($children as $key) {
1418
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
1419
    $element[$key]['#weight'] = $weight;
1420
    $element[$key]['#prefix'] = '<tr class="'.$odd_even.'"><td>'.t($element['#options'][$key]).'</td><td>';
1421
    $element[$key]['#suffix'] = '</td>';
1422
    unset($element[$key]['#title']);
1423
    $weight += 2;
1424
  }
1425
  $weight = 0;
1426

    
1427
  if (count($element['#options']) > 0) {
1428
    foreach ($element['#options'] as $key => $choice) {
1429
      if (!isset($element[$key.'_preferred'])) {
1430
        $element[$key.'_preferred'] = array(
1431
        '#type' => 'radio',
1432
        '#name' => $element['#parents'][0].'_preferred',
1433
        '#return_value' => check_plain($key),
1434
        '#default_value' => $element['#default_value_2'],
1435
        '#attributes' => $element['#attributes'],
1436
        '#parents' => $element['#parents'],
1437
        '#spawned' => TRUE,
1438
        '#weight' => $weight + 1,
1439
        '#prefix' => '<td>',
1440
        '#suffix' => '</td></tr>',
1441
        //'#submit' => 'submit_checkboxes_preferred'
1442
        );
1443
      }
1444
      $weight += 2;
1445
    }
1446
  }
1447

    
1448
  $element['table_end'] = array(
1449
  //'#type'=>'value',
1450
  '#value' => '</table>', '#weight'=>$weight++);
1451
  return $element;
1452
}
1453

    
1454

    
1455
function theme_checkboxes_preferred($element){
1456
  return theme('form_element',
1457
  array(
1458
      '#title' => $element['#title'],
1459
      '#description' => $element['#description'],
1460
      '#id' => $element['#id'],
1461
      '#required' => $element['#required'],
1462
      '#error' => $element['#error'],
1463
  ),
1464
  $element['#children']);
1465
}
1466

    
1467
function checkboxes_preferred_after_build($form, &$form_values){
1468

    
1469
  $parent_id = $form['#parents'][0];
1470

    
1471
  if($_POST && count($_POST) > 0){
1472
    // first pass of form processing
1473
    $preferred_layer = $_POST[$parent_id.'_preferred'];
1474
    $form['#value']['PREFERRED'] = $preferred_layer;
1475
    $form_values[$parent_id] = $form['#value'];
1476
  } else {
1477
    // second pass of form processing
1478
    $preferred_layer = $form['#value']['PREFERRED'];
1479
  }
1480

    
1481
  // also set the chosen value (not sure if this is good drupal style ....)
1482
  foreach( $children = element_children($form) as $key ){
1483
    if($form[$key]['#type'] == 'radio'){
1484
      $form[$key]['#value'] = $preferred_layer;
1485
    }
1486
  }
1487
  // the default layer mus always be enabled
1488
  $form[$preferred_layer]['#value'] = $preferred_layer;
1489

    
1490

    
1491
  return $form;
1492
}
1493

    
(12-12/12)