Project

General

Profile

Download (58.6 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
define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
33

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

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

    
58
function get_default_taxon_tab($index = false) {
59

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

    
80

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

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

    
105
	if (!$may_cache) {
106

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

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

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

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

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

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

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

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

    
229

    
230
}
231

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

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

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

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

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

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

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

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

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

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

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

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

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

    
375
    return system_settings_form($form);
376
}
377

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

    
382

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

    
389
	//drupal_goto('admin/settings/cdm_dataportal/layout/taxon');
390
	$form = array();
391
/*
392
	// -- tabbed pages -- //
393
	$form['cdm_dataportal_taxonpage_tabs'] = array(
394
    '#type' => 'checkbox',
395
    '#title' => t('Tabbed taxon page'),
396
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
397
    '#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.')
398
	);
399
*/
400
	$form['gen_layout'] = array(
401
		'#type' => 'fieldset',
402
	    '#title' => t('Portal Layout'),
403
        '#collapsible' => FALSE,
404
        '#collapsed' => FALSE,
405
	    '#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.'),
406
	);
407

    
408
	//---- footnotes ---//
409
	$form['gen_layout']['footnotes'] = array(
410
      '#type' => 'fieldset',
411
      '#title' => t('Footnotes'),
412
      '#collapsible' => FALSE,
413
      '#collapsed' => FALSE,
414
	  '#description' => t('Taxa data such authors, synonyms names, descriptions, media or distribution areas may have annotations or footnotes. When the footnotes are enabled
415
	                       they will be visible (if they exist).'),
416
	);
417

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

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

    
432
	//--- Advanced Search ---//
433
	$form['gen_layout']['asearch'] = array(
434
      '#type' => 'fieldset',
435
      '#title' => t('Advanced search'),
436
      '#collapsible' => FALSE,
437
      '#collapsed' => FALSE,
438
    );
439
    $form['gen_layout']['asearch']['cdm_dataportal_show_advanced_search'] = array(
440
      '#type' => 'checkbox',
441
      '#title' => t('Show advanced search link'),
442
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
443
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
444
    );
445

    
446
	return system_settings_form($form);
447
}
448

    
449
function cdm_dataportal_theming_form (){
450
    //--- Theme ---//
451
/*
452
    $form['cdm_dataportal_theming'] = array(
453
      '#type' => 'fieldset',
454
      '#title' => t('Theme Images'),
455
      '#collapsible' => FALSE,
456
      '#collapsed' => FALSE,
457
    );
458
*/
459
	$form = array('#attributes' => array('enctype' => 'multipart/form-data'));
460

    
461
    $form['cdm_dataportal_theming_right_image'] = array(
462
        '#type' => 'file',
463
        '#title' => t('Select top right image'),
464
        '#description' => t('Maximum dimensions are %dimensions and the maximum size is %size kB.',
465
                            array('%dimensions' =>  '250x250', '%size' => '30')),
466
    );
467
    $form['cdm_dataportal_theming_middle_image'] = array(
468
        '#type' => 'file',
469
        '#title' => t('Select top middle image'),
470
    );
471
    $form['test'] = array(
472
        '#type' => 'textfield',
473
        '#title' => t('test')
474
    );
475

    
476
    //$form['gen_layout']['theme']['#submit'][] = 'settings_validate_theme_pictures';
477
    $form['cdm_dataportal_theming']['submit'] = array(
478
      '#type' => 'submit',
479
      '#value' => t('Submit')
480
    );
481

    
482
    return $form;
483
}
484

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

    
492
	//check if directory exists
493
	if (!file_exists($dest)){
494
        if(!mkdir($dest, 0777, true)){//TODO: add rights, which rights should I add?
495
            drupal_set_message('Fail uploading the files; the directory '
496
                               . $dest . ' could not be created.',
497
                               'warning');
498
        }
499
	}
500
	//check if files already exist
501
	//if (file_exists($dest)) {
502
	//}
503

    
504
	//save the files
505
    $file = file_check_upload('cdm_dataportal_theming_middle_image');
506
    if ($file){
507
        $file = file_save_upload($file, 'files');
508
        drupal_set_message($file->filepath);
509
        file_move($file->filepath, $dest);
510
    }else{
511
    	drupal_set_message('Fail uploading the file, the file is not accepted.', 'warning');
512
    }
513
	//use banners in the selected theme
514
    //if (!copy($file, $file.'.bak')) {
515
    //    print ("failed to copy $file...<br>\n");
516
    //}
517

    
518
    //use the banners as default theme
519
}
520

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

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

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

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

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

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

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

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

    
593
	/* ======  TAXON_PROFILE ====== */
594

    
595
	$form['taxon_profile'] = array(
596
      '#type' => 'fieldset',
597
      '#title' => t('Taxon profile'),
598
      '#description' => t('<p>This section covers the setting related to the taxon profile tab, also known as the <strong>"General"</strong> tab.
599
                      It is possible to split the taxon profile in different tabs, visit the section Taxon tabs to discover and configure the tabs</p>'),
600
      '#collapsible' => FALSE,
601
      '#collapsed' => FALSE,
602
	);
603

    
604
	$form['taxon_profile']['cdm_dataportal_show_back_to_search_results'] = array(
605
	    '#type' => 'checkbox',
606
        '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
607
        '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
608
        '#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>')
609
	);
610

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

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

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

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

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

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

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

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

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

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

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

    
730

    
731
  /* ------ DISTRIBUTION LAYOUT ------ */
732

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

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

    
750
     $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] =  array(
751
    '#type'          => 'checkbox',
752
    '#title'         => t('Show TextData elements on top of the map'),
753
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
754
    '#description' => t('Check this if you want to appear all <code>TextData</code> elements on top of the map.
755
      Otherwise all <code>TextData</code> distribution elements will be listed below the other area elements.
756
      This option is useful if you need to have descriptive texts for each distribution map.'),
757
    );
758

    
759

    
760
 /* ====== SYNONYMY ====== */
761
  $form['taxon_profile']['synonymy'] = array(
762
      '#type' => 'fieldset',
763
      '#title' => t('Taxon Synonymy (Tab)'),
764
      '#collapsible' => TRUE,
765
      '#collapsed' => FALSE,
766
      '#description' => t('This section covers the settings related to the taxon <b>synonymy</b> tab.'),
767
  );
768

    
769
  $form['taxon_profile']['synonymy']['cdm_dataportal_nomref_in_title'] = array(
770
    '#type' => 'checkbox',
771
    '#title' => t('Show accepted taxon on top of the synonymy'),
772
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
773
    '#description' => t('If checked, the first homotypic taxon is a repetition of the accepted taxon most likely
774
                        with the full nomenclatural reference (depending on the currently chosen theme).')
775
  );
776

    
777
  $form['taxon_profile']['synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
778
    '#type' => 'checkbox',
779
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
780
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
781
    '#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.')
782
  );
783

    
784
  $name_relationships_terms = cdm_ws_get(CDM_WS_TERMVOCABULARY, UUID_NAME_RELATIONSHIP_TYPE);
785
  $name_rel_options = array();
786
  //$name_rel_options['default'] = 'Show all';
787
  foreach ($name_relationships_terms->terms as $element){
788
    $name_rel_options[$element->uuid] = t('Show "' . $element->representation_L10n_abbreviated . '" relationships');
789
  }
790

    
791
  $name_relationships_form['name_relationships_to_show']= array(
792
    '#type' => 'checkboxes',
793
    '#title' => t('Display name relationships'),
794
    '#default_value' => variable_get('name_relationships_to_show', 0),
795
    '#options' => $name_rel_options,
796
    '#description' => t('Select the name relationships you want to show for the accepted taxa.'),
797
  );
798

    
799
  $form['taxon_profile']['synonymy']['name_relationships'] = $name_relationships_form;
800
      /*
801
       $form['synonymy'][CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS] = array(
802
       '#type' => 'checkbox',
803
       '#title' => t('Show name relations of accepted taxa on taxon page'),
804
       '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT),
805
       //'#description' => t('Check this if you want the synonymy list to show all the name relationships where other names implies the accepted taxa.')
806
       '#description' => t('Check this if you want the synonymy list to show all the name relationships of accepted taxa.')
807
       );
808
     */
809
  $form['taxon_profile']['synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
810
    '#type' => 'checkbox',
811
    '#title' => t('Show taxon relations of accepted taxa on taxon page'),
812
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
813
    '#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.')
814
  );
815

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

    
832
  //-- MEDIA THUMBNAILS --//
833
  //$form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
834
  //$form_tittle = 'Taxon Images (Tab)';
835
  //$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.';
836
  //$form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed, $form_description);
837
  // --- MEDIA GALLERY ---- //
838
  //$form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
839
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
840
  $form_title = 'Media gallery (Tab)';
841
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
842
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
843
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
844
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
845
   <p><strong>Note:</strong> These settings are only taken into account when the standard
846
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
847
  //$form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
848
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
849

    
850

    
851
  return system_settings_form($form);
852
}
853

    
854
function cdm_settings_layout_search(){
855

    
856
	$form = array();
857

    
858
	$form['search_settings'] = array(
859
      '#type' => 'fieldset',
860
      '#title' => t('Taxa Search'),
861
      '#collapsible' => TRUE,
862
      '#collapsed' => FALSE,
863
	  '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
864
	                       the block <em>CDM Taxon Search</em> should be enabled and visible for users
865
	                       where they can write the text to be searched. You can find Drupal block configuration
866
	                       site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
867
      );
868

    
869
	$form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
870
    '#type' => 'textfield',
871
    '#title' => t('Results per page'),
872
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
873
    '#description' => t('Number of results to display per page.')
874
	);
875

    
876
	// --- SEARCH TAXA GALLERY ---- //
877
	$items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
878
	$collapsed = FALSE;
879
	$form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
880
	$form_title = 'Taxa Search thumbnails';
881
	$form_description = 'Search results may show thumbnails. ';
882
	$form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
883

    
884
	return system_settings_form($form);
885
}
886

    
887
function cdm_settings_layout_media(){
888

    
889
	$form = array();
890

    
891
	$form['media_settings'] = array(
892
      '#type' => 'fieldset',
893
      '#title' => t('Media display settings'),
894
      '#collapsible' => TRUE,
895
      '#collapsed' => FALSE,
896
	  '#description' => t('This section covers the settings related to the taxa media, that is how each single media should be displayed.'),
897
      );
898

    
899
	$form['media_settings']['image_gallery_viewer'] =  array(
900
    '#type'          => 'select',
901
    '#title'         => t('Image viewer'),
902
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
903
    '#options' => array('default' => t('Standard image viewer'),
904
                        'fsi' => t('FSI viewer (requires FSI server!)')),
905
	);
906

    
907
	// --- MEDIA GALLERY ---- //
908
	$form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
909
	$form_title = 'Standard viewer';
910
	$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>';
911
	//$form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
912
	$form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
913

    
914

    
915
	return system_settings_form($form);
916
}
917

    
918

    
919
/**
920
 * GEOSERVICE and Map settings
921
 * @return unknown_type
922
 */
923
function cdm_settings_geo(){
924

    
925
	$form = array();
926

    
927
	/*
928
	 * GEO SERVER
929
	 */
930

    
931
     $form['geoserver'] = array(
932
      '#type' => 'fieldset',
933
      '#title' => t('Geo Server Settings'),
934
      '#collapsible' => TRUE,
935
      '#collapsed' => TRUE,
936
      '#description' => t('Configuration and selection of your geo server. The Geo Server is the responsible for generating the maps.'),
937
	 );
938

    
939
	$form['geoserver']['edit_map_server'] = array(
940
    '#type' => 'select',
941
    '#title' => t('Geoservice access point URL'),
942
    '#default_value' => variable_get('edit_map_server', 'http://edit.br.fgov.be/edit_wp5/v1/'),
943

    
944
    '#options' => array(
945
	      EDIT_MAPSERVER_URI => 'EDIT Map Server',
946
	/*
947
	 'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server - Mirror 1',
948
	 'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server - Mirror 2',
949
	 */
950
	      'ALTERNATIVE' => '-- Alternative URL --'
951
	      ),
952
    '#description' => t('Select the Map Server you want the data portal to connect.
953
                         If you want to introduce a custom address just select the Alternative URL value and fill the field Geoservice
954
                         Access Point - Alternative URL with the custem ip address.')
955
	      );
956

    
957
	      $form['geoserver']['edit_map_server_alternative'] = array(
958
    '#type' => 'textfield',
959
    '#title' => t('Geoservice access point - alternative URL'),
960
    '#default_value' => variable_get('edit_map_server_alternative', ''),
961
    '#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.')
962
	      );
963

    
964

    
965
	/*
966
	 *  MAP SETTINGS
967
	 */
968

    
969
	      $form['map_settings'] = array(
970
      '#type' => 'fieldset',
971
      '#title' => t('Maps settings'),
972
      '#collapsible' => TRUE,
973
      '#collapsed' => TRUE,
974
	  '#description' => t('Configuration of the renderized maps.'),
975
	      );
976

    
977
	      $form['map_settings']['cdm_dataportal_geoservice_display_width'] = array(
978
    '#type' => 'textfield',
979
    '#title' => t('Maps size'),
980
    '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
981
    '#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.')
982
	      );
983

    
984
	      $form['map_settings']['cdm_dataportal_geoservice_bounding_box'] = array(
985
    '#type' => 'textfield',
986
    '#title' => t('Fixed bounding box'),
987
    '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
988
    '#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.')
989
	      );
990

    
991
	      $form['map_settings']['cdm_dataportal_geoservice_labels_on'] = array(
992
    '#type' => 'checkbox',
993
    '#title' => '<b>'.t('Display area labels').'</b>',
994
    '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
995
    '#description' => t('Check this if you like area names to be displayed in the maps. DOES IT WORKS???? ')
996
	      );
997

    
998
	      $form['map_settings']['cdm_dataportal_geoservice_map_caption'] = array(
999
    '#type' => 'textfield',
1000
    '#title' => t('Map caption'),
1001
    '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
1002
    '#description' => t('Define a caption for the map.')
1003
	      );
1004

    
1005
	      $form['map_settings']['cdm_dataportal_geoservice_distributionOpacity'] = array(
1006
    '#type' => 'textfield',
1007
    '#title' => t('Distribution layer opacity'),
1008
    '#default_value' => variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5'),
1009
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1010
                         fully visible, while a value near to 0.0 will be not much visible.')
1011
	      );
1012

    
1013
/*
1014
	      $form['map_settings']['cdm_dataportal_map_openlayers'] = array(
1015
    '#type' => 'checkbox',
1016
    '#title' => t('<b>Open Layers viewer</b>'),
1017
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1018
    '#description' => t('Display the maps in an interactive viewer which allows zooming and panning. If not enabled the maps will consist
1019
                         on a static image. If enabled you can configure the default layer (background of your maps) below. Only one of
1020
                         them will be renderized, the one selected as <em>Default</em>.')
1021
	      );
1022
*/
1023

    
1024
	      // --- OpenLayers Settings --- //
1025

    
1026
	      $form['openlayers'] = array(
1027
      '#type' => 'fieldset',
1028
      '#title' => t('OpenLayers settings'),
1029
      '#collapsible' => TRUE,
1030
	  '#collapsed' => TRUE,
1031
      //'#collapsed' => !variable_get('cdm_dataportal_map_openlayers', 1),
1032
	  '#description' => t('If you activate the interactive maps (OpenLayers Viewer checkbox). You need to configure which layer you prefer to use as map background.'),
1033
	      );
1034

    
1035
	      $baselayer_options = array(
1036
	      /*
1037
	       * NOTICE: must correspond to the layers defined in js/openlayers_,ap.js#getLayersByName()
1038
	       */
1039
    'osgeo_vmap0' => "OpenLayers World", // EPSG:4326
1040
    'metacarta_vmap0' => "Metacarta Vmap0" , // EPSG:4326, EPSG:900913
1041
	      // all others EPSG:900913 ...
1042
	  'edit-vmap0_world_basic' => 'EDIT Vmap0',
1043
	  'edit-etopo1' => "ETOPO1 Global Relief Model",
1044
    'osmarender' => 'OpenStreetMap',
1045
    //'oam' => 'OpenAerialMap', // currently unavailable
1046
    'gmap' => 'Google Streets',
1047
    'gsat' => 'Google Satellite',
1048
    'ghyb' => 'Google Hybrid',
1049
    'veroad' => 'Virtual Earth Roads',
1050
    'veaer' => 'Virtual Earth Aerial',
1051
    'vehyb' => 'Virtual Earth Hybrid'
1052
	      //  ,
1053
	      //    'yahoo' => 'Yahoo Street',
1054
	      //    'yahoosat' => 'Yahoo Satellite',
1055
	      //    'yahoohyb' => 'Yahoo Hybrid'
1056

    
1057
	      );
1058

    
1059
	      $form['openlayers']['cdm_dataportal_map_openlayers'] = array(
1060
    '#type' => 'checkbox',
1061
    '#title' => '<b>'.t('OpenLayers viewer').'</b>',
1062
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1063
    '#description' => t('Display the maps in an interactive viewer which allows zooming and panning. If not enabled the maps will consist
1064
                         on a static image. If enabled you can configure the default layer (background of your maps) below. Only one of
1065
                         them will be renderized.')
1066
	      );
1067
	      $form['openlayers']['baselayers'] = array(
1068
    '#type' => 'checkboxes_preferred',
1069
    '#title' => t('Baser Layers'),
1070
    '#options' => $baselayer_options,
1071
    '#default_value' => variable_get('baselayers', array('metacarta_vmap0' => "metacarta_vmap0", 'PREFERRED' => 'metacarta_vmap0')),
1072
    '#description' => t('')
1073
	      );
1074

    
1075
	      // cdm_dataportal_geoservice_showLayerSwitcher
1076
	      $form['openlayers']['cdm_dataportal_geoservice_showLayerSwitcher'] = array(
1077
    '#type' => 'checkbox',
1078
    '#title' => '<b>'.t('Show Layer Switcher').'</b>',
1079
    '#default_value' => variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE),
1080
    '#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.')
1081
	      );
1082

    
1083
	      $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1084
	      $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1085
	      $form['openlayers']['gmap_api_key'] = array(
1086
    '#type' => 'textfield',
1087
    '#title' => t('Gogle maps API key'),
1088
    '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1089
    '#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>
1090
         <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.')
1091
	      );
1092

    
1093
	      $form['cdm_dataportal_geoservice_map_legend'] = array(
1094
      '#type' => 'fieldset',
1095
      '#title' => t('Map legend'),
1096
      '#collapsible' => TRUE,
1097
      '#collapsed' => TRUE,
1098
	  '#description' => t('Configure the maps legend.')
1099
	      );
1100

    
1101
	      $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
1102
    '#type' => 'checkbox',
1103
    '#title' => '<b>'.t('Display a map legend').'</b>',
1104
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
1105
    '#description' => t('Check this if you like a legend to be displayed with the maps.')
1106
	      );
1107

    
1108
	      $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legendOpacity'] = array(
1109
    '#type' => 'textfield',
1110
    '#title' => t('Legend opacity'),
1111
    '#default_value' => variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'),
1112
    '#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
1113
                         to 0.0 will be not much visible.')
1114
	      );
1115

    
1116
	      $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
1117
    '#type' => 'textfield',
1118
    '#title' => t('Font size'),
1119
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
1120
    '#description' => t('Font size in pixels.')
1121
	      );
1122

    
1123
	      $fontStyles = array(0 => "plane", 1 => "italic");
1124
	      $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
1125
    '#type' => 'select',
1126
    '#title' => t('Available font styles'),
1127
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', false),
1128
    '#options' => $fontStyles,
1129
    '#description'   => t('Select a font style for the map legend.')
1130
	      );
1131

    
1132
	      $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
1133
    '#type' => 'textfield',
1134
    '#title' => t('Legend icon width'),
1135
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
1136
    '#description' => t('Legend icon width in pixels.')
1137
	      );
1138

    
1139
	      $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
1140
    '#type' => 'textfield',
1141
    '#title' => t('Legend icon height'),
1142
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
1143
    '#description' => t('Legend icon height in pixels.')
1144
	      );
1145

    
1146
	      return system_settings_form($form);
1147
}
1148

    
1149

    
1150
function cdm_settings_cache(){
1151

    
1152
  $form = array();
1153

    
1154
  $form['cache_settings'] = array(
1155
      '#type' => 'fieldset',
1156
      '#title' => t('Cache Settings'),
1157
      '#collapsible' => FALSE,
1158
      '#collapsed' => FALSE,
1159
	  '#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
1160
                           the portal response of taxa pages faster. This is possible because the sites are loaded from
1161
                           the cache and are not created from scratch.</p>'),
1162
      );
1163

    
1164
  $form['cache_settings']['cdm_webservice_cache'] =  array(
1165
    '#type'          => 'checkbox',
1166
    '#title'         => t('<strong>Enable caching</strong>'),
1167
	'#options'		 => cdm_help_general_cache(),
1168
    '#default_value' => variable_get('cdm_webservice_cache', 1),
1169
    '#description'   => t('<p>Enable drupal to load taxa pages from the cache.</p>' .
1170
	                       '<p><strong>Note:</strong> If taxa are modified by the editor or any other application the changes will be not
1171
	                       visible till the cache is erased. Therefore developers should deactived this feature when they
1172
	                       are working on the CDM Dataportal Module.</p>')
1173
    );
1174

    
1175
  $form['cache_settings']['cdm_run_cache'] = array(
1176
    '#value' => cdm_view_cache_site()
1177
  );
1178

    
1179
  return system_settings_form($form);
1180
}
1181

    
1182
/**
1183
 * @return walk and cache all taxon pages
1184
 */
1185
function cdm_view_cache_site(){
1186

    
1187
	$out = '';
1188

    
1189
    _add_js_progressbar();
1190
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cache_all_taxa.js');
1191

    
1192
	$request_params = array();
1193
	$request_params['query'] = '%';
1194
	$request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false); //cache only the dafault classification
1195
	$request_params['doTaxa'] = 1;
1196
	$request_params['doSynonyms'] = 0;
1197
	$request_params['doTaxaByCommonNames'] = 0;
1198
	$search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1199
	$search_url = uri_uriByProxy($search_url);
1200
	$taxon_page_url = url('cdm_dataportal/taxon/');
1201

    
1202

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

    
1209
	$out .= '<form id="cache_site">';
1210
	$out .= '<div>'.t('This caching process may take long time and could cause heavy load on your server').'</div>';
1211
	$out .= '<div id="progress"></div>';
1212
	$out .= '<input type="hidden" name="searchTaxaUrl" value="'.$search_url.'"/>';
1213
	$out .= '<input type="hidden" name="taxonPageUrl" value="'.$taxon_page_url.'"/>';
1214
	$out .= '<input type="button" name="start" value="'.t('Start').'"/>';
1215
	$out .= '<input type="button" name="stop" value="'.t('Stop').'"/>';
1216
	$out .= '</form>';
1217
	$out .= '</div>';
1218
	//  foreach($taxonPager->records as $taxon){
1219
	//    cdm_dataportal_taxon_view($uuid);
1220
	//  }
1221

    
1222
	return $out;
1223
}
1224

    
1225

    
1226
/**
1227
 * Implementation of hook_validate()
1228
 *
1229
 * @param $element
1230
 */
1231
function cdm_settings_validate($form_id, $form_values){
1232

    
1233
	if (!str_endsWith($form_values['cdm_webservice_url'], '/')) {
1234
		//form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
1235
		$form_values['cdm_webservice_url'] .= '/';
1236
	}
1237

    
1238
	if($form_values['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)){
1239
		cache_clear_all(NULL, 'cache_cdm_ws');
1240
		// better clear secref_cache since i can not be sure if the cache has not be used during this response
1241
		cdm_api_secref_cache_clear();
1242
	}
1243

    
1244
}
1245

    
1246
function getEDITMapServiceURI(){
1247

    
1248
	if(variable_get('edit_map_server', false) == 'ALTERNATIVE'){
1249
		return (variable_get('edit_map_server_alternative', false));
1250
	} else if(variable_get('edit_map_server', false)) {
1251
		return variable_get('edit_map_server', false);
1252
	} else {
1253
		return EDIT_MAPSERVER_URI;
1254
	}
1255

    
1256
}
1257

    
1258
/**
1259
 * Implementation of hook_elements()
1260
 *
1261
 * see http://drupal.org/node/37862 for an example
1262
 */
1263
function cdm_dataportal_elements() {
1264
	$type['checkboxes_preferred'] = array(
1265
    '#input' => TRUE,
1266
    '#process' => array('expand_checkboxes_preferred' => array()),
1267
    '#after_build' => array('checkboxes_preferred_after_build')
1268
	);
1269
	return $type;
1270
}
1271

    
1272
/**
1273
 * #process function for the custom form element type 'checkbox_preferred'
1274
 */
1275
function expand_checkboxes_preferred($element){
1276

    
1277
	// first of all create the checkboxes
1278
	$element = expand_checkboxes($element);
1279

    
1280
	$children = element_children($element);
1281
	$element['table_start'] = array(
1282
    '#value' => '<table class="checkboxes_preferred"><tr><th></th><th>'.t('Enabled').'</th><th>'.t('Default').'</th></tr>',
1283
    '#weight'=>-1
1284
	);
1285
	$weight = 0;
1286
	foreach ($children as $key) {
1287
		$odd_even = $weight % 4 == 0 ? 'odd' : 'even';
1288
		$element[$key]['#weight'] = $weight;
1289
		$element[$key]['#prefix'] = '<tr class="'.$odd_even.'"><td>'.t($element['#options'][$key]).'</td><td>';
1290
		$element[$key]['#suffix'] = '</td>';
1291
		unset($element[$key]['#title']);
1292
		$weight += 2;
1293
	}
1294
	$weight = 0;
1295

    
1296
	if (count($element['#options']) > 0) {
1297
		foreach ($element['#options'] as $key => $choice) {
1298
			if (!isset($element[$key.'_preferred'])) {
1299
				$element[$key.'_preferred'] = array(
1300
        '#type' => 'radio',
1301
        '#name' => $element['#parents'][0].'_preferred',
1302
        '#return_value' => check_plain($key),
1303
        '#default_value' => $element['#default_value_2'],
1304
        '#attributes' => $element['#attributes'],
1305
        '#parents' => $element['#parents'],
1306
        '#spawned' => TRUE,
1307
        '#weight' => $weight + 1,
1308
        '#prefix' => '<td>',
1309
        '#suffix' => '</td></tr>',
1310
				//'#submit' => 'submit_checkboxes_preferred'
1311
				);
1312
			}
1313
			$weight += 2;
1314
		}
1315
	}
1316

    
1317
	$element['table_end'] = array(
1318
	//'#type'=>'value',
1319
  '#value' => '</table>', '#weight'=>$weight++);
1320
	return $element;
1321
}
1322

    
1323

    
1324
function theme_checkboxes_preferred($element){
1325
	return theme('form_element',
1326
	array(
1327
      '#title' => $element['#title'],
1328
      '#description' => $element['#description'],
1329
      '#id' => $element['#id'],
1330
      '#required' => $element['#required'],
1331
      '#error' => $element['#error'],
1332
	),
1333
	$element['#children']);
1334
}
1335

    
1336
function checkboxes_preferred_after_build($form, &$form_values){
1337

    
1338
	$parent_id = $form['#parents'][0];
1339

    
1340
	if($_POST && count($_POST) > 0){
1341
		// first pass of form processing
1342
		$preferred_layer = $_POST[$parent_id.'_preferred'];
1343
		$form['#value']['PREFERRED'] = $preferred_layer;
1344
		$form_values[$parent_id] = $form['#value'];
1345
	} else {
1346
		// second pass of form processing
1347
		$preferred_layer = $form['#value']['PREFERRED'];
1348
	}
1349

    
1350
	// also set the chosen value (not sure if this is good drupal style ....)
1351
	foreach( $children = element_children($form) as $key ){
1352
		if($form[$key]['#type'] == 'radio'){
1353
			$form[$key]['#value'] = $preferred_layer;
1354
		}
1355
	}
1356
	// the default layer mus always be enabled
1357
	$form[$preferred_layer]['#value'] = $preferred_layer;
1358

    
1359

    
1360
	return $form;
1361
}
1362

    
(12-12/12)