Project

General

Profile

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

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

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

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

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

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

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

    
44
/* ---- MAP SETTING CONSTANTS ---- */
45
/**
46
 * @var array of URIs eg. http://edit.africamuseum.be"
47
 *   An options array
48
 */
49
define('EDIT_MAPSERVER_URI', serialize(
50
    array(
51
      'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)',
52
      'http://edit.br.fgov.be'=>'Secondary (http://edit.br.fgov.be)',
53
    )
54
  )
55
);
56
define('EDIT_MAPSERVER_PATH', '/edit_wp5');
57
/**
58
 * @var array of versions eg. "v1.2"
59
 *   An options array
60
 */
61
define('EDIT_MAPSERVER_VERSION', serialize(
62
    array(
63
      'v1' => 'v1' ,
64
      'v1.1' => 'v1.1',
65
      'v1.2_dev' => 'v1.2_dev'
66
    )
67
  )
68
);
69
define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
70
define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.1');
71

    
72
// --- Taxon profile settings --- /
73
define('LAYOUT_SETTING_PREFIX', 'layout_');
74
define('FEATURE_TREE_LAYOUT_DEFAULTS', serialize(
75
  array(
76
    'enabled' => FALSE,
77
    'enclosingTag' => 'ul',
78
    'entryEnclosingTag' => 'li',
79
    'glue' => ' ',
80
  )));
81

    
82
define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
83

    
84

    
85
/**
86
 * @todo document this function
87
 */
88
function get_taxon_tabs_list() {
89
  return array(
90
    0 => 'General',
91
    1 => 'Synonymy',
92
    2 => 'Images',
93
    3 => 'Specimens',
94
    4 => 'Keys',
95
  );
96
}
97

    
98
$taxon_tab_options = get_taxon_tabs_list();
99
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
100

    
101
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
102

    
103
/**
104
 * @todo document this function.
105
 */
106
function get_taxon_options_list() {
107
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
108
  foreach ($taxon_tab_options as $key => $value) {
109
    $taxon_tab_options[$key] = t($key);
110
  }
111
  return $taxon_tab_options;
112

    
113
}
114

    
115
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
116
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
117
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
118
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
119
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
120
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
121
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
122
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
123
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
124
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
125
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
126
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
127
/**
128
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
129
 * the snonymy.
130
 *
131
 * @var string
132
 */
133
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
134
/**
135
 * The drupal variable for the configuration of the information aggregation along
136
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
137
 *    - direct: the uuids of the taxon relationship types to take into account in invers
138
 *      direction.
139
 *    - invers: the uuids of the taxon relationship types to take into account in direct
140
 *      direction.
141
 *
142
 * @var String
143
 */
144
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
145
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
146
    array(
147
        'direct'=>array(),
148
        'invers'=>array()
149
     )
150
   ));
151
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
152
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
153
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
154

    
155
/**
156
 * @todo document this function.
157
 */
158
function getGallerySettings($gallery_config_form_name) {
159
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
160
  return variable_get($gallery_config_form_name, $default_values);
161
}
162

    
163
/**
164
 * Returns the string representation of the default tab.
165
 *
166
 * @param bool $returnTabIndex
167
 *   Defaults to FALSE, if set true this function will return the index number
168
 *   of the default tab. (used to supply default values to form elements).
169
 */
170
function get_default_taxon_tab($returnTabIndex = FALSE) {
171

    
172
  global $user;
173
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
174
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
175
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
176
  // Get the user value if the used has chosen to overwrite the system settings.
177
  $user_tab_on = variable_get($user_tab_active, FALSE);
178
  if ($user_tab_on) {
179
    $user_value = variable_get($user_tab, 0);
180
    $index_value = $user_value;
181
    // Get the system value.
182
  }
183
  else {
184
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
185
    $index_value = $system_value;
186
  }
187

    
188
  // Return the index value or the string representation.
189
  if ($returnTabIndex) {
190
    return $index_value;
191
  }
192
  else {
193
    return ($values[$index_value]);
194
  }
195

    
196
}
197

    
198
/**
199
 * @todo Please document this function.
200
 * @see http://drupal.org/node/1354
201
 */
202
function cdm_dataportal_menu_admin(&$items) {
203
  // Display section on admin/config page.
204
  $items['admin/config/cdm_dataportal'] = array(
205
    'title' => 'CDM Dataportal',
206
    'description' => 'Settings for the CDM DataPortal.',
207
    'position' => 'right',
208
    'weight' => 10,
209
    'page callback' => 'system_admin_menu_block_page',
210
    'access arguments' => array('cdm_settings_general'),
211
    'file' => 'system.admin.inc',
212
    'file path' => drupal_get_path('module', 'system'),
213
  );
214
  $items['admin/config/cdm_dataportal/settings'] = array(
215
    'title' => 'Settings',
216
    'description' => 'Settings for the CDM DataPortal.',
217
    'weight' => 0,
218
    'page callback' => 'drupal_get_form',
219
    'page arguments' => array('cdm_settings_general'),
220
    'access arguments' => array('administer cdm_dataportal'),
221
    'type' => MENU_NORMAL_ITEM,
222
  );
223
  $items['admin/config/cdm_dataportal/settings/general'] = array(
224
    'title' => 'General',
225
    'description' => 'General',
226
    'weight' => 0,
227
    'page callback' => 'drupal_get_form',
228
    'page arguments' => array('cdm_settings_general'),
229
    'access arguments' => array('administer cdm_dataportal'),
230
    'type' => MENU_DEFAULT_LOCAL_TASK,
231
  );
232

    
233
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
234
    'title' => 'Cache',
235
    'description' => 'Cache',
236
    'access arguments' => array('administer cdm_dataportal'),
237
    'page callback' => 'drupal_get_form',
238
    'page arguments' => array('cdm_settings_cache'),
239
    'weight' => 10,
240
    'type' => MENU_LOCAL_TASK,
241
  );
242

    
243
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
244
    'title' => 'Geo & Map',
245
    'description' => 'Geo & Map',
246
    'access arguments' => array('administer cdm_dataportal'),
247
    'page callback' => 'drupal_get_form',
248
    'page arguments' => array('cdm_settings_geo'),
249
    'weight' => 1,
250
    'type' => MENU_LOCAL_TASK,
251
  );
252

    
253
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
254
    'title' => 'Layout',
255
    'description' => 'Configure and adjust the layout of your DataPortal ',
256
    'access arguments' => array('administer cdm_dataportal'),
257
    'page callback' => 'drupal_get_form',
258
    'page arguments' => array('cdm_settings_layout'),
259
    'weight' => 2,
260
    'type' => MENU_LOCAL_TASK,
261
  );
262

    
263
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
264
    'title' => 'Taxon',
265
    'description' => 'Configure and adjust the layout of your DataPortal ',
266
    'access arguments' => array('administer cdm_dataportal'),
267
    'page callback' => 'drupal_get_form',
268
    'page arguments' => array('cdm_settings_layout_taxon'),
269
    'weight' => 1,
270
    'type' => MENU_LOCAL_TASK,
271
  );
272
  /*
273
  $items[] = array(
274
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
275
  'title' => t('Synonymy'),
276
  'description' => t('Configure and adjust the layout of your DataPortal '),
277
  'access' => user_access('administer cdm_dataportal'),
278
  'callback' => 'drupal_get_form',
279
  'callback arguments' => array('cdm_settings_layout_synonymy'),
280
  'weight' => 1,
281
  'type' => MENU_LOCAL_TASK,
282
  );
283

    
284
  $items[] = array(
285
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
286
  'title' => t('Specimens'),
287
  'description' => t('Configure and adjust the layout of your DataPortal '),
288
  'access' => user_access('administer cdm_dataportal'),
289
  'callback' => 'drupal_get_form',
290
  'callback arguments' => array('cdm_settings_layout_specimens'),
291
  'weight' => 1,
292
  'type' => MENU_LOCAL_TASK,
293
  );
294
  */
295
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
296
    'title' => 'Search',
297
    'description' => 'Configure and adjust the layout of your DataPortal ',
298
    'access arguments' => array('administer cdm_dataportal'),
299
    'page callback' => 'drupal_get_form',
300
    'page arguments' => array('cdm_settings_layout_search'),
301
    'weight' => 2,
302
    'type' => MENU_LOCAL_TASK,
303
  );
304

    
305
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
306
    'title' => 'Media',
307
    'description' => 'Configure and adjust the layout of your DataPortal ',
308
    'access arguments' => array('administer cdm_dataportal'),
309
    'page callback' => 'drupal_get_form',
310
    'page arguments' => array('cdm_settings_layout_media'),
311
    'weight' => 3,
312
    'type' => MENU_LOCAL_TASK,
313
  );
314
  /*
315
  // Path to banners configuration (DEFAULT THEME).
316
  $items[] = array(
317
  'path' => 'admin/config/cdm_dataportal/layout/theme',
318
  'title' => t('Theme'),
319
  'description' => t('Configure the drupal theme of your DataPortal '),
320
  'access' => user_access('administer cdm_dataportal'),
321
  'callback' => 'drupal_get_form',
322
  'callback arguments' => array('cdm_dataportal_theming_form'),
323
  'weight' => 4,
324
  'type' => MENU_LOCAL_TASK,
325
  );
326
  */
327
}
328

    
329
/**
330
 * @todo document this function.
331
 */
332
function cdm_help_general_cache() {
333
  $form = array();
334
  $form['cache_help'] = array(
335
    '#type' => 'fieldset',
336
    '#title' => t('Help'),
337
    '#collapsible' => TRUE,
338
    '#collapsed' => TRUE,
339
  );
340
  $form['cache_help']['test'] = array('#value' => t('probando'));
341
  return drupal_render($form);
342
  $res = array();
343
  $res['default'] = drupal_render($help);
344
  return $res;
345
}
346

    
347
/**
348
 * Configures the settings form for the CDM-API module.
349
 *
350
 * @return array
351
 *   Drupal settings form.
352
 */
353
function cdm_settings_general() {
354

    
355
  $form['cdm_webservice'] = array(
356
    '#type' => 'fieldset',
357
    '#title' => t('CDM Server'),
358
    '#collapsible' => FALSE,
359
    '#collapsed' => FALSE,
360
    '#description' => t('<em>CDM Server</em> makes the dialogue possible with
361
      <em>CDM Data Portal</em> thanks to its web services.'),
362
  );
363

    
364
  $form['cdm_webservice']['cdm_webservice_url'] = array(
365
    '#type' => 'textfield',
366
    '#title' => t('CDM web service URL') . ':',
367
    '#description' => t('This is the URL to the CDM-Server exposing your data
368
      e.g. <em>"http://localhost:8080/cichorieae/"</em> The URL <strong>must end
369
      with a slash</strong> character!'),
370
    '#default_value' => variable_get('cdm_webservice_url', NULL),
371
  );
372

    
373
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
374
    '#type' => 'checkbox',
375
    '#title' => t('<b>Debug CDM Web Service</b>'),
376
    '#default_value' => variable_get('cdm_webservice_debug', 1),
377
    '#description' => t('The black web service debug box will appear at the top
378
      of each page. When clicked it toggles open and provides a list of all HTTP
379
      requests which have been made while building of this page.<br />
380
      <strong>Note:</strong> this is a feature dedicated to developers. It will
381
      only be visible when logged in and if the user has suffucicient rights to
382
      see this debug box.'),
383
  );
384

    
385
  $form['cdm_webservice']['freetext_index'] = array(
386
    '#type' => 'fieldset',
387
    '#title' => t('Freetext index'),
388
    '#collapsible' => FALSE,
389
    '#collapsed' => FALSE,
390
  );
391

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

    
404
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
405
  $trigger_link_options = array(
406
    'attributes' => array(
407
      'class' => 'index-trigger',
408
    ),
409
  );
410
  $form['cdm_webservice']['freetext_index']['operations'] = array(
411
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
412
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
413
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
414
      ))
415
    . '<div id="index-progress"></div></div>',
416
  );
417
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
418

    
419
  $form['cdm_webservice']['proxy'] = array(
420
    '#type' => 'fieldset',
421
    '#title' => t('Proxy'),
422
    '#collapsible' => TRUE,
423
    '#collapsed' => TRUE,
424
  );
425

    
426
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
427
    '#type' => 'textfield',
428
    '#title' => t('Proxy URL') . ':',
429
    '#description' => t('If this proxy url is set the cdm api tries
430
    to connect the web service over the given proxy server.
431
    Otherwise proxy usage is deactivated.'),
432
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
433
  );
434

    
435
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
436
    '#type' => 'textfield',
437
    '#title' => t('Proxy port') . ':',
438
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
439
  );
440

    
441
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
442
    '#type' => 'textfield',
443
    '#title' => t('Login') . ':',
444
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
445
  );
446

    
447
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
448
    '#type' => 'textfield',
449
    '#title' => t('Password') . ':',
450
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
451
  );
452

    
453
  // TODO: settings are still incomplete, compare with
454
  // trunk/dataportal/inc/config_default.php.inc.
455
  $form['cdm_dataportal'] = array(
456
    '#type' => 'fieldset',
457
    '#title' => t('Taxon Tree'),
458
    '#collapsible' => FALSE,
459
    '#collapsed' => TRUE,
460
    '#description' => t('<p>When you explore your collection, you can navigate
461
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
462
      able to navigate through your collection the
463
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
464
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
465
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
466
      </a></p>'),
467
  );
468

    
469
  $form['cdm_dataportal'][CDM_TAXONOMICTREE_UUID] = array(
470
    '#type' => 'select',
471
    '#title' => t('Available classifications') . ':',
472
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
473
    '#options' => cdm_get_taxontrees_as_options(),
474
    '#description' => t('Select the default taxa classification for your
475
      <em>taxon tree</em>, the other classifications will be also available but
476
      with a manual user change.'),
477
  );
478

    
479
  $form['cdm_dataportal']['taxontree_ranklimit'] = array(
480
    '#type' => 'select',
481
    '#title' => t('Rank of highest displayed taxon') . ':',
482
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
483
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
484
    '#options' => cdm_rankVocabulary_as_option(),
485
    '#description' => t('This is the rank of the highest displayed taxon in the
486
      <em>taxon tree</em>. You can select here which rank should be at the top
487
      level of the tree structure.'),
488
  );
489

    
490
  $form['cdm_dataportal'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
491
      '#type' => 'fieldset',
492
      '#attributes' => array('class'=>array('clearfix')),
493
      '#title' => t('Information aggregation via taxon relationsships'),
494
      '#collapsible' => TRUE,
495
      '#collapsed' => TRUE,
496
      '#tree' => TRUE,
497
      '#description' => t('Information on taxa will be aggregated along the below chosen
498
          taxon relation ships. This will affect images and occurrences (specimens).
499
          Taxon relation ships are directed and point form one taxon to another. The taxon
500
          relationships to be taken into accunt can therefore configured for the direct direction
501
          and for the inverse.'),
502
  );
503

    
504
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
505
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
506

    
507
  $form['cdm_dataportal'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
508
      '#type' => 'checkboxes',
509
      '#title' => t('Direct'),
510
      '#options' => $taxonRelationshipTypeOptions,
511
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
512
  );
513
  $form['cdm_dataportal'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
514
      '#type' => 'checkboxes',
515
      '#title' => t('Invers'),
516
      '#options' => $taxonRelationshipTypeOptions,
517
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
518
  );
519

    
520
  // Comment @WA: D7 form api does not support reset buttons,
521
  // so to mimic the D5 reset button we add one like this.
522
  $form['actions']['reset'] = array(
523
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
524
    '#weight' => 1000,
525
  );
526

    
527
  return system_settings_form($form);
528
}
529

    
530

    
531
/**
532
 * LAYOUT settings
533
 * @return unknown_type
534
 *   todo
535
 */
536
function cdm_settings_layout() {
537

    
538
  // drupal_goto('admin/config/cdm_dataportal/layout/taxon');
539
  $form = array();
540
  /*
541
   // -- tabbed pages -- //
542
   $form['cdm_dataportal_taxonpage_tabs'] = array(
543
   '#type' => 'checkbox',
544
   '#title' => t('Tabbed taxon page'),
545
   '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
546
   '#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.')
547
   );
548
   */
549
  $form['gen_layout'] = array(
550
    '#type' => 'fieldset',
551
    '#title' => t('Portal Layout'),
552
    '#collapsible' => FALSE,
553
    '#collapsed' => FALSE,
554
    '#description' => t('This settings contains the general configurations
555
      layout. If you want to configure the specific sites layout visit the
556
      respective configuration site for taxon, search or media.'),
557
  );
558

    
559
  // ---- footnotes --- //
560
  $form['gen_layout']['footnotes'] = array(
561
    '#type' => 'fieldset',
562
    '#title' => t('Footnotes'),
563
    '#collapsible' => FALSE,
564
    '#collapsed' => FALSE,
565
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
566
      media or distribution areas may have annotations or footnotes. When the
567
      footnotes are enabled they will be visible (if they exist).'),
568
  );
569

    
570
  $form['gen_layout']['footnotes']['cdm_dataportal_all_footnotes'] = array(
571
    '#type' => 'checkbox',
572
    '#title' => t('Do not show footnotes'),
573
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
574
    '#description' => t('Check this if you do not want to show any footnotes'),
575
  );
576

    
577
  $form['gen_layout']['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
578
    '#type' => 'checkbox',
579
    '#title' => t('Do not show annotations footnotes'),
580
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
581
    '#description' => t('Check this if you do not want to show annotation footnotes'),
582
  );
583

    
584
  $annotationTypeOptions = cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE);
585
  // Additional option for the NULL case.
586
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
587
  $form['gen_layout']['footnotes']['annotations_types_as_footnotes'] = array(
588
    '#type' => 'checkboxes',
589
    '#title' => t('Annotation types as footnotes'),
590
    '#description' => t("Only annotations of the selected type will be displayed
591
       as footnotes. You may want to turn 'technical annotations' off."),
592
    '#options' => $annotationTypeOptions,
593
  );
594
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
595
  if (!empty($annotationsTypesAsFootnotes)) {
596
    $form['gen_layout']['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
597
  }
598

    
599
  // --- Advanced Search --- //
600
  $form['gen_layout']['asearch'] = array(
601
    '#type' => 'fieldset',
602
    '#title' => t('Advanced search'),
603
    '#collapsible' => FALSE,
604
    '#collapsed' => FALSE,
605
  );
606
  $form['gen_layout']['asearch']['cdm_dataportal_show_advanced_search'] = array(
607
    '#type' => 'checkbox',
608
    '#title' => t('Show advanced search link'),
609
    '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
610
    '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
611
  );
612

    
613
  // @WA: D7 form api does not support reset buttons,
614
  // so to mimic the D5 reset button we add one like this.
615
  $form['actions']['reset'] = array(
616
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
617
    '#weight' => 1000,
618
  );
619
  return system_settings_form($form);
620
}
621

    
622
/**
623
 * @todo Please document this function.
624
 * @see http://drupal.org/node/1354
625
 */
626
function cdm_dataportal_theming_form() {
627
  // --- Theme --- //
628
  /*
629
   $form['cdm_dataportal_theming'] = array(
630
   '#type' => 'fieldset',
631
   '#title' => t('Theme Images'),
632
   '#collapsible' => FALSE,
633
   '#collapsed' => FALSE,
634
   );
635
   */
636
  $form = array('#attributes' => array('enctype' => 'multipart/form-data'));
637

    
638
  $form['cdm_dataportal_theming_right_image'] = array(
639
    '#type' => 'file',
640
    '#title' => t('Select top right image'),
641
    '#description' => t('Maximum dimensions are %dimensions and the maximum size is %size kB.',
642
                            array('%dimensions' => '250x250', '%size' => '30')),
643
  );
644
  $form['cdm_dataportal_theming_middle_image'] = array(
645
    '#type' => 'file',
646
    '#title' => t('Select top middle image'),
647
  );
648
  $form['test'] = array(
649
    '#type' => 'textfield',
650
    '#title' => t('test'),
651
  );
652

    
653
  // $form['gen_layout']['theme']['#submit'][] = 'settings_validate_theme_pictures';
654
  $form['cdm_dataportal_theming']['submit'] = array(
655
    '#type' => 'submit',
656
    '#value' => t('Submit'),
657
  );
658

    
659
  return $form;
660
}
661

    
662
/**
663
 * @todo Please document this function.
664
 * @see http://drupal.org/node/1354
665
 */
666
function cdm_dataportal_theming_form_submit($form, &$form_state) {
667
  $validators = array();
668
  // Destination path where the files/banners will be saved.
669
  $dest = absolute_path_to_drupal() . '/' . path_to_theme() . '/images/banners';
670
  $dest = str_replace('/', DIRECTORY_SEPARATOR, $dest);
671
  // drupal_set_message($dest);
672
  // Check if directory exists.
673
  if (!file_exists($dest)) {
674

    
675
    // TODO: add rights, which rights should I add?
676
    if (!mkdir($dest, 0777, TRUE)) {
677
      drupal_set_message(t('Failed uploading the files; the directory !dest
678
        could not be created.', array('!dest' => $dest)), 'warning');
679
    }
680
  }
681
  // Check if files already exist.
682
  /*
683
  if (file_exists($dest)) {
684
  }
685
  */
686
  // Save the files.
687
  // TODO Modify the validators array to suit your needs.
688
  // This array is used in the revised file_save_upload.
689
  $validators = array(
690
    'file_validate_is_image' => array(),
691
    'file_validate_image_resolution' => array('85x85'),
692
    'file_validate_size' => array(30 * 1024),
693
  );
694

    
695
  $file = file_save_upload($dest, $validators);
696
  if ($file) {
697
    drupal_set_message($file->filepath);
698
    file_move($file->filepath, $dest);
699
  }
700
  else {
701
    drupal_set_message(t('Fail uploading the file, the file is not accepted.'), 'warning');
702
  }
703
  // Use banners in the selected theme.
704
  /*
705
  if (!copy($file, $file.'.bak')) {
706
    print ("failed to copy $file...<br>\n");
707
  }
708
  */
709
  // Use the banners as default theme.
710
}
711
/*
712
 function cdm_settings_layout_synonymy(){
713
 / * ====== SYNONYMY ====== * /
714
 $form['synonymy'] = array(
715
 '#type' => 'fieldset',
716
 '#title' => t('Synonymy'),
717
 '#collapsible' => TRUE,
718
 '#collapsed' => TRUE,
719
 '#description' => t('This section covers the settings related to the taxon <b>synonymy</b> tab.'),
720
 );
721

    
722
 $form['synonymy']['cdm_dataportal_nomref_in_title'] = array(
723
 '#type' => 'checkbox',
724
 '#title' => t('Show accepted taxon on top of the synonymy'),
725
 '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
726
 '#description' => t('If checked, the first homotypic taxon is a repetition of the accepted taxon most likely
727
 with the full nomenclatural reference (depending on the currently chosen theme).')
728
 );
729

    
730
 $form['synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
731
 '#type' => 'checkbox',
732
 '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
733
 '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
734
 '#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.')
735
 );
736

    
737
 $form['synonymy']['name_relationships']['name_relationships_to_show'] = array(
738
 '#type' => 'checkboxes',
739
 '#title' => t('Display name relationships'),
740
 '#default_value' => variable_get('name_relationships_to_show', 0),
741
 '#options' => $nameRelationshipTypeOptions,
742
 '#description' => t('Select the name relationships you want to show for the accepted taxa.'),
743
 );
744

    
745
 $form['synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
746
 '#type' => 'checkbox',
747
 '#title' => t('Show taxon relations ships of accepted taxon'),
748
 '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
749
 '#description' => t('If this option is enabled the synonymy will show the below selected taxon relationships of accepted taxa.')
750
 );
751

    
752
 $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE);
753
 $form['synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
754
 '#type' => 'checkboxes',
755
 '#title' => t('Taxon relationship types'),
756
 '#description' => t('Only taxon relationships of the selected type will be displayed'),
757
 '#options' => $taxonRelationshipTypeOptions,
758
 '#default_value' => variable_get('CDM_TAXON_RELATIONSHIP_TYPES', unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
759
 '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)
760
 );
761

    
762
 return system_settings_form($form);
763

    
764
 }
765
 */
766

    
767
/**
768
 * @todo Please document this function.
769
 * @see http://drupal.org/node/1354
770
 */
771
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
772
  $form[$form_name] = array(
773
    '#type' => 'fieldset',
774
    '#title' => t($form_title),
775
    '#collapsible' => TRUE,
776
    '#collapsed' => $collapsed,
777
    '#tree' => TRUE,
778
    '#description' => t($form_description),
779
  );
780

    
781
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
782
  $gallery_settings = variable_get($form_name, $default_values);
783
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
784
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
785
    /*
786
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
787
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
788
    '#type' => 'textfield',
789
    '#title' => t('Search Page Size'),
790
    '#default_value' => $test,
791
    '#description' => t('Number of Names to display per page in search results.')
792
    );
793
    */
794
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
795
      '#type' => 'checkbox',
796
      '#title' => t('Show media thumbnails for accepted taxa'),
797
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
798
    );
799

    
800
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
801
      '#type' => 'checkbox',
802
      '#title' => t('Show media thumbnails for synonyms'),
803
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
804
      '#description' => '',
805
    );
806
  }
807

    
808
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
809
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
810
    '#type' => 'checkbox',
811
    '#title' => t('Show captions under thumbnails'),
812
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
813
    '#description' => '',
814
  );
815

    
816
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
817
    '#type' => 'textfield',
818
    '#title' => t('Thumbnail size') . ':',
819
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
820
    '#description' => t('Select the size of each individual thumbnail.'),
821
  );
822

    
823
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
824
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
825
      '#type' => 'textfield',
826
      '#title' => t('Number of columns') . ':',
827
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
828
      '#description' => t('Group the thumbnails in columns: select how many
829
        columns the gallery should display.'),
830
    );
831
  }
832

    
833
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
834
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
835
      '#type' => 'textfield',
836
      '#title' => t('Maximum number of rows') . ':',
837
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
838
      '#description' => t('You can group the thumbnails in rows, select in how
839
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
840
        If you want an unlimited number of rows please set to 0.'),
841
    );
842
  }
843

    
844
  return $form;
845
}
846

    
847
/**
848
 * @todo document this function.
849
 */
850
function cdm_settings_layout_taxon() {
851
  $collapsed = FALSE;
852
  $form = array();
853

    
854
  // --------- TABBED TAXON ------- //
855
  $form['taxon_tabs'] = array(
856
    '#type' => 'fieldset',
857
    '#title' => t('Taxon tabs'),
858
    '#collapsible' => TRUE,
859
    '#collapsed' => FALSE,
860
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
861
      be splitted in four diferent tabs; General, Synonymy, Images and
862
      Specimens. If the taxon has no information for any of the tabs/sections
863
      such tab will be not displayed.'),
864
  );
865

    
866
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
867
    '#type' => 'checkbox',
868
    '#title' => t('Tabbed taxon page'),
869
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
870
    '#description' => t('<p>If selected split the taxon page into individual
871
      tabs for description, images, synonymy and specimens. If not the taxon
872
      data is rendered as a long single page without tabs.</p>'),
873
  );
874

    
875
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
876
    '#type' => 'checkboxes',
877
    '#title' => t('Tabs visibility options') . ':',
878
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
879
    '#options' => get_taxon_options_list(),
880
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
881
  );
882

    
883
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
884
    '#type' => 'select',
885
    '#title' => t('Default tab to display') . ':',
886
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
887
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
888
    '#description' => t('<p>Select the default tab to display when visiting a
889
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
890
      <strong>Note:</strong> After performing a search and clicking in any
891
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
892
      taxon and not the above selected tab.'),
893
  );
894

    
895
  $form['cdm_dataportal_show_back_to_search_results'] = array(
896
    '#type' => 'checkbox',
897
    '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
898
    '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
899
    '#description' => t('<p>If checked the link to search results is rendered at
900
       the top of the taxon site. Clicking on the link the last search performed
901
       is rendered again.</p>'),
902
  );
903

    
904
  /* ======  TAXON_PROFILE ====== */
905
  $form['taxon_profile'] = array(
906
    '#type' => 'fieldset',
907
    '#title' => t('Taxon profile (tab)'),
908
    '#description' => t('<p>This section covers the setting related to the taxon
909
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
910
    '#collapsible' => TRUE,
911
    '#collapsed' => TRUE,
912
  );
913

    
914
  // ---- PROFILE PICTURE ----//
915
  $form['taxon_profile']['picture'] = array(
916
    '#type' => 'fieldset',
917
    '#title' => t('Profile Picture'),
918
    '#collapsible' => TRUE,
919
    '#collapsed' => FALSE,
920
    '#description' => t('Select a profile picture for taxa. Like a facebook of plants.'),
921
  );
922

    
923
  $form['taxon_profile']['picture']['cdm_dataportal_show_default_image'] = array(
924
    '#type' => 'checkbox',
925
    '#title' => t('Enable profil picture'),
926
    '#default_value' => variable_get('cdm_dataportal_show_default_image', FALSE),
927
    '#description' => t('Show the profil picture.'),
928
  );
929

    
930
  $options = cdm_rankVocabulary_as_option();
931
  array_unshift($options, '-- DISABLED --');
932
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
933
    '#type' => 'select',
934
    '#title' => t('Hide picture for taxa above') . ':',
935
    '#default_value' => variable_get('image_hide_rank', '0'),
936
    '#options' => $options,
937
    '#description' => t('Select which rank of pictures should not have
938
      a profile picture.'),
939
  );
940
  // Show picture.
941
  $selectShowMedia = array(
942
    0 => "Show only taxon pictures",
943
    1 => "Show taxon and child taxa pictures",
944
  );
945

    
946
  $form['taxon_profile']['picture']['cdm_dataportal_show_media'] = array(
947
    '#type' => 'select',
948
    '#title' => t('Available picture files') . ':',
949
    '#default_value' => variable_get('cdm_dataportal_show_media', FALSE),
950
    '#options' => $selectShowMedia,
951
    '#description' => t("Show the profile pictures current taxon's children."),
952
  );
953

    
954
  // -- MEDIA THUMBNAILS -- //
955
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
956
  $form_title = 'Taxon Profile Images';
957
  $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>';
958
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
959

    
960
  // ---- FEATURE TREE ---- //
961
  $form['taxon_profile']['taxon_profile'] = array(
962
    '#type' => 'fieldset',
963
    '#title' => t('Features'),
964
    '#collapsible' => TRUE,
965
    '#collapsed' => FALSE,
966
    '#description' => t("This section covers settings related to the taxon's
967
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
968
      features such as description, distribution, common names, etc. that Drupal
969
      will render at the taxon profile page."),
970
  );
971
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
972
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
973
    '#type' => 'radios',
974
    '#title' => t('Taxon profile sections') . ':',
975
    '#default_value' => variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE),
976
    '#options' =>  $featureTrees['options'],
977
    // Comment @WA: because #options are sanitized in D7, it would
978
    // strip html like <fieldset>, so we put the fieldset in a suffix.
979
    '#field_suffix' => $featureTrees['treeRepresentations'],
980
    '#description' => t('Select the Feature Tree to be displayed at the taxon
981
      profile. Click "Show Details" to see the Feature Tree elements.'
982
    ),
983
  );
984
  $featureTrees = cdm_get_featureTrees_as_options();
985
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
986
    '#type' => 'radios',
987
    '#title' => t('Natural language representation of structured descriptions') . ':',
988
    '#default_value' => variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, NULL),
989
    '#options' => $featureTrees['options'],
990
      // Comment @WA: because #options are sanitized in D7, it would
991
      // strip html like <fieldset>, so we put the fieldset in a suffix.
992
    '#field_suffix' => $featureTrees['treeRepresentations'],
993
    '#description' => t('Taxon descriptions can be stored in a highly structured
994
      form. The feature tree selected here will be used to generate textual
995
      representation in natural language.'
996
      // If there is no applicable FeatureTree you can create a new one using the <a href="">FeatureTreeManager</a>'
997
    ),
998
  );
999

    
1000
  // ---- LAYOUT PER FEATURE ---- //
1001
  $feature_tree = get_profile_featureTree();
1002
  if (isset($feature_tree->root->children)) {
1003

    
1004
    $form_feature_list_layout = array(
1005
      '#title' => t('Taxon profile layout'),
1006
      '#collapsible' => TRUE,
1007
      '#collapsed' => FALSE,
1008
      '#type' => 'fieldset',
1009
      '#description' => t('Will be available in a future release.'),
1010
    );
1011

    
1012
    $feature_list_layout_settings_disabled = TRUE;
1013
    foreach ($feature_tree->root->children as $featureNode) {
1014

    
1015
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1016
        // Must not exceed 45 characters !!!
1017
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1018

    
1019
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1020
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1021

    
1022
        $form_feature_list_layout[$subform_id] = array(
1023
          '#tree' => TRUE,
1024
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1025
          '#collapsible' => FALSE,
1026
          '#collapsed' => FALSE,
1027
          '#type' => 'fieldset',
1028
          '#description' => t(''),
1029
        );
1030

    
1031
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1032
          '#type' => 'checkbox',
1033
          '#title' => t('Enable'),
1034
          '#default_value' => $settings['enabled'],
1035
          '#description' => t('Enable user defined layout for this feature'),
1036
        );
1037

    
1038
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1039
          '#type' => 'textfield',
1040
          '#title' => t('Enclosing tag'),
1041
          '#disabled' => !$settings['enabled'],
1042
          '#default_value' => $settings['enclosingTag'],
1043
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1044
        );
1045

    
1046
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1047
          '#type' => 'textfield',
1048
          '#title' => t('Entry enclosing tag'),
1049
          '#disabled' => !$settings['enabled'],
1050
          '#default_value' => $settings['entryEnclosingTag'],
1051
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1052
        );
1053

    
1054
        $form_feature_list_layout[$subform_id]['glue'] = array(
1055
          '#type' => 'textfield',
1056
          '#title' => t('Glue'),
1057
          '#disabled' => !$settings['enabled'],
1058
          '#default_value' => $settings['glue'],
1059
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1060
        );
1061

    
1062
      }
1063

    
1064
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1065
    }
1066
  }
1067

    
1068
  // ---- DISTRIBUTION LAYOUT ---- //
1069
  $form['taxon_profile']['distribution_layout'] = array(
1070
    '#title' => t('Distribution'),
1071
    '#collapsible' => TRUE,
1072
    '#collapsed' => FALSE,
1073
    '#type' => 'fieldset',
1074
    '#description' => t('Select if you want to sort or not the distribution text
1075
      located below the distribution map.'),
1076
  );
1077

    
1078
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1079
    '#type' => 'radios',
1080
    '#title' => t('Sort') . ':',
1081
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1082
    '#options' => array(
1083
      'NO_SORT' => t('Standard (No sort)'),
1084
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1085
    ),
1086
  );
1087

    
1088
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1089
    '#type' => 'checkbox',
1090
    '#title' => t('Show TextData elements on top of the map'),
1091
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1092
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1093
      elements on top of the map. Otherwise all <code>TextData</code>
1094
      distribution elements will be listed below the other area elements.
1095
      This option is useful if you need to have descriptive texts for each
1096
      distribution map.'),
1097
  );
1098

    
1099

    
1100
  /* ====== SYNONYMY ====== */
1101
  $form['taxon_synonymy'] = array(
1102
    '#type' => 'fieldset',
1103
    '#title' => t('Taxon synonymy (tab)'),
1104
    '#collapsible' => TRUE,
1105
    '#collapsed' => TRUE,
1106
    '#description' => t('This section covers the settings related to the taxon
1107
      <strong>synonymy</strong> tab.####'),
1108
  );
1109

    
1110
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1111
    '#type' => 'checkbox',
1112
    '#title' => t('Show accepted taxon on top of the synonymy'),
1113
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1114
    '#description' => t('If checked, the first homotypic taxon is a repetition
1115
      of the accepted taxon most likely with the full nomenclatural reference
1116
      (depending on the currently chosen theme).'),
1117
  );
1118

    
1119
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1120
    '#type' => 'checkbox',
1121
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1122
      coming from a synonym link.'),
1123
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1124
    '#description' => t('Check this if after doing a search and clicking on a
1125
      synonym you want to see the "accept of" text for the accepted synonym.'),
1126
  );
1127

    
1128
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1129
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1130
    '#type' => 'checkboxes',
1131
    '#title' => t('Display name relationships') . ':',
1132
    '#default_value' => variable_get('name_relationships_to_show', 0),
1133
    '#options' => $nameRelationshipTypeOptions,
1134
    '#description' => t('Select the name relationships you want to show for the
1135
      accepted taxa.'),
1136
  );
1137

    
1138
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1139
    '#type' => 'checkbox',
1140
    '#title' => t('Show taxon relations ships of accepted taxon'),
1141
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1142
    '#description' => t('If this option is enabled the synonymy will show the
1143
      below selected taxon relationships of accepted taxa.'),
1144
  );
1145

    
1146
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1147
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1148
    '#type' => 'checkboxes',
1149
    '#title' => t('Taxon relationship types') . ':',
1150
    '#description' => t('Only taxon relationships of the selected type will be
1151
      displayed'),
1152
    '#options' => $taxonRelationshipTypeOptions,
1153
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1154
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1155
  );
1156

    
1157
  // ====== SPECIMENS ====== //
1158
  $form['taxon_specimens'] = array(
1159
    '#type' => 'fieldset',
1160
    '#title' => t('Taxon specimens (tab)'),
1161
    '#collapsible' => TRUE,
1162
    '#collapsed' => TRUE,
1163
    '#description' => t('This section covers the settings related to the taxon
1164
      <strong>specimens</strong> tab.'),
1165
  );
1166

    
1167
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1168
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1169
      '#type' => 'radios',
1170
      '#title' => t('Specimen description feature tree') . ':',
1171
      '#default_value' => variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE),
1172
      '#options' =>  $featureTrees['options'],
1173
      // Comment @WA: because #options are sanitized in D7, it would
1174
      // strip html like <fieldset>, so we put the fieldset in a suffix.
1175
      '#field_suffix' => $featureTrees['treeRepresentations'],
1176
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1177
      ),
1178
  );
1179

    
1180
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1181
  $form_title = t('Specimen media');
1182
  $form_description = t('Specimens may have media which is displayed at the
1183
     Specimen tab/section as a gallery. It is possible to configure the
1184
     thumbnails gallery here, however for configuring how a single media should
1185
     be displayed please go to !url.</p>',
1186
     array(
1187
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1188
     ));
1189
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1190

    
1191
  // --- MEDIA GALLERY ---- //
1192
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1193
  $form_title = 'Media gallery (tab)';
1194
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1195
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1196
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1197
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1198
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1199
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1200
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1201

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

    
1211
/**
1212
 * @todo document this function.
1213
 */
1214
function cdm_settings_layout_search() {
1215

    
1216
  $form = array();
1217

    
1218
  $form['search_settings'] = array(
1219
    '#type' => 'fieldset',
1220
    '#title' => t('Taxa Search'),
1221
    '#collapsible' => TRUE,
1222
    '#collapsed' => TRUE,
1223
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1224
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1225
         where they can write the text to be searched. You can find Drupal block configuration
1226
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1227
  );
1228

    
1229
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1230
    '#type' => 'textfield',
1231
    '#title' => t('Results per page') . ':',
1232
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1233
    '#description' => t('Number of results to display per page.'),
1234
  );
1235

    
1236
  $form['search_settings']['cdm_search_taxa'] = array(
1237
    '#type' => 'checkbox',
1238
    '#title' => t('Sets the default value of <em>Search for accepted taxa</em> in the advanced search form.'),
1239
    '#default_value' => variable_get('cdm_search_taxa', 1),
1240
    '#description' => t('<p>If checked the <em>Search for accepted taxa </em> option will be enabled in the advanced form.</p>'),
1241
  );
1242

    
1243
  $form['search_settings']['cdm_search_synonyms'] = array(
1244
    '#type' => 'checkbox',
1245
    '#title' => t('Sets the default value of <em>Search for synonyms</em> in the advanced search form.'),
1246
    '#default_value' => variable_get('cdm_search_synonyms', 1),
1247
    '#description' => t('<p>If checked the <em>Search for synonyms</em> option will be enabled in the advanced form.</p>'),
1248
  );
1249

    
1250
  $form['search_settings']['cdm_search_common_names'] = array(
1251
    '#type' => 'checkbox',
1252
    '#title' => t('Sets the default value of <em>Search for common names</em> in the advanced search form.'),
1253
    '#default_value' => variable_get('cdm_search_common_names', 0),
1254
    '#description' => t('<p>If checked the <em>Search for common names</em> option will be enabled in the advanced form.</p>'),
1255
  );
1256

    
1257
  $form['search_settings']['cdm_search_use_default_values'] = array(
1258
    '#type' => 'checkbox',
1259
    '#title' => t('Sets use of default values in the advanced search form.'),
1260
    '#default_value' => variable_get('cdm_search_use_default_values', 1),
1261
    '#description' => t('<p>If checked the defqult values set abovewill be used for the search.</p>'),
1262
  );
1263

    
1264

    
1265
  // --- SEARCH TAXA GALLERY ---- //
1266
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1267
  $collapsed = FALSE;
1268
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1269
  $form_title = 'Taxa Search thumbnails';
1270
  $form_description = 'Search results may show thumbnails. ';
1271
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1272

    
1273
  // Comment @WA: D7 form api does not support reset buttons,
1274
  // so to mimic the D5 reset button we add one like this.
1275
  $form['actions']['reset'] = array(
1276
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1277
    '#weight' => 1000,
1278
  );
1279
  return system_settings_form($form);
1280
}
1281

    
1282
/**
1283
 * @todo document this function.
1284
 */
1285
function cdm_settings_layout_media() {
1286

    
1287
  $form = array();
1288

    
1289
  $form['media_settings'] = array(
1290
    '#type' => 'fieldset',
1291
    '#title' => t('Media display settings'),
1292
    '#collapsible' => TRUE,
1293
    '#collapsed' => FALSE,
1294
    '#description' => t('This section covers the settings related to the taxa media, that is how each single media should be displayed.'),
1295
  );
1296

    
1297
  $form['media_settings']['image_gallery_viewer'] = array(
1298
    '#type' => 'select',
1299
    '#title' => t('Image viewer') . ':',
1300
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1301
    '#options' => array(
1302
      'default' => t('Standard image viewer'),
1303
      'fsi' => t('FSI viewer (requires FSI server!)'),
1304
    ),
1305
  );
1306

    
1307
  // --- MEDIA GALLERY ---- //
1308
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1309
  $form_title = 'Standard viewer';
1310
  $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>';
1311
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1312
  // Comment @WA: $collapsed is not defined.
1313
  // $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1314
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1315

    
1316
  // @WA: D7 form api does not support reset buttons,
1317
  // so to mimic the D5 reset button we add one like this.
1318
  $form['actions']['reset'] = array(
1319
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1320
    '#weight' => 1000,
1321
  );
1322
  return system_settings_form($form);
1323
}
1324

    
1325
/**
1326
 * GEOSERVICE and Map settings.
1327
 */
1328
function cdm_settings_geo($form, &$form_state) {
1329

    
1330
  $form = array();
1331

    
1332
  /*
1333
  GEO SERVER
1334
  */
1335
  $form['edit_map_server'] = array(
1336
    '#type' => 'fieldset',
1337
    '#tree' => true,
1338
    '#title' => t('EDIT map service'),
1339
    '#collapsible' => TRUE,
1340
    '#collapsed' => TRUE,
1341
    '#description' => t('Configuration and selection of your geo server.
1342
      The Geo Server is responsible for generating the maps.'),
1343
  );
1344

    
1345
  $current_geoserver_settings = get_edit_map_service_settings();
1346

    
1347
  $form['edit_map_server']['base_uri'] = array(
1348
    '#type' => 'select',
1349
    '#title' => t('EDIT map service') . ':',
1350
    '#default_value' => $current_geoserver_settings['base_uri'],
1351
    '#options' => unserialize(EDIT_MAPSERVER_URI),
1352
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
1353
  );
1354
  $form['edit_map_server']['version'] = array(
1355
      '#type' => 'select',
1356
      '#title' => t('Version') . ':',
1357
      '#default_value' => $current_geoserver_settings['version'],
1358
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
1359
      '#description' => t('The version of the EDIT map services'),
1360
  );
1361

    
1362
  /*
1363
  MAP SETTINGS
1364
  */
1365
  $form['map_settings'] = array(
1366
    '#type' => 'fieldset',
1367
    '#title' => t('Maps settings'),
1368
    '#collapsible' => TRUE,
1369
    '#collapsed' => TRUE,
1370
    '#description' => t('General configuration for all map types.'),
1371
  );
1372

    
1373
  $form['map_settings']['cdm_dataportal_geoservice_display_width'] = array(
1374
    '#type' => 'textfield',
1375
    '#title' => t('Maps width') . ':',
1376
    '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
1377
    '#description' => t('Choose the width of your maps, the height will always
1378
      be the half of the width. A value of 500 means the size will be 500 pixels
1379
      width and 250 pixels height.'),
1380
  );
1381

    
1382
  $form['map_settings']['cdm_dataportal_geoservice_bounding_box'] = array(
1383
    '#type' => 'textfield',
1384
    '#title' => t('Fixed bounding box') . ':',
1385
    '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
1386
    '#description' => t('Define surrounding of area to be displayed in maps.
1387
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
1388
      to let the map <strong>automatically zoom</strong> to the distribution
1389
      area.'),
1390
  );
1391

    
1392
  $form['map_settings']['cdm_dataportal_geoservice_labels_on'] = array(
1393
    '#type' => 'checkbox',
1394
    '#title' => '<b>' . t('Display area labels') . '</b>',
1395
    '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
1396
    '#description' => t('Check this if you like area names to be displayed in the maps. DOES IT WORK???? '),
1397
  );
1398

    
1399
  $form['map_settings']['cdm_dataportal_geoservice_map_caption'] = array(
1400
    '#type' => 'textfield',
1401
    '#title' => t('Map caption') . ':',
1402
    '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
1403
    '#description' => t('Define a caption for the map.'),
1404
  );
1405

    
1406
  $form['map_settings']['cdm_dataportal_geoservice_distributionOpacity'] = array(
1407
    '#type' => 'textfield',
1408
    '#title' => t('Distribution layer opacity') . ':',
1409
    '#default_value' => variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5'),
1410
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1411
                           fully visible, while a value near to 0.0 will be not much visible.'),
1412
  );
1413

    
1414
  $form['map_settings']['cdm_dataportal_map_openlayers'] = array(
1415
    '#type' => 'radios',
1416
    '#title' => t('Map Viewer') . ':',
1417
    '#options' => array(
1418
      1 => "OpenLayers dynamic mapviewer",
1419
      0 => "Plain image",
1420
    ),
1421
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1422
    '#description' => t('You can choose from two different map viewers:
1423
      <ul><li><em>OpenLayers</em> displays the maps in an interactive viewer
1424
      which allows zooming and panning. If not enabled the maps will consist
1425
      on a static image. If enabled you can configure the default layer
1426
      (background of your maps) below. Only one of them will be rendered.</li>
1427
      <li><em>Plain image</em> displays the map as a plain non interactive
1428
      image.</li></ul>'),
1429
  );
1430

    
1431
  $openLayersEnabled = variable_get('cdm_dataportal_map_openlayers', 1) == 1;
1432

    
1433

    
1434
  // --- Plain Image Settings --- //
1435
  $form['map_image'] = array(
1436
    '#type' => 'fieldset',
1437
    '#title' => t('Plain image map settings'),
1438
    '#collapsible' => TRUE,
1439
    '#collapsed' => $openLayersEnabled,
1440
    '#description' => t('The settings in this section are still expertimental
1441
      and can only be used with the EDIT map service version 1.1 or above.'),
1442
  );
1443

    
1444
  $edit_mapserver_version = get_edit_map_service_version_number();
1445
  if ($edit_mapserver_version < 1.1) {
1446
    $form['map_image']['#description'] = '<div class="messages warning">' . t("The selected EDIT map service version has to small version number: $edit_mapserver_version") . '</div>'
1447
      . $form['map_image']['#description'];
1448
  }
1449

    
1450
  $form['map_image']['map_base_layer'] = array(
1451
    '#type' => 'textfield',
1452
    '#title' => t('Background layer') . ':',
1453
    '#default_value' => variable_get('map_base_layer', 'cyprusdivs'),
1454
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
1455
      '!url1' => l(t('deegree-csw'), 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
1456
      '!url2' => l(t('geoserver layers'), 'http://edit.africamuseum.be/geoserver/web/'), // http://edit.africamuseum.be/geoserver/rest/layers
1457
    )),
1458
  );
1459

    
1460
  $form['map_image']['map_bg_color'] = array(
1461
    '#type' => 'textfield',
1462
    '#title' => t('Background color') . ':',
1463
    '#default_value' => variable_get('map_bg_color', '1874CD'),
1464
  );
1465

    
1466
  $form['map_image']['map_base_layer_style'] = array(
1467
    '#type' => 'textfield',
1468
    '#title' => t('Background layer area style') . ':',
1469
     // Only line color by now.
1470
    '#default_value' => variable_get('map_base_layer_style', 'ffffff,606060,,'),
1471
    '#description' => t('Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}'),
1472
  );
1473

    
1474

    
1475
  // --- OpenLayers Settings --- //
1476
  $form['openlayers'] = array(
1477
    '#type' => 'fieldset',
1478
    '#title' => t('OpenLayers settings'),
1479
    '#collapsible' => TRUE,
1480
    '#collapsed' => !$openLayersEnabled,
1481
    '#description' => '',
1482
  );
1483

    
1484
  if (!$openLayersEnabled) {
1485
    $form['openlayers']['#description'] = '<div class="messages warning">' . t('The Openlayers viewer is currently not enabled! (see section Maps settings above )') . '</div>'
1486
      . $form['openlayers']['#description'];
1487
  }
1488

    
1489
  $baselayer_options = array(
1490
    /*
1491
   NOTICE: must correspond to the layers defined in
1492
   js/openlayers_,ap.js#getLayersByName()
1493
   */
1494
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
1495
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
1496
    // all others EPSG:900913
1497
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
1498
    'edit-etopo1' => "ETOPO1 Global Relief Model",
1499
    'mapnik' => 'OpenStreetMap',
1500
    'osmarender' => 'OpenStreetMap (Tiles@home)',
1501
    'gmap' => 'Google Streets',
1502
    'gsat' => 'Google Satellite',
1503
    'ghyb' => 'Google Hybrid',
1504
    'veroad' => 'Virtual Earth Roads',
1505
    'veaer' => 'Virtual Earth Aerial',
1506
    'vehyb' => 'Virtual Earth Hybrid',
1507
    // 'yahoo' => 'Yahoo Street',
1508
    // 'yahoosat' => 'Yahoo Satellite',
1509
    // 'yahoohyb' => 'Yahoo Hybrid',
1510
  );
1511

    
1512
  $form['openlayers']['baselayers'] = array(
1513
    '#type' => 'checkboxes_preferred',
1514
    '#title' => t('Base Layers') . ':',
1515
    '#options' => $baselayer_options,
1516
    '#default_value' => variable_get('baselayers', array('metacarta_vmap0' => "metacarta_vmap0", 'PREFERRED' => 'metacarta_vmap0')),
1517
    '#description' => t('Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.'),
1518
  );
1519

    
1520
  // cdm_dataportal_geoservice_showLayerSwitcher
1521
  $form['openlayers']['cdm_dataportal_geoservice_showLayerSwitcher'] = array(
1522
    '#type' => 'checkbox',
1523
    '#title' => '<b>' . t('Show Layer Switcher') . '</b>',
1524
    '#default_value' => variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE),
1525
    '#description' => t('
1526
      The Layer Switcher control displays a table of contents
1527
      for the map.  This allows the user interface to switch between
1528
      BaseLayers and to show or hide Overlays.  By default the switcher is
1529
      shown minimized on the right edge of the map, the user may expand it
1530
      by clicking on the handle.'
1531
    ),
1532
  );
1533

    
1534
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1535
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1536
  $form['openlayers']['gmap_api_key'] = array(
1537
    '#type' => 'textfield',
1538
    '#title' => t('Google maps API key') . ':',
1539
    '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1540
    '#description' => t('If you want to use the Google Maps Layer, a key is
1541
      needed. If you need a key, visit
1542
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
1543
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
1544
      is the default key for the localhost (127.0.0.1). The key in use is the
1545
      one above this text.', array('!localhostkey' => $localhostkey)),
1546
  );
1547

    
1548
  $form['cdm_dataportal_geoservice_map_legend'] = array(
1549
    '#type' => 'fieldset',
1550
    '#title' => t('Map legend'),
1551
    '#collapsible' => TRUE,
1552
    '#collapsed' => TRUE,
1553
    '#description' => t('Configure the maps legend.'),
1554
  );
1555

    
1556
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
1557
    '#type' => 'checkbox',
1558
    '#title' => '<b>' . t('Display a map legend') . '</b>',
1559
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
1560
    '#description' => t('Check this if you like a legend to be displayed with the maps.'),
1561
  );
1562

    
1563
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legendOpacity'] = array(
1564
    '#type' => 'textfield',
1565
    '#title' => t('Legend opacity'),
1566
    '#default_value' => variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'),
1567
    '#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
1568
                         to 0.0 will be not much visible.'),
1569
  );
1570

    
1571
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
1572
    '#type' => 'textfield',
1573
    '#title' => t('Font size'),
1574
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
1575
    '#description' => t('Font size in pixels.'),
1576
  );
1577

    
1578
  $fontStyles = array(
1579
    0 => "plane",
1580
    1 => "italic",
1581
  );
1582
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
1583
    '#type' => 'select',
1584
    '#title' => t('Available font styles'),
1585
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', FALSE),
1586
    '#options' => $fontStyles,
1587
    '#description' => t('Select a font style for the map legend.'),
1588
  );
1589

    
1590
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
1591
    '#type' => 'textfield',
1592
    '#title' => t('Legend icon width'),
1593
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
1594
    '#description' => t('Legend icon width in pixels.'),
1595
  );
1596
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
1597
    '#type' => 'textfield',
1598
    '#title' => t('Legend icon height'),
1599
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
1600
    '#description' => t('Legend icon height in pixels.'),
1601
  );
1602

    
1603
  // @WA: D7 form api does not support reset buttons,
1604
  // so to mimic the D5 reset button we add one like this.
1605
  $form['actions']['reset'] = array(
1606
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1607
    '#weight' => 1000,
1608
  );
1609

    
1610
  return system_settings_form($form);
1611
}
1612

    
1613
/**
1614
 * @todo document this function.
1615
 */
1616
function cdm_settings_cache() {
1617

    
1618
  $form = array();
1619

    
1620
  $form['cache_settings'] = array(
1621
    '#type' => 'fieldset',
1622
    '#title' => t('Cache Settings'),
1623
    '#collapsible' => FALSE,
1624
    '#collapsed' => FALSE,
1625
    '#description' => t('<p>When caching is enabled all single taxon sites are
1626
      stored in an internal drupal cache doing the portal response of taxa pages
1627
      faster. This is possible because the sites are loaded from the cache and
1628
      are not created from scratch.</p>'),
1629
  );
1630

    
1631
  $form['cache_settings']['cdm_webservice_cache'] = array(
1632
    '#type' => 'checkbox',
1633
    '#title' => t('<strong>Enable caching</strong>'),
1634
    '#options' => cdm_help_general_cache(),
1635
    '#default_value' => variable_get('cdm_webservice_cache', 1),
1636
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
1637
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
1638
       application the changes will be not visible till the cache is erased.
1639
       Therefore developers should deactived this feature when they are working
1640
       on the CDM Dataportal Module.</p>'),
1641
  );
1642

    
1643
  $form['cache_settings']['cdm_run_cache'] = array(
1644
    '#markup' => cdm_view_cache_site(),
1645
  );
1646

    
1647
  // @WA: D7 form api does not support reset buttons,
1648
  // so to mimic the D5 reset button we add one like this.
1649
  $form['actions']['reset'] = array(
1650
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1651
    '#weight' => 1000,
1652
  );
1653
  return system_settings_form($form);
1654
}
1655

    
1656
/**
1657
 * Walk and cache all taxon pages.
1658
 */
1659
function cdm_view_cache_site() {
1660

    
1661
  $out = '';
1662

    
1663
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
1664

    
1665
  $request_params = array();
1666
  $request_params['query'] = '%';
1667
  // Cache only the dafault classification.
1668
  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', FALSE);
1669
  $request_params['doTaxa'] = 1;
1670
  $request_params['doSynonyms'] = 0;
1671
  $request_params['doTaxaByCommonNames'] = 0;
1672

    
1673
  $search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND . ".json", NULL, queryString($request_params));
1674

    
1675
  $search_url = uri_uriByProxy($search_url);
1676
  $search_url = rtrim($search_url, '/');
1677
  $taxon_page_url = url('cdm_dataportal/taxon/');
1678

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

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

    
1688
  // Comment @WA: A form within a form is not valid html and not needed here.
1689
  // Also, it would be recommended just to include this part of the form in the
1690
  // rest of the form array in cdm_settings_cache().
1691
  // $out .= '<form id="cache_site">';
1692
  $out .= '<input type="hidden" name="searchTaxaUrl" value="' . $search_url . '"/>';
1693
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . $taxon_page_url . '"/>';
1694
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
1695
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
1696
  // $out .= '</form>';
1697
  $out .= '</div>';
1698
  /*
1699
  foreach($taxonPager->records as $taxon){
1700
    cdm_dataportal_taxon_view($uuid);
1701
  }
1702
  */
1703
  return $out;
1704
}
1705

    
1706
/**
1707
 * Form validation handler for ?
1708
 *
1709
 * Comment @WA: currently this handler is not used.
1710
 * It seems partly for cdm_settings_general en partly for cdm_settings_cache?
1711
 * Then you can change the name into cdm_settings_general_validate() or
1712
 * cdm_settings_cache_validate().
1713
 * But cdm_api_secref_cache_clear is not doing anything (yet)?
1714
 */
1715
function cdm_settings_validate($form, &$form_state) {
1716

    
1717
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
1718
    // form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
1719
    $form_state['values']['cdm_webservice_url'] .= '/';
1720
  }
1721

    
1722
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
1723
    cache_clear_all(NULL, 'cache_cdm_ws');
1724
    // Better clear secref_cache since I can not be sure if the cache has not
1725
    // be used during this response.
1726
    cdm_api_secref_cache_clear();
1727
  }
1728
}
1729

    
1730
/**
1731
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
1732
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
1733
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
1734
 *  - version: the version, e.g.: v1.1
1735
 *
1736
 * @return array
1737
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
1738
 */
1739
function get_edit_map_service_settings() {
1740

    
1741
  $settings = variable_get('edit_map_server', array(
1742
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
1743
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
1744
      )
1745
  );
1746
  // replace old non tree like settings by default
1747
  // TODO to be removed after release 3.1.5
1748
  if(!is_array($settings)){
1749
    variable_del('edit_map_server');
1750
    return get_edit_map_service_settings();
1751
  }
1752

    
1753
  return $settings;
1754
}
1755

    
1756
/**
1757
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
1758
 *
1759
 * @return string
1760
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
1761
 */
1762
function get_edit_map_service_full_uri() {
1763
  $settings = get_edit_map_service_settings();
1764
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
1765
}
1766

    
1767

    
1768
/**
1769
 * Returns the version number of the currently selected edit mapserver as a float
1770
 *
1771
 * @return float
1772
 *   The version number of the currently selected edit mapserver as a float.
1773
 *   Returns 0 on error.
1774
 */
1775
function get_edit_map_service_version_number() {
1776

    
1777
  $pattern = '/v([\d\.]+).*$/';
1778

    
1779
  $settings = get_edit_map_service_settings();
1780
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
1781
  if (isset($matches[1])) {
1782
    // Convert string to float.
1783
    $version = 1 + $matches[1][0] - 1;
1784
    return $version;
1785
  }
1786
  else {
1787
    // Report error.
1788
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
1789
        array(
1790
          '!version' => $settings['version'],
1791
          'warning')
1792
        )
1793
      );
1794
    return 0;
1795
  }
1796
}
1797

    
1798
/**
1799
 * Returns the array of selected items in a options array
1800
 *
1801
 * @param array $options
1802
 *   An options array as generated by a form element like checkoxes, select ...,
1803
 */
1804
function get_selection($options) {
1805
  $selection = array();
1806
  foreach ($options as $key=>$val) {
1807
    if (!empty($val)) {
1808
      $selection[] = $val;
1809
    }
1810
  }
1811
  return $selection;
1812
}
1813

    
1814

    
1815
/**
1816
 * Implements hook_element_info().
1817
 *
1818
 * Allows modules to declare their own Form API element types and specify their default values.
1819
 *
1820
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
1821
 */
1822
function cdm_dataportal_element_info() {
1823
  $type['checkboxes_preferred'] = array(
1824
    '#input' => TRUE,
1825
    '#process' => array('checkboxes_preferred_expand'),
1826
    '#after_build' => array('checkboxes_preferred_after_build'),
1827
    '#theme' => array('checkboxes_preferred'),
1828
    // '#theme_wrapper' => array('form_element'),
1829
  );
1830
  return $type;
1831
}
1832

    
1833
/**
1834
 * #process callback function for the custom form element type 'checkbox_preferred'
1835
 *
1836
 *
1837
 */
1838
function checkboxes_preferred_expand($element, &$form_state, $form) {
1839

    
1840
  // First of all create checkboxes for each of the elements
1841
  $element = form_process_checkboxes($element);
1842

    
1843
  $children = element_children($element);
1844

    
1845
  $element['table_start'] = array(
1846
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
1847
    '#weight' => -1,
1848
  );
1849

    
1850
  // prepare first part each of the table rows which contains the row label
1851
  $weight = 0;
1852
  foreach ($children as $key) {
1853
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
1854
    $element[$key]['#weight'] = $weight;
1855
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
1856
    $element[$key]['#suffix'] = '</td>';
1857
    unset($element[$key]['#title']);
1858
    $weight += 2;
1859
  }
1860
  $weight = 0;
1861

    
1862
  // add a radio button to each of the checkboxes, the
1863
  // check boxes have already been created at the beginning
1864
  // of this function
1865
  if (count($element['#options']) > 0) {
1866
    foreach ($element['#options'] as $key => $choice) {
1867
      if (!isset($element[$key . '_preferred'])) {
1868
        $element[$key . '_preferred'] = array(
1869
          '#type' => 'radio',
1870
          '#name' => $element['#parents'][0] . '_preferred',
1871
          '#return_value' => check_plain($key),
1872
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
1873
          '#attributes' => $element['#attributes'],
1874
          '#parents' => $element['#parents'],
1875
          // '#spawned' => TRUE,
1876
          '#weight' => $weight + 1,
1877
          '#prefix' => '<td>',        // add a prefix to start a new table cell
1878
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
1879
        );
1880
      }
1881
      $weight += 2;
1882
    }
1883
  }
1884

    
1885
  // end the table
1886
  $element['table_end'] = array(
1887
    '#markup' => '</table>',
1888
    '#weight' => $weight++,
1889
  );
1890

    
1891
  return $element;
1892
}
1893

    
1894
/**
1895
 * Theme function for the custom form field 'checkboxes_preferred'.
1896
 */
1897
function theme_checkboxes_preferred($variables) {
1898
  $element = $variables['element'];
1899
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
1900
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
1901
  $out .= drupal_render_children($element);
1902
  $out .= '<div class="description">' . $element['#description'] . '</div>';
1903
  $out .= '</div>';
1904
  return $out;
1905
}
1906

    
1907
/**
1908
 * Callback for checkboxes preferred for widget which will
1909
 * be called after the form or element is built. The call
1910
 * back is configured in the form element by setting it as
1911
 * #after_build parameter.
1912
 *
1913
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
1914
 *
1915
 * @param $form
1916
 *   Nested array of form elements that comprise the form.
1917
 * @param $form_state
1918
 *   A keyed array containing the current state of the form.
1919
 *
1920
 * @return the modified form array
1921
 */
1922
function checkboxes_preferred_after_build($form, &$form_state) {
1923

    
1924
  $parent_id = $form['#parents'][0];
1925

    
1926
  if ($_POST && count($_POST) > 0) {
1927
    // First pass of form processing.
1928
    $preferred_layer = $_POST[$parent_id . '_preferred'];
1929
    $form['#value']['PREFERRED'] = $preferred_layer;
1930
    $form_state[$parent_id] = $form['#value'];
1931
    $form_state['values']['baselayers'] = $form['#value'];
1932
  }
1933
  else {
1934
    // Second pass of form processing.
1935
    $preferred_layer = $form['#value']['PREFERRED'];
1936
  }
1937

    
1938
  // Also set the chosen value (not sure if this is good Drupal style ....).
1939
  foreach ($children = element_children($form) as $key) {
1940
    if (!empty($form[$key]['#type']) && $form[$key]['#type'] == 'radio') {
1941
      $form[$key]['#value'] = $preferred_layer;
1942
    }
1943
  }
1944
  // The default layer must always be enabled.
1945
  $form[$preferred_layer]['#value'] = $preferred_layer;
1946

    
1947
  return $form;
1948
}
(13-13/13)