Project

General

Profile

Download (71.7 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?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.br.fgov.be/edit_wp5/v1');
45
define('EDIT_MAPSERVER_V11_URI', 'http://edit.br.fgov.be/edit_wp5/v1.1');
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() {
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_V1_URI),
1267
    '#options' => array(
1268
      EDIT_MAPSERVER_V1_URI => 'EDIT Map Server v1',
1269
      EDIT_MAPSERVER_V11_URI => 'EDIT Map Server v1.1',
1270
      /*
1271
      'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server - Mirror 1',
1272
      'http://edit.br.fgov.be/edit_wp5/v1/' => 'EDIT Map Server - Mirror 2',
1273
      */
1274
      'ALTERNATIVE' => '-- Alternative URL --',
1275
    ),
1276
    '#description' => t('Select the Map Server you want the data portal to
1277
      connect. If you want to introduce a custom address just select the
1278
      Alternative URL value and fill the field Geoservice Access Point
1279
      - Alternative URL with the custom ip address.'),
1280
  );
1281
1282
  $form['geoserver']['edit_map_server_alternative'] = array(
1283
    '#type' => 'textfield',
1284
    '#title' => t('Geoservice access point - alternative URL') . ':',
1285
    '#default_value' => variable_get('edit_map_server_alternative', ''),
1286
    '#description' => t('Alternative URL of a EDIT Map Service to be used by
1287
      this portal. You must choose the option <i>-- Alternative URL --</i> in
1288
      the chooser above to enable this url.'),
1289
  );
1290
1291
  /*
1292
  MAP SETTINGS
1293
  */
1294
  $form['map_settings'] = array(
1295
    '#type' => 'fieldset',
1296
    '#title' => t('Maps settings'),
1297
    '#collapsible' => TRUE,
1298
    '#collapsed' => TRUE,
1299
    '#description' => t('General configuration for all map types.'),
1300
  );
1301
1302
  $form['map_settings']['cdm_dataportal_geoservice_display_width'] = array(
1303
    '#type' => 'textfield',
1304
    '#title' => t('Maps width') . ':',
1305
    '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
1306
    '#description' => t('Choose the width of your maps, the height will always
1307
      be the half of the width. A value of 500 means the size will be 500 pixels
1308
      width and 250 pixels height.'),
1309
  );
1310
1311
  $form['map_settings']['cdm_dataportal_geoservice_bounding_box'] = array(
1312
    '#type' => 'textfield',
1313
    '#title' => t('Fixed bounding box') . ':',
1314
    '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
1315
    '#description' => t('Define surrounding of area to be displayed in maps.
1316
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
1317
      to let the map <strong>automatically zoom</strong> to the distribution
1318
      area.'),
1319
  );
1320
1321
  $form['map_settings']['cdm_dataportal_geoservice_labels_on'] = array(
1322
    '#type' => 'checkbox',
1323
    '#title' => '<b>' . t('Display area labels') . '</b>',
1324
    '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
1325
    '#description' => t('Check this if you like area names to be displayed in the maps. DOES IT WORK???? '),
1326
  );
1327
1328
  $form['map_settings']['cdm_dataportal_geoservice_map_caption'] = array(
1329
    '#type' => 'textfield',
1330
    '#title' => t('Map caption') . ':',
1331
    '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
1332
    '#description' => t('Define a caption for the map.'),
1333
  );
1334
1335
  $form['map_settings']['cdm_dataportal_geoservice_distributionOpacity'] = array(
1336
    '#type' => 'textfield',
1337
    '#title' => t('Distribution layer opacity') . ':',
1338
    '#default_value' => variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5'),
1339
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1340
                           fully visible, while a value near to 0.0 will be not much visible.'),
1341
  );
1342
1343
  $form['map_settings']['cdm_dataportal_map_openlayers'] = array(
1344
    '#type' => 'radios',
1345
    '#title' => t('Map Viewer') . ':',
1346
    '#options' => array(
1347
      1 => "OpenLayers dynamic mapviewer",
1348
      0 => "Plain image",
1349
    ),
1350
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1351
    '#description' => t('You can choose from two different map viewers:
1352
      <ul><li><em>OpenLayers</em> displays the maps in an interactive viewer
1353
      which allows zooming and panning. If not enabled the maps will consist
1354
      on a static image. If enabled you can configure the default layer
1355
      (background of your maps) below. Only one of them will be rendered.</li>
1356
      <li><em>Plain image</em> displays the map as a plain non interactive
1357
      image.</li></ul>'),
1358
  );
1359
1360
  $openLayersEnabled = variable_get('cdm_dataportal_map_openlayers', 1) == 1;
1361
1362
1363
  // --- Plain Image Settings --- //
1364
  $form['map_image'] = array(
1365
    '#type' => 'fieldset',
1366
    '#title' => t('Plain image map settings'),
1367
    '#collapsible' => TRUE,
1368
    '#collapsed' => $openLayersEnabled,
1369
    '#description' => t('The settings in this section are still expertimental
1370
      and can only be used with the EDIT map service version 1.1 or above.'),
1371
  );
1372
1373
  $edit_mapserver_version = getEDITMapServiceVersionNumber();
1374
  if ($edit_mapserver_version < 1.1) {
1375
    $form['map_image']['#description'] = '<div class="messages warning">' . t("The selected EDIT map service version has to small version number: $edit_mapserver_version") . '</div>'
1376
      . $form['map_image']['#description'];
1377
  }
1378
1379
  $form['map_image']['map_base_layer'] = array(
1380
    '#type' => 'textfield',
1381
    '#title' => t('Background layer') . ':',
1382
    '#default_value' => variable_get('map_base_layer', 'cyprusdivs'),
1383
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
1384
      '!url1' => l(t('deegree-csw'), 'http://edit2.br.fgov.be:8080/deegree-csw/md_search.jsp'),
1385
      '!url2' => l(t('geoserver layers'), 'http://edit.br.fgov.be:8080/geoserver/rest/layers'),
1386
    )),
1387
  );
1388
1389
  $form['map_image']['map_bg_color'] = array(
1390
    '#type' => 'textfield',
1391
    '#title' => t('Background color') . ':',
1392
    '#default_value' => variable_get('map_bg_color', '1874CD'),
1393
  );
1394
1395
  $form['map_image']['map_base_layer_style'] = array(
1396
    '#type' => 'textfield',
1397
    '#title' => t('Background layer area style') . ':',
1398
     // Only line color by now.
1399
    '#default_value' => variable_get('map_base_layer_style', 'ffffff,606060,,'),
1400
    '#description' => t('Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}'),
1401
  );
1402
1403
1404
  // --- OpenLayers Settings --- //
1405
  $form['openlayers'] = array(
1406
    '#type' => 'fieldset',
1407
    '#title' => t('OpenLayers settings'),
1408
    '#collapsible' => TRUE,
1409
    '#collapsed' => !$openLayersEnabled,
1410
    '#description' => '',
1411
  );
1412
1413
  if (!$openLayersEnabled) {
1414
    $form['openlayers']['#description'] = '<div class="messages warning">' . t('The Openlayers viewer is currently not enabled! (see section Maps settings above )') . '</div>'
1415
      . $form['openlayers']['#description'];
1416
  }
1417
1418
  $baselayer_options = array(
1419
    /*
1420
   NOTICE: must correspond to the layers defined in
1421
   js/openlayers_,ap.js#getLayersByName()
1422
   */
1423
    // osgeo_vmap0 projections: EPSG:4326: EPSG:900913
1424
    'osgeo_vmap0' => "Metacarta Vmap0",
1425
    // 'metacarta_vmap0' => "Metacarta Vmap0" , // EPSG:4326, EPSG:900913
1426
    // all others EPSG:900913
1427
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
1428
    'edit-etopo1' => "ETOPO1 Global Relief Model",
1429
    'mapnik' => 'OpenStreetMap',
1430
    'osmarender' => 'OpenStreetMap (Tiles@home)',
1431
    'gmap' => 'Google Streets',
1432
    'gsat' => 'Google Satellite',
1433
    'ghyb' => 'Google Hybrid',
1434
    'veroad' => 'Virtual Earth Roads',
1435
    'veaer' => 'Virtual Earth Aerial',
1436
    'vehyb' => 'Virtual Earth Hybrid',
1437
    // 'yahoo' => 'Yahoo Street',
1438
    // 'yahoosat' => 'Yahoo Satellite',
1439
    // 'yahoohyb' => 'Yahoo Hybrid',
1440
  );
1441
1442
  $form['openlayers']['baselayers'] = array(
1443
    '#type' => 'checkboxes_preferred',
1444
    '#title' => t('Base Layers') . ':',
1445
    '#options' => $baselayer_options,
1446
    '#default_value' => variable_get('baselayers', array('metacarta_vmap0' => "metacarta_vmap0", 'PREFERRED' => 'metacarta_vmap0')),
1447
    '#description' => t('Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.'),
1448
  );
1449
1450
  // cdm_dataportal_geoservice_showLayerSwitcher
1451
  $form['openlayers']['cdm_dataportal_geoservice_showLayerSwitcher'] = array(
1452
    '#type' => 'checkbox',
1453
    '#title' => '<b>' . t('Show Layer Switcher') . '</b>',
1454
    '#default_value' => variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE),
1455
    '#description' => t('
1456
      The Layer Switcher control displays a table of contents
1457
      for the map.  This allows the user interface to switch between
1458
      BaseLayers and to show or hide Overlays.  By default the switcher is
1459
      shown minimized on the right edge of the map, the user may expand it
1460
      by clicking on the handle.'
1461
    ),
1462
  );
1463
1464
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1465
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1466
  $form['openlayers']['gmap_api_key'] = array(
1467
    '#type' => 'textfield',
1468
    '#title' => t('Google maps API key') . ':',
1469
    '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1470
    '#description' => t('If you want to use the Google Maps Layer, a key is
1471
      needed. If you need a key, visit
1472
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
1473
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
1474
      is the default key for the localhost (127.0.0.1). The key in use is the
1475
      one above this text.', array('!localhostkey' => $localhostkey)),
1476
  );
1477
1478
  $form['cdm_dataportal_geoservice_map_legend'] = array(
1479
    '#type' => 'fieldset',
1480
    '#title' => t('Map legend'),
1481
    '#collapsible' => TRUE,
1482
    '#collapsed' => TRUE,
1483
    '#description' => t('Configure the maps legend.'),
1484
  );
1485
1486
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
1487
    '#type' => 'checkbox',
1488
    '#title' => '<b>' . t('Display a map legend') . '</b>',
1489
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
1490
    '#description' => t('Check this if you like a legend to be displayed with the maps.'),
1491
  );
1492
1493
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legendOpacity'] = array(
1494
    '#type' => 'textfield',
1495
    '#title' => t('Legend opacity'),
1496
    '#default_value' => variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'),
1497
    '#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
1498
                         to 0.0 will be not much visible.'),
1499
  );
1500
1501
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
1502
    '#type' => 'textfield',
1503
    '#title' => t('Font size'),
1504
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
1505
    '#description' => t('Font size in pixels.'),
1506
  );
1507
1508
  $fontStyles = array(
1509
    0 => "plane",
1510
    1 => "italic",
1511
  );
1512
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
1513
    '#type' => 'select',
1514
    '#title' => t('Available font styles'),
1515
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', FALSE),
1516
    '#options' => $fontStyles,
1517
    '#description' => t('Select a font style for the map legend.'),
1518
  );
1519
1520
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
1521
    '#type' => 'textfield',
1522
    '#title' => t('Legend icon width'),
1523
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
1524
    '#description' => t('Legend icon width in pixels.'),
1525
  );
1526
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
1527
    '#type' => 'textfield',
1528
    '#title' => t('Legend icon height'),
1529
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
1530
    '#description' => t('Legend icon height in pixels.'),
1531
  );
1532
1533
  // @WA: D7 form api does not support reset buttons,
1534
  // so to mimic the D5 reset button we add one like this.
1535
  $form['actions']['reset'] = array(
1536
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1537
    '#weight' => 1000,
1538
  );
1539
  return system_settings_form($form);
1540
}
1541
1542
/**
1543
 * @todo document this function.
1544
 */
1545
function cdm_settings_cache() {
1546
1547
  $form = array();
1548
1549
  $form['cache_settings'] = array(
1550
    '#type' => 'fieldset',
1551
    '#title' => t('Cache Settings'),
1552
    '#collapsible' => FALSE,
1553
    '#collapsed' => FALSE,
1554
    '#description' => t('<p>When caching is enabled all single taxon sites are
1555
      stored in an internal drupal cache doing the portal response of taxa pages
1556
      faster. This is possible because the sites are loaded from the cache and
1557
      are not created from scratch.</p>'),
1558
  );
1559
1560
  $form['cache_settings']['cdm_webservice_cache'] = array(
1561
    '#type' => 'checkbox',
1562
    '#title' => t('<strong>Enable caching</strong>'),
1563
    '#options' => cdm_help_general_cache(),
1564
    '#default_value' => variable_get('cdm_webservice_cache', 1),
1565
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
1566
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
1567
       application the changes will be not visible till the cache is erased.
1568
       Therefore developers should deactived this feature when they are working
1569
       on the CDM Dataportal Module.</p>'),
1570
  );
1571
1572
  $form['cache_settings']['cdm_run_cache'] = array(
1573
    '#markup' => cdm_view_cache_site(),
1574
  );
1575
1576
  // @WA: D7 form api does not support reset buttons,
1577
  // so to mimic the D5 reset button we add one like this.
1578
  $form['actions']['reset'] = array(
1579
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1580
    '#weight' => 1000,
1581
  );
1582
  return system_settings_form($form);
1583
}
1584
1585
/**
1586
 * Walk and cache all taxon pages.
1587
 */
1588
function cdm_view_cache_site() {
1589
1590
  $out = '';
1591
1592
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
1593
1594
  $request_params = array();
1595
  $request_params['query'] = '%';
1596
  // Cache only the dafault classification.
1597
  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', FALSE);
1598
  $request_params['doTaxa'] = 1;
1599
  $request_params['doSynonyms'] = 0;
1600
  $request_params['doTaxaByCommonNames'] = 0;
1601
1602
  $search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND . ".json", NULL, queryString($request_params));
1603
1604
  $search_url = uri_uriByProxy($search_url);
1605
  $search_url = rtrim($search_url, '/');
1606
  $taxon_page_url = url('cdm_dataportal/taxon/');
1607
1608
  $out .= t('<p><strong>Cache all taxon pages</strong></p>');
1609
  $out .= '<p>When you launch the cache process the cache is filled and ready to be enabled.<br/>
1610
  Remember that when you load the taxa from the cache last changes on taxa will be not visible till you erase
1611
  the cache and fill it again.</p>';
1612
  $out .= '<p>Before  running the cache bot you have to empty the cache manually.</p>';
1613
1614
  $out .= '<div>' . t('This caching process may take long time and could cause heavy load on your server') . '</div>';
1615
  $out .= '<div id="progress"></div>';
1616
1617
  // Comment @WA: A form within a form is not valid html and not needed here.
1618
  // Also, it would be recommended just to include this part of the form in the
1619
  // rest of the form array in cdm_settings_cache().
1620
  // $out .= '<form id="cache_site">';
1621
  $out .= '<input type="hidden" name="searchTaxaUrl" value="' . $search_url . '"/>';
1622
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . $taxon_page_url . '"/>';
1623
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
1624
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
1625
  // $out .= '</form>';
1626
  $out .= '</div>';
1627
  /*
1628
  foreach($taxonPager->records as $taxon){
1629
    cdm_dataportal_taxon_view($uuid);
1630
  }
1631
  */
1632
  return $out;
1633
}
1634
1635
/**
1636
 * Form validation handler for ?
1637
 *
1638
 * Comment @WA: currently this handler is not used.
1639
 * It seems partly for cdm_settings_general en partly for cdm_settings_cache?
1640
 * Then you can change the name into cdm_settings_general_validate() or
1641
 * cdm_settings_cache_validate().
1642
 * But cdm_api_secref_cache_clear is not doing anything (yet)?
1643
 */
1644
function cdm_settings_validate($form, &$form_state) {
1645
1646
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
1647
    // form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
1648
    $form_state['values']['cdm_webservice_url'] .= '/';
1649
  }
1650
1651
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
1652
    cache_clear_all(NULL, 'cache_cdm_ws');
1653
    // Better clear secref_cache since I can not be sure if the cache has not
1654
    // be used during this response.
1655
    cdm_api_secref_cache_clear();
1656
  }
1657
}
1658
1659
/**
1660
 * @todo document this function.
1661
 */
1662
function getEDITMapServiceURI() {
1663
1664
  if (variable_get('edit_map_server', FALSE) == 'ALTERNATIVE') {
1665
    return (variable_get('edit_map_server_alternative', FALSE));
1666
  }
1667
  elseif (variable_get('edit_map_server', FALSE)) {
1668
    return variable_get('edit_map_server', FALSE);
1669
  }
1670
  else {
1671
    return EDIT_MAPSERVER_V1_URI;
1672
  }
1673
1674
}
1675
1676
/**
1677
 * @todo document this function.
1678
 *
1679
 * @return float
1680
 *   The version number of the currently selected edit mapserver as a float.
1681
 *   Returns 0 on error.
1682
 */
1683
function getEDITMapServiceVersionNumber() {
1684
1685
  $pattern = '/v([\d\.]+)$/';
1686
1687
  $url = getEDITMapServiceURI();
1688
  preg_match($pattern, $url, $matches, PREG_OFFSET_CAPTURE, 3);
1689
  if (isset($matches[1])) {
1690
    // Convert string to float.
1691
    $version = 1 + $matches[1][0] - 1;
1692
    return $version;
1693
  }
1694
  else {
1695
    // Report error.
1696
    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');
1697
    return 0;
1698
  }
1699
}
1700
1701
/**
1702
 * Implements hook_element_info().
1703
 *
1704 14feebe9 Andreas Kohlbecker
 * Allows modules to declare their own Form API element types and specify their default values.
1705
 *
1706
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
1707 6657531f Andreas Kohlbecker
 */
1708
function cdm_dataportal_element_info() {
1709
  $type['checkboxes_preferred'] = array(
1710
    '#input' => TRUE,
1711 14feebe9 Andreas Kohlbecker
    '#process' => array('checkboxes_preferred_expand'),
1712 6657531f Andreas Kohlbecker
    '#after_build' => array('checkboxes_preferred_after_build'),
1713
    '#theme' => array('checkboxes_preferred'),
1714
    // '#theme_wrapper' => array('form_element'),
1715
  );
1716
  return $type;
1717
}
1718
1719
/**
1720 14feebe9 Andreas Kohlbecker
 * #process callback function for the custom form element type 'checkbox_preferred'
1721
 *
1722
 *
1723 6657531f Andreas Kohlbecker
 */
1724 14feebe9 Andreas Kohlbecker
function checkboxes_preferred_expand($element, &$form_state, $form) {
1725
1726
  // First of all create checkboxes for each of the elements
1727 6657531f Andreas Kohlbecker
  $element = form_process_checkboxes($element);
1728
1729
  $children = element_children($element);
1730
1731
  $element['table_start'] = array(
1732
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
1733
    '#weight' => -1,
1734
  );
1735
1736 14feebe9 Andreas Kohlbecker
  // prepare first part each of the table rows which contains the row label
1737 6657531f Andreas Kohlbecker
  $weight = 0;
1738
  foreach ($children as $key) {
1739
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
1740
    $element[$key]['#weight'] = $weight;
1741
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
1742
    $element[$key]['#suffix'] = '</td>';
1743
    unset($element[$key]['#title']);
1744
    $weight += 2;
1745
  }
1746
  $weight = 0;
1747
1748 14feebe9 Andreas Kohlbecker
  // add a radio button to each of the checkboxes, the
1749
  // check boxes have already been created at the beginning
1750
  // of this function
1751 6657531f Andreas Kohlbecker
  if (count($element['#options']) > 0) {
1752
    foreach ($element['#options'] as $key => $choice) {
1753
      if (!isset($element[$key . '_preferred'])) {
1754
        $element[$key . '_preferred'] = array(
1755
          '#type' => 'radio',
1756
          '#name' => $element['#parents'][0] . '_preferred',
1757
          '#return_value' => check_plain($key),
1758
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
1759
          '#attributes' => $element['#attributes'],
1760
          // '#spawned' => TRUE,
1761
          '#weight' => $weight + 1,
1762 14feebe9 Andreas Kohlbecker
          '#prefix' => '<td>',        // add a prefix to start a new table cell
1763
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
1764 6657531f Andreas Kohlbecker
        );
1765
      }
1766
      $weight += 2;
1767
    }
1768
  }
1769
1770 14feebe9 Andreas Kohlbecker
  // end the table
1771 6657531f Andreas Kohlbecker
  $element['table_end'] = array(
1772
    '#markup' => '</table>',
1773
    '#weight' => $weight++,
1774
  );
1775
1776
  return $element;
1777
}
1778
1779
/**
1780
 * Theme function for the custom form field 'checkboxes_preferred'.
1781
 */
1782
function theme_checkboxes_preferred($variables) {
1783
  $element = $variables['element'];
1784
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
1785
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
1786
  $out .= drupal_render_children($element);
1787
  $out .= '<div class="description">' . $element['#description'] . '</div>';
1788
  $out .= '</div>';
1789
  return $out;
1790
}
1791
1792
/**
1793 14feebe9 Andreas Kohlbecker
 * Callback for checkboxes preferred for widget which will
1794
 * be called after the form or element is built. The call
1795
 * back is configured in the form element by setting it as
1796
 * #after_build parameter.
1797
 *
1798
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
1799
 *
1800
 * @param $form
1801
 *   Nested array of form elements that comprise the form.
1802
 * @param $form_state
1803
 *   A keyed array containing the current state of the form.
1804
 *
1805
 * @return the modified form array
1806 6657531f Andreas Kohlbecker
 */
1807
function checkboxes_preferred_after_build($form, &$form_state) {
1808
1809
  $parent_id = $form['#parents'][0];
1810
1811
  if ($_POST && count($_POST) > 0) {
1812
    // First pass of form processing.
1813
    $preferred_layer = $_POST[$parent_id . '_preferred'];
1814
    $form['#value']['PREFERRED'] = $preferred_layer;
1815
    $form_state[$parent_id] = $form['#value'];
1816
  }
1817
  else {
1818
    // Second pass of form processing.
1819
    $preferred_layer = $form['#value']['PREFERRED'];
1820
  }
1821
1822
  // Also set the chosen value (not sure if this is good Drupal style ....).
1823
  foreach ($children = element_children($form) as $key) {
1824
    if (!empty($form[$key]['#type']) && $form[$key]['#type'] == 'radio') {
1825
      $form[$key]['#value'] = $preferred_layer;
1826
    }
1827
  }
1828
  // The default layer must always be enabled.
1829
  $form[$preferred_layer]['#value'] = $preferred_layer;
1830
1831
  return $form;
1832
}