Project

General

Profile

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

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

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

    
13
/* gallery variables */
14
$gallery_settings = array(
15
    "cdm_dataportal_show_taxon_thumbnails" => 1,
16
    "cdm_dataportal_show_synonym_thumbnails" => 0,
17
    "cdm_dataportal_show_thumbnail_captions" => 1,
18
    "cdm_dataportal_media_maxextend" => 120,
19
    "cdm_dataportal_media_cols" => 3,
20
    "cdm_dataportal_media_maxRows" => 1);
21

    
22

    
23
$taxon_tab_options = array(
24
  0 => 'General',
25
  1 => 'Synonymy',
26
  2 => 'Images',
27
  3 => 'Specimens',
28
  CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX => 'Last visited tab',
29
);
30

    
31
define('EDIT_MAPSERVER_V1_URI', 'http://edit.br.fgov.be/edit_wp5/v1');
32
define('EDIT_MAPSERVER_V11_URI', 'http://edit.br.fgov.be/edit_wp5/v1.1');
33
define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
34

    
35
// --- Taxon profile settings --- /
36
define (LAYOUT_SETTING_PREFIX, 'layout_');
37
define (FEATURE_TREE_LAYOUT_DEFAULTS, serialize(
38
    array(
39
    'enabled'=> false,
40
    'enclosingTag' => 'ul',
41
    'entryEnclosingTag' => 'li',
42
    'glue' => ' '
43
    )
44
  ));
45

    
46
/**
47
 * default settings for all gallerys
48
 * @var unknown_type
49
 */
50
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
51
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
52
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
53
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
54
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
55
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
56
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
57
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
58
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
59
//define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
60
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
61
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
62
define('CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
63
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
64

    
65
function getGallerySettings($gallery_config_form_name){
66
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
67
  return variable_get($gallery_config_form_name, $default_values);
68
}
69

    
70
function get_default_taxon_tab($index = false) {
71

    
72
  global $user;
73
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
74
  $user_tab_active = 'cdm_dataportal_' .$user->uid . '_default_tab_active';
75
  $user_tab = 'cdm_dataportal_' .$user->uid . '_default_tab';
76
  //get the user value
77
  $user_tab_on = variable_get($user_tab_active, false);
78
  if($user_tab_on){
79
    $user_value = variable_get($user_tab, 0);
80
    $index_value = $user_value;
81
  //get the system value
82
  }else{
83
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
84
    $index_value = $system_value;
85
  }
86
  if (!index){
87
     return ($values[$index_value]);
88
  }else{
89
     return $index_value;
90
  }
91

    
92

    
93
  switch ($value){
94
    case 0:
95
      $res = 'General';
96
      break;
97
    case 1:
98
      $res = 'Synonymy';
99
      break;
100
    case 2:
101
      $res = 'Images';
102
      break;
103
    case 3:
104
      $res = 'Specimens';
105
      break;
106
    case 4:
107
      $res = 'last_visited_tab';
108
      break;
109
    default:
110
      $res = 'General';
111
  }
112
  return $res;
113
}
114

    
115
function cdm_dataportal_menu_admin($may_cache, &$items){
116

    
117
  if (!$may_cache) {
118

    
119
    $items[] = array(
120
      'path' => 'admin/settings/cdm_dataportal',
121
      'title' => t('CDM Dataportal'),
122
      'description' => t('Setting for the CDM DataPortal'),
123
      'access' => user_access('administer cdm_dataportal'),
124
      'callback' => 'drupal_get_form',
125
      'callback arguments' => array('cdm_settings_general'),
126
      'type' => MENU_NORMAL_ITEM,
127
    );
128

    
129
    $items[] = array(
130
      'path' => 'admin/settings/cdm_dataportal/general',
131
      'title' => t('General'),
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
      'weight' => 0,
137
      'type' => MENU_LOCAL_TASK,
138
    );
139

    
140
    $items[] = array(
141
      'path' => 'admin/settings/cdm_dataportal/cachesite',
142
      'title' => t('Cache'),
143
      'description' => t('Cache'),
144
      'access' => user_access('administer cdm_dataportal'),
145
      'callback' => 'drupal_get_form',
146
      'callback arguments' => array('cdm_settings_cache'),
147
      'weight' => 10,
148
      'type' => MENU_LOCAL_TASK,
149
    );
150

    
151
    $items[] = array(
152
      'path' => 'admin/settings/cdm_dataportal/geo',
153
      'title' => t('Geo & Map'),
154
      'description' => t('Geo & Map'),
155
      'access' => user_access('administer cdm_dataportal'),
156
      'callback' => 'drupal_get_form',
157
      'callback arguments' => array('cdm_settings_geo'),
158
      'weight' => 1,
159
      'type' => MENU_LOCAL_TASK,
160
    );
161

    
162
    $items[] = array(
163
      'path' => 'admin/settings/cdm_dataportal/layout',
164
      'title' => t('Layout'),
165
      'description' => t('Configure and adjust the layout of your DataPortal '),
166
      'access' => user_access('administer cdm_dataportal'),
167
      'callback' => 'drupal_get_form',
168
      'callback arguments' => array('cdm_settings_layout'),
169
      'weight' => 2,
170
      'type' => MENU_LOCAL_TASK,
171
    );
172

    
173
    $items[] = array(
174
      'path' => 'admin/settings/cdm_dataportal/layout/taxon',
175
      'title' => t('Taxon'),
176
      'description' => t('Configure and adjust the layout of your DataPortal '),
177
      'access' => user_access('administer cdm_dataportal'),
178
      'callback' => 'drupal_get_form',
179
      'callback arguments' => array('cdm_settings_layout_taxon'),
180
      'weight' => 1,
181
      'type' => MENU_LOCAL_TASK,
182
    );
183
/*
184
    $items[] = array(
185
      'path' => 'admin/settings/cdm_dataportal/layout/synonymy',
186
      'title' => t('Synonymy'),
187
      'description' => t('Configure and adjust the layout of your DataPortal '),
188
      'access' => user_access('administer cdm_dataportal'),
189
      'callback' => 'drupal_get_form',
190
      'callback arguments' => array('cdm_settings_layout_synonymy'),
191
      'weight' => 1,
192
      'type' => MENU_LOCAL_TASK,
193
    );
194

    
195
    $items[] = array(
196
      'path' => 'admin/settings/cdm_dataportal/layout/specimens',
197
      'title' => t('Specimens'),
198
      'description' => t('Configure and adjust the layout of your DataPortal '),
199
      'access' => user_access('administer cdm_dataportal'),
200
      'callback' => 'drupal_get_form',
201
      'callback arguments' => array('cdm_settings_layout_specimens'),
202
      'weight' => 1,
203
      'type' => MENU_LOCAL_TASK,
204
    );
205
*/
206
    $items[] = array(
207
      'path' => 'admin/settings/cdm_dataportal/layout/search',
208
      'title' => t('Search'),
209
      'description' => t('Configure and adjust the layout of your DataPortal '),
210
      'access' => user_access('administer cdm_dataportal'),
211
      'callback' => 'drupal_get_form',
212
      'callback arguments' => array('cdm_settings_layout_search'),
213
      'weight' => 2,
214
      'type' => MENU_LOCAL_TASK,
215
    );
216

    
217
    $items[] = array(
218
      'path' => 'admin/settings/cdm_dataportal/layout/media',
219
      'title' => t('Media'),
220
      'description' => t('Configure and adjust the layout of your DataPortal '),
221
      'access' => user_access('administer cdm_dataportal'),
222
      'callback' => 'drupal_get_form',
223
      'callback arguments' => array('cdm_settings_layout_media'),
224
      'weight' => 3,
225
      'type' => MENU_LOCAL_TASK,
226
    );
227
/*   Path to banners configuration (DEFAULT THEME)
228
    $items[] = array(
229
      'path' => 'admin/settings/cdm_dataportal/layout/theme',
230
      'title' => t('Theme'),
231
      'description' => t('Configure the drupal theme of your DataPortal '),
232
      'access' => user_access('administer cdm_dataportal'),
233
      'callback' => 'drupal_get_form',
234
      'callback arguments' => array('cdm_dataportal_theming_form'),
235
      'weight' => 4,
236
      'type' => MENU_LOCAL_TASK,
237
        );
238
*/
239
  }
240

    
241

    
242
}
243

    
244
function cdm_help_general_cache(){
245
  $form = array();
246
  $form['cache_help'] = array(
247
    '#type' => 'fieldset',
248
  '#title' => t('Help'),
249
  '#collapsible' => TRUE,
250
  '#collapsed' => TRUE,
251
  );
252
  $form['cache_help']['test'] = array('#value' => t('probando'));
253
  return drupal_render($form);
254
  $res = array();
255
  $res['default'] = drupal_render($help);
256
  return $res;
257
}
258

    
259
/**
260
 * Configures the settings form for the CDM-API module.
261
 *
262
 * @return Array Drupal settings form
263
 */
264
function cdm_settings_general(){
265

    
266
  $form['cdm_webservice'] = array(
267
      '#type' => 'fieldset',
268
      '#title' => t('CDM Server'),
269
      '#collapsible' => FALSE,
270
      '#collapsed' => FALSE,
271
    '#description' => t('<em>CDM Server</em> makes possible the dialogue with
272
                         <em>CDM Data Portal</em> thanks to his web services.'),
273
  );
274

    
275
  $form['cdm_webservice']['cdm_webservice_url'] =  array(
276
    '#type' => 'textfield',
277
    '#title'         => t('CDM web service URL'),
278
    '#description'   => t('This is the ip address of the location of the CDM Web Server which contains
279
                           your collection database. The address must follow the format <em>"http://X:Y/Z"</em>
280
                           where "<em>X</em>" is the ip address of the machine where the server is running, "<em>Y</em>" is
281
                           the port number where the server is listening and "<em>Z</em>" the name of the database
282
                           where your collection is, e.g. <em>"http://160.45.63.201:8080/palmae"</em>'),
283
    '#default_value' => variable_get('cdm_webservice_url', NULL),
284
  );
285

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

    
321
    $form['cdm_webservice']['proxy'] = array(
322
      '#type' => 'fieldset',
323
      '#title' => t('Proxy'),
324
      '#collapsible' => TRUE,
325
      '#collapsed' => TRUE
326
    );
327

    
328
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] =  array(
329
    '#type' => 'textfield',
330
    '#title'         => t('Proxy URL'),
331
    '#description'   => t('If this proxy url is set the cdm api tries
332
    to connect the web service over the given proxy server.
333
    Otherwise proxy usage is deactivated.'),
334
    '#default_value' => variable_get('cdm_webservice_proxy_url', false),
335
    );
336

    
337
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] =  array(
338
    '#type' => 'textfield',
339
    '#title'         => t('Proxy port'),
340
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
341
    );
342

    
343
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] =  array(
344
    '#type' => 'textfield',
345
    '#title'         => t('Login'),
346
    '#default_value' => variable_get('cdm_webservice_proxy_usr', false),
347
    );
348

    
349
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] =  array(
350
    '#type' => 'textfield',
351
    '#title'         => t('Password'),
352
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', false),
353
    );
354

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

    
369
    $form['cdm_dataportal'][CDM_TAXONOMICTREE_UUID] = array(
370
      '#type' => 'select',
371
      '#title'         => t('Available classifications'),
372
      '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, false),
373
      '#options' => cdm_get_taxontrees_as_options(),
374
      '#description'   => t('Select the default taxa classification for your <em>taxon tree</em>,
375
                             the other classifications will be also available but with a manual user change.')
376
    );
377

    
378
    $form['cdm_dataportal']['taxontree_ranklimit'] =  array(
379
    '#type'          => 'select',
380
    '#title'         => t('Rank of highest displayed taxon'),
381
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT), //before DEFAULT_TAXONTREE_RANKLIMIT_UUID
382
    '#options'       => cdm_rankVocabulary_as_option(),
383
    '#description'   => t('This is the rank of the highest displayed taxon in the <em>taxon tree</em>. You can
384
                           select here which rank should be at the top level of the tree structure.'),
385
  );
386

    
387
    return system_settings_form($form);
388
}
389

    
390
function gen_layout_form_submit ($form, $form_values) {
391
  drupal_set_message('This is a test!');
392
}
393

    
394

    
395
/**
396
 * LAYOUT settings
397
 * @return unknown_type
398
 */
399
function cdm_settings_layout(){
400

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

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

    
430
  $form['gen_layout']['footnotes']['cdm_dataportal_all_footnotes'] = array(
431
      '#type' => 'checkbox',
432
      '#title' => t('Do not show footnotes'),
433
      '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
434
      '#description' => t('Check this if you do not want to show any footnotes')
435
  );
436

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

    
444
  //--- Advanced Search ---//
445
  $form['gen_layout']['asearch'] = array(
446
      '#type' => 'fieldset',
447
      '#title' => t('Advanced search'),
448
      '#collapsible' => FALSE,
449
      '#collapsed' => FALSE,
450
    );
451
    $form['gen_layout']['asearch']['cdm_dataportal_show_advanced_search'] = array(
452
      '#type' => 'checkbox',
453
      '#title' => t('Show advanced search link'),
454
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
455
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
456
    );
457

    
458
  return system_settings_form($form);
459
}
460

    
461
function cdm_dataportal_theming_form (){
462
    //--- Theme ---//
463
/*
464
    $form['cdm_dataportal_theming'] = array(
465
      '#type' => 'fieldset',
466
      '#title' => t('Theme Images'),
467
      '#collapsible' => FALSE,
468
      '#collapsed' => FALSE,
469
    );
470
*/
471
  $form = array('#attributes' => array('enctype' => 'multipart/form-data'));
472

    
473
    $form['cdm_dataportal_theming_right_image'] = array(
474
        '#type' => 'file',
475
        '#title' => t('Select top right image'),
476
        '#description' => t('Maximum dimensions are %dimensions and the maximum size is %size kB.',
477
                            array('%dimensions' =>  '250x250', '%size' => '30')),
478
    );
479
    $form['cdm_dataportal_theming_middle_image'] = array(
480
        '#type' => 'file',
481
        '#title' => t('Select top middle image'),
482
    );
483
    $form['test'] = array(
484
        '#type' => 'textfield',
485
        '#title' => t('test')
486
    );
487

    
488
    //$form['gen_layout']['theme']['#submit'][] = 'settings_validate_theme_pictures';
489
    $form['cdm_dataportal_theming']['submit'] = array(
490
      '#type' => 'submit',
491
      '#value' => t('Submit')
492
    );
493

    
494
    return $form;
495
}
496

    
497
function cdm_dataportal_theming_form_submit (&$form, &$form_values){
498
  $validators = array();
499
  //destination path where the files/banners will be saved
500
  $dest = absolute_path_to_drupal() . '/' . path_to_theme() . '/images/banners';
501
  $dest = str_replace('/', DIRECTORY_SEPARATOR, $dest);
502
  //drupal_set_message($dest);
503

    
504
  //check if directory exists
505
  if (!file_exists($dest)){
506
        if(!mkdir($dest, 0777, true)){//TODO: add rights, which rights should I add?
507
            drupal_set_message('Fail uploading the files; the directory '
508
                               . $dest . ' could not be created.',
509
                               'warning');
510
        }
511
  }
512
  //check if files already exist
513
  //if (file_exists($dest)) {
514
  //}
515

    
516
  //save the files
517
    $file = file_check_upload('cdm_dataportal_theming_middle_image');
518
    if ($file){
519
        $file = file_save_upload($file, 'files');
520
        drupal_set_message($file->filepath);
521
        file_move($file->filepath, $dest);
522
    }else{
523
      drupal_set_message('Fail uploading the file, the file is not accepted.', 'warning');
524
    }
525
  //use banners in the selected theme
526
    //if (!copy($file, $file.'.bak')) {
527
    //    print ("failed to copy $file...<br>\n");
528
    //}
529

    
530
    //use the banners as default theme
531
}
532

    
533
function cdm_settings_layout_synonymy(){
534
  /* ====== SYNONYMY ====== */
535
  $form['synonymy'] = array(
536
      '#type' => 'fieldset',
537
      '#title' => t('Synonymy'),
538
      '#collapsible' => TRUE,
539
      '#collapsed' => FALSE,
540
      '#description' => t('This section covers the settings related to the taxon <b>synonymy</b> tab.'),
541
  );
542

    
543
  $form['synonymy']['cdm_dataportal_nomref_in_title'] = array(
544
    '#type' => 'checkbox',
545
    '#title' => t('Show accepted taxon on top of the synonymy'),
546
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
547
    '#description' => t('If checked, the first homotypic taxon is a repetition of the accepted taxon most likely
548
                        with the full nomenclatural reference (depending on the currently chosen theme).')
549
  );
550

    
551
  $form['synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
552
    '#type' => 'checkbox',
553
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
554
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
555
    '#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.')
556
  );
557

    
558
  $name_relationships_terms = cdm_ws_get(CDM_WS_TERMVOCABULARY, UUID_NAME_RELATIONSHIP_TYPE);
559
  $name_rel_options = array();
560
  //$name_rel_options['default'] = 'Show all';
561
  foreach ($name_relationships_terms->terms as $element){
562
    $name_rel_options[$element->uuid] = t('Show "' . $element->representation_L10n_abbreviated . '" relationships');
563
  }
564

    
565
  $name_relationships_form['name_relationships_to_show']= array(
566
    '#type' => 'checkboxes',
567
    '#title' => t('Display name relationships'),
568
    '#default_value' => variable_get('name_relationships_to_show', 0),
569
    '#options' => $name_rel_options,
570
    '#description' => t('Select the name relationships you want to show for the accepted taxa.'),
571
  );
572

    
573
  $form['synonymy']['name_relationships'] = $name_relationships_form;
574
      /*
575
       $form['synonymy'][CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS] = array(
576
       '#type' => 'checkbox',
577
       '#title' => t('Show name relations of accepted taxa on taxon page'),
578
       '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT),
579
       //'#description' => t('Check this if you want the synonymy list to show all the name relationships where other names implies the accepted taxa.')
580
       '#description' => t('Check this if you want the synonymy list to show all the name relationships of accepted taxa.')
581
       );
582
     */
583
  $form['synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
584
    '#type' => 'checkbox',
585
    '#title' => t('Show taxon relations of accepted taxa on taxon page'),
586
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
587
    '#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.')
588
  );
589

    
590
  return system_settings_form($form);
591
      /*
592
       $form['synonymy']['cdm_dataportal_name_relations_skiptype_basionym'] = array(
593
       '#type' => 'checkbox',
594
       '#title' => t('Exclude the basionym relationship type from the taxon page'),
595
       '#default_value' => variable_get('cdm_dataportal_name_relations_skiptype_basionym', 1),
596
       '#description' => t('')
597
       );
598
       */
599
}
600

    
601
function cdm_settings_layout_taxon(){
602
  $collapsed = false;
603
  $form = array();
604

    
605
  /* ======  TAXON_PROFILE ====== */
606

    
607
  $form['taxon_profile'] = array(
608
      '#type' => 'fieldset',
609
      '#title' => t('Taxon profile'),
610
      '#description' => t('<p>This section covers the setting related to the taxon profile tab, also known as the <strong>"General"</strong> tab.
611
                      It is possible to split the taxon profile in different tabs, visit the section Taxon tabs to discover and configure the tabs</p>'),
612
      '#collapsible' => FALSE,
613
      '#collapsed' => FALSE,
614
  );
615

    
616
  $form['taxon_profile']['cdm_dataportal_show_back_to_search_results'] = array(
617
      '#type' => 'checkbox',
618
        '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
619
        '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
620
        '#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>')
621
  );
622

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

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

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

    
651

    
652
  // ---- PROFILE PICTURE ----//
653
  $form['taxon_profile']['picture'] = array(
654
      '#type' => 'fieldset',
655
      '#title' => t('Profile Picture'),
656
      '#collapsible' => TRUE,
657
      '#collapsed' => FALSE,
658
    '#description' => t('Select a profile picture for taxa. Like a facebook of plants.'),
659
  );
660

    
661
  $form['taxon_profile']['picture']['cdm_dataportal_show_default_image'] = array(
662
      '#type' => 'checkbox',
663
      '#title' => t('Enable profil picture'),
664
      '#default_value' => variable_get('cdm_dataportal_show_default_image', false),
665
      '#description'   => t('Show the profil picture.')
666
  );
667

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

    
681
  $form['taxon_profile']['picture']['cdm_dataportal_show_media'] = array(
682
      '#type' => 'select',
683
      '#title' => t('Available picture files'),
684
      '#default_value' => variable_get('cdm_dataportal_show_media', false),
685
      '#options' => $selectShowMedia,
686
      '#description'   => t('Show the profil pictures current taxon\'s children.')
687
  );
688

    
689
  // ---- FEATURE TREE ---- //
690
  $form['taxon_profile']['taxon_profile'] = array(
691
  '#type' => 'fieldset',
692
     '#title' => t('Features'),
693
     '#collapsible' => TRUE,
694
     '#collapsed' => FALSE,
695
  '#description' => t('This section covers settings related to the taxon\'s <em>Feature Tree</em>. The <em>feature tree</em> are the taxon\'s
696
                        features such description, distribution, common names, etc. that drupal will render at his taxon profile page.'),
697
  );
698

    
699
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID] = array(
700
      '#type' => 'radios',
701
      '#title'         => t('Taxon profile sections'),
702
      '#default_value' => variable_get(CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE),
703
      '#options' => cdm_get_featureTrees_as_options(TRUE),
704
      '#description'   => t('Select the Feature Tree to be displayed at the taxon profile. Click "Show Details" to see the Feature Tree elemets.'
705
      )
706
  );
707

    
708
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
709
    '#type' => 'radios',
710
    '#title'         => t('Natural language representation of structured descriptions'),
711
    '#default_value' => variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, null),
712
    '#options' => cdm_get_featureTrees_as_options(),
713
    '#description'   => t('Taxon descriptions can be stored in a highly structured form.'.
714
      ' The feature tree selected here will be used to generate textual representation in natural language.'
715
      //.' If there is no applicable FeatureTree you can create a new one using the <a href="">FeatureTreeManager</a>'
716
    )
717
  );
718

    
719
  //---- LAYOUT PER FEATURE ---- //
720
  $feature_tree = cdm_ws_get(CDM_WS_FEATURETREES, variable_get(CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE));
721

    
722
  if( isset($feature_tree->root->children) ){
723

    
724
    $form_feature_list_layout = array(
725
      '#title' => t('Taxon profile layout'),
726
      '#collapsible' => TRUE,
727
      '#collapsed' => FALSE,
728
      '#type' => 'fieldset',
729
      '#description' => t('Will be availbale in a future release.'),
730
    );
731

    
732
    $feature_list_layout_settings_disabled = true;
733
    foreach( $feature_tree->root->children as $featureNode ){
734

    
735

    
736
      if( !$feature_list_layout_settings_disabled && isset($featureNode->feature) ) {
737

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

    
740
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
741

    
742

    
743
        $form_feature_list_layout[$subform_id] = array(
744
          '#tree' => TRUE,
745
           '#title' => $featureNode->feature->representation_L10n,
746
          '#collapsible' => FALSE,
747
          '#collapsed' => FALSE,
748
          '#type' => 'fieldset',
749
          '#description' => t('')
750
        );
751

    
752
        $form_feature_list_layout[$subform_id]['enabled'] = array(
753
          '#type' => 'checkbox',
754
           '#title' => t('Enable'),
755
          '#default_value' => $settings['enabled'],
756
          '#description' => t('Enable user defined layout for this feature')
757
        );
758

    
759
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
760
          '#type' => 'textfield',
761
           '#title' => t('Enclosing tag'),
762
          '#disabled' => !$settings['enabled'],
763
          '#default_value' => $settings['enclosingTag'],
764
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'"
765
        );
766

    
767
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
768
          '#type' => 'textfield',
769
           '#title' => t('Entry enclosing tag'),
770
          '#disabled' => !$settings['enabled'],
771
          '#default_value' => $settings['entryEnclosingTag'],
772
          '#description' => t('Default is: ') . "'<code>". $systemDefaults['entryEnclosingTag'] ."</code>'"
773
        );
774

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

    
783
      }
784

    
785
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
786
    }
787
  }
788

    
789

    
790
  //---- DISTRIBUTION LAYOUT ---- //
791

    
792
  $form['taxon_profile']['distribution_layout'] = array(
793
    '#title' => t('Distribution'),
794
    '#collapsible' => TRUE,
795
    '#collapsed' => FALSE,
796
    '#type' => 'fieldset',
797
    '#description' => t('Select if you want to sort or not the distribution text located below the distribution map.'),
798
  );
799

    
800
  $form['taxon_profile']['distribution_layout']['distribution_sort'] =  array(
801
  '#type'          => 'radios',
802
  '#title'         => t('Sort'),
803
  '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
804
  '#options' => array(
805
      'NO_SORT' => t('Standard (No sort)'),
806
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
807
    ));
808

    
809
   $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] =  array(
810
  '#type'          => 'checkbox',
811
  '#title'         => t('Show TextData elements on top of the map'),
812
  '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
813
  '#description' => t('Check this if you want to appear all <code>TextData</code> elements on top of the map.
814
    Otherwise all <code>TextData</code> distribution elements will be listed below the other area elements.
815
    This option is useful if you need to have descriptive texts for each distribution map.'),
816
  );
817

    
818

    
819
/* ====== SYNONYMY ====== */
820
  $form['taxon_profile']['synonymy'] = array(
821
      '#type' => 'fieldset',
822
      '#title' => t('Taxon Synonymy (Tab)'),
823
      '#collapsible' => TRUE,
824
      '#collapsed' => FALSE,
825
      '#description' => t('This section covers the settings related to the taxon <b>synonymy</b> tab.'),
826
  );
827

    
828
  $form['taxon_profile']['synonymy']['cdm_dataportal_nomref_in_title'] = array(
829
    '#type' => 'checkbox',
830
    '#title' => t('Show accepted taxon on top of the synonymy'),
831
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
832
    '#description' => t('If checked, the first homotypic taxon is a repetition of the accepted taxon most likely
833
                        with the full nomenclatural reference (depending on the currently chosen theme).')
834
  );
835

    
836
  $form['taxon_profile']['synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
837
    '#type' => 'checkbox',
838
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
839
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
840
    '#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.')
841
  );
842

    
843
  $name_relationships_terms = cdm_ws_get(CDM_WS_TERMVOCABULARY, UUID_NAME_RELATIONSHIP_TYPE);
844
  $name_rel_options = array();
845
  //$name_rel_options['default'] = 'Show all';
846
  foreach ($name_relationships_terms->terms as $element){
847
    $name_rel_options[$element->uuid] = t('Show "' . $element->representation_L10n_abbreviated . '" relationships');
848
  }
849

    
850
  $name_relationships_form['name_relationships_to_show']= array(
851
    '#type' => 'checkboxes',
852
    '#title' => t('Display name relationships'),
853
    '#default_value' => variable_get('name_relationships_to_show', 0),
854
    '#options' => $name_rel_options,
855
    '#description' => t('Select the name relationships you want to show for the accepted taxa.'),
856
  );
857

    
858
  $form['taxon_profile']['synonymy']['name_relationships'] = $name_relationships_form;
859
      /*
860
       $form['synonymy'][CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS] = array(
861
       '#type' => 'checkbox',
862
       '#title' => t('Show name relations of accepted taxa on taxon page'),
863
       '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT),
864
       //'#description' => t('Check this if you want the synonymy list to show all the name relationships where other names implies the accepted taxa.')
865
       '#description' => t('Check this if you want the synonymy list to show all the name relationships of accepted taxa.')
866
       );
867
     */
868
  $form['taxon_profile']['synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
869
    '#type' => 'checkbox',
870
    '#title' => t('Show taxon relations of accepted taxa on taxon page'),
871
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
872
    '#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.')
873
  );
874

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

    
891
  //-- MEDIA THUMBNAILS --//
892
  //$form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
893
  //$form_tittle = 'Taxon Images (Tab)';
894
  //$form_description = 'This section covers the settings related to the taxon images tab. Taxon images display all the media (in this case images) found for a given taxon as a thumbnails.';
895
  //$form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed, $form_description);
896
  // --- MEDIA GALLERY ---- //
897
  //$form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
898
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
899
  $form_title = 'Media gallery (Tab)';
900
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
901
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
902
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
903
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
904
   <p><strong>Note:</strong> These settings are only taken into account when the standard
905
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
906
  //$form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
907
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
908

    
909

    
910
  return system_settings_form($form);
911
}
912

    
913
function cdm_settings_layout_search(){
914

    
915
  $form = array();
916

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

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

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

    
943
  return system_settings_form($form);
944
}
945

    
946
function cdm_settings_layout_media(){
947

    
948
  $form = array();
949

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

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

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

    
973

    
974
  return system_settings_form($form);
975
}
976

    
977

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

    
984
  $form = array();
985

    
986
  /*
987
   * GEO SERVER
988
   */
989

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

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

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

    
1023

    
1024
  /*
1025
   *  MAP SETTINGS
1026
   */
1027

    
1028
    $form['map_settings'] = array(
1029
      '#type' => 'fieldset',
1030
      '#title' => t('Maps settings'),
1031
      '#collapsible' => TRUE,
1032
      '#collapsed' => TRUE,
1033
      '#description' => t('Configuration of the renderized maps.'),
1034
     );
1035

    
1036
    $form['map_settings']['cdm_dataportal_geoservice_display_width'] = array(
1037
      '#type' => 'textfield',
1038
      '#title' => t('Maps size'),
1039
      '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
1040
      '#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.')
1041
    );
1042

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

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

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

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

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

    
1082
    $openLayersEnabled = variable_get('cdm_dataportal_map_openlayers', 1) === 1;
1083

    
1084

    
1085
    // --- Plain Image Settings --- //
1086

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

    
1096
    if (variable_get('edit_map_server', EDIT_MAPSERVER_V1_URI) !=  EDIT_MAPSERVER_V11_URI) {
1097
      $form['map_image']['#description'] = '<div class="messages warning">' . t("The selected EDIT map service version has to small version number! ") . '</div>'
1098
      . $form['map_image']['#description'];
1099
    }
1100

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

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

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

    
1123

    
1124
    // --- OpenLayers Settings --- //
1125

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

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

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

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

    
1170
  // cdm_dataportal_geoservice_showLayerSwitcher
1171
  $form['openlayers']['cdm_dataportal_geoservice_showLayerSwitcher'] = array(
1172
    '#type' => 'checkbox',
1173
    '#title' => '<b>'.t('Show Layer Switcher').'</b>',
1174
    '#default_value' => variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE),
1175
    '#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.')
1176
  );
1177

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

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

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

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

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

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

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

    
1240
        return system_settings_form($form);
1241
}
1242

    
1243

    
1244
function cdm_settings_cache(){
1245

    
1246
  $form = array();
1247

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

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

    
1269
  $form['cache_settings']['cdm_run_cache'] = array(
1270
    '#value' => cdm_view_cache_site()
1271
  );
1272

    
1273
  return system_settings_form($form);
1274
}
1275

    
1276
/**
1277
 * @return walk and cache all taxon pages
1278
 */
1279
function cdm_view_cache_site(){
1280

    
1281
  $out = '';
1282

    
1283
    _add_js_progressbar();
1284
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cache_all_taxa.js');
1285

    
1286
  $request_params = array();
1287
  $request_params['query'] = '%';
1288
  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false); //cache only the dafault classification
1289
  $request_params['doTaxa'] = 1;
1290
  $request_params['doSynonyms'] = 0;
1291
  $request_params['doTaxaByCommonNames'] = 0;
1292
  $search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1293
  $search_url = uri_uriByProxy($search_url);
1294
  $taxon_page_url = url('cdm_dataportal/taxon/');
1295

    
1296

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

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

    
1316
  return $out;
1317
}
1318

    
1319

    
1320
/**
1321
 * Implementation of hook_validate()
1322
 *
1323
 * @param $element
1324
 */
1325
function cdm_settings_validate($form_id, $form_values){
1326

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

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

    
1338
}
1339

    
1340
function getEDITMapServiceURI(){
1341

    
1342
  if(variable_get('edit_map_server', false) == 'ALTERNATIVE'){
1343
    return (variable_get('edit_map_server_alternative', false));
1344
  } else if(variable_get('edit_map_server', false)) {
1345
    return variable_get('edit_map_server', false);
1346
  } else {
1347
    return EDIT_MAPSERVER_V1_URI;
1348
  }
1349

    
1350
}
1351

    
1352
/**
1353
 * Implementation of hook_elements()
1354
 *
1355
 * see http://drupal.org/node/37862 for an example
1356
 */
1357
function cdm_dataportal_elements() {
1358
  $type['checkboxes_preferred'] = array(
1359
    '#input' => TRUE,
1360
    '#process' => array('expand_checkboxes_preferred' => array()),
1361
    '#after_build' => array('checkboxes_preferred_after_build')
1362
  );
1363
  return $type;
1364
}
1365

    
1366
/**
1367
 * #process function for the custom form element type 'checkbox_preferred'
1368
 */
1369
function expand_checkboxes_preferred($element){
1370

    
1371
  // first of all create the checkboxes
1372
  $element = expand_checkboxes($element);
1373

    
1374
  $children = element_children($element);
1375
  $element['table_start'] = array(
1376
    '#value' => '<table class="checkboxes_preferred"><tr><th></th><th>'.t('Enabled').'</th><th>'.t('Default').'</th></tr>',
1377
    '#weight'=>-1
1378
  );
1379
  $weight = 0;
1380
  foreach ($children as $key) {
1381
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
1382
    $element[$key]['#weight'] = $weight;
1383
    $element[$key]['#prefix'] = '<tr class="'.$odd_even.'"><td>'.t($element['#options'][$key]).'</td><td>';
1384
    $element[$key]['#suffix'] = '</td>';
1385
    unset($element[$key]['#title']);
1386
    $weight += 2;
1387
  }
1388
  $weight = 0;
1389

    
1390
  if (count($element['#options']) > 0) {
1391
    foreach ($element['#options'] as $key => $choice) {
1392
      if (!isset($element[$key.'_preferred'])) {
1393
        $element[$key.'_preferred'] = array(
1394
        '#type' => 'radio',
1395
        '#name' => $element['#parents'][0].'_preferred',
1396
        '#return_value' => check_plain($key),
1397
        '#default_value' => $element['#default_value_2'],
1398
        '#attributes' => $element['#attributes'],
1399
        '#parents' => $element['#parents'],
1400
        '#spawned' => TRUE,
1401
        '#weight' => $weight + 1,
1402
        '#prefix' => '<td>',
1403
        '#suffix' => '</td></tr>',
1404
        //'#submit' => 'submit_checkboxes_preferred'
1405
        );
1406
      }
1407
      $weight += 2;
1408
    }
1409
  }
1410

    
1411
  $element['table_end'] = array(
1412
  //'#type'=>'value',
1413
  '#value' => '</table>', '#weight'=>$weight++);
1414
  return $element;
1415
}
1416

    
1417

    
1418
function theme_checkboxes_preferred($element){
1419
  return theme('form_element',
1420
  array(
1421
      '#title' => $element['#title'],
1422
      '#description' => $element['#description'],
1423
      '#id' => $element['#id'],
1424
      '#required' => $element['#required'],
1425
      '#error' => $element['#error'],
1426
  ),
1427
  $element['#children']);
1428
}
1429

    
1430
function checkboxes_preferred_after_build($form, &$form_values){
1431

    
1432
  $parent_id = $form['#parents'][0];
1433

    
1434
  if($_POST && count($_POST) > 0){
1435
    // first pass of form processing
1436
    $preferred_layer = $_POST[$parent_id.'_preferred'];
1437
    $form['#value']['PREFERRED'] = $preferred_layer;
1438
    $form_values[$parent_id] = $form['#value'];
1439
  } else {
1440
    // second pass of form processing
1441
    $preferred_layer = $form['#value']['PREFERRED'];
1442
  }
1443

    
1444
  // also set the chosen value (not sure if this is good drupal style ....)
1445
  foreach( $children = element_children($form) as $key ){
1446
    if($form[$key]['#type'] == 'radio'){
1447
      $form[$key]['#value'] = $preferred_layer;
1448
    }
1449
  }
1450
  // the default layer mus always be enabled
1451
  $form[$preferred_layer]['#value'] = $preferred_layer;
1452

    
1453

    
1454
  return $form;
1455
}
1456

    
(12-12/12)