Project

General

Profile

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

    
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
 * default settings for all gallerys
23
 * @var unknown_type
24
 */
25
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
26
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
27
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
28
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
29
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
30
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
31
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
32
//define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
33
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
34
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
35
define('CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
36
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
37

    
38
function getGallerySettings($gallery_config_form_name){
39
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
40
  return variable_get($gallery_config_form_name, $default_values);
41
}
42

    
43

    
44
function cdm_dataportal_menu_admin($may_cache, &$items){
45

    
46
	if (!$may_cache) {
47

    
48
		$items[] = array(
49
      'path' => 'admin/settings/cdm_dataportal',
50
      'title' => t('CDM Dataportal'),
51
      'description' => t('Setting for the CDM DataPortal'),
52
      'access' => user_access('administer cdm_dataportal'),
53
      'callback' => 'drupal_get_form',
54
      'callback arguments' => 'cdm_settings_general',
55
      'type' => MENU_NORMAL_ITEM,
56
    );
57

    
58
    $items[] = array(
59
      'path' => 'admin/settings/cdm_dataportal/general',
60
      'title' => t('General'),
61
      'description' => t('Setting for the CDM DataPortal'),
62
      'access' => user_access('administer cdm_dataportal'),
63
      'callback' => 'drupal_get_form',
64
      'callback arguments' => 'cdm_settings_general',
65
    'weight' => 0,
66
      'type' => MENU_LOCAL_TASK,
67
    );
68

    
69
    $items[] = array(
70
      'path' => 'admin/settings/cdm_dataportal/cachesite',
71
      'title' => t('Cache'),
72
      'description' => t('Cache the whole CDM DataPortal site'),
73
      'access' => user_access('administer cdm_dataportal'),
74
      'callback' => 'cdm_view_cache_site',
75
      'weight' => 10,
76
      'type' => MENU_LOCAL_TASK,
77
    );
78

    
79
    $items[] = array(
80
      'path' => 'admin/settings/cdm_dataportal/geo',
81
      'title' => t('Geo & Map'),
82
      'description' => t('Geo & Map'),
83
      'access' => user_access('administer cdm_dataportal'),
84
      'callback' => 'drupal_get_form',
85
      'callback arguments' => 'cdm_settings_geo',
86
      'weight' => 1,
87
      'type' => MENU_LOCAL_TASK,
88
    );
89

    
90
    $items[] = array(
91
      'path' => 'admin/settings/cdm_dataportal/layout',
92
      'title' => t('Layout'),
93
      'description' => t('Configure and adjust the layout of your DataPortal '),
94
      'access' => user_access('administer cdm_dataportal'),
95
      'callback' => 'drupal_get_form',
96
      'callback arguments' => 'cdm_settings_layout',
97
      'weight' => 2,
98
      'type' => MENU_LOCAL_TASK,
99
    );
100

    
101
    $items[] = array(
102
      'path' => 'admin/settings/cdm_dataportal/layout/taxon',
103
      'title' => t('Taxon'),
104
      'description' => t('Configure and adjust the layout of your DataPortal '),
105
      'access' => user_access('administer cdm_dataportal'),
106
      'callback' => 'drupal_get_form',
107
      'callback arguments' => 'cdm_settings_layout_taxon',
108
      'weight' => 1,
109
      'type' => MENU_LOCAL_TASK,
110
    );
111

    
112
    $items[] = array(
113
      'path' => 'admin/settings/cdm_dataportal/layout/search',
114
      'title' => t('Search'),
115
      'description' => t('Configure and adjust the layout of your DataPortal '),
116
      'access' => user_access('administer cdm_dataportal'),
117
      'callback' => 'drupal_get_form',
118
      'callback arguments' => 'cdm_settings_layout_search',
119
      'weight' => 2,
120
      'type' => MENU_LOCAL_TASK,
121
    );
122

    
123
     $items[] = array(
124
      'path' => 'admin/settings/cdm_dataportal/layout/media',
125
      'title' => t('Media'),
126
      'description' => t('Configure and adjust the layout of your DataPortal '),
127
      'access' => user_access('administer cdm_dataportal'),
128
      'callback' => 'drupal_get_form',
129
      'callback arguments' => 'cdm_settings_layout_media',
130
      'weight' => 3,
131
      'type' => MENU_LOCAL_TASK,
132
    );
133

    
134
	}
135

    
136

    
137
}
138

    
139

    
140
/**
141
 * Configures the settings form for the CDM-API module.
142
 *
143
 * @return Array Drupal settings form
144
 */
145
function cdm_settings_general(){
146

    
147
  $form['cdm_webservice'] = array(
148
      '#type' => 'fieldset',
149
      '#title' => t('CDM Web Service'),
150
      '#collapsible' => FALSE,
151
      '#collapsed' => FALSE,
152
  );
153

    
154
  $form['cdm_webservice']['cdm_webservice_url'] =  array(
155
    '#type' => 'textfield',
156
    '#title'         => t('CDM Web Service URL'),
157
    '#description'   => t('The URL of CDM Webservice which delivers the data to be published.'),
158
    '#default_value' => variable_get('cdm_webservice_url', NULL),
159
  );
160

    
161
  $form['cdm_webservice']['taxontree_ranklimit'] =  array(
162
    '#type'          => 'select',
163
    '#title'         => t('Rank of highest displayed taxon'),
164
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT), //before DEFAULT_TAXONTREE_RANKLIMIT_UUID
165
    '#options'       => cdm_rankVocabulary_as_option(),
166
    '#description'   => t('The rank of the highest displayed taxon in the taxontree.'),
167
  );
168

    
169
  $form['cdm_webservice']['cdm_webservice_cache'] =  array(
170
    '#type' => 'checkbox',
171
    '#title'         => t('Enable Caching'),
172
    '#default_value' => variable_get('cdm_webservice_cache', 1),
173
    '#description'   => t('Enable caching of webservice responses on simple requests, '
174
    .'that is requests which only have one parameter generally a UUID or a concatenation of UUIDs')
175
    );
176

    
177
    $form['cdm_webservice']['proxy'] = array(
178
      '#type' => 'fieldset',
179
      '#title' => t('Proxy'),
180
      '#collapsible' => TRUE,
181
      '#collapsed' => TRUE
182
    );
183

    
184
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] =  array(
185
    '#type' => 'textfield',
186
    '#title'         => t('Proxy URL'),
187
    '#description'   => t('If this proxy url is set the cdm api tries
188
    to connect the web service over the given proxy server.
189
    Otherwise proxy usage is deactivated.'),
190
    '#default_value' => variable_get('cdm_webservice_proxy_url', false),
191
    );
192

    
193
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] =  array(
194
    '#type' => 'textfield',
195
    '#title'         => t('Proxy Port'),
196
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
197
    );
198

    
199
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] =  array(
200
    '#type' => 'textfield',
201
    '#title'         => t('Login'),
202
    '#default_value' => variable_get('cdm_webservice_proxy_usr', false),
203
    );
204

    
205
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] =  array(
206
    '#type' => 'textfield',
207
    '#title'         => t('Password'),
208
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', false),
209
    );
210

    
211
    $form['cdm_webservice']['cdm_webservice_debug'] =  array(
212
    '#type' => 'checkbox',
213
    '#title'         => t('Debug CDM Web Service'),
214
    '#default_value' => variable_get('cdm_webservice_debug', 1),
215
    '#description'   => t('Enable CDM Web Service debugging messages. Only visible for the super administrator or for users having the permission <em>administer cdm_api</em>!')
216
    );
217

    
218
    //TODO: settings are still incomplete, compare with trunk/dataportal/inc/config_default.php.inc
219
    $form['cdm_dataportal'] = array(
220
      '#type' => 'fieldset',
221
      '#title' => t('CDM DataPortal'),
222
      '#collapsible' => FALSE,
223
      '#collapsed' => TRUE,
224
    );
225

    
226
    $form['cdm_dataportal'][CDM_TAXONOMICTREE_UUID] = array(
227
      '#type' => 'select',
228
      '#title'         => t('Available classifications'),
229
      '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, false),
230
      '#options' => cdm_get_taxontrees_as_options(),
231
      '#description'   => t('Select the default classification to be used.')
232
    );
233

    
234
    return system_settings_form($form);
235
}
236

    
237

    
238

    
239
/**
240
 * LAYOUT settings
241
 * @return unknown_type
242
 */
243
function cdm_settings_layout(){
244

    
245
  $form = array();
246

    
247

    
248
  //---- footnotes ---//
249
  $form['footnotes'] = array(
250
      '#type' => 'fieldset',
251
      '#title' => t('Footnotes'),
252
      '#collapsible' => FALSE,
253
      '#collapsed' => FALSE,
254
  );
255

    
256
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
257
      '#type' => 'checkbox',
258
      '#title' => t('Do not show footnotes'),
259
      '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
260
      '#description' => t('Check this if you do not want to show any footnotes')
261
  );
262

    
263
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
264
      '#type' => 'checkbox',
265
      '#title' => t('Do not show annotations footnotes'),
266
      '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
267
      '#description' => t('Check this if you do not want to show annotation footnotes')
268
  );
269

    
270
  return system_settings_form($form);
271
}
272

    
273
function cdm_settings_layout_taxon(){
274

    
275
	$form = array();
276

    
277
  $form['cdm_dataportal_taxonpage_tabs'] = array(
278
    '#type' => 'checkbox',
279
    '#title' => t('Tabbed taxon page'),
280
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
281
    '#description' => t('Split the taxon page into individual tabs for description, images, synonymy')
282
  );
283

    
284
   //---- IMAGES ----//
285
  $form['images'] = array(
286
      '#type' => 'fieldset',
287
      '#title' => t('Images'),
288
      '#collapsible' => FALSE,
289
      '#collapsed' => FALSE,
290
  );
291
  $options = cdm_rankVocabulary_as_option();
292
  array_unshift($options, '-- DISABLED --');
293
  $form['images']['image_hide_rank'] =  array(
294
      '#type'          => 'select',
295
      '#title'         => t('Hide Images for Taxa above'),
296
      '#default_value' => variable_get('image_hide_rank', '0'),
297
      '#options'       => $options,
298
      '#description'   => t(''),
299
  );
300
  //show media
301
  $selectShowMedia = array(0 => "Show only taxon media",
302
  1 => "Show taxon and child taxon media");
303
  $form['images']['cdm_dataportal_show_media'] = array(
304
      '#type' => 'select',
305
      '#title' => t('Available media files'),
306
      '#default_value' => variable_get('cdm_dataportal_show_media', false),
307
      '#options' => $selectShowMedia,
308
      '#description'   => t('Select if a taxon should show only his media or also child media.')
309
  );
310
  $selectShowMedia = array(0 => "Show only taxon media",
311
  1 => "Show taxon and child taxon media");
312
  $form['images']['cdm_dataportal_show_default_image'] = array(
313
      '#type' => 'checkbox',
314
      '#title' => t('Show default image'),
315
      '#default_value' => variable_get('cdm_dataportal_show_default_image', false),
316
      '#description'   => t('Select if the taxon profile page should display the default image if no image is available for the chosen taxon.')
317
  );
318

    
319
  /* ===  TAXON_PROFILE === */
320
   $form['taxon_profile'] = array(
321
      '#type' => 'fieldset',
322
      '#title' => t('Taxon profile'),
323
      '#description'   => t('This section covers setting related to the taxon profile tab, also known as the <strong>"General"</strong> tab.'),
324
      '#collapsible' => TRUE,
325
      '#collapsed' => FALSE,
326
  );
327

    
328
  $form['taxon_profile'][CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID] = array(
329
      '#type' => 'radios',
330
      '#title'         => t('Taxon profile sections'),
331
      '#default_value' => variable_get(CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE),
332
      '#options' => cdm_get_featureTrees_as_options(TRUE),
333
      '#description'   => t('Select a FeatureTree to specify the kins and order of sections to be displayd in the taxon profile.'
334
  )
335
  );
336

    
337
  $form['taxon_profile'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
338
      '#type' => 'radios',
339
      '#title'         => t('Natural language representation of structured descriptions'),
340
      '#default_value' => variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, null),
341
      '#options' => cdm_get_featureTrees_as_options(),
342
      '#description'   => t('Taxon descriptions can be stored in a highly structured form.'.
343
        ' The feature tree selected here will be used to generate textual representation in natural language.'
344
        //.' If there is no applicable FeatureTree you can create a new one using the <a href="">FeatureTreeManager</a>'
345
  )
346
  );
347

    
348
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
349
  $form_tittle = 'Images';
350
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
351

    
352
  //-- DISTRIBUTION LAYOUT --//
353
  $form['taxon_profile']['distribution_layout'] = array(
354
        '#title' => t('Distribution layout'),
355
        '#collapsible' => TRUE,
356
        '#collapsed' => FALSE,
357
        '#type' => 'fieldset',
358
  );
359

    
360
  $form['taxon_profile']['distribution_layout']['distribution_sort'] =  array(
361
    '#type'          => 'radios',
362
    '#title'         => t('Sort'),
363
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
364
    '#options' => array(
365
        'NO_SORT' => t('Standard (No sort)'),
366
        'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
367
  ));
368

    
369
  //---- SYNONYMY ----//
370
  $form['synonymy'] = array(
371
      '#type' => 'fieldset',
372
      '#title' => t('Synonymy'),
373
      '#collapsible' => TRUE,
374
      '#collapsed' => FALSE,
375
  );
376

    
377
  $form['synonymy']['cdm_dataportal_nomref_in_title'] = array(
378
    '#type' => 'checkbox',
379
    '#title' => t('Show accepted taxon on top of the synonymy'),
380
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
381
    '#description' => t('If checked, the first homotypic taxon is a repetition of the accepted taxon most likely
382
                        with the full nomenclatural reference (depending on the currently chosen theme).')
383
  );
384

    
385
  $form['synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
386
    '#type' => 'checkbox',
387
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
388
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
389
    '#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.')
390
  );
391

    
392
  $name_relationships_terms = cdm_ws_get(CDM_WS_TERMVOCABULARY, UUID_NAME_RELATIONSHIP_TYPE);
393
  $name_rel_options = array();
394
  //$name_rel_options['default'] = 'Show all';
395
  foreach ($name_relationships_terms->terms as $element){
396
    $name_rel_options[$element->uuid] = t('Show "' . $element->representation_L10n_abbreviated . '" relationships');
397
  }
398

    
399
  $name_relationships_form['name_relationships_to_show']= array(
400
  '#type' => 'checkboxes',
401
  '#title' => t('Display name relationships'),
402
  '#default_value' => variable_get('name_relationships_to_show', 0),
403
  '#options' => $name_rel_options,
404
  '#description' => t('Select the name relationships you want to show for the accepted taxa.'),
405
  );
406

    
407
  $form['synonymy']['name_relationships'] = $name_relationships_form;
408
/*
409
  $form['synonymy'][CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS] = array(
410
    '#type' => 'checkbox',
411
    '#title' => t('Show name relations of accepted taxa on taxon page'),
412
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT),
413
    //'#description' => t('Check this if you want the synonymy list to show all the name relationships where other names implies the accepted taxa.')
414
    '#description' => t('Check this if you want the synonymy list to show all the name relationships of accepted taxa.')
415
  );
416
*/
417
  $form['synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
418
    '#type' => 'checkbox',
419
    '#title' => t('Show taxon relations of accepted taxa on taxon page'),
420
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
421
    '#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.')
422
  );
423

    
424
/*
425
  $form['synonymy']['cdm_dataportal_name_relations_skiptype_basionym'] = array(
426
    '#type' => 'checkbox',
427
    '#title' => t('Exclude the basionym relationship type from the taxon page'),
428
    '#default_value' => variable_get('cdm_dataportal_name_relations_skiptype_basionym', 1),
429
    '#description' => t('')
430
  );
431
*/
432

    
433
  /*
434
   $form['cdm_dataportal_descriptions_separated'] = array(
435
   '#type' => 'checkbox',
436
   '#title' => t('Separate Descriptions'),
437
   '#default_value' => variable_get('cdm_dataportal_descriptions_separated', 0),
438
   '#description' => t('By default corresponding elements of different descriptions are joined together'
439
   .' into a common section per feature (i.e. type of description).'
440
   .' Check this box to allow displaying all descriptions separately.')
441
   );
442
   */
443

    
444
   // --- SPECIMENs --- //
445
    $form['specimens'] = array(
446
      '#type' => 'fieldset',
447
      '#title' => t('Specimens'),
448
      '#collapsible' => TRUE,
449
      '#collapsed' => FALSE,
450
  );
451
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
452
  $form_tittle = 'Specimen media gallery';
453
  $form['specimens'] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
454

    
455
	return system_settings_form($form);
456
}
457

    
458
function cdm_settings_layout_search(){
459
  $form = array();
460

    
461
  $form['cdm_dataportal_search_items_on_page'] = array(
462
    '#type' => 'textfield',
463
    '#title' => t('Search Page Size'),
464
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
465
    '#description' => t('Number of Names to display per page in search results.')
466
  );
467

    
468
  // --- SEARCH TAXA GALLERY ---- //
469
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
470
  $collapsed = FALSE;
471
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
472
  $form_tittle = 'Media Thumbnails';
473
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
474

    
475
  return system_settings_form($form);
476
}
477

    
478
function cdm_settings_layout_media(){
479
  $form = array();
480

    
481
  $form['image_gallery_viewer'] =  array(
482
    '#type'          => 'select',
483
    '#title'         => t('Image Gallery Viewer'),
484
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
485
    '#options' => array(
486
        'default' => t('Standart image gallery'),
487
        'fsi' => t('FSI viewer (requires FSI server!)'),
488
  ));
489

    
490
  // --- MEDIA GALLERY ---- //
491
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
492
  $form_tittle = 'Media gallery';
493
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
494

    
495

    
496
  return system_settings_form($form);
497
}
498

    
499

    
500
/**
501
 * GEOSERVICE and Map settings
502
 * @return unknown_type
503
 */
504
function cdm_settings_geo(){
505

    
506
  $form = array();
507

    
508
  $form['edit_map_server'] = array(
509
    '#type' => 'select',
510
    '#title' => t('Geoservice Access Point URL'),
511
    '#default_value' => variable_get('edit_map_server', 'http://edit.br.fgov.be/edit_wp5/v1/'),
512
    '#options' => array(
513
	      'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server',
514
      /*
515
        'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server - Mirror 1',
516
        'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server - Mirror 2',
517
       */
518
	      'ALTERNATIVE' => '-- Alternative URL --'
519
	    ),
520
    '#description' => t('Base URL of the geoservice to be used by this portal')
521
  );
522

    
523
  $form['edit_map_server_alternative'] = array(
524
    '#type' => 'textfield',
525
    '#title' => t('Geoservice Access Point - Alternative URL'),
526
    '#default_value' => variable_get('edit_map_server_alternative', ''),
527
    '#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.')
528
  );
529

    
530
  $form['cdm_dataportal_geoservice_display_width'] = array(
531
    '#type' => 'textfield',
532
    '#title' => t('Geoservice Display Width'),
533
    '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
534
    '#description' => t('Width of the image generated by geoservice')
535
  );
536

    
537
  $form['cdm_dataportal_geoservice_bounding_box'] = array(
538
    '#type' => 'textfield',
539
    '#title' => t('Fixed Geoservice Bounding Box'),
540
    '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
541
    '#description' => t('Define urrounding 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.')
542
  );
543

    
544
  $form['cdm_dataportal_geoservice_labels_on'] = array(
545
    '#type' => 'checkbox',
546
    '#title' => t('Display Country Labels'),
547
    '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
548
    '#description' => t('Check this if you like country names to be displayed in the maps. ')
549
  );
550

    
551
  $form['cdm_dataportal_geoservice_map_caption'] = array(
552
    '#type' => 'textfield',
553
    '#title' => t('Map Caption'),
554
    '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
555
    '#description' => t('Define a caption for the map.')
556
  );
557

    
558
  $form['cdm_dataportal_map_openlayers'] = array(
559
    '#type' => 'checkbox',
560
    '#title' => t('OpenLayers Viewer'),
561
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
562
    '#description' => t('Display the maps in an interactive viewer which allows zooming and panning.')
563
  );
564

    
565

    
566
  // --- OpenLayers Settings --- //
567

    
568
  $form['openlayers'] = array(
569
      '#type' => 'fieldset',
570
      '#title' => t('OpenLayers Settings'),
571
      '#collapsible' => FALSE,
572
      '#collapsed' => !variable_get('cdm_dataportal_map_openlayers', 1)
573
  );
574

    
575
  $baselayer_options = array(
576
    /*
577
     * NOTICE: must correspond to the layers defined in js/openlayers_,ap.js#getLayersByName()
578
     */
579
    'osgeo_vmap0' => "OpenLayers World", // EPSG:4326
580
    'metacarta_vmap0' => "Metacarta Vmap0" , // EPSG:4326, EPSG:900913
581
    // all others EPSG:900913 ...
582
    'osmarender' => 'OpenStreetMap',
583
    'oam' => 'OpenAerialMap',
584
    'gmap' => 'Google Streets',
585
    'gsat' => 'Google Satellite',
586
    'ghyb' => 'Google Hybrid',
587
    'veroad' => 'Virtual Earth Roads',
588
    'veaer' => 'Virtual Earth Aerial',
589
    'vehyb' => 'Virtual Earth Hybrid'
590
//  ,
591
//    'yahoo' => 'Yahoo Street',
592
//    'yahoosat' => 'Yahoo Satellite',
593
//    'yahoohyb' => 'Yahoo Hybrid'
594

    
595
  );
596
  $form['openlayers']['baselayers'] = array(
597
    '#type' => 'checkboxes_preferred',
598
    '#title' => t('Baser Layers'),
599
    '#options' => $baselayer_options,
600
    '#default_value' => variable_get('baselayers', array('metacarta_vmap0' => "metacarta_vmap0", 'PREFERRED' => 'metacarta_vmap0')),
601
    '#description' => t('')
602
  );
603

    
604
  // cdm_dataportal_geoservice_showLayerSwitcher
605
  $form['openlayers']['cdm_dataportal_geoservice_showLayerSwitcher'] = array(
606
    '#type' => 'checkbox',
607
    '#title' => t('Show LayerSwitcher'),
608
    '#default_value' => variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE),
609
    '#description' => t('The LayerSwitcher 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.')
610
  );
611

    
612
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
613
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
614
  $form['openlayers']['gmap_api_key'] = array(
615
    '#type' => 'textfield',
616
    '#title' => t('Gogle Maps API Key'),
617
    '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
618
    '#description' => t('Gogle Maps API Key, the key set by default <code>'.$localhostkey.'</code> is a key for the localhost = 127.0.0.1 The key in use is the one above this text.')
619
  );
620

    
621
  $form['openlayers']['cdm_dataportal_geoservice_distributionOpacity'] = array(
622
    '#type' => 'textfield',
623
    '#title' => t('Distribution Layer Opacity'),
624
    '#default_value' => variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5'),
625
    '#description' => t('Valid values range from 0.0 to 1.0. You can choose to let the underlying layers shine through if you select a value < 1.0. A value of 1.0 will cause a full opacity of the ditribution layer.')
626
  );
627

    
628
  $form['openlayers']['cdm_dataportal_geoservice_legendOpacity'] = array(
629
    '#type' => 'textfield',
630
    '#title' => t('Legend Opacity'),
631
    '#default_value' => variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'),
632
    '#description' => t('Valid values range from 0.0 to 1.0. You can choose to let the layers shine through the legend if you select a value < 1.0. A value of 1.0 will cause a full opacity of the legend.')
633
  );
634

    
635
  $form['cdm_dataportal_geoservice_map_legend'] = array(
636
      '#type' => 'fieldset',
637
      '#title' => t('Map Legend'),
638
      '#collapsible' => FALSE,
639
      '#collapsed' => TRUE,
640
  );
641

    
642
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
643
    '#type' => 'checkbox',
644
    '#title' => t('Display a map legend'),
645
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
646
    '#description' => t('Check this if you like a legend to be displayed with the maps. ')
647
  );
648

    
649
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
650
    '#type' => 'textfield',
651
    '#title' => t('Font size'),
652
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
653
    '#description' => t('Font size in pixels.')
654
  );
655

    
656
  $fontStyles = array(0 => "plane", 1 => "italic");
657
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
658
    '#type' => 'select',
659
    '#title' => t('Available font styles'),
660
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', false),
661
    '#options' => $fontStyles,
662
    '#description'   => t('Select a font style for the map legend.')
663
  );
664

    
665
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
666
    '#type' => 'textfield',
667
    '#title' => t('Icon width'),
668
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
669
    '#description' => t('Icon width in pixels.')
670
  );
671

    
672
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
673
    '#type' => 'textfield',
674
    '#title' => t('Icon height'),
675
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
676
    '#description' => t('Icon height in pixels.')
677
  );
678

    
679
  return system_settings_form($form);
680
}
681

    
682
/**
683
 * @return walk and cache all taxon pages
684
 */
685
function cdm_view_cache_site(){
686

    
687
  _add_js_progressbar();
688

    
689
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cache_all_taxa.js');
690

    
691
  $out = '';
692

    
693
  $request_params = array();
694
  $request_params['query'] = '%';
695
  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false); //cache only the dafault classification
696
  $request_params['doTaxa'] = 1;
697
  $request_params['doSynonyms'] = 0;
698
  $request_params['doTaxaByCommonNames'] = 0;
699
  $search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
700
  $search_url = uri_uriByProxy($search_url);
701
  $taxon_page_url = url('cdm_dataportal/taxon/');
702

    
703
  $out .= '<form id="cache_site">';
704
  $out .= '<br /><h4>'.t('Cache all taxon pages').'</h4>';
705
  $out .= 'Before  running the cache bot you have to empty the cache manually:<ul>'
706
  .'<li>Navigate to "Site Configuration -> General"</li>'
707
  .'<li>Uncheck "Enable Caching" checkbox</li>'
708
  .'<li>Check "Enable Caching" checkbox</li>'
709
  .'</ul>';
710
  $out .= '<div>'.t('This caching process may take long time and could cause heavy load on your server').'</div>';
711
  $out .= '<div id="progress"></div>';
712
  $out .= '<input type="hidden" name="searchTaxaUrl" value="'.$search_url.'"/>';
713
  $out .= '<input type="hidden" name="taxonPageUrl" value="'.$taxon_page_url.'"/>';
714
  $out .= '<input type="button" name="start" value="'.t('Start').'"/>';
715
  $out .= '<input type="button" name="stop" value="'.t('Stop').'"/>';
716
  $out .= '</form>';
717
  $out .= '</div>';
718
  //  foreach($taxonPager->records as $taxon){
719
  //    cdm_dataportal_taxon_view($uuid);
720
  //  }
721

    
722
  return $out;
723
}
724

    
725

    
726
/**
727
 * Implementation of hook_validate()
728
 *
729
 * @param $element
730
 */
731
function cdm_settings_validate($form_id, $form_values){
732

    
733
  if (!str_endsWith($form_values['cdm_webservice_url'], '/')) {
734
    //form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
735
    $form_values['cdm_webservice_url'] .= '/';
736
  }
737

    
738
  if($form_values['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)){
739
    cache_clear_all(NULL, 'cache_cdm_ws');
740
    // better clear secref_cache since i can not be sure if the cache has not be used during this response
741
    cdm_api_secref_cache_clear();
742
  }
743

    
744
}
745

    
746
function getEDITMapServiceURI(){
747

    
748
  if(variable_get('edit_map_server', false) == 'ALTERNATIVE'){
749
  	return (variable_get('edit_map_server_alternative', false));
750
  } else {
751
  	return variable_get('edit_map_server', false);
752
  }
753

    
754
}
755

    
756
/**
757
 * Implementation of hook_elements()
758
 *
759
 * see http://drupal.org/node/37862 for an example
760
 */
761
function cdm_dataportal_elements() {
762
   $type['checkboxes_preferred'] = array(
763
    '#input' => TRUE,
764
    '#process' => array('expand_checkboxes_preferred' => array()),
765
    '#after_build' => array('checkboxes_preferred_after_build')
766
    );
767
   return $type;
768
}
769

    
770
/**
771
 * #process function for the custom form element type 'checkbox_preferred'
772
 */
773
function expand_checkboxes_preferred($element){
774

    
775
	// first of all create the checkboxes
776
  $element = expand_checkboxes($element);
777

    
778
  $children = element_children($element);
779
  $element['table_start'] = array(
780
    '#value' => '<table class="checkboxes_preferred"><tr><th></th><th>'.t('Enabled').'</th><th>'.t('Default').'</th></tr>',
781
    '#weight'=>-1
782
  );
783
  $weight = 0;
784
  foreach ($children as $key) {
785
  	$odd_even = $weight % 4 == 0 ? 'odd' : 'even';
786
    $element[$key]['#weight'] = $weight;
787
    $element[$key]['#prefix'] = '<tr class="'.$odd_even.'"><td>'.t($element['#options'][$key]).'</td><td>';
788
    $element[$key]['#suffix'] = '</td>';
789
    unset($element[$key]['#title']);
790
    $weight += 2;
791
  }
792
  $weight = 0;
793

    
794
  if (count($element['#options']) > 0) {
795
    foreach ($element['#options'] as $key => $choice) {
796
      if (!isset($element[$key.'_preferred'])) {
797
        $element[$key.'_preferred'] = array(
798
        '#type' => 'radio',
799
        '#name' => $element['#parents'][0].'_preferred',
800
        '#return_value' => check_plain($key),
801
        '#default_value' => $element['#default_value_2'],
802
        '#attributes' => $element['#attributes'],
803
        '#parents' => $element['#parents'],
804
        '#spawned' => TRUE,
805
        '#weight' => $weight + 1,
806
        '#prefix' => '<td>',
807
        '#suffix' => '</td></tr>',
808
        //'#submit' => 'submit_checkboxes_preferred'
809
        );
810
      }
811
      $weight += 2;
812
    }
813
  }
814

    
815
  $element['table_end'] = array(
816
  //'#type'=>'value',
817
  '#value' => '</table>', '#weight'=>$weight++);
818
  return $element;
819
}
820

    
821

    
822
function theme_checkboxes_preferred($element){
823
  return theme('form_element',
824
     array(
825
      '#title' => $element['#title'],
826
      '#description' => $element['#description'],
827
      '#id' => $element['#id'],
828
      '#required' => $element['#required'],
829
      '#error' => $element['#error'],
830
      ),
831
     $element['#children']);
832
}
833

    
834
function checkboxes_preferred_after_build($form, &$form_values){
835

    
836
	$parent_id = $form['#parents'][0];
837

    
838
	if($_POST && count($_POST) > 0){
839
		// first pass of form processing
840
		$preferred_layer = $_POST[$parent_id.'_preferred'];
841
	  $form['#value']['PREFERRED'] = $preferred_layer;
842
	  $form_values[$parent_id] = $form['#value'];
843
	} else {
844
		// second pass of form processing
845
    $preferred_layer = $form['#value']['PREFERRED'];
846
	}
847

    
848
  // also set the chosen value (not sure if this is good drupal style ....)
849
  foreach( $children = element_children($form) as $key ){
850
      if($form[$key]['#type'] == 'radio'){
851
        $form[$key]['#value'] = $preferred_layer;
852
      }
853
  }
854
  // the default layer mus always be enabled
855
  $form[$preferred_layer]['#value'] = $preferred_layer;
856

    
857

    
858
  return $form;
859
}
860

    
(10-10/10)