Project

General

Profile

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

    
651
  /* ======  TAXON_PROFILE ====== */
652

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

    
661

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

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

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

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

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

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

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

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

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

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

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

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

    
751

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

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

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

    
758

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

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

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

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

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

    
799
      }
800

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

    
805

    
806
  //---- DISTRIBUTION LAYOUT ---- //
807

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

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

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

    
834

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

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

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

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

    
868

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

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

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

    
902

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

    
914

    
915
  return system_settings_form($form);
916
}
917

    
918
function cdm_settings_layout_search(){
919

    
920
  $form = array();
921

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

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

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

    
947
    $form['search_settings']['cdm_search_taxa'] = array(
948
    	'#type' => 'checkbox',
949
        '#title' => t('Sets the default value of <em>Search for accepted taxa</em> in the advanced search form.'),
950
        '#default_value' => variable_get('cdm_search_taxa', 1),
951
        '#description' => t('<p>If checked the <em>Search for accepted taxa </em> option will be enabled in the advanced form.</p>')
952
  	);
953

    
954
  	$form['search_settings']['cdm_search_synonyms'] = array(
955
    	'#type' => 'checkbox',
956
        '#title' => t('Sets the default value of <em>Search for synonyms</em> in the advanced search form.'),
957
        '#default_value' => variable_get('cdm_search_synonyms', 1),
958
        '#description' => t('<p>If checked the <em>Search for synonyms</em> option will be enabled in the advanced form.</p>')
959
  	);
960

    
961
  	$form['search_settings']['cdm_search_common_names'] = array(
962
    	'#type' => 'checkbox',
963
        '#title' => t('Sets the default value of <em>Search for common names</em> in the advanced search form.'),
964
        '#default_value' => variable_get('cdm_search_common_names', 0),
965
        '#description' => t('<p>If checked the <em>Search for common names</em> option will be enabled in the advanced form.</p>')
966
  	);
967

    
968
  	$form['search_settings']['cdm_search_use_default_values'] = array(
969
  	    	'#type' => 'checkbox',
970
  	        '#title' => t('Sets use of default values in the advanced search form.'),
971
  	        '#default_value' => variable_get('cdm_search_use_default_values', 1),
972
  	        '#description' => t('<p>If checked the defqult values set abovewill be used for the search.</p>')
973
  	);
974

    
975

    
976
  // --- SEARCH TAXA GALLERY ---- //
977
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
978
  $collapsed = FALSE;
979
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
980
  $form_title = 'Taxa Search thumbnails';
981
  $form_description = 'Search results may show thumbnails. ';
982
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
983

    
984
  return system_settings_form($form);
985
}
986

    
987
function cdm_settings_layout_media(){
988

    
989
  $form = array();
990

    
991
  $form['media_settings'] = array(
992
      '#type' => 'fieldset',
993
      '#title' => t('Media display settings'),
994
      '#collapsible' => TRUE,
995
      '#collapsed' => FALSE,
996
      '#description' => t('This section covers the settings related to the taxa media, that is how each single media should be displayed.'),
997
      );
998

    
999
  $form['media_settings']['image_gallery_viewer'] =  array(
1000
    '#type'          => 'select',
1001
    '#title'         => t('Image viewer'),
1002
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1003
    '#options' => array('default' => t('Standard image viewer'),
1004
                        'fsi' => t('FSI viewer (requires FSI server!)')),
1005
  );
1006

    
1007
  // --- MEDIA GALLERY ---- //
1008
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1009
  $form_title = 'Standard viewer';
1010
  $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>';
1011
  //$form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1012
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1013

    
1014

    
1015
  return system_settings_form($form);
1016
}
1017

    
1018

    
1019
/**
1020
 * GEOSERVICE and Map settings
1021
 * @return unknown_type
1022
 */
1023
function cdm_settings_geo(){
1024

    
1025
  $form = array();
1026

    
1027
  /*
1028
   * GEO SERVER
1029
   */
1030

    
1031
  $form['geoserver'] = array(
1032
    '#type' => 'fieldset',
1033
    '#title' => t('Geo Server Settings'),
1034
    '#collapsible' => TRUE,
1035
    '#collapsed' => TRUE,
1036
    '#description' => t('Configuration and selection of your geo server. The Geo Server is the responsible for generating the maps.'),
1037
  );
1038

    
1039
  $form['geoserver']['edit_map_server'] = array(
1040
    '#type' => 'select',
1041
    '#title' => t('Geoservice access point URL'),
1042
    '#default_value' => variable_get('edit_map_server', EDIT_MAPSERVER_V1_URI),
1043
    '#options' => array(
1044
        EDIT_MAPSERVER_V1_URI => 'EDIT Map Server v1',
1045
        EDIT_MAPSERVER_V11_URI => 'EDIT Map Server v1.1',
1046
        /*
1047
        'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server - Mirror 1',
1048
        'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server - Mirror 2',
1049
         */
1050
        'ALTERNATIVE' => '-- Alternative URL --'
1051
        ),
1052
    '#description' => t('Select the Map Server you want the data portal to connect.'
1053
         . 'If you want to introduce a custom address just select the Alternative URL value and fill the field Geoservice'
1054
         . 'Access Point - Alternative URL with the custem ip address.')
1055
    );
1056

    
1057
    $form['geoserver']['edit_map_server_alternative'] = array(
1058
      '#type' => 'textfield',
1059
      '#title' => t('Geoservice access point - alternative URL'),
1060
      '#default_value' => variable_get('edit_map_server_alternative', ''),
1061
      '#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.')
1062
    );
1063

    
1064

    
1065
  /*
1066
   *  MAP SETTINGS
1067
   */
1068

    
1069
    $form['map_settings'] = array(
1070
      '#type' => 'fieldset',
1071
      '#title' => t('Maps settings'),
1072
      '#collapsible' => TRUE,
1073
      '#collapsed' => TRUE,
1074
      '#description' => t('General configuration for all map types.'),
1075
     );
1076

    
1077
    $form['map_settings']['cdm_dataportal_geoservice_display_width'] = array(
1078
      '#type' => 'textfield',
1079
      '#title' => t('Maps width'),
1080
      '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
1081
      '#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.')
1082
    );
1083

    
1084
    $form['map_settings']['cdm_dataportal_geoservice_bounding_box'] = array(
1085
      '#type' => 'textfield',
1086
      '#title' => t('Fixed bounding box'),
1087
      '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
1088
      '#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.')
1089
    );
1090

    
1091
    $form['map_settings']['cdm_dataportal_geoservice_labels_on'] = array(
1092
      '#type' => 'checkbox',
1093
      '#title' => '<b>'.t('Display area labels').'</b>',
1094
      '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
1095
      '#description' => t('Check this if you like area names to be displayed in the maps. DOES IT WORKS???? ')
1096
    );
1097

    
1098
    $form['map_settings']['cdm_dataportal_geoservice_map_caption'] = array(
1099
      '#type' => 'textfield',
1100
      '#title' => t('Map caption'),
1101
      '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
1102
      '#description' => t('Define a caption for the map.')
1103
    );
1104

    
1105
    $form['map_settings']['cdm_dataportal_geoservice_distributionOpacity'] = array(
1106
      '#type' => 'textfield',
1107
      '#title' => t('Distribution layer opacity'),
1108
      '#default_value' => variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5'),
1109
      '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1110
                           fully visible, while a value near to 0.0 will be not much visible.')
1111
    );
1112

    
1113
    $form['map_settings']['cdm_dataportal_map_openlayers'] = array(
1114
      '#type' => 'radios',
1115
      '#title' => '<b>'.t('Map Viewer').'</b>',
1116
      '#options' => array(1 => "OpenLayers dynamic mapviewer", 0 => "Plain image" ),
1117
      '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1118
      '#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
1119
                           on a static image. If enabled you can configure the default layer (background of your maps) below. Only one of
1120
                           them will be renderized.</li><li><em>Plain image</em> displays the map as a plain non interactive image</li></ul>')
1121
    );
1122

    
1123
    $openLayersEnabled = variable_get('cdm_dataportal_map_openlayers', 1) == 1;
1124

    
1125

    
1126
    // --- Plain Image Settings --- //
1127

    
1128
    $form['map_image'] = array(
1129
      '#type' => 'fieldset',
1130
      '#title' => t('Plain image map settings'),
1131
      '#collapsible' => TRUE,
1132
      '#collapsed' => $openLayersEnabled,
1133
      '#description' => 'The settings in this section are still expertimental '
1134
        .'and can onyl be used with the EDIT map service version 1.1 or above.'
1135
    );
1136

    
1137
    $edit_mapserver_version = getEDITMapServiceVersionNumber();
1138
    if ($edit_mapserver_version < 1.1) {
1139
      $form['map_image']['#description'] = '<div class="messages warning">' . t("The selected EDIT map service version has to small version number: $edit_mapserver_version") . '</div>'
1140
      . $form['map_image']['#description'];
1141
    }
1142

    
1143
    $form['map_image']['map_base_layer'] = array(
1144
      '#type' => 'textfield',
1145
      '#title' => t('Background layer'),
1146
      '#default_value' => variable_get('map_base_layer', 'cyprusdivs'),
1147
      '#description' => t('Background layer. for available layers inspect')
1148
        . l(" deegree-csw ",  "http://edit2.br.fgov.be:8080/deegree-csw/md_search.jsp") . t('or')
1149
        . l(" geoserver layers ", "http://edit.br.fgov.be:8080/geoserver/rest/layers")
1150
    );
1151

    
1152
    $form['map_image']['map_bg_color'] = array(
1153
      '#type' => 'textfield',
1154
      '#title' => t('Background color'),
1155
      '#default_value' => variable_get('map_bg_color', '1874CD')
1156
    );
1157

    
1158
    $form['map_image']['map_base_layer_style'] = array(
1159
      '#type' => 'textfield',
1160
      '#title' => t('Background layer area style'),
1161
      '#default_value' => variable_get('map_base_layer_style', 'ffffff,606060,,'), // only line color by now
1162
      '#description' => t('Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}')
1163
    );
1164

    
1165

    
1166
    // --- OpenLayers Settings --- //
1167

    
1168
    $form['openlayers'] = array(
1169
      '#type' => 'fieldset',
1170
      '#title' => t('OpenLayers settings'),
1171
      '#collapsible' => TRUE,
1172
      '#collapsed' => !$openLayersEnabled,
1173
      '#description' => ''
1174
    );
1175

    
1176
    if( !$openLayersEnabled ){
1177
      $form['openlayers']['#description'] = '<div class="messages warning">' . t("The Openlayers viewer is currently not enabled! (see section Maps settings above )") . '</div>'
1178
      . $form['openlayers']['#description'];
1179
    }
1180

    
1181
    $baselayer_options = array(
1182
      /*
1183
       * NOTICE: must correspond to the layers defined in js/openlayers_,ap.js#getLayersByName()
1184
       */
1185
      'osgeo_vmap0' => "Metacarta Vmap0", // EPSG:4326: EPSG:900913
1186
//       'metacarta_vmap0' => "Metacarta Vmap0" , // EPSG:4326, EPSG:900913
1187
       // all others EPSG:900913
1188
//       'edit-vmap0_world_basic' => 'EDIT Vmap0',
1189
      'edit-etopo1' => "ETOPO1 Global Relief Model",
1190
      'mapnik' => 'OpenStreetMap',
1191
      'osmarender' => 'OpenStreetMap (Tiles@home)',
1192
      'gmap' => 'Google Streets',
1193
      'gsat' => 'Google Satellite',
1194
      'ghyb' => 'Google Hybrid',
1195
      'veroad' => 'Virtual Earth Roads',
1196
      'veaer' => 'Virtual Earth Aerial',
1197
      'vehyb' => 'Virtual Earth Hybrid'
1198
       //  ,
1199
       //    'yahoo' => 'Yahoo Street',
1200
       //    'yahoosat' => 'Yahoo Satellite',
1201
       //    'yahoohyb' => 'Yahoo Hybrid'
1202
    );
1203

    
1204
    $form['openlayers']['baselayers'] = array(
1205
      '#type' => 'checkboxes_preferred',
1206
      '#title' => t('Baser Layers'),
1207
      '#options' => $baselayer_options,
1208
      '#default_value' => variable_get('baselayers', array('metacarta_vmap0' => "metacarta_vmap0", 'PREFERRED' => 'metacarta_vmap0')),
1209
      '#description' => t('Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.')
1210
     );
1211

    
1212
  // cdm_dataportal_geoservice_showLayerSwitcher
1213
  $form['openlayers']['cdm_dataportal_geoservice_showLayerSwitcher'] = array(
1214
    '#type' => 'checkbox',
1215
    '#title' => '<b>'.t('Show Layer Switcher').'</b>',
1216
    '#default_value' => variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE),
1217
    '#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.')
1218
  );
1219

    
1220
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1221
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1222
  $form['openlayers']['gmap_api_key'] = array(
1223
    '#type' => 'textfield',
1224
    '#title' => t('Gogle maps API key'),
1225
    '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1226
    '#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>
1227
         <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.')
1228
   );
1229

    
1230
  $form['cdm_dataportal_geoservice_map_legend'] = array(
1231
     '#type' => 'fieldset',
1232
     '#title' => t('Map legend'),
1233
     '#collapsible' => TRUE,
1234
     '#collapsed' => TRUE,
1235
     '#description' => t('Configure the maps legend.')
1236
  );
1237

    
1238
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
1239
    '#type' => 'checkbox',
1240
    '#title' => '<b>'.t('Display a map legend').'</b>',
1241
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
1242
    '#description' => t('Check this if you like a legend to be displayed with the maps.')
1243
  );
1244

    
1245
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legendOpacity'] = array(
1246
    '#type' => 'textfield',
1247
    '#title' => t('Legend opacity'),
1248
    '#default_value' => variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'),
1249
    '#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
1250
                         to 0.0 will be not much visible.')
1251
  );
1252

    
1253
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
1254
    '#type' => 'textfield',
1255
    '#title' => t('Font size'),
1256
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
1257
    '#description' => t('Font size in pixels.')
1258
  );
1259

    
1260
  $fontStyles = array(0 => "plane", 1 => "italic");
1261
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
1262
    '#type' => 'select',
1263
    '#title' => t('Available font styles'),
1264
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', false),
1265
    '#options' => $fontStyles,
1266
    '#description'   => t('Select a font style for the map legend.')
1267
  );
1268

    
1269
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
1270
    '#type' => 'textfield',
1271
    '#title' => t('Legend icon width'),
1272
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
1273
    '#description' => t('Legend icon width in pixels.')
1274
  );
1275
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
1276
    '#type' => 'textfield',
1277
    '#title' => t('Legend icon height'),
1278
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
1279
    '#description' => t('Legend icon height in pixels.')
1280
  );
1281

    
1282
        return system_settings_form($form);
1283
}
1284

    
1285

    
1286
function cdm_settings_cache(){
1287

    
1288
  $form = array();
1289

    
1290
  $form['cache_settings'] = array(
1291
      '#type' => 'fieldset',
1292
      '#title' => t('Cache Settings'),
1293
      '#collapsible' => FALSE,
1294
      '#collapsed' => FALSE,
1295
    '#description' => t('<p>When caching is enabled all single taxon sites are stored in an internal drupal cache doing
1296
                           the portal response of taxa pages faster. This is possible because the sites are loaded from
1297
                           the cache and are not created from scratch.</p>'),
1298
      );
1299

    
1300
  $form['cache_settings']['cdm_webservice_cache'] =  array(
1301
    '#type'          => 'checkbox',
1302
    '#title'         => t('<strong>Enable caching</strong>'),
1303
  '#options'     => cdm_help_general_cache(),
1304
    '#default_value' => variable_get('cdm_webservice_cache', 1),
1305
    '#description'   => t('<p>Enable drupal to load taxa pages from the cache.</p>' .
1306
                         '<p><strong>Note:</strong> If taxa are modified by the editor or any other application the changes will be not
1307
                         visible till the cache is erased. Therefore developers should deactived this feature when they
1308
                         are working on the CDM Dataportal Module.</p>')
1309
    );
1310

    
1311
  $form['cache_settings']['cdm_run_cache'] = array(
1312
    '#value' => cdm_view_cache_site()
1313
  );
1314

    
1315
  return system_settings_form($form);
1316
}
1317

    
1318
/**
1319
 * @return walk and cache all taxon pages
1320
 */
1321
function cdm_view_cache_site(){
1322

    
1323
  $out = '';
1324

    
1325
  _add_js_progressbar();
1326
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cache_all_taxa.js');
1327

    
1328
  $request_params = array();
1329
  $request_params['query'] = '%';
1330
  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false); //cache only the dafault classification
1331
  $request_params['doTaxa'] = 1;
1332
  $request_params['doSynonyms'] = 0;
1333
  $request_params['doTaxaByCommonNames'] = 0;
1334

    
1335
  $search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND . ".json", null, queryString($request_params));
1336
  $search_url = uri_uriByProxy($search_url);
1337
  $taxon_page_url = url('cdm_dataportal/taxon/');
1338

    
1339

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

    
1346
  $out .= '<form id="cache_site">';
1347
  $out .= '<div>'.t('This caching process may take long time and could cause heavy load on your server').'</div>';
1348
  $out .= '<div id="progress"></div>';
1349
  $out .= '<input type="hidden" name="searchTaxaUrl" value="'.$search_url.'"/>';
1350
  $out .= '<input type="hidden" name="taxonPageUrl" value="'.$taxon_page_url.'"/>';
1351
  $out .= '<input type="button" name="start" value="'.t('Start').'"/>';
1352
  $out .= '<input type="button" name="stop" value="'.t('Stop').'"/>';
1353
  $out .= '</form>';
1354
  $out .= '</div>';
1355
  //  foreach($taxonPager->records as $taxon){
1356
  //    cdm_dataportal_taxon_view($uuid);
1357
  //  }
1358

    
1359
  return $out;
1360
}
1361

    
1362

    
1363
/**
1364
 * Implementation of hook_validate()
1365
 *
1366
 * @param $element
1367
 */
1368
function cdm_settings_validate($form_id, $form_values){
1369

    
1370
  if (!str_endsWith($form_values['cdm_webservice_url'], '/')) {
1371
    //form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
1372
    $form_values['cdm_webservice_url'] .= '/';
1373
  }
1374

    
1375
  if($form_values['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)){
1376
    cache_clear_all(NULL, 'cache_cdm_ws');
1377
    // better clear secref_cache since i can not be sure if the cache has not be used during this response
1378
    cdm_api_secref_cache_clear();
1379
  }
1380

    
1381
}
1382

    
1383
function getEDITMapServiceURI(){
1384

    
1385
  if(variable_get('edit_map_server', false) == 'ALTERNATIVE'){
1386
    return (variable_get('edit_map_server_alternative', false));
1387
  } else if(variable_get('edit_map_server', false)) {
1388
    return variable_get('edit_map_server', false);
1389
  } else {
1390
    return EDIT_MAPSERVER_V1_URI;
1391
  }
1392

    
1393
}
1394

    
1395
/**
1396
 *
1397
 * @return float the version number of the currently selected edit mapserver as a float. Returns 0 on error
1398
 */
1399
function getEDITMapServiceVersionNumber() {
1400

    
1401
      $pattern = '/v([\d\.]+)$/';
1402

    
1403
      $url = getEDITMapServiceURI();
1404
      preg_match($pattern, $url, $matches, PREG_OFFSET_CAPTURE, 3);
1405
      if( isset($matches[1]) ){
1406
        $version = 1 + $matches[1][0] -1; // convert string to float
1407
        return $version;
1408
      } else {
1409
        // report error
1410
        drupal_set_message(" Invalid version number in EDIT map service URL: '" + variable_get('edit_map_server', EDIT_MAPSERVER_V1_URI) + "'", "waring");
1411
        return 0;
1412
      }
1413
}
1414

    
1415
/**
1416
 * Implementation of hook_elements()
1417
 *
1418
 * see http://drupal.org/node/37862 for an example
1419
 */
1420
function cdm_dataportal_elements() {
1421
  $type['checkboxes_preferred'] = array(
1422
    '#input' => TRUE,
1423
    '#process' => array('expand_checkboxes_preferred' => array()),
1424
    '#after_build' => array('checkboxes_preferred_after_build')
1425
  );
1426
  return $type;
1427
}
1428

    
1429
/**
1430
 * #process function for the custom form element type 'checkbox_preferred'
1431
 */
1432
function expand_checkboxes_preferred($element){
1433

    
1434
  // first of all create the checkboxes
1435
  $element = expand_checkboxes($element);
1436

    
1437
  $children = element_children($element);
1438
  $element['table_start'] = array(
1439
    '#value' => '<table class="checkboxes_preferred"><tr><th></th><th>'.t('Enabled').'</th><th>'.t('Default').'</th></tr>',
1440
    '#weight'=>-1
1441
  );
1442
  $weight = 0;
1443
  foreach ($children as $key) {
1444
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
1445
    $element[$key]['#weight'] = $weight;
1446
    $element[$key]['#prefix'] = '<tr class="'.$odd_even.'"><td>'.t($element['#options'][$key]).'</td><td>';
1447
    $element[$key]['#suffix'] = '</td>';
1448
    unset($element[$key]['#title']);
1449
    $weight += 2;
1450
  }
1451
  $weight = 0;
1452

    
1453
  if (count($element['#options']) > 0) {
1454
    foreach ($element['#options'] as $key => $choice) {
1455
      if (!isset($element[$key.'_preferred'])) {
1456
        $element[$key.'_preferred'] = array(
1457
        '#type' => 'radio',
1458
        '#name' => $element['#parents'][0].'_preferred',
1459
        '#return_value' => check_plain($key),
1460
        '#default_value' => $element['#default_value_2'],
1461
        '#attributes' => $element['#attributes'],
1462
        '#parents' => $element['#parents'],
1463
        '#spawned' => TRUE,
1464
        '#weight' => $weight + 1,
1465
        '#prefix' => '<td>',
1466
        '#suffix' => '</td></tr>',
1467
        //'#submit' => 'submit_checkboxes_preferred'
1468
        );
1469
      }
1470
      $weight += 2;
1471
    }
1472
  }
1473

    
1474
  $element['table_end'] = array(
1475
  //'#type'=>'value',
1476
  '#value' => '</table>', '#weight'=>$weight++);
1477
  return $element;
1478
}
1479

    
1480

    
1481
function theme_checkboxes_preferred($element){
1482
  return theme('form_element',
1483
  array(
1484
      '#title' => $element['#title'],
1485
      '#description' => $element['#description'],
1486
      '#id' => $element['#id'],
1487
      '#required' => $element['#required'],
1488
      '#error' => $element['#error'],
1489
  ),
1490
  $element['#children']);
1491
}
1492

    
1493
function checkboxes_preferred_after_build($form, &$form_values){
1494

    
1495
  $parent_id = $form['#parents'][0];
1496

    
1497
  if($_POST && count($_POST) > 0){
1498
    // first pass of form processing
1499
    $preferred_layer = $_POST[$parent_id.'_preferred'];
1500
    $form['#value']['PREFERRED'] = $preferred_layer;
1501
    $form_values[$parent_id] = $form['#value'];
1502
  } else {
1503
    // second pass of form processing
1504
    $preferred_layer = $form['#value']['PREFERRED'];
1505
  }
1506

    
1507
  // also set the chosen value (not sure if this is good drupal style ....)
1508
  foreach( $children = element_children($form) as $key ){
1509
    if($form[$key]['#type'] == 'radio'){
1510
      $form[$key]['#value'] = $preferred_layer;
1511
    }
1512
  }
1513
  // the default layer mus always be enabled
1514
  $form[$preferred_layer]['#value'] = $preferred_layer;
1515

    
1516

    
1517
  return $form;
1518
}
1519

    
(12-12/12)