Project

General

Profile

Download (71.8 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_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
103

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

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

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

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

    
145
}
146

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
459
  return system_settings_form($form);
460
}
461

    
462

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

    
470
  // drupal_goto('admin/config/cdm_dataportal/layout/taxon');
471
  $form = array();
472
  /*
473
   // -- tabbed pages -- //
474
   $form['cdm_dataportal_taxonpage_tabs'] = array(
475
   '#type' => 'checkbox',
476
   '#title' => t('Tabbed taxon page'),
477
   '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
478
   '#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.')
479
   );
480
   */
481
  $form['gen_layout'] = array(
482
    '#type' => 'fieldset',
483
    '#title' => t('Portal Layout'),
484
    '#collapsible' => FALSE,
485
    '#collapsed' => FALSE,
486
    '#description' => t('This settings contains the general configurations
487
      layout. If you want to configure the specific sites layout visit the
488
      respective configuration site for taxon, search or media.'),
489
  );
490

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

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

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

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

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

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

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

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

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

    
591
  return $form;
592
}
593

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

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

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

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

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

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

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

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

    
694
 return system_settings_form($form);
695

    
696
 }
697
 */
698

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

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

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

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

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

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

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

    
776
  return $form;
777
}
778

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

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

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

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

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

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

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

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

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

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

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

    
886
  // -- MEDIA THUMBNAILS -- //
887
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
888
  $form_title = 'Taxon Profile Images';
889
  $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>';
890
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
891

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

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

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

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

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

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

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

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

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

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

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

    
994
      }
995

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

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

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

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

    
1031

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

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

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

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

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

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

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

    
1099
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1100
  $form_title = t('Specimen media');
1101
  $form_description = t('Specimens may have media which is displayed at the
1102
     Specimen tab/section as a gallery. It is possible to configure the
1103
     thumbnails gallery here, however for configuring how a single media should
1104
     be displayed please go to !url.</p>',
1105
     array(
1106
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1107
     ));
1108
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1109

    
1110
  // --- MEDIA GALLERY ---- //
1111
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1112
  $form_title = 'Media gallery (tab)';
1113
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1114
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1115
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1116
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1117
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1118
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1119
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1120

    
1121
  // Comment @WA: D7 form api does not support reset buttons,
1122
  // so to mimic the D5 reset button we add one like this.
1123
  $form['actions']['reset'] = array(
1124
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1125
    '#weight' => 1000,
1126
  );
1127
  return system_settings_form($form);
1128
}
1129

    
1130
/**
1131
 * @todo document this function.
1132
 */
1133
function cdm_settings_layout_search() {
1134

    
1135
  $form = array();
1136

    
1137
  $form['search_settings'] = array(
1138
    '#type' => 'fieldset',
1139
    '#title' => t('Taxa Search'),
1140
    '#collapsible' => TRUE,
1141
    '#collapsed' => TRUE,
1142
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1143
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1144
         where they can write the text to be searched. You can find Drupal block configuration
1145
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1146
  );
1147

    
1148
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1149
    '#type' => 'textfield',
1150
    '#title' => t('Results per page') . ':',
1151
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1152
    '#description' => t('Number of results to display per page.'),
1153
  );
1154

    
1155
  $form['search_settings']['cdm_search_taxa'] = array(
1156
    '#type' => 'checkbox',
1157
    '#title' => t('Sets the default value of <em>Search for accepted taxa</em> in the advanced search form.'),
1158
    '#default_value' => variable_get('cdm_search_taxa', 1),
1159
    '#description' => t('<p>If checked the <em>Search for accepted taxa </em> option will be enabled in the advanced form.</p>'),
1160
  );
1161

    
1162
  $form['search_settings']['cdm_search_synonyms'] = array(
1163
    '#type' => 'checkbox',
1164
    '#title' => t('Sets the default value of <em>Search for synonyms</em> in the advanced search form.'),
1165
    '#default_value' => variable_get('cdm_search_synonyms', 1),
1166
    '#description' => t('<p>If checked the <em>Search for synonyms</em> option will be enabled in the advanced form.</p>'),
1167
  );
1168

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

    
1176
  $form['search_settings']['cdm_search_use_default_values'] = array(
1177
    '#type' => 'checkbox',
1178
    '#title' => t('Sets use of default values in the advanced search form.'),
1179
    '#default_value' => variable_get('cdm_search_use_default_values', 1),
1180
    '#description' => t('<p>If checked the defqult values set abovewill be used for the search.</p>'),
1181
  );
1182

    
1183

    
1184
  // --- SEARCH TAXA GALLERY ---- //
1185
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1186
  $collapsed = FALSE;
1187
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1188
  $form_title = 'Taxa Search thumbnails';
1189
  $form_description = 'Search results may show thumbnails. ';
1190
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1191

    
1192
  // Comment @WA: D7 form api does not support reset buttons,
1193
  // so to mimic the D5 reset button we add one like this.
1194
  $form['actions']['reset'] = array(
1195
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1196
    '#weight' => 1000,
1197
  );
1198
  return system_settings_form($form);
1199
}
1200

    
1201
/**
1202
 * @todo document this function.
1203
 */
1204
function cdm_settings_layout_media() {
1205

    
1206
  $form = array();
1207

    
1208
  $form['media_settings'] = array(
1209
    '#type' => 'fieldset',
1210
    '#title' => t('Media display settings'),
1211
    '#collapsible' => TRUE,
1212
    '#collapsed' => FALSE,
1213
    '#description' => t('This section covers the settings related to the taxa media, that is how each single media should be displayed.'),
1214
  );
1215

    
1216
  $form['media_settings']['image_gallery_viewer'] = array(
1217
    '#type' => 'select',
1218
    '#title' => t('Image viewer') . ':',
1219
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1220
    '#options' => array(
1221
      'default' => t('Standard image viewer'),
1222
      'fsi' => t('FSI viewer (requires FSI server!)'),
1223
    ),
1224
  );
1225

    
1226
  // --- MEDIA GALLERY ---- //
1227
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1228
  $form_title = 'Standard viewer';
1229
  $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>';
1230
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1231
  // Comment @WA: $collapsed is not defined.
1232
  // $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1233
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1234

    
1235
  // @WA: D7 form api does not support reset buttons,
1236
  // so to mimic the D5 reset button we add one like this.
1237
  $form['actions']['reset'] = array(
1238
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1239
    '#weight' => 1000,
1240
  );
1241
  return system_settings_form($form);
1242
}
1243

    
1244
/**
1245
 * GEOSERVICE and Map settings.
1246
 */
1247
function cdm_settings_geo($form, &$form_state) {
1248

    
1249
  $form = array();
1250

    
1251
  /*
1252
  GEO SERVER
1253
  */
1254
  $form['geoserver'] = array(
1255
    '#type' => 'fieldset',
1256
    '#title' => t('Geo Server Settings'),
1257
    '#collapsible' => TRUE,
1258
    '#collapsed' => TRUE,
1259
    '#description' => t('Configuration and selection of your geo server.
1260
      The Geo Server is responsible for generating the maps.'),
1261
  );
1262

    
1263
  $form['geoserver']['edit_map_server'] = array(
1264
    '#type' => 'select',
1265
    '#title' => t('Geoservice access point URL') . ':',
1266
    '#default_value' => variable_get('edit_map_server', EDIT_MAPSERVER_V11_URI),
1267
    '#options' => array(
1268
      EDIT_MAPSERVER_V1_URI => 'EDIT Map Server v1',
1269
      EDIT_MAPSERVER_V11_URI => 'EDIT Map Server v1.1',
1270
      'ALTERNATIVE' => '-- Alternative URL --',
1271
    ),
1272
    '#description' => t('Select the Map Server you want the data portal to
1273
      connect. If you want to introduce a custom address just select the
1274
      Alternative URL value and fill the field Geoservice Access Point
1275
      - Alternative URL with the custom ip address.'),
1276
  );
1277

    
1278
  $form['geoserver']['edit_map_server_alternative'] = array(
1279
    '#type' => 'textfield',
1280
    '#title' => t('Geoservice access point - alternative URL') . ':',
1281
    '#default_value' => variable_get('edit_map_server_alternative', ''),
1282
    '#description' => t('Alternative URL of a EDIT Map Service to be used by
1283
      this portal. You must choose the option <i>-- Alternative URL --</i> in
1284
      the chooser above to enable this url.'),
1285
  );
1286

    
1287
  /*
1288
  MAP SETTINGS
1289
  */
1290
  $form['map_settings'] = array(
1291
    '#type' => 'fieldset',
1292
    '#title' => t('Maps settings'),
1293
    '#collapsible' => TRUE,
1294
    '#collapsed' => TRUE,
1295
    '#description' => t('General configuration for all map types.'),
1296
  );
1297

    
1298
  $form['map_settings']['cdm_dataportal_geoservice_display_width'] = array(
1299
    '#type' => 'textfield',
1300
    '#title' => t('Maps width') . ':',
1301
    '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
1302
    '#description' => t('Choose the width of your maps, the height will always
1303
      be the half of the width. A value of 500 means the size will be 500 pixels
1304
      width and 250 pixels height.'),
1305
  );
1306

    
1307
  $form['map_settings']['cdm_dataportal_geoservice_bounding_box'] = array(
1308
    '#type' => 'textfield',
1309
    '#title' => t('Fixed bounding box') . ':',
1310
    '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
1311
    '#description' => t('Define surrounding of area to be displayed in maps.
1312
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
1313
      to let the map <strong>automatically zoom</strong> to the distribution
1314
      area.'),
1315
  );
1316

    
1317
  $form['map_settings']['cdm_dataportal_geoservice_labels_on'] = array(
1318
    '#type' => 'checkbox',
1319
    '#title' => '<b>' . t('Display area labels') . '</b>',
1320
    '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
1321
    '#description' => t('Check this if you like area names to be displayed in the maps. DOES IT WORK???? '),
1322
  );
1323

    
1324
  $form['map_settings']['cdm_dataportal_geoservice_map_caption'] = array(
1325
    '#type' => 'textfield',
1326
    '#title' => t('Map caption') . ':',
1327
    '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
1328
    '#description' => t('Define a caption for the map.'),
1329
  );
1330

    
1331
  $form['map_settings']['cdm_dataportal_geoservice_distributionOpacity'] = array(
1332
    '#type' => 'textfield',
1333
    '#title' => t('Distribution layer opacity') . ':',
1334
    '#default_value' => variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5'),
1335
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1336
                           fully visible, while a value near to 0.0 will be not much visible.'),
1337
  );
1338

    
1339
  $form['map_settings']['cdm_dataportal_map_openlayers'] = array(
1340
    '#type' => 'radios',
1341
    '#title' => t('Map Viewer') . ':',
1342
    '#options' => array(
1343
      1 => "OpenLayers dynamic mapviewer",
1344
      0 => "Plain image",
1345
    ),
1346
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1347
    '#description' => t('You can choose from two different map viewers:
1348
      <ul><li><em>OpenLayers</em> displays the maps in an interactive viewer
1349
      which allows zooming and panning. If not enabled the maps will consist
1350
      on a static image. If enabled you can configure the default layer
1351
      (background of your maps) below. Only one of them will be rendered.</li>
1352
      <li><em>Plain image</em> displays the map as a plain non interactive
1353
      image.</li></ul>'),
1354
  );
1355

    
1356
  $openLayersEnabled = variable_get('cdm_dataportal_map_openlayers', 1) == 1;
1357

    
1358

    
1359
  // --- Plain Image Settings --- //
1360
  $form['map_image'] = array(
1361
    '#type' => 'fieldset',
1362
    '#title' => t('Plain image map settings'),
1363
    '#collapsible' => TRUE,
1364
    '#collapsed' => $openLayersEnabled,
1365
    '#description' => t('The settings in this section are still expertimental
1366
      and can only be used with the EDIT map service version 1.1 or above.'),
1367
  );
1368

    
1369
  $edit_mapserver_version = getEDITMapServiceVersionNumber();
1370
  if ($edit_mapserver_version < 1.1) {
1371
    $form['map_image']['#description'] = '<div class="messages warning">' . t("The selected EDIT map service version has to small version number: $edit_mapserver_version") . '</div>'
1372
      . $form['map_image']['#description'];
1373
  }
1374

    
1375
  $form['map_image']['map_base_layer'] = array(
1376
    '#type' => 'textfield',
1377
    '#title' => t('Background layer') . ':',
1378
    '#default_value' => variable_get('map_base_layer', 'cyprusdivs'),
1379
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
1380
      '!url1' => l(t('deegree-csw'), 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
1381
      '!url2' => l(t('geoserver layers'), 'http://edit.africamuseum.be/geoserver/web/'), // http://edit.africamuseum.be/geoserver/rest/layers
1382
    )),
1383
  );
1384

    
1385
  $form['map_image']['map_bg_color'] = array(
1386
    '#type' => 'textfield',
1387
    '#title' => t('Background color') . ':',
1388
    '#default_value' => variable_get('map_bg_color', '1874CD'),
1389
  );
1390

    
1391
  $form['map_image']['map_base_layer_style'] = array(
1392
    '#type' => 'textfield',
1393
    '#title' => t('Background layer area style') . ':',
1394
     // Only line color by now.
1395
    '#default_value' => variable_get('map_base_layer_style', 'ffffff,606060,,'),
1396
    '#description' => t('Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}'),
1397
  );
1398

    
1399

    
1400
  // --- OpenLayers Settings --- //
1401
  $form['openlayers'] = array(
1402
    '#type' => 'fieldset',
1403
    '#title' => t('OpenLayers settings'),
1404
    '#collapsible' => TRUE,
1405
    '#collapsed' => !$openLayersEnabled,
1406
    '#description' => '',
1407
  );
1408

    
1409
  if (!$openLayersEnabled) {
1410
    $form['openlayers']['#description'] = '<div class="messages warning">' . t('The Openlayers viewer is currently not enabled! (see section Maps settings above )') . '</div>'
1411
      . $form['openlayers']['#description'];
1412
  }
1413

    
1414
  $baselayer_options = array(
1415
    /*
1416
   NOTICE: must correspond to the layers defined in
1417
   js/openlayers_,ap.js#getLayersByName()
1418
   */
1419
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
1420
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
1421
    // all others EPSG:900913
1422
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
1423
    'edit-etopo1' => "ETOPO1 Global Relief Model",
1424
    'mapnik' => 'OpenStreetMap',
1425
    'osmarender' => 'OpenStreetMap (Tiles@home)',
1426
    'gmap' => 'Google Streets',
1427
    'gsat' => 'Google Satellite',
1428
    'ghyb' => 'Google Hybrid',
1429
    'veroad' => 'Virtual Earth Roads',
1430
    'veaer' => 'Virtual Earth Aerial',
1431
    'vehyb' => 'Virtual Earth Hybrid',
1432
    // 'yahoo' => 'Yahoo Street',
1433
    // 'yahoosat' => 'Yahoo Satellite',
1434
    // 'yahoohyb' => 'Yahoo Hybrid',
1435
  );
1436

    
1437
  $form['openlayers']['baselayers'] = array(
1438
    '#type' => 'checkboxes_preferred',
1439
    '#title' => t('Base Layers') . ':',
1440
    '#options' => $baselayer_options,
1441
    '#default_value' => variable_get('baselayers', array('metacarta_vmap0' => "metacarta_vmap0", 'PREFERRED' => 'metacarta_vmap0')),
1442
    '#description' => t('Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.'),
1443
  );
1444

    
1445
  // cdm_dataportal_geoservice_showLayerSwitcher
1446
  $form['openlayers']['cdm_dataportal_geoservice_showLayerSwitcher'] = array(
1447
    '#type' => 'checkbox',
1448
    '#title' => '<b>' . t('Show Layer Switcher') . '</b>',
1449
    '#default_value' => variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE),
1450
    '#description' => t('
1451
      The Layer Switcher control displays a table of contents
1452
      for the map.  This allows the user interface to switch between
1453
      BaseLayers and to show or hide Overlays.  By default the switcher is
1454
      shown minimized on the right edge of the map, the user may expand it
1455
      by clicking on the handle.'
1456
    ),
1457
  );
1458

    
1459
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1460
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1461
  $form['openlayers']['gmap_api_key'] = array(
1462
    '#type' => 'textfield',
1463
    '#title' => t('Google maps API key') . ':',
1464
    '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1465
    '#description' => t('If you want to use the Google Maps Layer, a key is
1466
      needed. If you need a key, visit
1467
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
1468
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
1469
      is the default key for the localhost (127.0.0.1). The key in use is the
1470
      one above this text.', array('!localhostkey' => $localhostkey)),
1471
  );
1472

    
1473
  $form['cdm_dataportal_geoservice_map_legend'] = array(
1474
    '#type' => 'fieldset',
1475
    '#title' => t('Map legend'),
1476
    '#collapsible' => TRUE,
1477
    '#collapsed' => TRUE,
1478
    '#description' => t('Configure the maps legend.'),
1479
  );
1480

    
1481
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
1482
    '#type' => 'checkbox',
1483
    '#title' => '<b>' . t('Display a map legend') . '</b>',
1484
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
1485
    '#description' => t('Check this if you like a legend to be displayed with the maps.'),
1486
  );
1487

    
1488
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legendOpacity'] = array(
1489
    '#type' => 'textfield',
1490
    '#title' => t('Legend opacity'),
1491
    '#default_value' => variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'),
1492
    '#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
1493
                         to 0.0 will be not much visible.'),
1494
  );
1495

    
1496
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
1497
    '#type' => 'textfield',
1498
    '#title' => t('Font size'),
1499
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
1500
    '#description' => t('Font size in pixels.'),
1501
  );
1502

    
1503
  $fontStyles = array(
1504
    0 => "plane",
1505
    1 => "italic",
1506
  );
1507
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
1508
    '#type' => 'select',
1509
    '#title' => t('Available font styles'),
1510
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', FALSE),
1511
    '#options' => $fontStyles,
1512
    '#description' => t('Select a font style for the map legend.'),
1513
  );
1514

    
1515
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
1516
    '#type' => 'textfield',
1517
    '#title' => t('Legend icon width'),
1518
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
1519
    '#description' => t('Legend icon width in pixels.'),
1520
  );
1521
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
1522
    '#type' => 'textfield',
1523
    '#title' => t('Legend icon height'),
1524
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
1525
    '#description' => t('Legend icon height in pixels.'),
1526
  );
1527

    
1528
  // @WA: D7 form api does not support reset buttons,
1529
  // so to mimic the D5 reset button we add one like this.
1530
  $form['actions']['reset'] = array(
1531
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1532
    '#weight' => 1000,
1533
  );
1534

    
1535
  return system_settings_form($form);
1536
}
1537

    
1538
/**
1539
 * @todo document this function.
1540
 */
1541
function cdm_settings_cache() {
1542

    
1543
  $form = array();
1544

    
1545
  $form['cache_settings'] = array(
1546
    '#type' => 'fieldset',
1547
    '#title' => t('Cache Settings'),
1548
    '#collapsible' => FALSE,
1549
    '#collapsed' => FALSE,
1550
    '#description' => t('<p>When caching is enabled all single taxon sites are
1551
      stored in an internal drupal cache doing the portal response of taxa pages
1552
      faster. This is possible because the sites are loaded from the cache and
1553
      are not created from scratch.</p>'),
1554
  );
1555

    
1556
  $form['cache_settings']['cdm_webservice_cache'] = array(
1557
    '#type' => 'checkbox',
1558
    '#title' => t('<strong>Enable caching</strong>'),
1559
    '#options' => cdm_help_general_cache(),
1560
    '#default_value' => variable_get('cdm_webservice_cache', 1),
1561
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
1562
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
1563
       application the changes will be not visible till the cache is erased.
1564
       Therefore developers should deactived this feature when they are working
1565
       on the CDM Dataportal Module.</p>'),
1566
  );
1567

    
1568
  $form['cache_settings']['cdm_run_cache'] = array(
1569
    '#markup' => cdm_view_cache_site(),
1570
  );
1571

    
1572
  // @WA: D7 form api does not support reset buttons,
1573
  // so to mimic the D5 reset button we add one like this.
1574
  $form['actions']['reset'] = array(
1575
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1576
    '#weight' => 1000,
1577
  );
1578
  return system_settings_form($form);
1579
}
1580

    
1581
/**
1582
 * Walk and cache all taxon pages.
1583
 */
1584
function cdm_view_cache_site() {
1585

    
1586
  $out = '';
1587

    
1588
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
1589

    
1590
  $request_params = array();
1591
  $request_params['query'] = '%';
1592
  // Cache only the dafault classification.
1593
  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', FALSE);
1594
  $request_params['doTaxa'] = 1;
1595
  $request_params['doSynonyms'] = 0;
1596
  $request_params['doTaxaByCommonNames'] = 0;
1597

    
1598
  $search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND . ".json", NULL, queryString($request_params));
1599

    
1600
  $search_url = uri_uriByProxy($search_url);
1601
  $search_url = rtrim($search_url, '/');
1602
  $taxon_page_url = url('cdm_dataportal/taxon/');
1603

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

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

    
1613
  // Comment @WA: A form within a form is not valid html and not needed here.
1614
  // Also, it would be recommended just to include this part of the form in the
1615
  // rest of the form array in cdm_settings_cache().
1616
  // $out .= '<form id="cache_site">';
1617
  $out .= '<input type="hidden" name="searchTaxaUrl" value="' . $search_url . '"/>';
1618
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . $taxon_page_url . '"/>';
1619
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
1620
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
1621
  // $out .= '</form>';
1622
  $out .= '</div>';
1623
  /*
1624
  foreach($taxonPager->records as $taxon){
1625
    cdm_dataportal_taxon_view($uuid);
1626
  }
1627
  */
1628
  return $out;
1629
}
1630

    
1631
/**
1632
 * Form validation handler for ?
1633
 *
1634
 * Comment @WA: currently this handler is not used.
1635
 * It seems partly for cdm_settings_general en partly for cdm_settings_cache?
1636
 * Then you can change the name into cdm_settings_general_validate() or
1637
 * cdm_settings_cache_validate().
1638
 * But cdm_api_secref_cache_clear is not doing anything (yet)?
1639
 */
1640
function cdm_settings_validate($form, &$form_state) {
1641

    
1642
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
1643
    // form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
1644
    $form_state['values']['cdm_webservice_url'] .= '/';
1645
  }
1646

    
1647
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
1648
    cache_clear_all(NULL, 'cache_cdm_ws');
1649
    // Better clear secref_cache since I can not be sure if the cache has not
1650
    // be used during this response.
1651
    cdm_api_secref_cache_clear();
1652
  }
1653
}
1654

    
1655
/**
1656
 * @todo document this function.
1657
 */
1658
function getEDITMapServiceURI() {
1659

    
1660
  if (variable_get('edit_map_server', FALSE) == 'ALTERNATIVE') {
1661
    return (variable_get('edit_map_server_alternative', FALSE));
1662
  }
1663
  elseif (variable_get('edit_map_server', FALSE)) {
1664
    return variable_get('edit_map_server', FALSE);
1665
  }
1666
  else {
1667
    return EDIT_MAPSERVER_V1_URI;
1668
  }
1669

    
1670
}
1671

    
1672
/**
1673
 * @todo document this function.
1674
 *
1675
 * @return float
1676
 *   The version number of the currently selected edit mapserver as a float.
1677
 *   Returns 0 on error.
1678
 */
1679
function getEDITMapServiceVersionNumber() {
1680

    
1681
  $pattern = '/v([\d\.]+)$/';
1682

    
1683
  $url = getEDITMapServiceURI();
1684
  preg_match($pattern, $url, $matches, PREG_OFFSET_CAPTURE, 3);
1685
  if (isset($matches[1])) {
1686
    // Convert string to float.
1687
    $version = 1 + $matches[1][0] - 1;
1688
    return $version;
1689
  }
1690
  else {
1691
    // Report error.
1692
    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');
1693
    return 0;
1694
  }
1695
}
1696

    
1697
/**
1698
 * Implements hook_element_info().
1699
 *
1700
 * Allows modules to declare their own Form API element types and specify their default values.
1701
 *
1702
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
1703
 */
1704
function cdm_dataportal_element_info() {
1705
  $type['checkboxes_preferred'] = array(
1706
    '#input' => TRUE,
1707
    '#process' => array('checkboxes_preferred_expand'),
1708
    '#after_build' => array('checkboxes_preferred_after_build'),
1709
    '#theme' => array('checkboxes_preferred'),
1710
    // '#theme_wrapper' => array('form_element'),
1711
  );
1712
  return $type;
1713
}
1714

    
1715
/**
1716
 * #process callback function for the custom form element type 'checkbox_preferred'
1717
 *
1718
 *
1719
 */
1720
function checkboxes_preferred_expand($element, &$form_state, $form) {
1721

    
1722
  // First of all create checkboxes for each of the elements
1723
  $element = form_process_checkboxes($element);
1724

    
1725
  $children = element_children($element);
1726

    
1727
  $element['table_start'] = array(
1728
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
1729
    '#weight' => -1,
1730
  );
1731

    
1732
  // prepare first part each of the table rows which contains the row label
1733
  $weight = 0;
1734
  foreach ($children as $key) {
1735
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
1736
    $element[$key]['#weight'] = $weight;
1737
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
1738
    $element[$key]['#suffix'] = '</td>';
1739
    unset($element[$key]['#title']);
1740
    $weight += 2;
1741
  }
1742
  $weight = 0;
1743

    
1744
  // add a radio button to each of the checkboxes, the
1745
  // check boxes have already been created at the beginning
1746
  // of this function
1747
  if (count($element['#options']) > 0) {
1748
    foreach ($element['#options'] as $key => $choice) {
1749
      if (!isset($element[$key . '_preferred'])) {
1750
        $element[$key . '_preferred'] = array(
1751
          '#type' => 'radio',
1752
          '#name' => $element['#parents'][0] . '_preferred',
1753
          '#return_value' => check_plain($key),
1754
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
1755
          '#attributes' => $element['#attributes'],
1756
          '#parents' => $element['#parents'],
1757
          // '#spawned' => TRUE,
1758
          '#weight' => $weight + 1,
1759
          '#prefix' => '<td>',        // add a prefix to start a new table cell
1760
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
1761
        );
1762
      }
1763
      $weight += 2;
1764
    }
1765
  }
1766

    
1767
  // end the table
1768
  $element['table_end'] = array(
1769
    '#markup' => '</table>',
1770
    '#weight' => $weight++,
1771
  );
1772

    
1773
  return $element;
1774
}
1775

    
1776
/**
1777
 * Theme function for the custom form field 'checkboxes_preferred'.
1778
 */
1779
function theme_checkboxes_preferred($variables) {
1780
  $element = $variables['element'];
1781
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
1782
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
1783
  $out .= drupal_render_children($element);
1784
  $out .= '<div class="description">' . $element['#description'] . '</div>';
1785
  $out .= '</div>';
1786
  return $out;
1787
}
1788

    
1789
/**
1790
 * Callback for checkboxes preferred for widget which will
1791
 * be called after the form or element is built. The call
1792
 * back is configured in the form element by setting it as
1793
 * #after_build parameter.
1794
 *
1795
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
1796
 *
1797
 * @param $form
1798
 *   Nested array of form elements that comprise the form.
1799
 * @param $form_state
1800
 *   A keyed array containing the current state of the form.
1801
 *
1802
 * @return the modified form array
1803
 */
1804
function checkboxes_preferred_after_build($form, &$form_state) {
1805

    
1806
  $parent_id = $form['#parents'][0];
1807

    
1808
  if ($_POST && count($_POST) > 0) {
1809
    // First pass of form processing.
1810
    $preferred_layer = $_POST[$parent_id . '_preferred'];
1811
    $form['#value']['PREFERRED'] = $preferred_layer;
1812
    $form_state[$parent_id] = $form['#value'];
1813
    $form_state['values']['baselayers'] = $form['#value'];
1814
  }
1815
  else {
1816
    // Second pass of form processing.
1817
    $preferred_layer = $form['#value']['PREFERRED'];
1818
  }
1819

    
1820
  // Also set the chosen value (not sure if this is good Drupal style ....).
1821
  foreach ($children = element_children($form) as $key) {
1822
    if (!empty($form[$key]['#type']) && $form[$key]['#type'] == 'radio') {
1823
      $form[$key]['#value'] = $preferred_layer;
1824
    }
1825
  }
1826
  // The default layer must always be enabled.
1827
  $form[$preferred_layer]['#value'] = $preferred_layer;
1828

    
1829
  return $form;
1830
}
(13-13/13)