Project

General

Profile

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

    
391
/**
392
 * LAYOUT settings
393
 * @return unknown_type
394
 */
395
function cdm_settings_layout(){
396

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

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

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

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

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

    
454
  return system_settings_form($form);
455
}
456

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

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

    
484
    //$form['gen_layout']['theme']['#submit'][] = 'settings_validate_theme_pictures';
485
    $form['cdm_dataportal_theming']['submit'] = array(
486
      '#type' => 'submit',
487
      '#value' => t('Submit')
488
    );
489

    
490
    return $form;
491
}
492

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

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

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

    
526
    //use the banners as default theme
527
}
528

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

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

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

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

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

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

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

    
597
function cdm_settings_layout_taxon(){
598
  $collapsed = false;
599
  $form = array();
600

    
601
  //--------- TABBED TAXON -------//
602
  $form['taxon_tabs'] = array(
603
    '#type' => 'fieldset',
604
      '#title' => t('Taxon tabs'),
605
      '#collapsible' => TRUE,
606
      '#collapsed' => FALSE,
607
    '#description' => t('If tabbed taxon page is enabled the taxon profile will be splitted in four diferent tabs;
608
             General, Synonymy, Images and Specimens. If the taxon has no information for any of the tabs/sections such tab will be not displayed.'),
609
  );
610

    
611

    
612
    $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
613
    '#type' => 'checkbox',
614
    '#title' => t('Tabbed taxon page'),
615
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
616
    '#description' => t('<p>If selected split the taxon page into individual tabs for description, images, synonymy and specimens.
617
                            If not the taxon data is renderized as a long single page without tabs.</p>')
618
  );
619

    
620
  $form['taxon_tabs']['cdm_dataportal_detault_tab'] =  array(
621
      '#type'          => 'select',
622
      '#title'         => t('Default tab to display'),
623
      '#default_value' => variable_get('cdm_dataportal_detault_tab', 0),
624
      '#options'       => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
625
      '#description'   => t('<p>Select the default tab to display when visiting a taxon page. Only available if Tabbed Taxon Page is enable.</p>
626
              <strong>Note:</strong> After performing a search and clicking in any synonym, the taxon tab
627
              to be renderized will be the synonymy of the accepted taxon and not the above selected tab.'),
628
  );
629

    
630
  $form['cdm_dataportal_show_back_to_search_results'] = array(
631
      '#type' => 'checkbox',
632
        '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
633
        '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
634
        '#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>')
635
  );
636

    
637
  /* ======  TAXON_PROFILE ====== */
638

    
639
  $form['taxon_profile'] = array(
640
      '#type' => 'fieldset',
641
      '#title' => t('Taxon profile (tab)'),
642
      '#description' => t('<p>This section covers the setting related to the taxon profile tab, also known as the <strong>"General"</strong> tab.</p>'),
643
      '#collapsible' => TRUE,
644
      '#collapsed' => TRUE,
645
  );
646

    
647

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

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

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

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

    
685
  //-- MEDIA THUMBNAILS --//
686
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
687
  $form_title = 'Taxon Profile Images';
688
  $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>';
689
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
690

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

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

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

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

    
724
  if( isset($feature_tree->root->children) ){
725

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

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

    
737

    
738
      if( !$feature_list_layout_settings_disabled && isset($featureNode->feature) ) {
739

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

    
742
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
743

    
744

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

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

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

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

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

    
785
      }
786

    
787
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
788
    }
789
  }
790

    
791

    
792
  //---- DISTRIBUTION LAYOUT ---- //
793

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

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

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

    
820

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

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

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

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

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

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

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

    
893

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

    
905

    
906
  return system_settings_form($form);
907
}
908

    
909
function cdm_settings_layout_search(){
910

    
911
  $form = array();
912

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

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

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

    
939
  return system_settings_form($form);
940
}
941

    
942
function cdm_settings_layout_media(){
943

    
944
  $form = array();
945

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

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

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

    
969

    
970
  return system_settings_form($form);
971
}
972

    
973

    
974
/**
975
 * GEOSERVICE and Map settings
976
 * @return unknown_type
977
 */
978
function cdm_settings_geo(){
979

    
980
  $form = array();
981

    
982
  /*
983
   * GEO SERVER
984
   */
985

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

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

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

    
1019

    
1020
  /*
1021
   *  MAP SETTINGS
1022
   */
1023

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

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

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

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

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

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

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

    
1078
    $openLayersEnabled = variable_get('cdm_dataportal_map_openlayers', 1) === 1;
1079

    
1080

    
1081
    // --- Plain Image Settings --- //
1082

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

    
1092
    $edit_mapserver_version = getEDITMapServiceVersionNumber();
1093
    if ($edit_mapserver_version < 1.1) {
1094
      $form['map_image']['#description'] = '<div class="messages warning">' . t("The selected EDIT map service version has to small version number: $edit_mapserver_version") . '</div>'
1095
      . $form['map_image']['#description'];
1096
    }
1097

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

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

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

    
1120

    
1121
    // --- OpenLayers Settings --- //
1122

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

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

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

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

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

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

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

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

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

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

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

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

    
1237
        return system_settings_form($form);
1238
}
1239

    
1240

    
1241
function cdm_settings_cache(){
1242

    
1243
  $form = array();
1244

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

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

    
1266
  $form['cache_settings']['cdm_run_cache'] = array(
1267
    '#value' => cdm_view_cache_site()
1268
  );
1269

    
1270
  return system_settings_form($form);
1271
}
1272

    
1273
/**
1274
 * @return walk and cache all taxon pages
1275
 */
1276
function cdm_view_cache_site(){
1277

    
1278
  $out = '';
1279

    
1280
  _add_js_progressbar();
1281
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cache_all_taxa.js');
1282

    
1283
  $request_params = array();
1284
  $request_params['query'] = '%';
1285
  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false); //cache only the dafault classification
1286
  $request_params['doTaxa'] = 1;
1287
  $request_params['doSynonyms'] = 0;
1288
  $request_params['doTaxaByCommonNames'] = 0;
1289

    
1290
  $search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND . ".json", null, queryString($request_params));
1291
  $search_url = uri_uriByProxy($search_url);
1292
  $taxon_page_url = url('cdm_dataportal/taxon/');
1293

    
1294

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

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

    
1314
  return $out;
1315
}
1316

    
1317

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

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

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

    
1336
}
1337

    
1338
function getEDITMapServiceURI(){
1339

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

    
1348
}
1349

    
1350
/**
1351
 *
1352
 * @return float the version number of the currently selected edit mapserver as a float. Returns 0 on error
1353
 */
1354
function getEDITMapServiceVersionNumber() {
1355

    
1356
      $pattern = '/v(\d+\.\d+)/';
1357

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

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

    
1384
/**
1385
 * #process function for the custom form element type 'checkbox_preferred'
1386
 */
1387
function expand_checkboxes_preferred($element){
1388

    
1389
  // first of all create the checkboxes
1390
  $element = expand_checkboxes($element);
1391

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

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

    
1429
  $element['table_end'] = array(
1430
  //'#type'=>'value',
1431
  '#value' => '</table>', '#weight'=>$weight++);
1432
  return $element;
1433
}
1434

    
1435

    
1436
function theme_checkboxes_preferred($element){
1437
  return theme('form_element',
1438
  array(
1439
      '#title' => $element['#title'],
1440
      '#description' => $element['#description'],
1441
      '#id' => $element['#id'],
1442
      '#required' => $element['#required'],
1443
      '#error' => $element['#error'],
1444
  ),
1445
  $element['#children']);
1446
}
1447

    
1448
function checkboxes_preferred_after_build($form, &$form_values){
1449

    
1450
  $parent_id = $form['#parents'][0];
1451

    
1452
  if($_POST && count($_POST) > 0){
1453
    // first pass of form processing
1454
    $preferred_layer = $_POST[$parent_id.'_preferred'];
1455
    $form['#value']['PREFERRED'] = $preferred_layer;
1456
    $form_values[$parent_id] = $form['#value'];
1457
  } else {
1458
    // second pass of form processing
1459
    $preferred_layer = $form['#value']['PREFERRED'];
1460
  }
1461

    
1462
  // also set the chosen value (not sure if this is good drupal style ....)
1463
  foreach( $children = element_children($form) as $key ){
1464
    if($form[$key]['#type'] == 'radio'){
1465
      $form[$key]['#value'] = $preferred_layer;
1466
    }
1467
  }
1468
  // the default layer mus always be enabled
1469
  $form[$preferred_layer]['#value'] = $preferred_layer;
1470

    
1471

    
1472
  return $form;
1473
}
1474

    
(12-12/12)