Project

General

Profile

Download (72.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * CDM Dataportal settings.
5
 */
6

    
7
// TODO Genus UUID.
8
define('DEFAULT_TAXONTREE_RANKLIMIT', '1b11c34c-48a8-4efa-98d5-84f7f66ef43a');
9
define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
10

    
11
define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
12
define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
13
define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
14
define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
15
define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
16
define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
17

    
18
/* annotationTypeKeys */
19
$annotationTypeKeys = array_keys(cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE));
20
if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
21
  $annotationTypeKeys = array_flip($annotationTypeKeys);
22

    
23
  // Technical annotation are off by default.
24
  unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
25
  $annotationTypeKeys = array_flip($annotationTypeKeys);
26
  // Additional value for the NULL case.
27
  $annotationTypeKeys[] = 'NULL_VALUE';
28
}
29
define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
30

    
31
/* taxonRelationshipTypes */
32
define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
33

    
34
/* Gallery variables. */
35
$gallery_settings = array(
36
  "cdm_dataportal_show_taxon_thumbnails" => 1,
37
  "cdm_dataportal_show_synonym_thumbnails" => 0,
38
  "cdm_dataportal_show_thumbnail_captions" => 1,
39
  "cdm_dataportal_media_maxextend" => 120,
40
  "cdm_dataportal_media_cols" => 3,
41
  "cdm_dataportal_media_maxRows" => 1,
42
);
43

    
44
define('EDIT_MAPSERVER_V1_URI', 'http://edit.africamuseum.be/edit_wp5/v1'); // fall back server is http://edit.br.fgov.be
45
define('EDIT_MAPSERVER_V11_URI', 'http://edit.africamuseum.be/edit_wp5/v1.1'); // fall back server is http://edit.br.fgov.be
46
define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
47

    
48
// --- Taxon profile settings --- /
49
define('LAYOUT_SETTING_PREFIX', 'layout_');
50
define('FEATURE_TREE_LAYOUT_DEFAULTS', serialize(
51
  array(
52
    'enabled' => FALSE,
53
    'enclosingTag' => 'ul',
54
    'entryEnclosingTag' => 'li',
55
    'glue' => ' ',
56
  )));
57

    
58
/**
59
 * @todo document this function
60
 */
61
function get_taxon_tabs_list() {
62
  return array(
63
    0 => 'General',
64
    1 => 'Synonymy',
65
    2 => 'Images',
66
    3 => 'Specimens',
67
    4 => 'Keys',
68
  );
69
}
70

    
71
$taxon_tab_options = get_taxon_tabs_list();
72
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
73

    
74
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
75

    
76
/**
77
 * @todo document this function.
78
 */
79
function get_taxon_options_list() {
80
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
81
  foreach ($taxon_tab_options as $key => $value) {
82
    $taxon_tab_options[$key] = t($key);
83
  }
84
  return $taxon_tab_options;
85

    
86
}
87

    
88
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
89
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
90
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
91
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
92
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
93
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
94
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
95
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
96
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
97
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
98
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
99
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
100
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
101
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
102
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
103
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
104

    
105
/**
106
 * @todo document this function.
107
 */
108
function getGallerySettings($gallery_config_form_name) {
109
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
110
  return variable_get($gallery_config_form_name, $default_values);
111
}
112

    
113
/**
114
 * Returns the string representation of the default tab.
115
 *
116
 * @param bool $returnTabIndex
117
 *   Defaults to FALSE, if set true this function will return the index number
118
 *   of the default tab. (used to supply default values to form elements).
119
 */
120
function get_default_taxon_tab($returnTabIndex = FALSE) {
121

    
122
  global $user;
123
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
124
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
125
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
126
  // Get the user value if the used has chosen to overwrite the system settings.
127
  $user_tab_on = variable_get($user_tab_active, FALSE);
128
  if ($user_tab_on) {
129
    $user_value = variable_get($user_tab, 0);
130
    $index_value = $user_value;
131
    // Get the system value.
132
  }
133
  else {
134
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
135
    $index_value = $system_value;
136
  }
137

    
138
  // Return the index value or the string representation.
139
  if ($returnTabIndex) {
140
    return $index_value;
141
  }
142
  else {
143
    return ($values[$index_value]);
144
  }
145

    
146
}
147

    
148
/**
149
 * @todo Please document this function.
150
 * @see http://drupal.org/node/1354
151
 */
152
function cdm_dataportal_menu_admin(&$items) {
153
  // Display section on admin/config page.
154
  $items['admin/config/cdm_dataportal'] = array(
155
    'title' => 'CDM Dataportal',
156
    'description' => 'Settings for the CDM DataPortal.',
157
    'position' => 'right',
158
    'weight' => 10,
159
    'page callback' => 'system_admin_menu_block_page',
160
    'access arguments' => array('cdm_settings_general'),
161
    'file' => 'system.admin.inc',
162
    'file path' => drupal_get_path('module', 'system'),
163
  );
164
  $items['admin/config/cdm_dataportal/settings'] = array(
165
    'title' => 'Settings',
166
    'description' => 'Settings for the CDM DataPortal.',
167
    'weight' => 0,
168
    'page callback' => 'drupal_get_form',
169
    'page arguments' => array('cdm_settings_general'),
170
    'access arguments' => array('administer cdm_dataportal'),
171
    'type' => MENU_NORMAL_ITEM,
172
  );
173
  $items['admin/config/cdm_dataportal/settings/general'] = array(
174
    'title' => 'General',
175
    'description' => 'General',
176
    'weight' => 0,
177
    'page callback' => 'drupal_get_form',
178
    'page arguments' => array('cdm_settings_general'),
179
    'access arguments' => array('administer cdm_dataportal'),
180
    'type' => MENU_DEFAULT_LOCAL_TASK,
181
  );
182

    
183
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
184
    'title' => 'Cache',
185
    'description' => 'Cache',
186
    'access arguments' => array('administer cdm_dataportal'),
187
    'page callback' => 'drupal_get_form',
188
    'page arguments' => array('cdm_settings_cache'),
189
    'weight' => 10,
190
    'type' => MENU_LOCAL_TASK,
191
  );
192

    
193
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
194
    'title' => 'Geo & Map',
195
    'description' => 'Geo & Map',
196
    'access arguments' => array('administer cdm_dataportal'),
197
    'page callback' => 'drupal_get_form',
198
    'page arguments' => array('cdm_settings_geo'),
199
    'weight' => 1,
200
    'type' => MENU_LOCAL_TASK,
201
  );
202

    
203
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
204
    'title' => 'Layout',
205
    'description' => 'Configure and adjust the layout of your DataPortal ',
206
    'access arguments' => array('administer cdm_dataportal'),
207
    'page callback' => 'drupal_get_form',
208
    'page arguments' => array('cdm_settings_layout'),
209
    'weight' => 2,
210
    'type' => MENU_LOCAL_TASK,
211
  );
212

    
213
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
214
    'title' => 'Taxon',
215
    'description' => 'Configure and adjust the layout of your DataPortal ',
216
    'access arguments' => array('administer cdm_dataportal'),
217
    'page callback' => 'drupal_get_form',
218
    'page arguments' => array('cdm_settings_layout_taxon'),
219
    'weight' => 1,
220
    'type' => MENU_LOCAL_TASK,
221
  );
222
  /*
223
  $items[] = array(
224
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
225
  'title' => t('Synonymy'),
226
  'description' => t('Configure and adjust the layout of your DataPortal '),
227
  'access' => user_access('administer cdm_dataportal'),
228
  'callback' => 'drupal_get_form',
229
  'callback arguments' => array('cdm_settings_layout_synonymy'),
230
  'weight' => 1,
231
  'type' => MENU_LOCAL_TASK,
232
  );
233

    
234
  $items[] = array(
235
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
236
  'title' => t('Specimens'),
237
  'description' => t('Configure and adjust the layout of your DataPortal '),
238
  'access' => user_access('administer cdm_dataportal'),
239
  'callback' => 'drupal_get_form',
240
  'callback arguments' => array('cdm_settings_layout_specimens'),
241
  'weight' => 1,
242
  'type' => MENU_LOCAL_TASK,
243
  );
244
  */
245
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
246
    'title' => 'Search',
247
    'description' => 'Configure and adjust the layout of your DataPortal ',
248
    'access arguments' => array('administer cdm_dataportal'),
249
    'page callback' => 'drupal_get_form',
250
    'page arguments' => array('cdm_settings_layout_search'),
251
    'weight' => 2,
252
    'type' => MENU_LOCAL_TASK,
253
  );
254

    
255
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
256
    'title' => 'Media',
257
    'description' => 'Configure and adjust the layout of your DataPortal ',
258
    'access arguments' => array('administer cdm_dataportal'),
259
    'page callback' => 'drupal_get_form',
260
    'page arguments' => array('cdm_settings_layout_media'),
261
    'weight' => 3,
262
    'type' => MENU_LOCAL_TASK,
263
  );
264
  /*
265
  // Path to banners configuration (DEFAULT THEME).
266
  $items[] = array(
267
  'path' => 'admin/config/cdm_dataportal/layout/theme',
268
  'title' => t('Theme'),
269
  'description' => t('Configure the drupal theme of your DataPortal '),
270
  'access' => user_access('administer cdm_dataportal'),
271
  'callback' => 'drupal_get_form',
272
  'callback arguments' => array('cdm_dataportal_theming_form'),
273
  'weight' => 4,
274
  'type' => MENU_LOCAL_TASK,
275
  );
276
  */
277
}
278

    
279
/**
280
 * @todo document this function.
281
 */
282
function cdm_help_general_cache() {
283
  $form = array();
284
  $form['cache_help'] = array(
285
    '#type' => 'fieldset',
286
    '#title' => t('Help'),
287
    '#collapsible' => TRUE,
288
    '#collapsed' => TRUE,
289
  );
290
  $form['cache_help']['test'] = array('#value' => t('probando'));
291
  return drupal_render($form);
292
  $res = array();
293
  $res['default'] = drupal_render($help);
294
  return $res;
295
}
296

    
297
/**
298
 * Configures the settings form for the CDM-API module.
299
 *
300
 * @return array
301
 *   Drupal settings form.
302
 */
303
function cdm_settings_general() {
304

    
305
  $form['cdm_webservice'] = array(
306
    '#type' => 'fieldset',
307
    '#title' => t('CDM Server'),
308
    '#collapsible' => FALSE,
309
    '#collapsed' => FALSE,
310
    '#description' => t('<em>CDM Server</em> makes the dialogue possible with
311
      <em>CDM Data Portal</em> thanks to its web services.'),
312
  );
313

    
314
  $form['cdm_webservice']['cdm_webservice_url'] = array(
315
    '#type' => 'textfield',
316
    '#title' => t('CDM web service URL') . ':',
317
    '#description' => t('This is the URL to the CDM-Server exposing your data
318
      e.g. <em>"http://localhost:8080/cichorieae/"</em> The URL <strong>must end
319
      with a slash</strong> character!'),
320
    '#default_value' => variable_get('cdm_webservice_url', NULL),
321
  );
322

    
323
  /*
324
  MOVED TO DATAPORTAL
325
  $form['cdm_webservice']['taxontree_ranklimit'] =  array(
326
  '#type'          => 'select',
327
  '#title'         => t('Rank of highest displayed taxon'),
328
  '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT), //before DEFAULT_TAXONTREE_RANKLIMIT_UUID
329
  '#options'       => cdm_rankVocabulary_as_option(),
330
  '#description'   => t('The rank of the highest displayed taxon in the <em>taxontree</em>. When you explore
331
  your collection, you can navigate it through a tree structure (<em>taxontree</em>). You can
332
  select here which rank should be at the top level of the tree structure.'),
333
  );
334
  */
335

    
336
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
337
    '#type' => 'checkbox',
338
    '#title' => t('<b>Debug CDM Web Service</b>'),
339
    '#default_value' => variable_get('cdm_webservice_debug', 1),
340
    '#description' => t('The black web service debug box will appear at the top
341
      of each page. When clicked it toggles open and provides a list of all HTTP
342
      requests which have been made while building of this page.<br />
343
      <strong>Note:</strong> this is a feature dedicated to developers. It will
344
      only be visible when logged in and if the user has suffucicient rights to
345
      see this debug box.'),
346
  );
347

    
348
  $form['cdm_webservice']['freetext_index'] = array(
349
    '#type' => 'fieldset',
350
    '#title' => t('Freetext index'),
351
    '#collapsible' => FALSE,
352
    '#collapsed' => FALSE,
353
  );
354

    
355
  // Check the cdmserver port number and display a waring if it is not port 80
356
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
357
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
358
    $form['cdm_webservice']['freetext_index']['message'] = array(
359
      '#markup' => "<div class=\"description\">"
360
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'."
361
      . " Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server."
362
      . " You may want to contact the maintainer of the according CDM Server in order to solve this problem.", array('!port' => $portNumberMatch[1][0]))
363
      . "</div>",
364
    );
365
  };
366

    
367
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
368
  $trigger_link_options = array(
369
    'attributes' => array(
370
      'class' => 'index-trigger',
371
    ),
372
  );
373
  $form['cdm_webservice']['freetext_index']['operations'] = array(
374
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
375
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
376
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
377
      ))
378
    . '<div id="index-progress"></div></div>',
379
  );
380
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
381

    
382
  $form['cdm_webservice']['proxy'] = array(
383
    '#type' => 'fieldset',
384
    '#title' => t('Proxy'),
385
    '#collapsible' => TRUE,
386
    '#collapsed' => TRUE,
387
  );
388

    
389
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
390
    '#type' => 'textfield',
391
    '#title' => t('Proxy URL') . ':',
392
    '#description' => t('If this proxy url is set the cdm api tries
393
    to connect the web service over the given proxy server.
394
    Otherwise proxy usage is deactivated.'),
395
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
396
  );
397

    
398
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
399
    '#type' => 'textfield',
400
    '#title' => t('Proxy port') . ':',
401
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
402
  );
403

    
404
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
405
    '#type' => 'textfield',
406
    '#title' => t('Login') . ':',
407
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
408
  );
409

    
410
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
411
    '#type' => 'textfield',
412
    '#title' => t('Password') . ':',
413
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
414
  );
415

    
416
  // TODO: settings are still incomplete, compare with
417
  // trunk/dataportal/inc/config_default.php.inc.
418
  $form['cdm_dataportal'] = array(
419
    '#type' => 'fieldset',
420
    '#title' => t('Taxon Tree'),
421
    '#collapsible' => FALSE,
422
    '#collapsed' => TRUE,
423
    '#description' => t('<p>When you explore your collection, you can navigate
424
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
425
      able to navigate through your collection the
426
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
427
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
428
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
429
      </a></p>'),
430
  );
431

    
432
  $form['cdm_dataportal'][CDM_TAXONOMICTREE_UUID] = array(
433
    '#type' => 'select',
434
    '#title' => t('Available classifications') . ':',
435
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
436
    '#options' => cdm_get_taxontrees_as_options(),
437
    '#description' => t('Select the default taxa classification for your
438
      <em>taxon tree</em>, the other classifications will be also available but
439
      with a manual user change.'),
440
  );
441

    
442
  $form['cdm_dataportal']['taxontree_ranklimit'] = array(
443
    '#type' => 'select',
444
    '#title' => t('Rank of highest displayed taxon') . ':',
445
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
446
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
447
    '#options' => cdm_rankVocabulary_as_option(),
448
    '#description' => t('This is the rank of the highest displayed taxon in the
449
      <em>taxon tree</em>. You can select here which rank should be at the top
450
      level of the tree structure.'),
451
  );
452

    
453
  // Comment @WA: D7 form api does not support reset buttons,
454
  // so to mimic the D5 reset button we add one like this.
455
  $form['actions']['reset'] = array(
456
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
457
    '#weight' => 1000,
458
  );
459

    
460
  return system_settings_form($form);
461
}
462

    
463

    
464
/**
465
 * LAYOUT settings
466
 * @return unknown_type
467
 *   todo
468
 */
469
function cdm_settings_layout() {
470

    
471
  // drupal_goto('admin/config/cdm_dataportal/layout/taxon');
472
  $form = array();
473
  /*
474
   // -- tabbed pages -- //
475
   $form['cdm_dataportal_taxonpage_tabs'] = array(
476
   '#type' => 'checkbox',
477
   '#title' => t('Tabbed taxon page'),
478
   '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
479
   '#description' => t('If selected split the taxon page into individual tabs for description, images, synonymy. If not the taxon data is rendered as a long single page without tabs.')
480
   );
481
   */
482
  $form['gen_layout'] = array(
483
    '#type' => 'fieldset',
484
    '#title' => t('Portal Layout'),
485
    '#collapsible' => FALSE,
486
    '#collapsed' => FALSE,
487
    '#description' => t('This settings contains the general configurations
488
      layout. If you want to configure the specific sites layout visit the
489
      respective configuration site for taxon, search or media.'),
490
  );
491

    
492
  // ---- footnotes --- //
493
  $form['gen_layout']['footnotes'] = array(
494
    '#type' => 'fieldset',
495
    '#title' => t('Footnotes'),
496
    '#collapsible' => FALSE,
497
    '#collapsed' => FALSE,
498
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
499
      media or distribution areas may have annotations or footnotes. When the
500
      footnotes are enabled they will be visible (if they exist).'),
501
  );
502

    
503
  $form['gen_layout']['footnotes']['cdm_dataportal_all_footnotes'] = array(
504
    '#type' => 'checkbox',
505
    '#title' => t('Do not show footnotes'),
506
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
507
    '#description' => t('Check this if you do not want to show any footnotes'),
508
  );
509

    
510
  $form['gen_layout']['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
511
    '#type' => 'checkbox',
512
    '#title' => t('Do not show annotations footnotes'),
513
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
514
    '#description' => t('Check this if you do not want to show annotation footnotes'),
515
  );
516

    
517
  $annotationTypeOptions = cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE);
518
  // Additional option for the NULL case.
519
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
520
  $form['gen_layout']['footnotes']['annotations_types_as_footnotes'] = array(
521
    '#type' => 'checkboxes',
522
    '#title' => t('Annotation types as footnotes'),
523
    '#description' => t("Only annotations of the selected type will be displayed
524
       as footnotes. You may want to turn 'technical annotations' off."),
525
    '#options' => $annotationTypeOptions,
526
  );
527
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
528
  if (!empty($annotationsTypesAsFootnotes)) {
529
    $form['gen_layout']['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
530
  }
531

    
532
  // --- Advanced Search --- //
533
  $form['gen_layout']['asearch'] = array(
534
    '#type' => 'fieldset',
535
    '#title' => t('Advanced search'),
536
    '#collapsible' => FALSE,
537
    '#collapsed' => FALSE,
538
  );
539
  $form['gen_layout']['asearch']['cdm_dataportal_show_advanced_search'] = array(
540
    '#type' => 'checkbox',
541
    '#title' => t('Show advanced search link'),
542
    '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
543
    '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
544
  );
545

    
546
  // @WA: D7 form api does not support reset buttons,
547
  // so to mimic the D5 reset button we add one like this.
548
  $form['actions']['reset'] = array(
549
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
550
    '#weight' => 1000,
551
  );
552
  return system_settings_form($form);
553
}
554

    
555
/**
556
 * @todo Please document this function.
557
 * @see http://drupal.org/node/1354
558
 */
559
function cdm_dataportal_theming_form() {
560
  // --- Theme --- //
561
  /*
562
   $form['cdm_dataportal_theming'] = array(
563
   '#type' => 'fieldset',
564
   '#title' => t('Theme Images'),
565
   '#collapsible' => FALSE,
566
   '#collapsed' => FALSE,
567
   );
568
   */
569
  $form = array('#attributes' => array('enctype' => 'multipart/form-data'));
570

    
571
  $form['cdm_dataportal_theming_right_image'] = array(
572
    '#type' => 'file',
573
    '#title' => t('Select top right image'),
574
    '#description' => t('Maximum dimensions are %dimensions and the maximum size is %size kB.',
575
                            array('%dimensions' => '250x250', '%size' => '30')),
576
  );
577
  $form['cdm_dataportal_theming_middle_image'] = array(
578
    '#type' => 'file',
579
    '#title' => t('Select top middle image'),
580
  );
581
  $form['test'] = array(
582
    '#type' => 'textfield',
583
    '#title' => t('test'),
584
  );
585

    
586
  // $form['gen_layout']['theme']['#submit'][] = 'settings_validate_theme_pictures';
587
  $form['cdm_dataportal_theming']['submit'] = array(
588
    '#type' => 'submit',
589
    '#value' => t('Submit'),
590
  );
591

    
592
  return $form;
593
}
594

    
595
/**
596
 * @todo Please document this function.
597
 * @see http://drupal.org/node/1354
598
 */
599
function cdm_dataportal_theming_form_submit($form, &$form_state) {
600
  $validators = array();
601
  // Destination path where the files/banners will be saved.
602
  $dest = absolute_path_to_drupal() . '/' . path_to_theme() . '/images/banners';
603
  $dest = str_replace('/', DIRECTORY_SEPARATOR, $dest);
604
  // drupal_set_message($dest);
605
  // Check if directory exists.
606
  if (!file_exists($dest)) {
607

    
608
    // TODO: add rights, which rights should I add?
609
    if (!mkdir($dest, 0777, TRUE)) {
610
      drupal_set_message(t('Failed uploading the files; the directory !dest
611
        could not be created.', array('!dest' => $dest)), 'warning');
612
    }
613
  }
614
  // Check if files already exist.
615
  /*
616
  if (file_exists($dest)) {
617
  }
618
  */
619
  // Save the files.
620
  // TODO Modify the validators array to suit your needs.
621
  // This array is used in the revised file_save_upload.
622
  $validators = array(
623
    'file_validate_is_image' => array(),
624
    'file_validate_image_resolution' => array('85x85'),
625
    'file_validate_size' => array(30 * 1024),
626
  );
627

    
628
  $file = file_save_upload($dest, $validators);
629
  if ($file) {
630
    drupal_set_message($file->filepath);
631
    file_move($file->filepath, $dest);
632
  }
633
  else {
634
    drupal_set_message(t('Fail uploading the file, the file is not accepted.'), 'warning');
635
  }
636
  // Use banners in the selected theme.
637
  /*
638
  if (!copy($file, $file.'.bak')) {
639
    print ("failed to copy $file...<br>\n");
640
  }
641
  */
642
  // Use the banners as default theme.
643
}
644
/*
645
 function cdm_settings_layout_synonymy(){
646
 / * ====== SYNONYMY ====== * /
647
 $form['synonymy'] = array(
648
 '#type' => 'fieldset',
649
 '#title' => t('Synonymy'),
650
 '#collapsible' => TRUE,
651
 '#collapsed' => TRUE,
652
 '#description' => t('This section covers the settings related to the taxon <b>synonymy</b> tab.'),
653
 );
654

    
655
 $form['synonymy']['cdm_dataportal_nomref_in_title'] = array(
656
 '#type' => 'checkbox',
657
 '#title' => t('Show accepted taxon on top of the synonymy'),
658
 '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
659
 '#description' => t('If checked, the first homotypic taxon is a repetition of the accepted taxon most likely
660
 with the full nomenclatural reference (depending on the currently chosen theme).')
661
 );
662

    
663
 $form['synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
664
 '#type' => 'checkbox',
665
 '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
666
 '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
667
 '#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.')
668
 );
669

    
670
 $form['synonymy']['name_relationships']['name_relationships_to_show'] = array(
671
 '#type' => 'checkboxes',
672
 '#title' => t('Display name relationships'),
673
 '#default_value' => variable_get('name_relationships_to_show', 0),
674
 '#options' => $nameRelationshipTypeOptions,
675
 '#description' => t('Select the name relationships you want to show for the accepted taxa.'),
676
 );
677

    
678
 $form['synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
679
 '#type' => 'checkbox',
680
 '#title' => t('Show taxon relations ships of accepted taxon'),
681
 '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
682
 '#description' => t('If this option is enabled the synonymy will show the below selected taxon relationships of accepted taxa.')
683
 );
684

    
685
 $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE);
686
 $form['synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
687
 '#type' => 'checkboxes',
688
 '#title' => t('Taxon relationship types'),
689
 '#description' => t('Only taxon relationships of the selected type will be displayed'),
690
 '#options' => $taxonRelationshipTypeOptions,
691
 '#default_value' => variable_get('CDM_TAXON_RELATIONSHIP_TYPES', unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
692
 '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)
693
 );
694

    
695
 return system_settings_form($form);
696

    
697
 }
698
 */
699

    
700
/**
701
 * @todo Please document this function.
702
 * @see http://drupal.org/node/1354
703
 */
704
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
705
  $form[$form_name] = array(
706
    '#type' => 'fieldset',
707
    '#title' => t($form_title),
708
    '#collapsible' => TRUE,
709
    '#collapsed' => $collapsed,
710
    '#tree' => TRUE,
711
    '#description' => t($form_description),
712
  );
713

    
714
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
715
  $gallery_settings = variable_get($form_name, $default_values);
716
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
717
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
718
    /*
719
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
720
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
721
    '#type' => 'textfield',
722
    '#title' => t('Search Page Size'),
723
    '#default_value' => $test,
724
    '#description' => t('Number of Names to display per page in search results.')
725
    );
726
    */
727
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
728
      '#type' => 'checkbox',
729
      '#title' => t('Show media thumbnails for accepted taxa'),
730
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
731
    );
732

    
733
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
734
      '#type' => 'checkbox',
735
      '#title' => t('Show media thumbnails for synonyms'),
736
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
737
      '#description' => '',
738
    );
739
  }
740

    
741
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
742
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
743
    '#type' => 'checkbox',
744
    '#title' => t('Show captions under thumbnails'),
745
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
746
    '#description' => '',
747
  );
748

    
749
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
750
    '#type' => 'textfield',
751
    '#title' => t('Thumbnail size') . ':',
752
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
753
    '#description' => t('Select the size of each individual thumbnail.'),
754
  );
755

    
756
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
757
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
758
      '#type' => 'textfield',
759
      '#title' => t('Number of columns') . ':',
760
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
761
      '#description' => t('Group the thumbnails in columns: select how many
762
        columns the gallery should display.'),
763
    );
764
  }
765

    
766
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
767
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
768
      '#type' => 'textfield',
769
      '#title' => t('Maximum number of rows') . ':',
770
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
771
      '#description' => t('You can group the thumbnails in rows, select in how
772
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
773
        If you want an unlimited number of rows please set to 0.'),
774
    );
775
  }
776

    
777
  return $form;
778
}
779

    
780
/**
781
 * @todo document this function.
782
 */
783
function cdm_settings_layout_taxon() {
784
  $collapsed = FALSE;
785
  $form = array();
786

    
787
  // --------- TABBED TAXON ------- //
788
  $form['taxon_tabs'] = array(
789
    '#type' => 'fieldset',
790
    '#title' => t('Taxon tabs'),
791
    '#collapsible' => TRUE,
792
    '#collapsed' => FALSE,
793
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
794
      be splitted in four diferent tabs; General, Synonymy, Images and
795
      Specimens. If the taxon has no information for any of the tabs/sections
796
      such tab will be not displayed.'),
797
  );
798

    
799
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
800
    '#type' => 'checkbox',
801
    '#title' => t('Tabbed taxon page'),
802
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
803
    '#description' => t('<p>If selected split the taxon page into individual
804
      tabs for description, images, synonymy and specimens. If not the taxon
805
      data is rendered as a long single page without tabs.</p>'),
806
  );
807

    
808
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
809
    '#type' => 'checkboxes',
810
    '#title' => t('Tabs visibility options') . ':',
811
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
812
    '#options' => get_taxon_options_list(),
813
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
814
  );
815

    
816
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
817
    '#type' => 'select',
818
    '#title' => t('Default tab to display') . ':',
819
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
820
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
821
    '#description' => t('<p>Select the default tab to display when visiting a
822
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
823
      <strong>Note:</strong> After performing a search and clicking in any
824
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
825
      taxon and not the above selected tab.'),
826
  );
827

    
828
  $form['cdm_dataportal_show_back_to_search_results'] = array(
829
    '#type' => 'checkbox',
830
    '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
831
    '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
832
    '#description' => t('<p>If checked the link to search results is rendered at
833
       the top of the taxon site. Clicking on the link the last search performed
834
       is rendered again.</p>'),
835
  );
836

    
837
  /* ======  TAXON_PROFILE ====== */
838
  $form['taxon_profile'] = array(
839
    '#type' => 'fieldset',
840
    '#title' => t('Taxon profile (tab)'),
841
    '#description' => t('<p>This section covers the setting related to the taxon
842
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
843
    '#collapsible' => TRUE,
844
    '#collapsed' => TRUE,
845
  );
846

    
847
  // ---- PROFILE PICTURE ----//
848
  $form['taxon_profile']['picture'] = array(
849
    '#type' => 'fieldset',
850
    '#title' => t('Profile Picture'),
851
    '#collapsible' => TRUE,
852
    '#collapsed' => FALSE,
853
    '#description' => t('Select a profile picture for taxa. Like a facebook of plants.'),
854
  );
855

    
856
  $form['taxon_profile']['picture']['cdm_dataportal_show_default_image'] = array(
857
    '#type' => 'checkbox',
858
    '#title' => t('Enable profil picture'),
859
    '#default_value' => variable_get('cdm_dataportal_show_default_image', FALSE),
860
    '#description' => t('Show the profil picture.'),
861
  );
862

    
863
  $options = cdm_rankVocabulary_as_option();
864
  array_unshift($options, '-- DISABLED --');
865
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
866
    '#type' => 'select',
867
    '#title' => t('Hide picture for taxa above') . ':',
868
    '#default_value' => variable_get('image_hide_rank', '0'),
869
    '#options' => $options,
870
    '#description' => t('Select which rank of pictures should not have
871
      a profile picture.'),
872
  );
873
  // Show picture.
874
  $selectShowMedia = array(
875
    0 => "Show only taxon pictures",
876
    1 => "Show taxon and child taxa pictures",
877
  );
878

    
879
  $form['taxon_profile']['picture']['cdm_dataportal_show_media'] = array(
880
    '#type' => 'select',
881
    '#title' => t('Available picture files') . ':',
882
    '#default_value' => variable_get('cdm_dataportal_show_media', FALSE),
883
    '#options' => $selectShowMedia,
884
    '#description' => t("Show the profile pictures current taxon's children."),
885
  );
886

    
887
  // -- MEDIA THUMBNAILS -- //
888
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
889
  $form_title = 'Taxon Profile Images';
890
  $form_description = '<p>The different section in the taxon  profile can have images associated with them. These images are displayed in a gallery of thumbnails wich can be configuered here:</p>';
891
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
892

    
893
  // ---- FEATURE TREE ---- //
894
  $form['taxon_profile']['taxon_profile'] = array(
895
    '#type' => 'fieldset',
896
    '#title' => t('Features'),
897
    '#collapsible' => TRUE,
898
    '#collapsed' => FALSE,
899
    '#description' => t("This section covers settings related to the taxon's
900
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
901
      features such as description, distribution, common names, etc. that Drupal
902
      will render at the taxon profile page."),
903
  );
904
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
905
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
906
    '#type' => 'radios',
907
    '#title' => t('Taxon profile sections') . ':',
908
    '#default_value' => variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE),
909
    '#options' =>  $featureTrees['options'],
910
    // Comment @WA: because #options are sanitized in D7, it would
911
    // strip html like <fieldset>, so we put the fieldset in a suffix.
912
    '#field_suffix' => $featureTrees['treeRepresentations'],
913
    '#description' => t('Select the Feature Tree to be displayed at the taxon
914
      profile. Click "Show Details" to see the Feature Tree elements.'
915
    ),
916
  );
917
  $featureTrees = cdm_get_featureTrees_as_options();
918
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
919
    '#type' => 'radios',
920
    '#title' => t('Natural language representation of structured descriptions') . ':',
921
    '#default_value' => variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, NULL),
922
    '#options' => $featureTrees['options'],
923
      // Comment @WA: because #options are sanitized in D7, it would
924
      // strip html like <fieldset>, so we put the fieldset in a suffix.
925
    '#field_suffix' => $featureTrees['treeRepresentations'],
926
    '#description' => t('Taxon descriptions can be stored in a highly structured
927
      form. The feature tree selected here will be used to generate textual
928
      representation in natural language.'
929
      // If there is no applicable FeatureTree you can create a new one using the <a href="">FeatureTreeManager</a>'
930
    ),
931
  );
932

    
933
  // ---- LAYOUT PER FEATURE ---- //
934
  $feature_tree = get_profile_featureTree();
935
  if (isset($feature_tree->root->children)) {
936

    
937
    $form_feature_list_layout = array(
938
      '#title' => t('Taxon profile layout'),
939
      '#collapsible' => TRUE,
940
      '#collapsed' => FALSE,
941
      '#type' => 'fieldset',
942
      '#description' => t('Will be available in a future release.'),
943
    );
944

    
945
    $feature_list_layout_settings_disabled = TRUE;
946
    foreach ($feature_tree->root->children as $featureNode) {
947

    
948
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
949
        // Must not exceed 45 characters !!!
950
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
951

    
952
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
953
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
954

    
955
        $form_feature_list_layout[$subform_id] = array(
956
          '#tree' => TRUE,
957
          '#title' => 'test' . $featureNode->feature->representation_L10n,
958
          '#collapsible' => FALSE,
959
          '#collapsed' => FALSE,
960
          '#type' => 'fieldset',
961
          '#description' => t(''),
962
        );
963

    
964
        $form_feature_list_layout[$subform_id]['enabled'] = array(
965
          '#type' => 'checkbox',
966
          '#title' => t('Enable'),
967
          '#default_value' => $settings['enabled'],
968
          '#description' => t('Enable user defined layout for this feature'),
969
        );
970

    
971
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
972
          '#type' => 'textfield',
973
          '#title' => t('Enclosing tag'),
974
          '#disabled' => !$settings['enabled'],
975
          '#default_value' => $settings['enclosingTag'],
976
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
977
        );
978

    
979
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
980
          '#type' => 'textfield',
981
          '#title' => t('Entry enclosing tag'),
982
          '#disabled' => !$settings['enabled'],
983
          '#default_value' => $settings['entryEnclosingTag'],
984
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
985
        );
986

    
987
        $form_feature_list_layout[$subform_id]['glue'] = array(
988
          '#type' => 'textfield',
989
          '#title' => t('Glue'),
990
          '#disabled' => !$settings['enabled'],
991
          '#default_value' => $settings['glue'],
992
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
993
        );
994

    
995
      }
996

    
997
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
998
    }
999
  }
1000

    
1001
  // ---- DISTRIBUTION LAYOUT ---- //
1002
  $form['taxon_profile']['distribution_layout'] = array(
1003
    '#title' => t('Distribution'),
1004
    '#collapsible' => TRUE,
1005
    '#collapsed' => FALSE,
1006
    '#type' => 'fieldset',
1007
    '#description' => t('Select if you want to sort or not the distribution text
1008
      located below the distribution map.'),
1009
  );
1010

    
1011
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1012
    '#type' => 'radios',
1013
    '#title' => t('Sort') . ':',
1014
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1015
    '#options' => array(
1016
      'NO_SORT' => t('Standard (No sort)'),
1017
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1018
    ),
1019
  );
1020

    
1021
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1022
    '#type' => 'checkbox',
1023
    '#title' => t('Show TextData elements on top of the map'),
1024
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1025
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1026
      elements on top of the map. Otherwise all <code>TextData</code>
1027
      distribution elements will be listed below the other area elements.
1028
      This option is useful if you need to have descriptive texts for each
1029
      distribution map.'),
1030
  );
1031

    
1032

    
1033
  /* ====== SYNONYMY ====== */
1034
  $form['taxon_synonymy'] = array(
1035
    '#type' => 'fieldset',
1036
    '#title' => t('Taxon synonymy (tab)'),
1037
    '#collapsible' => TRUE,
1038
    '#collapsed' => TRUE,
1039
    '#description' => t('This section covers the settings related to the taxon
1040
      <strong>synonymy</strong> tab.####'),
1041
  );
1042

    
1043
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1044
    '#type' => 'checkbox',
1045
    '#title' => t('Show accepted taxon on top of the synonymy'),
1046
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1047
    '#description' => t('If checked, the first homotypic taxon is a repetition
1048
      of the accepted taxon most likely with the full nomenclatural reference
1049
      (depending on the currently chosen theme).'),
1050
  );
1051

    
1052
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1053
    '#type' => 'checkbox',
1054
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1055
      coming from a synonym link.'),
1056
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1057
    '#description' => t('Check this if after doing a search and clicking on a
1058
      synonym you want to see the "accept of" text for the accepted synonym.'),
1059
  );
1060

    
1061
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1062
  $form['name_relationships']['name_relationships_to_show'] = array(
1063
    '#type' => 'checkboxes',
1064
    '#title' => t('Display name relationships') . ':',
1065
    '#default_value' => variable_get('name_relationships_to_show', 0),
1066
    '#options' => $nameRelationshipTypeOptions,
1067
    '#description' => t('Select the name relationships you want to show for the
1068
      accepted taxa.'),
1069
  );
1070

    
1071
  $form[CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1072
    '#type' => 'checkbox',
1073
    '#title' => t('Show taxon relations ships of accepted taxon'),
1074
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1075
    '#description' => t('If this option is enabled the synonymy will show the
1076
      below selected taxon relationships of accepted taxa.'),
1077
  );
1078

    
1079
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1080
  $form[CDM_TAXON_RELATIONSHIP_TYPES] = array(
1081
    '#type' => 'checkboxes',
1082
    '#title' => t('Taxon relationship types') . ':',
1083
    '#description' => t('Only taxon relationships of the selected type will be
1084
      displayed'),
1085
    '#options' => $taxonRelationshipTypeOptions,
1086
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1087
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1088
  );
1089

    
1090
  // ====== SPECIMENS ====== //
1091
  $form['taxon_specimens'] = array(
1092
    '#type' => 'fieldset',
1093
    '#title' => t('Taxon specimens (tab)'),
1094
    '#collapsible' => TRUE,
1095
    '#collapsed' => TRUE,
1096
    '#description' => t('This section covers the settings related to the taxon
1097
      <strong>specimens</strong> tab.'),
1098
  );
1099

    
1100
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1101
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1102
      '#type' => 'radios',
1103
      '#title' => t('Specimen description feature tree') . ':',
1104
      '#default_value' => variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE),
1105
      '#options' =>  $featureTrees['options'],
1106
      // Comment @WA: because #options are sanitized in D7, it would
1107
      // strip html like <fieldset>, so we put the fieldset in a suffix.
1108
      '#field_suffix' => $featureTrees['treeRepresentations'],
1109
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1110
      ),
1111
  );
1112

    
1113
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1114
  $form_title = t('Specimen media');
1115
  $form_description = t('Specimens may have media which is displayed at the
1116
     Specimen tab/section as a gallery. It is possible to configure the
1117
     thumbnails gallery here, however for configuring how a single media should
1118
     be displayed please go to !url.</p>',
1119
     array(
1120
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1121
     ));
1122
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1123

    
1124
  // --- MEDIA GALLERY ---- //
1125
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1126
  $form_title = 'Media gallery (tab)';
1127
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1128
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1129
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1130
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1131
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1132
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1133
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1134

    
1135
  // Comment @WA: D7 form api does not support reset buttons,
1136
  // so to mimic the D5 reset button we add one like this.
1137
  $form['actions']['reset'] = array(
1138
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1139
    '#weight' => 1000,
1140
  );
1141
  return system_settings_form($form);
1142
}
1143

    
1144
/**
1145
 * @todo document this function.
1146
 */
1147
function cdm_settings_layout_search() {
1148

    
1149
  $form = array();
1150

    
1151
  $form['search_settings'] = array(
1152
    '#type' => 'fieldset',
1153
    '#title' => t('Taxa Search'),
1154
    '#collapsible' => TRUE,
1155
    '#collapsed' => TRUE,
1156
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1157
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1158
         where they can write the text to be searched. You can find Drupal block configuration
1159
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1160
  );
1161

    
1162
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1163
    '#type' => 'textfield',
1164
    '#title' => t('Results per page') . ':',
1165
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1166
    '#description' => t('Number of results to display per page.'),
1167
  );
1168

    
1169
  $form['search_settings']['cdm_search_taxa'] = array(
1170
    '#type' => 'checkbox',
1171
    '#title' => t('Sets the default value of <em>Search for accepted taxa</em> in the advanced search form.'),
1172
    '#default_value' => variable_get('cdm_search_taxa', 1),
1173
    '#description' => t('<p>If checked the <em>Search for accepted taxa </em> option will be enabled in the advanced form.</p>'),
1174
  );
1175

    
1176
  $form['search_settings']['cdm_search_synonyms'] = array(
1177
    '#type' => 'checkbox',
1178
    '#title' => t('Sets the default value of <em>Search for synonyms</em> in the advanced search form.'),
1179
    '#default_value' => variable_get('cdm_search_synonyms', 1),
1180
    '#description' => t('<p>If checked the <em>Search for synonyms</em> option will be enabled in the advanced form.</p>'),
1181
  );
1182

    
1183
  $form['search_settings']['cdm_search_common_names'] = array(
1184
    '#type' => 'checkbox',
1185
    '#title' => t('Sets the default value of <em>Search for common names</em> in the advanced search form.'),
1186
    '#default_value' => variable_get('cdm_search_common_names', 0),
1187
    '#description' => t('<p>If checked the <em>Search for common names</em> option will be enabled in the advanced form.</p>'),
1188
  );
1189

    
1190
  $form['search_settings']['cdm_search_use_default_values'] = array(
1191
    '#type' => 'checkbox',
1192
    '#title' => t('Sets use of default values in the advanced search form.'),
1193
    '#default_value' => variable_get('cdm_search_use_default_values', 1),
1194
    '#description' => t('<p>If checked the defqult values set abovewill be used for the search.</p>'),
1195
  );
1196

    
1197

    
1198
  // --- SEARCH TAXA GALLERY ---- //
1199
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1200
  $collapsed = FALSE;
1201
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1202
  $form_title = 'Taxa Search thumbnails';
1203
  $form_description = 'Search results may show thumbnails. ';
1204
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1205

    
1206
  // Comment @WA: D7 form api does not support reset buttons,
1207
  // so to mimic the D5 reset button we add one like this.
1208
  $form['actions']['reset'] = array(
1209
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1210
    '#weight' => 1000,
1211
  );
1212
  return system_settings_form($form);
1213
}
1214

    
1215
/**
1216
 * @todo document this function.
1217
 */
1218
function cdm_settings_layout_media() {
1219

    
1220
  $form = array();
1221

    
1222
  $form['media_settings'] = array(
1223
    '#type' => 'fieldset',
1224
    '#title' => t('Media display settings'),
1225
    '#collapsible' => TRUE,
1226
    '#collapsed' => FALSE,
1227
    '#description' => t('This section covers the settings related to the taxa media, that is how each single media should be displayed.'),
1228
  );
1229

    
1230
  $form['media_settings']['image_gallery_viewer'] = array(
1231
    '#type' => 'select',
1232
    '#title' => t('Image viewer') . ':',
1233
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1234
    '#options' => array(
1235
      'default' => t('Standard image viewer'),
1236
      'fsi' => t('FSI viewer (requires FSI server!)'),
1237
    ),
1238
  );
1239

    
1240
  // --- MEDIA GALLERY ---- //
1241
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1242
  $form_title = 'Standard viewer';
1243
  $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>';
1244
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1245
  // Comment @WA: $collapsed is not defined.
1246
  // $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1247
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1248

    
1249
  // @WA: D7 form api does not support reset buttons,
1250
  // so to mimic the D5 reset button we add one like this.
1251
  $form['actions']['reset'] = array(
1252
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1253
    '#weight' => 1000,
1254
  );
1255
  return system_settings_form($form);
1256
}
1257

    
1258
/**
1259
 * GEOSERVICE and Map settings.
1260
 */
1261
function cdm_settings_geo($form, &$form_state) {
1262

    
1263
  $form = array();
1264

    
1265
  /*
1266
  GEO SERVER
1267
  */
1268
  $form['geoserver'] = array(
1269
    '#type' => 'fieldset',
1270
    '#title' => t('Geo Server Settings'),
1271
    '#collapsible' => TRUE,
1272
    '#collapsed' => TRUE,
1273
    '#description' => t('Configuration and selection of your geo server.
1274
      The Geo Server is responsible for generating the maps.'),
1275
  );
1276

    
1277
  $form['geoserver']['edit_map_server'] = array(
1278
    '#type' => 'select',
1279
    '#title' => t('Geoservice access point URL') . ':',
1280
    '#default_value' => variable_get('edit_map_server', EDIT_MAPSERVER_V11_URI),
1281
    '#options' => array(
1282
      EDIT_MAPSERVER_V1_URI => 'EDIT Map Server v1',
1283
      EDIT_MAPSERVER_V11_URI => 'EDIT Map Server v1.1',
1284
      'ALTERNATIVE' => '-- Alternative URL --',
1285
    ),
1286
    '#description' => t('Select the Map Server you want the data portal to
1287
      connect. If you want to introduce a custom address just select the
1288
      Alternative URL value and fill the field Geoservice Access Point
1289
      - Alternative URL with the custom ip address.'),
1290
  );
1291

    
1292
  $form['geoserver']['edit_map_server_alternative'] = array(
1293
    '#type' => 'textfield',
1294
    '#title' => t('Geoservice access point - alternative URL') . ':',
1295
    '#default_value' => variable_get('edit_map_server_alternative', ''),
1296
    '#description' => t('Alternative URL of a EDIT Map Service to be used by
1297
      this portal. You must choose the option <i>-- Alternative URL --</i> in
1298
      the chooser above to enable this url.'),
1299
  );
1300

    
1301
  /*
1302
  MAP SETTINGS
1303
  */
1304
  $form['map_settings'] = array(
1305
    '#type' => 'fieldset',
1306
    '#title' => t('Maps settings'),
1307
    '#collapsible' => TRUE,
1308
    '#collapsed' => TRUE,
1309
    '#description' => t('General configuration for all map types.'),
1310
  );
1311

    
1312
  $form['map_settings']['cdm_dataportal_geoservice_display_width'] = array(
1313
    '#type' => 'textfield',
1314
    '#title' => t('Maps width') . ':',
1315
    '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
1316
    '#description' => t('Choose the width of your maps, the height will always
1317
      be the half of the width. A value of 500 means the size will be 500 pixels
1318
      width and 250 pixels height.'),
1319
  );
1320

    
1321
  $form['map_settings']['cdm_dataportal_geoservice_bounding_box'] = array(
1322
    '#type' => 'textfield',
1323
    '#title' => t('Fixed bounding box') . ':',
1324
    '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
1325
    '#description' => t('Define surrounding of area to be displayed in maps.
1326
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
1327
      to let the map <strong>automatically zoom</strong> to the distribution
1328
      area.'),
1329
  );
1330

    
1331
  $form['map_settings']['cdm_dataportal_geoservice_labels_on'] = array(
1332
    '#type' => 'checkbox',
1333
    '#title' => '<b>' . t('Display area labels') . '</b>',
1334
    '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
1335
    '#description' => t('Check this if you like area names to be displayed in the maps. DOES IT WORK???? '),
1336
  );
1337

    
1338
  $form['map_settings']['cdm_dataportal_geoservice_map_caption'] = array(
1339
    '#type' => 'textfield',
1340
    '#title' => t('Map caption') . ':',
1341
    '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
1342
    '#description' => t('Define a caption for the map.'),
1343
  );
1344

    
1345
  $form['map_settings']['cdm_dataportal_geoservice_distributionOpacity'] = array(
1346
    '#type' => 'textfield',
1347
    '#title' => t('Distribution layer opacity') . ':',
1348
    '#default_value' => variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5'),
1349
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1350
                           fully visible, while a value near to 0.0 will be not much visible.'),
1351
  );
1352

    
1353
  $form['map_settings']['cdm_dataportal_map_openlayers'] = array(
1354
    '#type' => 'radios',
1355
    '#title' => t('Map Viewer') . ':',
1356
    '#options' => array(
1357
      1 => "OpenLayers dynamic mapviewer",
1358
      0 => "Plain image",
1359
    ),
1360
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1361
    '#description' => t('You can choose from two different map viewers:
1362
      <ul><li><em>OpenLayers</em> displays the maps in an interactive viewer
1363
      which allows zooming and panning. If not enabled the maps will consist
1364
      on a static image. If enabled you can configure the default layer
1365
      (background of your maps) below. Only one of them will be rendered.</li>
1366
      <li><em>Plain image</em> displays the map as a plain non interactive
1367
      image.</li></ul>'),
1368
  );
1369

    
1370
  $openLayersEnabled = variable_get('cdm_dataportal_map_openlayers', 1) == 1;
1371

    
1372

    
1373
  // --- Plain Image Settings --- //
1374
  $form['map_image'] = array(
1375
    '#type' => 'fieldset',
1376
    '#title' => t('Plain image map settings'),
1377
    '#collapsible' => TRUE,
1378
    '#collapsed' => $openLayersEnabled,
1379
    '#description' => t('The settings in this section are still expertimental
1380
      and can only be used with the EDIT map service version 1.1 or above.'),
1381
  );
1382

    
1383
  $edit_mapserver_version = getEDITMapServiceVersionNumber();
1384
  if ($edit_mapserver_version < 1.1) {
1385
    $form['map_image']['#description'] = '<div class="messages warning">' . t("The selected EDIT map service version has to small version number: $edit_mapserver_version") . '</div>'
1386
      . $form['map_image']['#description'];
1387
  }
1388

    
1389
  $form['map_image']['map_base_layer'] = array(
1390
    '#type' => 'textfield',
1391
    '#title' => t('Background layer') . ':',
1392
    '#default_value' => variable_get('map_base_layer', 'cyprusdivs'),
1393
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
1394
      '!url1' => l(t('deegree-csw'), 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
1395
      '!url2' => l(t('geoserver layers'), 'http://edit.africamuseum.be/geoserver/web/'), // http://edit.africamuseum.be/geoserver/rest/layers
1396
    )),
1397
  );
1398

    
1399
  $form['map_image']['map_bg_color'] = array(
1400
    '#type' => 'textfield',
1401
    '#title' => t('Background color') . ':',
1402
    '#default_value' => variable_get('map_bg_color', '1874CD'),
1403
  );
1404

    
1405
  $form['map_image']['map_base_layer_style'] = array(
1406
    '#type' => 'textfield',
1407
    '#title' => t('Background layer area style') . ':',
1408
     // Only line color by now.
1409
    '#default_value' => variable_get('map_base_layer_style', 'ffffff,606060,,'),
1410
    '#description' => t('Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}'),
1411
  );
1412

    
1413

    
1414
  // --- OpenLayers Settings --- //
1415
  $form['openlayers'] = array(
1416
    '#type' => 'fieldset',
1417
    '#title' => t('OpenLayers settings'),
1418
    '#collapsible' => TRUE,
1419
    '#collapsed' => !$openLayersEnabled,
1420
    '#description' => '',
1421
  );
1422

    
1423
  if (!$openLayersEnabled) {
1424
    $form['openlayers']['#description'] = '<div class="messages warning">' . t('The Openlayers viewer is currently not enabled! (see section Maps settings above )') . '</div>'
1425
      . $form['openlayers']['#description'];
1426
  }
1427

    
1428
  $baselayer_options = array(
1429
    /*
1430
   NOTICE: must correspond to the layers defined in
1431
   js/openlayers_,ap.js#getLayersByName()
1432
   */
1433
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
1434
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
1435
    // all others EPSG:900913
1436
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
1437
    'edit-etopo1' => "ETOPO1 Global Relief Model",
1438
    'mapnik' => 'OpenStreetMap',
1439
    'osmarender' => 'OpenStreetMap (Tiles@home)',
1440
    'gmap' => 'Google Streets',
1441
    'gsat' => 'Google Satellite',
1442
    'ghyb' => 'Google Hybrid',
1443
    'veroad' => 'Virtual Earth Roads',
1444
    'veaer' => 'Virtual Earth Aerial',
1445
    'vehyb' => 'Virtual Earth Hybrid',
1446
    // 'yahoo' => 'Yahoo Street',
1447
    // 'yahoosat' => 'Yahoo Satellite',
1448
    // 'yahoohyb' => 'Yahoo Hybrid',
1449
  );
1450

    
1451
  $form['openlayers']['baselayers'] = array(
1452
    '#type' => 'checkboxes_preferred',
1453
    '#title' => t('Base Layers') . ':',
1454
    '#options' => $baselayer_options,
1455
    '#default_value' => variable_get('baselayers', array('metacarta_vmap0' => "metacarta_vmap0", 'PREFERRED' => 'metacarta_vmap0')),
1456
    '#description' => t('Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.'),
1457
  );
1458

    
1459
  // cdm_dataportal_geoservice_showLayerSwitcher
1460
  $form['openlayers']['cdm_dataportal_geoservice_showLayerSwitcher'] = array(
1461
    '#type' => 'checkbox',
1462
    '#title' => '<b>' . t('Show Layer Switcher') . '</b>',
1463
    '#default_value' => variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE),
1464
    '#description' => t('
1465
      The Layer Switcher control displays a table of contents
1466
      for the map.  This allows the user interface to switch between
1467
      BaseLayers and to show or hide Overlays.  By default the switcher is
1468
      shown minimized on the right edge of the map, the user may expand it
1469
      by clicking on the handle.'
1470
    ),
1471
  );
1472

    
1473
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1474
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1475
  $form['openlayers']['gmap_api_key'] = array(
1476
    '#type' => 'textfield',
1477
    '#title' => t('Google maps API key') . ':',
1478
    '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1479
    '#description' => t('If you want to use the Google Maps Layer, a key is
1480
      needed. If you need a key, visit
1481
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
1482
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
1483
      is the default key for the localhost (127.0.0.1). The key in use is the
1484
      one above this text.', array('!localhostkey' => $localhostkey)),
1485
  );
1486

    
1487
  $form['cdm_dataportal_geoservice_map_legend'] = array(
1488
    '#type' => 'fieldset',
1489
    '#title' => t('Map legend'),
1490
    '#collapsible' => TRUE,
1491
    '#collapsed' => TRUE,
1492
    '#description' => t('Configure the maps legend.'),
1493
  );
1494

    
1495
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
1496
    '#type' => 'checkbox',
1497
    '#title' => '<b>' . t('Display a map legend') . '</b>',
1498
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
1499
    '#description' => t('Check this if you like a legend to be displayed with the maps.'),
1500
  );
1501

    
1502
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legendOpacity'] = array(
1503
    '#type' => 'textfield',
1504
    '#title' => t('Legend opacity'),
1505
    '#default_value' => variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'),
1506
    '#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
1507
                         to 0.0 will be not much visible.'),
1508
  );
1509

    
1510
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
1511
    '#type' => 'textfield',
1512
    '#title' => t('Font size'),
1513
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
1514
    '#description' => t('Font size in pixels.'),
1515
  );
1516

    
1517
  $fontStyles = array(
1518
    0 => "plane",
1519
    1 => "italic",
1520
  );
1521
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
1522
    '#type' => 'select',
1523
    '#title' => t('Available font styles'),
1524
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', FALSE),
1525
    '#options' => $fontStyles,
1526
    '#description' => t('Select a font style for the map legend.'),
1527
  );
1528

    
1529
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
1530
    '#type' => 'textfield',
1531
    '#title' => t('Legend icon width'),
1532
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
1533
    '#description' => t('Legend icon width in pixels.'),
1534
  );
1535
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
1536
    '#type' => 'textfield',
1537
    '#title' => t('Legend icon height'),
1538
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
1539
    '#description' => t('Legend icon height in pixels.'),
1540
  );
1541

    
1542
  // @WA: D7 form api does not support reset buttons,
1543
  // so to mimic the D5 reset button we add one like this.
1544
  $form['actions']['reset'] = array(
1545
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1546
    '#weight' => 1000,
1547
  );
1548

    
1549
  return system_settings_form($form);
1550
}
1551

    
1552
/**
1553
 * @todo document this function.
1554
 */
1555
function cdm_settings_cache() {
1556

    
1557
  $form = array();
1558

    
1559
  $form['cache_settings'] = array(
1560
    '#type' => 'fieldset',
1561
    '#title' => t('Cache Settings'),
1562
    '#collapsible' => FALSE,
1563
    '#collapsed' => FALSE,
1564
    '#description' => t('<p>When caching is enabled all single taxon sites are
1565
      stored in an internal drupal cache doing the portal response of taxa pages
1566
      faster. This is possible because the sites are loaded from the cache and
1567
      are not created from scratch.</p>'),
1568
  );
1569

    
1570
  $form['cache_settings']['cdm_webservice_cache'] = array(
1571
    '#type' => 'checkbox',
1572
    '#title' => t('<strong>Enable caching</strong>'),
1573
    '#options' => cdm_help_general_cache(),
1574
    '#default_value' => variable_get('cdm_webservice_cache', 1),
1575
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
1576
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
1577
       application the changes will be not visible till the cache is erased.
1578
       Therefore developers should deactived this feature when they are working
1579
       on the CDM Dataportal Module.</p>'),
1580
  );
1581

    
1582
  $form['cache_settings']['cdm_run_cache'] = array(
1583
    '#markup' => cdm_view_cache_site(),
1584
  );
1585

    
1586
  // @WA: D7 form api does not support reset buttons,
1587
  // so to mimic the D5 reset button we add one like this.
1588
  $form['actions']['reset'] = array(
1589
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1590
    '#weight' => 1000,
1591
  );
1592
  return system_settings_form($form);
1593
}
1594

    
1595
/**
1596
 * Walk and cache all taxon pages.
1597
 */
1598
function cdm_view_cache_site() {
1599

    
1600
  $out = '';
1601

    
1602
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
1603

    
1604
  $request_params = array();
1605
  $request_params['query'] = '%';
1606
  // Cache only the dafault classification.
1607
  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', FALSE);
1608
  $request_params['doTaxa'] = 1;
1609
  $request_params['doSynonyms'] = 0;
1610
  $request_params['doTaxaByCommonNames'] = 0;
1611

    
1612
  $search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND . ".json", NULL, queryString($request_params));
1613

    
1614
  $search_url = uri_uriByProxy($search_url);
1615
  $search_url = rtrim($search_url, '/');
1616
  $taxon_page_url = url('cdm_dataportal/taxon/');
1617

    
1618
  $out .= t('<p><strong>Cache all taxon pages</strong></p>');
1619
  $out .= '<p>When you launch the cache process the cache is filled and ready to be enabled.<br/>
1620
  Remember that when you load the taxa from the cache last changes on taxa will be not visible till you erase
1621
  the cache and fill it again.</p>';
1622
  $out .= '<p>Before  running the cache bot you have to empty the cache manually.</p>';
1623

    
1624
  $out .= '<div>' . t('This caching process may take long time and could cause heavy load on your server') . '</div>';
1625
  $out .= '<div id="progress"></div>';
1626

    
1627
  // Comment @WA: A form within a form is not valid html and not needed here.
1628
  // Also, it would be recommended just to include this part of the form in the
1629
  // rest of the form array in cdm_settings_cache().
1630
  // $out .= '<form id="cache_site">';
1631
  $out .= '<input type="hidden" name="searchTaxaUrl" value="' . $search_url . '"/>';
1632
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . $taxon_page_url . '"/>';
1633
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
1634
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
1635
  // $out .= '</form>';
1636
  $out .= '</div>';
1637
  /*
1638
  foreach($taxonPager->records as $taxon){
1639
    cdm_dataportal_taxon_view($uuid);
1640
  }
1641
  */
1642
  return $out;
1643
}
1644

    
1645
/**
1646
 * Form validation handler for ?
1647
 *
1648
 * Comment @WA: currently this handler is not used.
1649
 * It seems partly for cdm_settings_general en partly for cdm_settings_cache?
1650
 * Then you can change the name into cdm_settings_general_validate() or
1651
 * cdm_settings_cache_validate().
1652
 * But cdm_api_secref_cache_clear is not doing anything (yet)?
1653
 */
1654
function cdm_settings_validate($form, &$form_state) {
1655

    
1656
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
1657
    // form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
1658
    $form_state['values']['cdm_webservice_url'] .= '/';
1659
  }
1660

    
1661
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
1662
    cache_clear_all(NULL, 'cache_cdm_ws');
1663
    // Better clear secref_cache since I can not be sure if the cache has not
1664
    // be used during this response.
1665
    cdm_api_secref_cache_clear();
1666
  }
1667
}
1668

    
1669
/**
1670
 * @todo document this function.
1671
 */
1672
function getEDITMapServiceURI() {
1673

    
1674
  if (variable_get('edit_map_server', FALSE) == 'ALTERNATIVE') {
1675
    return (variable_get('edit_map_server_alternative', FALSE));
1676
  }
1677
  elseif (variable_get('edit_map_server', FALSE)) {
1678
    return variable_get('edit_map_server', FALSE);
1679
  }
1680
  else {
1681
    return EDIT_MAPSERVER_V1_URI;
1682
  }
1683

    
1684
}
1685

    
1686
/**
1687
 * @todo document this function.
1688
 *
1689
 * @return float
1690
 *   The version number of the currently selected edit mapserver as a float.
1691
 *   Returns 0 on error.
1692
 */
1693
function getEDITMapServiceVersionNumber() {
1694

    
1695
  $pattern = '/v([\d\.]+)$/';
1696

    
1697
  $url = getEDITMapServiceURI();
1698
  preg_match($pattern, $url, $matches, PREG_OFFSET_CAPTURE, 3);
1699
  if (isset($matches[1])) {
1700
    // Convert string to float.
1701
    $version = 1 + $matches[1][0] - 1;
1702
    return $version;
1703
  }
1704
  else {
1705
    // Report error.
1706
    drupal_set_message(t(" Invalid version number in EDIT map service URL: '!edit_mapserver'", array('!edit_mapserver' => variable_get('edit_map_server', EDIT_MAPSERVER_V1_URI))), 'warning');
1707
    return 0;
1708
  }
1709
}
1710

    
1711

    
1712
/**
1713
 * Implements hook_element_info().
1714
 *
1715
 * Allows modules to declare their own Form API element types and specify their default values.
1716
 *
1717
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
1718
 */
1719
function cdm_dataportal_element_info() {
1720
  $type['checkboxes_preferred'] = array(
1721
    '#input' => TRUE,
1722
    '#process' => array('checkboxes_preferred_expand'),
1723
    '#after_build' => array('checkboxes_preferred_after_build'),
1724
    '#theme' => array('checkboxes_preferred'),
1725
    // '#theme_wrapper' => array('form_element'),
1726
  );
1727
  return $type;
1728
}
1729

    
1730
/**
1731
 * #process callback function for the custom form element type 'checkbox_preferred'
1732
 *
1733
 *
1734
 */
1735
function checkboxes_preferred_expand($element, &$form_state, $form) {
1736

    
1737
  // First of all create checkboxes for each of the elements
1738
  $element = form_process_checkboxes($element);
1739

    
1740
  $children = element_children($element);
1741

    
1742
  $element['table_start'] = array(
1743
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
1744
    '#weight' => -1,
1745
  );
1746

    
1747
  // prepare first part each of the table rows which contains the row label
1748
  $weight = 0;
1749
  foreach ($children as $key) {
1750
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
1751
    $element[$key]['#weight'] = $weight;
1752
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
1753
    $element[$key]['#suffix'] = '</td>';
1754
    unset($element[$key]['#title']);
1755
    $weight += 2;
1756
  }
1757
  $weight = 0;
1758

    
1759
  // add a radio button to each of the checkboxes, the
1760
  // check boxes have already been created at the beginning
1761
  // of this function
1762
  if (count($element['#options']) > 0) {
1763
    foreach ($element['#options'] as $key => $choice) {
1764
      if (!isset($element[$key . '_preferred'])) {
1765
        $element[$key . '_preferred'] = array(
1766
          '#type' => 'radio',
1767
          '#name' => $element['#parents'][0] . '_preferred',
1768
          '#return_value' => check_plain($key),
1769
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
1770
          '#attributes' => $element['#attributes'],
1771
          '#parents' => $element['#parents'],
1772
          // '#spawned' => TRUE,
1773
          '#weight' => $weight + 1,
1774
          '#prefix' => '<td>',        // add a prefix to start a new table cell
1775
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
1776
        );
1777
      }
1778
      $weight += 2;
1779
    }
1780
  }
1781

    
1782
  // end the table
1783
  $element['table_end'] = array(
1784
    '#markup' => '</table>',
1785
    '#weight' => $weight++,
1786
  );
1787

    
1788
  return $element;
1789
}
1790

    
1791
/**
1792
 * Theme function for the custom form field 'checkboxes_preferred'.
1793
 */
1794
function theme_checkboxes_preferred($variables) {
1795
  $element = $variables['element'];
1796
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
1797
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
1798
  $out .= drupal_render_children($element);
1799
  $out .= '<div class="description">' . $element['#description'] . '</div>';
1800
  $out .= '</div>';
1801
  return $out;
1802
}
1803

    
1804
/**
1805
 * Callback for checkboxes preferred for widget which will
1806
 * be called after the form or element is built. The call
1807
 * back is configured in the form element by setting it as
1808
 * #after_build parameter.
1809
 *
1810
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
1811
 *
1812
 * @param $form
1813
 *   Nested array of form elements that comprise the form.
1814
 * @param $form_state
1815
 *   A keyed array containing the current state of the form.
1816
 *
1817
 * @return the modified form array
1818
 */
1819
function checkboxes_preferred_after_build($form, &$form_state) {
1820

    
1821
  $parent_id = $form['#parents'][0];
1822

    
1823
  if ($_POST && count($_POST) > 0) {
1824
    // First pass of form processing.
1825
    $preferred_layer = $_POST[$parent_id . '_preferred'];
1826
    $form['#value']['PREFERRED'] = $preferred_layer;
1827
    $form_state[$parent_id] = $form['#value'];
1828
    $form_state['values']['baselayers'] = $form['#value'];
1829
  }
1830
  else {
1831
    // Second pass of form processing.
1832
    $preferred_layer = $form['#value']['PREFERRED'];
1833
  }
1834

    
1835
  // Also set the chosen value (not sure if this is good Drupal style ....).
1836
  foreach ($children = element_children($form) as $key) {
1837
    if (!empty($form[$key]['#type']) && $form[$key]['#type'] == 'radio') {
1838
      $form[$key]['#value'] = $preferred_layer;
1839
    }
1840
  }
1841
  // The default layer must always be enabled.
1842
  $form[$preferred_layer]['#value'] = $preferred_layer;
1843

    
1844
  return $form;
1845
}
(13-13/13)