Project

General

Profile

Download (57.8 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_URI', 'http://edit.br.fgov.be/edit_wp5/v1/');
32

    
33
/**
34
 * default settings for all gallerys
35
 * @var unknown_type
36
 */
37
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
38
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
39
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
40
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
41
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
42
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
43
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
44
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
45
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
46
//define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
47
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
48
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
49
define('CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
50
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
51

    
52
function getGallerySettings($gallery_config_form_name){
53
	$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
54
	return variable_get($gallery_config_form_name, $default_values);
55
}
56

    
57
function get_default_taxon_tab($index = false) {
58

    
59
	global $user;
60
	$values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
61
	$user_tab_active = 'cdm_dataportal_' .$user->uid . '_default_tab_active';
62
	$user_tab = 'cdm_dataportal_' .$user->uid . '_default_tab';
63
	//get the user value
64
	$user_tab_on = variable_get($user_tab_active, false);
65
	if($user_tab_on){
66
		$user_value = variable_get($user_tab, 0);
67
		$index_value = $user_value;
68
	//get the system value
69
	}else{
70
		$system_value = variable_get('cdm_dataportal_default_tab', 0);
71
		$index_value = $system_value;
72
	}
73
	if (!index){
74
	   return ($values[$index_value]);
75
	}else{
76
	   return $index_value;
77
	}
78
	
79

    
80
	switch ($value){
81
		case 0:
82
			$res = 'General';
83
			break;
84
		case 1:
85
			$res = 'Synonymy';
86
			break;
87
		case 2:
88
			$res = 'Images';
89
			break;
90
		case 3:
91
			$res = 'Specimens';
92
			break;
93
		case 4:
94
			$res = 'last_visited_tab';
95
			break;
96
		default:
97
			$res = 'General';
98
	}
99
	return $res;
100
}
101

    
102
function cdm_dataportal_menu_admin($may_cache, &$items){
103

    
104
	if (!$may_cache) {
105

    
106
		$items[] = array(
107
      'path' => 'admin/settings/cdm_dataportal',
108
      'title' => t('CDM Dataportal'),
109
      'description' => t('Setting for the CDM DataPortal'),
110
      'access' => user_access('administer cdm_dataportal'),
111
      'callback' => 'drupal_get_form',
112
      'callback arguments' => 'cdm_settings_general',
113
      'type' => MENU_NORMAL_ITEM,
114
		);
115

    
116
		$items[] = array(
117
      'path' => 'admin/settings/cdm_dataportal/general',
118
      'title' => t('General'),
119
      'description' => t('Setting for the CDM DataPortal'),
120
      'access' => user_access('administer cdm_dataportal'),
121
      'callback' => 'drupal_get_form',
122
      'callback arguments' => 'cdm_settings_general',
123
      'weight' => 0,
124
      'type' => MENU_LOCAL_TASK,
125
		);
126

    
127
		$items[] = array(
128
      'path' => 'admin/settings/cdm_dataportal/cachesite',
129
      'title' => t('Cache'),
130
      'description' => t('Cache'),
131
      'access' => user_access('administer cdm_dataportal'),
132
      'callback' => 'drupal_get_form',
133
      'callback arguments' => 'cdm_settings_cache',
134
      'weight' => 10,
135
      'type' => MENU_LOCAL_TASK,
136
		);
137

    
138
		$items[] = array(
139
      'path' => 'admin/settings/cdm_dataportal/geo',
140
      'title' => t('Geo & Map'),
141
      'description' => t('Geo & Map'),
142
      'access' => user_access('administer cdm_dataportal'),
143
      'callback' => 'drupal_get_form',
144
      'callback arguments' => 'cdm_settings_geo',
145
      'weight' => 1,
146
      'type' => MENU_LOCAL_TASK,
147
		);
148

    
149
		$items[] = array(
150
      'path' => 'admin/settings/cdm_dataportal/layout',
151
      'title' => t('Layout'),
152
      'description' => t('Configure and adjust the layout of your DataPortal '),
153
      'access' => user_access('administer cdm_dataportal'),
154
      'callback' => 'drupal_get_form',
155
      'callback arguments' => 'cdm_settings_layout',
156
      'weight' => 2,
157
      'type' => MENU_LOCAL_TASK,
158
		);
159

    
160
		$items[] = array(
161
      'path' => 'admin/settings/cdm_dataportal/layout/taxon',
162
      'title' => t('Taxon'),
163
      'description' => t('Configure and adjust the layout of your DataPortal '),
164
      'access' => user_access('administer cdm_dataportal'),
165
      'callback' => 'drupal_get_form',
166
      'callback arguments' => 'cdm_settings_layout_taxon',
167
      'weight' => 1,
168
      'type' => MENU_LOCAL_TASK,
169
		);
170
/*
171
		$items[] = array(
172
      'path' => 'admin/settings/cdm_dataportal/layout/synonymy',
173
      'title' => t('Synonymy'),
174
      'description' => t('Configure and adjust the layout of your DataPortal '),
175
      'access' => user_access('administer cdm_dataportal'),
176
      'callback' => 'drupal_get_form',
177
      'callback arguments' => 'cdm_settings_layout_synonymy',
178
      'weight' => 1,
179
      'type' => MENU_LOCAL_TASK,
180
		);
181

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

    
204
		$items[] = array(
205
      'path' => 'admin/settings/cdm_dataportal/layout/media',
206
      'title' => t('Media'),
207
      'description' => t('Configure and adjust the layout of your DataPortal '),
208
      'access' => user_access('administer cdm_dataportal'),
209
      'callback' => 'drupal_get_form',
210
      'callback arguments' => 'cdm_settings_layout_media',
211
      'weight' => 3,
212
      'type' => MENU_LOCAL_TASK,
213
		);
214
/*   Path to banners configuration (DEFAULT THEME)		
215
		$items[] = array(
216
      'path' => 'admin/settings/cdm_dataportal/layout/theme',
217
      'title' => t('Theme'),
218
      'description' => t('Configure the drupal theme of your DataPortal '),
219
      'access' => user_access('administer cdm_dataportal'),
220
      'callback' => 'drupal_get_form',
221
      'callback arguments' => array('cdm_dataportal_theming_form'),
222
      'weight' => 4,
223
      'type' => MENU_LOCAL_TASK,
224
        );
225
*/
226
	}
227

    
228

    
229
}
230

    
231
function cdm_help_general_cache(){
232
  $form = array();
233
  $form['cache_help'] = array(
234
  	'#type' => 'fieldset',
235
 	'#title' => t('Help'),
236
	'#collapsible' => TRUE,
237
	'#collapsed' => TRUE,
238
  );
239
  $form['cache_help']['test'] = array('#value' => t('probando'));
240
  return drupal_render($form);
241
  $res = array();
242
  $res['default'] = drupal_render($help);
243
  return $res;
244
}
245

    
246
/**
247
 * Configures the settings form for the CDM-API module.
248
 *
249
 * @return Array Drupal settings form
250
 */
251
function cdm_settings_general(){
252

    
253
	$form['cdm_webservice'] = array(
254
      '#type' => 'fieldset',
255
      '#title' => t('CDM Server'),
256
      '#collapsible' => FALSE,
257
      '#collapsed' => FALSE,
258
	  '#description' => t('<em>CDM Server</em> makes possible the dialogue with
259
	                       <em>CDM Data Portal</em> thanks to his web services.'),
260
	);
261

    
262
	$form['cdm_webservice']['cdm_webservice_url'] =  array(
263
    '#type' => 'textfield',
264
    '#title'         => t('CDM web service URL'),
265
    '#description'   => t('This is the ip address of the location of the CDM Web Server which contains
266
                           your collection database. The address must follow the format <em>"http://X:Y/Z"</em>
267
                           where "<em>X</em>" is the ip address of the machine where the server is running, "<em>Y</em>" is
268
                           the port number where the server is listening and "<em>Z</em>" the name of the database
269
                           where your collection is, e.g. <em>"http://160.45.63.201:8080/palmae"</em>'),
270
    '#default_value' => variable_get('cdm_webservice_url', NULL),
271
	);
272

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

    
308
    $form['cdm_webservice']['proxy'] = array(
309
      '#type' => 'fieldset',
310
      '#title' => t('Proxy'),
311
      '#collapsible' => TRUE,
312
      '#collapsed' => TRUE
313
    );
314

    
315
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] =  array(
316
    '#type' => 'textfield',
317
    '#title'         => t('Proxy URL'),
318
    '#description'   => t('If this proxy url is set the cdm api tries
319
    to connect the web service over the given proxy server.
320
    Otherwise proxy usage is deactivated.'),
321
    '#default_value' => variable_get('cdm_webservice_proxy_url', false),
322
    );
323

    
324
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] =  array(
325
    '#type' => 'textfield',
326
    '#title'         => t('Proxy port'),
327
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
328
    );
329

    
330
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] =  array(
331
    '#type' => 'textfield',
332
    '#title'         => t('Login'),
333
    '#default_value' => variable_get('cdm_webservice_proxy_usr', false),
334
    );
335

    
336
    $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] =  array(
337
    '#type' => 'textfield',
338
    '#title'         => t('Password'),
339
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', false),
340
    );
341

    
342
    //TODO: settings are still incomplete, compare with trunk/dataportal/inc/config_default.php.inc
343
    $form['cdm_dataportal'] = array(
344
      '#type' => 'fieldset',
345
      '#title' => t('Taxon Tree'),
346
      '#collapsible' => FALSE,
347
      '#collapsed' => TRUE,
348
      '#description' => t('<p>When you explore your collection, you can navigate it through a
349
                           tree structure also called <em>Taxon Tree</em>.</p><p>To be able to navigate through
350
                           your collection the
351
                           <a href="http://drupal.org/handbook/blocks">drupal block</a>
352
                           <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
353
                           <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p>'),
354
    );
355

    
356
    $form['cdm_dataportal'][CDM_TAXONOMICTREE_UUID] = array(
357
      '#type' => 'select',
358
      '#title'         => t('Available classifications'),
359
      '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, false),
360
      '#options' => cdm_get_taxontrees_as_options(),
361
      '#description'   => t('Select the default taxa classification for your <em>taxon tree</em>,
362
                             the other classifications will be also available but with a manual user change.')
363
    );
364

    
365
    $form['cdm_dataportal']['taxontree_ranklimit'] =  array(
366
    '#type'          => 'select',
367
    '#title'         => t('Rank of highest displayed taxon'),
368
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT), //before DEFAULT_TAXONTREE_RANKLIMIT_UUID
369
    '#options'       => cdm_rankVocabulary_as_option(),
370
    '#description'   => t('This is the rank of the highest displayed taxon in the <em>taxon tree</em>. You can
371
                           select here which rank should be at the top level of the tree structure.'),
372
	);
373

    
374
    return system_settings_form($form);
375
}
376

    
377
function gen_layout_form_submit ($form, $form_values) {
378
	drupal_set_message('This is a test!');
379
}
380

    
381

    
382
/**
383
 * LAYOUT settings
384
 * @return unknown_type
385
 */
386
function cdm_settings_layout(){
387

    
388
	//drupal_goto('admin/settings/cdm_dataportal/layout/taxon');
389
	$form = array();
390
/*
391
	// -- tabbed pages -- //
392
	$form['cdm_dataportal_taxonpage_tabs'] = array(
393
    '#type' => 'checkbox',
394
    '#title' => t('Tabbed taxon page'),
395
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
396
    '#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.')
397
	);
398
*/
399
	$form['gen_layout'] = array(
400
		'#type' => 'fieldset',
401
	    '#title' => t('Portal Layout'),
402
        '#collapsible' => FALSE,
403
        '#collapsed' => FALSE,
404
	    '#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.'),
405
	);
406
	
407
	//---- footnotes ---//
408
	$form['gen_layout']['footnotes'] = array(
409
      '#type' => 'fieldset',
410
      '#title' => t('Footnotes'),
411
      '#collapsible' => FALSE,
412
      '#collapsed' => FALSE,
413
	  '#description' => t('Taxa data such authors, synonyms names, descriptions, media or distribution areas may have annotations or footnotes. When the footnotes are enabled
414
	                       they will be visible (if they exist).'),
415
	);
416

    
417
	$form['gen_layout']['footnotes']['cdm_dataportal_all_footnotes'] = array(
418
      '#type' => 'checkbox',
419
      '#title' => t('Do not show footnotes'),
420
      '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
421
      '#description' => t('Check this if you do not want to show any footnotes')
422
	);
423

    
424
	$form['gen_layout']['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
425
      '#type' => 'checkbox',
426
      '#title' => t('Do not show annotations footnotes'),
427
      '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
428
      '#description' => t('Check this if you do not want to show annotation footnotes')
429
	);
430
	
431
	//--- Advanced Search ---//
432
	$form['gen_layout']['asearch'] = array(
433
      '#type' => 'fieldset',
434
      '#title' => t('Advanced search'),
435
      '#collapsible' => FALSE,
436
      '#collapsed' => FALSE,
437
    );
438
    $form['gen_layout']['asearch']['cdm_dataportal_show_advanced_search'] = array(
439
      '#type' => 'checkbox',
440
      '#title' => t('Show advanced search link'),
441
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
442
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
443
    );
444
        
445
	return system_settings_form($form);
446
}
447

    
448
function cdm_dataportal_theming_form (){
449
    //--- Theme ---//
450
/*    
451
    $form['cdm_dataportal_theming'] = array(
452
      '#type' => 'fieldset',
453
      '#title' => t('Theme Images'),
454
      '#collapsible' => FALSE,
455
      '#collapsed' => FALSE,
456
    );
457
*/
458
	$form = array('#attributes' => array('enctype' => 'multipart/form-data'));
459
	
460
    $form['cdm_dataportal_theming_right_image'] = array(
461
        '#type' => 'file',
462
        '#title' => t('Select top right image'),
463
        '#description' => t('Maximum dimensions are %dimensions and the maximum size is %size kB.', 
464
                            array('%dimensions' =>  '250x250', '%size' => '30')),
465
    );
466
    $form['cdm_dataportal_theming_middle_image'] = array(
467
        '#type' => 'file',
468
        '#title' => t('Select top middle image'),
469
    );
470
    $form['test'] = array(
471
        '#type' => 'textfield',
472
        '#title' => t('test')
473
    );
474
    
475
    //$form['gen_layout']['theme']['#submit'][] = 'settings_validate_theme_pictures';
476
    $form['cdm_dataportal_theming']['submit'] = array(
477
      '#type' => 'submit',
478
      '#value' => t('Submit')
479
    );
480
    
481
    return $form;
482
}
483

    
484
function cdm_dataportal_theming_form_submit (&$form, &$form_values){
485
	$validators = array();	
486
	//destination path where the files/banners will be saved
487
	$dest = absolute_path_to_drupal() . '/' . path_to_theme() . '/images/banners';
488
	$dest = str_replace('/', DIRECTORY_SEPARATOR, $dest);	
489
	//drupal_set_message($dest);
490

    
491
	//check if directory exists
492
	if (!file_exists($dest)){
493
        if(!mkdir($dest, 0777, true)){//TODO: add rights, which rights should I add?
494
            drupal_set_message('Fail uploading the files; the directory '
495
                               . $dest . ' could not be created.', 
496
                               'warning');
497
        }       
498
	}
499
	//check if files already exist
500
	//if (file_exists($dest)) {
501
	//}	
502
	
503
	//save the files
504
    $file = file_check_upload('cdm_dataportal_theming_middle_image');
505
    if ($file){
506
        $file = file_save_upload($file, 'files');
507
        drupal_set_message($file->filepath);
508
        file_move($file->filepath, $dest);
509
    }else{
510
    	drupal_set_message('Fail uploading the file, the file is not accepted.', 'warning');
511
    }
512
	//use banners in the selected theme
513
    //if (!copy($file, $file.'.bak')) {
514
    //    print ("failed to copy $file...<br>\n");
515
    //}
516
    
517
    //use the banners as default theme
518
}
519

    
520
function cdm_settings_layout_synonymy(){
521
  /* ====== SYNONYMY ====== */
522
  $form['synonymy'] = array(
523
      '#type' => 'fieldset',
524
      '#title' => t('Synonymy'),
525
      '#collapsible' => TRUE,
526
      '#collapsed' => FALSE,
527
      '#description' => t('This section covers the settings related to the taxon <b>synonymy</b> tab.'),
528
  );
529

    
530
  $form['synonymy']['cdm_dataportal_nomref_in_title'] = array(
531
    '#type' => 'checkbox',
532
    '#title' => t('Show accepted taxon on top of the synonymy'),
533
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
534
    '#description' => t('If checked, the first homotypic taxon is a repetition of the accepted taxon most likely
535
                        with the full nomenclatural reference (depending on the currently chosen theme).')
536
  );
537

    
538
  $form['synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
539
    '#type' => 'checkbox',
540
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
541
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
542
    '#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.')
543
  );
544

    
545
  $name_relationships_terms = cdm_ws_get(CDM_WS_TERMVOCABULARY, UUID_NAME_RELATIONSHIP_TYPE);
546
  $name_rel_options = array();
547
  //$name_rel_options['default'] = 'Show all';
548
  foreach ($name_relationships_terms->terms as $element){
549
    $name_rel_options[$element->uuid] = t('Show "' . $element->representation_L10n_abbreviated . '" relationships');
550
  }
551

    
552
  $name_relationships_form['name_relationships_to_show']= array(
553
    '#type' => 'checkboxes',
554
    '#title' => t('Display name relationships'),
555
    '#default_value' => variable_get('name_relationships_to_show', 0),
556
    '#options' => $name_rel_options,
557
    '#description' => t('Select the name relationships you want to show for the accepted taxa.'),
558
  );
559

    
560
  $form['synonymy']['name_relationships'] = $name_relationships_form;
561
      /*
562
       $form['synonymy'][CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS] = array(
563
       '#type' => 'checkbox',
564
       '#title' => t('Show name relations of accepted taxa on taxon page'),
565
       '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT),
566
       //'#description' => t('Check this if you want the synonymy list to show all the name relationships where other names implies the accepted taxa.')
567
       '#description' => t('Check this if you want the synonymy list to show all the name relationships of accepted taxa.')
568
       );
569
     */
570
  $form['synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
571
    '#type' => 'checkbox',
572
    '#title' => t('Show taxon relations of accepted taxa on taxon page'),
573
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
574
    '#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.')
575
  );
576

    
577
  return system_settings_form($form);
578
      /*
579
       $form['synonymy']['cdm_dataportal_name_relations_skiptype_basionym'] = array(
580
       '#type' => 'checkbox',
581
       '#title' => t('Exclude the basionym relationship type from the taxon page'),
582
       '#default_value' => variable_get('cdm_dataportal_name_relations_skiptype_basionym', 1),
583
       '#description' => t('')
584
       );
585
       */
586
}
587

    
588
function cdm_settings_layout_taxon(){
589
  $collapsed = false;
590
  $form = array();
591

    
592
	/* ======  TAXON_PROFILE ====== */
593

    
594
	$form['taxon_profile'] = array(
595
      '#type' => 'fieldset',
596
      '#title' => t('Taxon profile'),
597
      '#description' => t('<p>This section covers the setting related to the taxon profile tab, also known as the <strong>"General"</strong> tab.
598
                      It is possible to split the taxon profile in different tabs, visit the section Taxon tabs to discover and configure the tabs</p>'),
599
      '#collapsible' => FALSE,
600
      '#collapsed' => FALSE,
601
	);
602
	
603
	$form['taxon_profile']['cdm_dataportal_show_back_to_search_results'] = array(
604
	    '#type' => 'checkbox',
605
        '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
606
        '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
607
        '#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>')
608
	);
609

    
610
	//--------- TABBED TAXON -------//
611
	$form['taxon_profile']['taxon_tabs'] = array(
612
	  '#type' => 'fieldset',
613
      '#title' => t('Taxon tabs'),
614
      '#collapsible' => TRUE,
615
      '#collapsed' => FALSE,
616
	  '#description' => t('If tabbed taxon page is enabled the taxon profile will be splitted in four diferent tabs;
617
	           General, Synonymy, Images and Specimens. If the taxon has no information for any of the tabs/sections such tab will be not displayed.'),
618
	);
619

    
620
	$form['taxon_profile']['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
621
    '#type' => 'checkbox',
622
    '#title' => t('Tabbed taxon page'),
623
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
624
    '#description' => t('<p>If selected split the taxon page into individual tabs for description, images, synonymy and specimens.
625
                            If not the taxon data is renderized as a long single page without tabs.</p>')
626
	);
627

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

    
638
/* THIS SECTION HAS BEEN MOVED TO LAYOUT
639
	//---- footnotes ---//
640
	$form['taxon_profile']['footnotes'] = array(
641
      '#type' => 'fieldset',
642
      '#title' => t('Footnotes'),
643
      '#collapsible' => TRUE,
644
      '#collapsed' => TRUE,
645
	  '#description' => t('Taxa data such authors, synonyms names or some taxa description text may have annotations or footnotes. When the footnotes are enabled
646
	                       they will be visible (if they exist). Taxon synonymy and taxon speciemens sections or tabs may contain also footnotes.'),
647
	);
648

    
649
	$form['taxon_profile']['footnotes']['cdm_dataportal_all_footnotes'] = array(
650
      '#type' => 'checkbox',
651
      '#title' => t('Do not show footnotes'),
652
      '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
653
      '#description' => t('Check this if you do not want to show any footnotes')
654
	);
655

    
656
	$form['taxon_profile']['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
657
      '#type' => 'checkbox',
658
      '#title' => t('Do not show annotations footnotes'),
659
      '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
660
      '#description' => t('Check this if you do not want to show annotation footnotes')
661
	);
662
*/
663
	// ---- PROFILE PICTURE ----//
664
	$form['taxon_profile']['picture'] = array(
665
      '#type' => 'fieldset',
666
      '#title' => t('Profile Picture'),
667
      '#collapsible' => TRUE,
668
      '#collapsed' => FALSE,
669
	  '#description' => t('Select a profile picture for taxa. Like a facebook of plants.'),
670
	);
671

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

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

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

    
700
	//-- FEATURE TREE --//
701
	$form['taxon_profile']['taxon_profile'] = array(
702
	 '#type' => 'fieldset',
703
     '#title' => t('Features'),
704
     '#collapsible' => TRUE,
705
     '#collapsed' => FALSE,
706
	 '#description' => t('This section covers settings related to the taxon\'s <em>Feature Tree</em>. The <em>feature tree</em> are the taxon\'s
707
	                      features such description, distribution, common names, etc. that drupal will render at his taxon profile page.'),
708
	);
709
	$form['taxon_profile']['taxon_profile'][CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID] = array(
710
      '#type' => 'radios',
711
      '#title'         => t('Taxon profile sections'),
712
      '#default_value' => variable_get(CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE),
713
      '#options' => cdm_get_featureTrees_as_options(TRUE),
714
      '#description'   => t('Select the Feature Tree to be displayed at the taxon profile. Click "Show Details" to see the Feature Tree elemets.'
715
      )
716
      );
717

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

    
729

    
730
  /* ------ DISTRIBUTION LAYOUT ------ */
731

    
732
      $form['taxon_profile']['distribution_layout'] = array(
733
        '#title' => t('Distribution'),
734
        '#collapsible' => TRUE,
735
        '#collapsed' => FALSE,
736
        '#type' => 'fieldset',
737
      	'#description' => t('Select if you want to sort or not the distribution text located below the distribution map.'),
738
      );
739

    
740
      $form['taxon_profile']['distribution_layout']['distribution_sort'] =  array(
741
    '#type'          => 'radios',
742
    '#title'         => t('Sort'),
743
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
744
    '#options' => array(
745
        'NO_SORT' => t('Standard (No sort)'),
746
        'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
747
      ));
748

    
749
 /* ====== SYNONYMY ====== */
750
  $form['taxon_profile']['synonymy'] = array(
751
      '#type' => 'fieldset',
752
      '#title' => t('Taxon Synonymy (Tab)'),
753
      '#collapsible' => TRUE,
754
      '#collapsed' => FALSE,
755
      '#description' => t('This section covers the settings related to the taxon <b>synonymy</b> tab.'),
756
  );
757

    
758
  $form['taxon_profile']['synonymy']['cdm_dataportal_nomref_in_title'] = array(
759
    '#type' => 'checkbox',
760
    '#title' => t('Show accepted taxon on top of the synonymy'),
761
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
762
    '#description' => t('If checked, the first homotypic taxon is a repetition of the accepted taxon most likely
763
                        with the full nomenclatural reference (depending on the currently chosen theme).')
764
  );
765

    
766
  $form['taxon_profile']['synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
767
    '#type' => 'checkbox',
768
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
769
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
770
    '#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.')
771
  );
772

    
773
  $name_relationships_terms = cdm_ws_get(CDM_WS_TERMVOCABULARY, UUID_NAME_RELATIONSHIP_TYPE);
774
  $name_rel_options = array();
775
  //$name_rel_options['default'] = 'Show all';
776
  foreach ($name_relationships_terms->terms as $element){
777
    $name_rel_options[$element->uuid] = t('Show "' . $element->representation_L10n_abbreviated . '" relationships');
778
  }
779

    
780
  $name_relationships_form['name_relationships_to_show']= array(
781
    '#type' => 'checkboxes',
782
    '#title' => t('Display name relationships'),
783
    '#default_value' => variable_get('name_relationships_to_show', 0),
784
    '#options' => $name_rel_options,
785
    '#description' => t('Select the name relationships you want to show for the accepted taxa.'),
786
  );
787

    
788
  $form['taxon_profile']['synonymy']['name_relationships'] = $name_relationships_form;
789
      /*
790
       $form['synonymy'][CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS] = array(
791
       '#type' => 'checkbox',
792
       '#title' => t('Show name relations of accepted taxa on taxon page'),
793
       '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT),
794
       //'#description' => t('Check this if you want the synonymy list to show all the name relationships where other names implies the accepted taxa.')
795
       '#description' => t('Check this if you want the synonymy list to show all the name relationships of accepted taxa.')
796
       );
797
     */
798
  $form['taxon_profile']['synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
799
    '#type' => 'checkbox',
800
    '#title' => t('Show taxon relations of accepted taxa on taxon page'),
801
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
802
    '#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.')
803
  );
804

    
805
  // ====== SPECIMENS ====== //
806
  $form['taxon_profile']['specimens'] = array(
807
      '#type' => 'fieldset',
808
      '#title' => t('Taxon Specimens (Tab)'),
809
      '#collapsible' => TRUE,
810
      '#collapsed' => FALSE,
811
      '#description' => t('This section covers the settings related to the taxon <b>specimens</b> tab.'),
812
  );
813
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
814
  $form_title = 'Specimen media';
815
  $form_description = 'Specimens may have media which is displayed at the Specimen tab/section as a gallery.
816
   It is possible to configure the thumbnails gallery here, however for configuring how a single media should 
817
   be displayed please go to <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>';
818
  $form['taxon_profile']['specimens'][] =
819
    cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
820

    
821
  //-- MEDIA THUMBNAILS --//
822
  //$form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
823
  //$form_tittle = 'Taxon Images (Tab)';
824
  //$form_description = 'This section covers the settings related to the taxon images tab. Taxon images display all the media (in this case images) found for a given taxon as a thumbnails.';
825
  //$form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed, $form_description);
826
  // --- MEDIA GALLERY ---- //
827
  //$form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
828
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
829
  $form_title = 'Media gallery (Tab)';
830
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
831
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure 
832
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to 
833
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
834
   <p><strong>Note:</strong> These settings are only taken into account when the standard 
835
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
836
  //$form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
837
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
838

    
839
  
840
  return system_settings_form($form);
841
}
842

    
843
function cdm_settings_layout_search(){
844

    
845
	$form = array();
846

    
847
	$form['search_settings'] = array(
848
      '#type' => 'fieldset',
849
      '#title' => t('Taxa Search'),
850
      '#collapsible' => TRUE,
851
      '#collapsed' => FALSE,
852
	  '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
853
	                       the block <em>CDM Taxon Search</em> should be enabled and visible for users
854
	                       where they can write the text to be searched. You can find Drupal block configuration
855
	                       site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
856
      );
857

    
858
	$form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
859
    '#type' => 'textfield',
860
    '#title' => t('Results per page'),
861
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
862
    '#description' => t('Number of results to display per page.')
863
	);
864

    
865
	// --- SEARCH TAXA GALLERY ---- //
866
	$items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
867
	$collapsed = FALSE;
868
	$form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
869
	$form_title = 'Taxa Search thumbnails';
870
	$form_description = 'Search results may show thumbnails. ';
871
	$form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
872

    
873
	return system_settings_form($form);
874
}
875

    
876
function cdm_settings_layout_media(){
877

    
878
	$form = array();
879

    
880
	$form['media_settings'] = array(
881
      '#type' => 'fieldset',
882
      '#title' => t('Media display settings'),
883
      '#collapsible' => TRUE,
884
      '#collapsed' => FALSE,
885
	  '#description' => t('This section covers the settings related to the taxa media, that is how each single media should be displayed.'),
886
      );
887

    
888
	$form['media_settings']['image_gallery_viewer'] =  array(
889
    '#type'          => 'select',
890
    '#title'         => t('Image viewer'),
891
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
892
    '#options' => array('default' => t('Standard image viewer'),
893
                        'fsi' => t('FSI viewer (requires FSI server!)')),
894
	);
895

    
896
	// --- MEDIA GALLERY ---- //
897
	$form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
898
	$form_title = 'Standard viewer';
899
	$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>';
900
	//$form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
901
	$form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
902

    
903

    
904
	return system_settings_form($form);
905
}
906

    
907

    
908
/**
909
 * GEOSERVICE and Map settings
910
 * @return unknown_type
911
 */
912
function cdm_settings_geo(){
913

    
914
	$form = array();
915

    
916
	/*
917
	 * GEO SERVER
918
	 */
919

    
920
     $form['geoserver'] = array(
921
      '#type' => 'fieldset',
922
      '#title' => t('Geo Server Settings'),
923
      '#collapsible' => TRUE,
924
      '#collapsed' => TRUE,
925
      '#description' => t('Configuration and selection of your geo server. The Geo Server is the responsible for generating the maps.'),
926
	 );
927

    
928
	$form['geoserver']['edit_map_server'] = array(
929
    '#type' => 'select',
930
    '#title' => t('Geoservice access point URL'),
931
    '#default_value' => variable_get('edit_map_server', 'http://edit.br.fgov.be/edit_wp5/v1/'),
932

    
933
    '#options' => array(
934
	      EDIT_MAPSERVER_URI => 'EDIT Map Server',
935
	/*
936
	 'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server - Mirror 1',
937
	 'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server - Mirror 2',
938
	 */
939
	      'ALTERNATIVE' => '-- Alternative URL --'
940
	      ),
941
    '#description' => t('Select the Map Server you want the data portal to connect.
942
                         If you want to introduce a custom address just select the Alternative URL value and fill the field Geoservice
943
                         Access Point - Alternative URL with the custem ip address.')
944
	      );
945

    
946
	      $form['geoserver']['edit_map_server_alternative'] = array(
947
    '#type' => 'textfield',
948
    '#title' => t('Geoservice access point - alternative URL'),
949
    '#default_value' => variable_get('edit_map_server_alternative', ''),
950
    '#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.')
951
	      );
952

    
953

    
954
	/*
955
	 *  MAP SETTINGS
956
	 */
957

    
958
	      $form['map_settings'] = array(
959
      '#type' => 'fieldset',
960
      '#title' => t('Maps settings'),
961
      '#collapsible' => TRUE,
962
      '#collapsed' => TRUE,
963
	  '#description' => t('Configuration of the renderized maps.'),
964
	      );
965

    
966
	      $form['map_settings']['cdm_dataportal_geoservice_display_width'] = array(
967
    '#type' => 'textfield',
968
    '#title' => t('Maps size'),
969
    '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
970
    '#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.')
971
	      );
972

    
973
	      $form['map_settings']['cdm_dataportal_geoservice_bounding_box'] = array(
974
    '#type' => 'textfield',
975
    '#title' => t('Fixed bounding box'),
976
    '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
977
    '#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.')
978
	      );
979

    
980
	      $form['map_settings']['cdm_dataportal_geoservice_labels_on'] = array(
981
    '#type' => 'checkbox',
982
    '#title' => '<b>'.t('Display area labels').'</b>',
983
    '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
984
    '#description' => t('Check this if you like area names to be displayed in the maps. DOES IT WORKS???? ')
985
	      );
986

    
987
	      $form['map_settings']['cdm_dataportal_geoservice_map_caption'] = array(
988
    '#type' => 'textfield',
989
    '#title' => t('Map caption'),
990
    '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
991
    '#description' => t('Define a caption for the map.')
992
	      );
993

    
994
	      $form['map_settings']['cdm_dataportal_geoservice_distributionOpacity'] = array(
995
    '#type' => 'textfield',
996
    '#title' => t('Distribution layer opacity'),
997
    '#default_value' => variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5'),
998
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
999
                         fully visible, while a value near to 0.0 will be not much visible.')
1000
	      );
1001

    
1002
/*
1003
	      $form['map_settings']['cdm_dataportal_map_openlayers'] = array(
1004
    '#type' => 'checkbox',
1005
    '#title' => t('<b>Open Layers viewer</b>'),
1006
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1007
    '#description' => t('Display the maps in an interactive viewer which allows zooming and panning. If not enabled the maps will consist
1008
                         on a static image. If enabled you can configure the default layer (background of your maps) below. Only one of
1009
                         them will be renderized, the one selected as <em>Default</em>.')
1010
	      );
1011
*/
1012

    
1013
	      // --- OpenLayers Settings --- //
1014

    
1015
	      $form['openlayers'] = array(
1016
      '#type' => 'fieldset',
1017
      '#title' => t('OpenLayers settings'),
1018
      '#collapsible' => TRUE,
1019
	  '#collapsed' => TRUE,
1020
      //'#collapsed' => !variable_get('cdm_dataportal_map_openlayers', 1),
1021
	  '#description' => t('If you activate the interactive maps (OpenLayers Viewer checkbox). You need to configure which layer you prefer to use as map background.'),
1022
	      );
1023

    
1024
	      $baselayer_options = array(
1025
	      /*
1026
	       * NOTICE: must correspond to the layers defined in js/openlayers_,ap.js#getLayersByName()
1027
	       */
1028
    'osgeo_vmap0' => "OpenLayers World", // EPSG:4326
1029
    'metacarta_vmap0' => "Metacarta Vmap0" , // EPSG:4326, EPSG:900913
1030
	      // all others EPSG:900913 ...
1031
    'osmarender' => 'OpenStreetMap',
1032
    //'oam' => 'OpenAerialMap', // currently unavailable
1033
    'gmap' => 'Google Streets',
1034
    'gsat' => 'Google Satellite',
1035
    'ghyb' => 'Google Hybrid',
1036
    'veroad' => 'Virtual Earth Roads',
1037
    'veaer' => 'Virtual Earth Aerial',
1038
    'vehyb' => 'Virtual Earth Hybrid'
1039
	      //  ,
1040
	      //    'yahoo' => 'Yahoo Street',
1041
	      //    'yahoosat' => 'Yahoo Satellite',
1042
	      //    'yahoohyb' => 'Yahoo Hybrid'
1043

    
1044
	      );
1045

    
1046
	      $form['openlayers']['cdm_dataportal_map_openlayers'] = array(
1047
    '#type' => 'checkbox',
1048
    '#title' => '<b>'.t('OpenLayers viewer').'</b>',
1049
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1050
    '#description' => t('Display the maps in an interactive viewer which allows zooming and panning. If not enabled the maps will consist
1051
                         on a static image. If enabled you can configure the default layer (background of your maps) below. Only one of
1052
                         them will be renderized.')
1053
	      );
1054
	      $form['openlayers']['baselayers'] = array(
1055
    '#type' => 'checkboxes_preferred',
1056
    '#title' => t('Baser Layers'),
1057
    '#options' => $baselayer_options,
1058
    '#default_value' => variable_get('baselayers', array('metacarta_vmap0' => "metacarta_vmap0", 'PREFERRED' => 'metacarta_vmap0')),
1059
    '#description' => t('')
1060
	      );
1061

    
1062
	      // cdm_dataportal_geoservice_showLayerSwitcher
1063
	      $form['openlayers']['cdm_dataportal_geoservice_showLayerSwitcher'] = array(
1064
    '#type' => 'checkbox',
1065
    '#title' => '<b>'.t('Show Layer Switcher').'</b>',
1066
    '#default_value' => variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE),
1067
    '#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.')
1068
	      );
1069

    
1070
	      $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1071
	      $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1072
	      $form['openlayers']['gmap_api_key'] = array(
1073
    '#type' => 'textfield',
1074
    '#title' => t('Gogle maps API key'),
1075
    '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1076
    '#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>
1077
         <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.')
1078
	      );
1079

    
1080
	      $form['cdm_dataportal_geoservice_map_legend'] = array(
1081
      '#type' => 'fieldset',
1082
      '#title' => t('Map legend'),
1083
      '#collapsible' => TRUE,
1084
      '#collapsed' => TRUE,
1085
	  '#description' => t('Configure the maps legend.')
1086
	      );
1087

    
1088
	      $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
1089
    '#type' => 'checkbox',
1090
    '#title' => '<b>'.t('Display a map legend').'</b>',
1091
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
1092
    '#description' => t('Check this if you like a legend to be displayed with the maps.')
1093
	      );
1094

    
1095
	      $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legendOpacity'] = array(
1096
    '#type' => 'textfield',
1097
    '#title' => t('Legend opacity'),
1098
    '#default_value' => variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'),
1099
    '#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
1100
                         to 0.0 will be not much visible.')
1101
	      );
1102

    
1103
	      $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
1104
    '#type' => 'textfield',
1105
    '#title' => t('Font size'),
1106
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
1107
    '#description' => t('Font size in pixels.')
1108
	      );
1109

    
1110
	      $fontStyles = array(0 => "plane", 1 => "italic");
1111
	      $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
1112
    '#type' => 'select',
1113
    '#title' => t('Available font styles'),
1114
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', false),
1115
    '#options' => $fontStyles,
1116
    '#description'   => t('Select a font style for the map legend.')
1117
	      );
1118

    
1119
	      $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
1120
    '#type' => 'textfield',
1121
    '#title' => t('Legend icon width'),
1122
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
1123
    '#description' => t('Legend icon width in pixels.')
1124
	      );
1125

    
1126
	      $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
1127
    '#type' => 'textfield',
1128
    '#title' => t('Legend icon height'),
1129
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
1130
    '#description' => t('Legend icon height in pixels.')
1131
	      );
1132

    
1133
	      return system_settings_form($form);
1134
}
1135

    
1136

    
1137
function cdm_settings_cache(){
1138

    
1139
  $form = array();
1140

    
1141
  $form['cache_settings'] = array(
1142
      '#type' => 'fieldset',
1143
      '#title' => t('Cache Settings'),
1144
      '#collapsible' => FALSE,
1145
      '#collapsed' => FALSE,
1146
	  '#description' => t('<p>TODO: cache process does not work, check java script.</p><p>When caching is enabled all single taxon sites are stored in an internal drupal cache doing
1147
                           the portal response of taxa pages faster. This is possible because the sites are loaded from
1148
                           the cache and are not created from scratch.</p>'),
1149
      );
1150

    
1151
  $form['cache_settings']['cdm_webservice_cache'] =  array(
1152
    '#type'          => 'checkbox',
1153
    '#title'         => t('<strong>Enable caching</strong>'),
1154
	'#options'		 => cdm_help_general_cache(),
1155
    '#default_value' => variable_get('cdm_webservice_cache', 1),
1156
    '#description'   => t('<p>Enable drupal to load taxa pages from the cache.</p>' .
1157
	                       '<p><strong>Note:</strong> If taxa are modified by the editor or any other application the changes will be not
1158
	                       visible till the cache is erased. Therefore developers should deactived this feature when they
1159
	                       are working on the CDM Dataportal Module.</p>')
1160
    );
1161

    
1162
  $form['cache_settings']['cdm_run_cache'] = array(
1163
    '#value' => cdm_view_cache_site()
1164
  );
1165

    
1166
  return system_settings_form($form);
1167
}
1168

    
1169
/**
1170
 * @return walk and cache all taxon pages
1171
 */
1172
function cdm_view_cache_site(){
1173

    
1174
	$out = '';
1175

    
1176
    _add_js_progressbar();
1177
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cache_all_taxa.js');
1178

    
1179
	$request_params = array();
1180
	$request_params['query'] = '%';
1181
	$request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false); //cache only the dafault classification
1182
	$request_params['doTaxa'] = 1;
1183
	$request_params['doSynonyms'] = 0;
1184
	$request_params['doTaxaByCommonNames'] = 0;
1185
	$search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1186
	$search_url = uri_uriByProxy($search_url);
1187
	$taxon_page_url = url('cdm_dataportal/taxon/');
1188

    
1189

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

    
1196
	$out .= '<form id="cache_site">';
1197
	$out .= '<div>'.t('This caching process may take long time and could cause heavy load on your server').'</div>';
1198
	$out .= '<div id="progress"></div>';
1199
	$out .= '<input type="hidden" name="searchTaxaUrl" value="'.$search_url.'"/>';
1200
	$out .= '<input type="hidden" name="taxonPageUrl" value="'.$taxon_page_url.'"/>';
1201
	$out .= '<input type="button" name="start" value="'.t('Start').'"/>';
1202
	$out .= '<input type="button" name="stop" value="'.t('Stop').'"/>';
1203
	$out .= '</form>';
1204
	$out .= '</div>';
1205
	//  foreach($taxonPager->records as $taxon){
1206
	//    cdm_dataportal_taxon_view($uuid);
1207
	//  }
1208

    
1209
	return $out;
1210
}
1211

    
1212

    
1213
/**
1214
 * Implementation of hook_validate()
1215
 *
1216
 * @param $element
1217
 */
1218
function cdm_settings_validate($form_id, $form_values){
1219

    
1220
	if (!str_endsWith($form_values['cdm_webservice_url'], '/')) {
1221
		//form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
1222
		$form_values['cdm_webservice_url'] .= '/';
1223
	}
1224

    
1225
	if($form_values['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)){
1226
		cache_clear_all(NULL, 'cache_cdm_ws');
1227
		// better clear secref_cache since i can not be sure if the cache has not be used during this response
1228
		cdm_api_secref_cache_clear();
1229
	}
1230

    
1231
}
1232

    
1233
function getEDITMapServiceURI(){
1234

    
1235
	if(variable_get('edit_map_server', false) == 'ALTERNATIVE'){
1236
		return (variable_get('edit_map_server_alternative', false));
1237
	} else if(variable_get('edit_map_server', false)) {
1238
		return variable_get('edit_map_server', false);
1239
	} else {
1240
		return EDIT_MAPSERVER_URI;
1241
	}
1242

    
1243
}
1244

    
1245
/**
1246
 * Implementation of hook_elements()
1247
 *
1248
 * see http://drupal.org/node/37862 for an example
1249
 */
1250
function cdm_dataportal_elements() {
1251
	$type['checkboxes_preferred'] = array(
1252
    '#input' => TRUE,
1253
    '#process' => array('expand_checkboxes_preferred' => array()),
1254
    '#after_build' => array('checkboxes_preferred_after_build')
1255
	);
1256
	return $type;
1257
}
1258

    
1259
/**
1260
 * #process function for the custom form element type 'checkbox_preferred'
1261
 */
1262
function expand_checkboxes_preferred($element){
1263

    
1264
	// first of all create the checkboxes
1265
	$element = expand_checkboxes($element);
1266

    
1267
	$children = element_children($element);
1268
	$element['table_start'] = array(
1269
    '#value' => '<table class="checkboxes_preferred"><tr><th></th><th>'.t('Enabled').'</th><th>'.t('Default').'</th></tr>',
1270
    '#weight'=>-1
1271
	);
1272
	$weight = 0;
1273
	foreach ($children as $key) {
1274
		$odd_even = $weight % 4 == 0 ? 'odd' : 'even';
1275
		$element[$key]['#weight'] = $weight;
1276
		$element[$key]['#prefix'] = '<tr class="'.$odd_even.'"><td>'.t($element['#options'][$key]).'</td><td>';
1277
		$element[$key]['#suffix'] = '</td>';
1278
		unset($element[$key]['#title']);
1279
		$weight += 2;
1280
	}
1281
	$weight = 0;
1282

    
1283
	if (count($element['#options']) > 0) {
1284
		foreach ($element['#options'] as $key => $choice) {
1285
			if (!isset($element[$key.'_preferred'])) {
1286
				$element[$key.'_preferred'] = array(
1287
        '#type' => 'radio',
1288
        '#name' => $element['#parents'][0].'_preferred',
1289
        '#return_value' => check_plain($key),
1290
        '#default_value' => $element['#default_value_2'],
1291
        '#attributes' => $element['#attributes'],
1292
        '#parents' => $element['#parents'],
1293
        '#spawned' => TRUE,
1294
        '#weight' => $weight + 1,
1295
        '#prefix' => '<td>',
1296
        '#suffix' => '</td></tr>',
1297
				//'#submit' => 'submit_checkboxes_preferred'
1298
				);
1299
			}
1300
			$weight += 2;
1301
		}
1302
	}
1303

    
1304
	$element['table_end'] = array(
1305
	//'#type'=>'value',
1306
  '#value' => '</table>', '#weight'=>$weight++);
1307
	return $element;
1308
}
1309

    
1310

    
1311
function theme_checkboxes_preferred($element){
1312
	return theme('form_element',
1313
	array(
1314
      '#title' => $element['#title'],
1315
      '#description' => $element['#description'],
1316
      '#id' => $element['#id'],
1317
      '#required' => $element['#required'],
1318
      '#error' => $element['#error'],
1319
	),
1320
	$element['#children']);
1321
}
1322

    
1323
function checkboxes_preferred_after_build($form, &$form_values){
1324

    
1325
	$parent_id = $form['#parents'][0];
1326

    
1327
	if($_POST && count($_POST) > 0){
1328
		// first pass of form processing
1329
		$preferred_layer = $_POST[$parent_id.'_preferred'];
1330
		$form['#value']['PREFERRED'] = $preferred_layer;
1331
		$form_values[$parent_id] = $form['#value'];
1332
	} else {
1333
		// second pass of form processing
1334
		$preferred_layer = $form['#value']['PREFERRED'];
1335
	}
1336

    
1337
	// also set the chosen value (not sure if this is good drupal style ....)
1338
	foreach( $children = element_children($form) as $key ){
1339
		if($form[$key]['#type'] == 'radio'){
1340
			$form[$key]['#value'] = $preferred_layer;
1341
		}
1342
	}
1343
	// the default layer mus always be enabled
1344
	$form[$preferred_layer]['#value'] = $preferred_layer;
1345

    
1346

    
1347
	return $form;
1348
}
1349

    
(12-12/12)