Project

General

Profile

Download (99.4 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

    
35

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

    
67
// --- Taxon profile settings --- /
68
define('LAYOUT_SETTING_PREFIX', 'layout_');
69
define('FEATURE_TREE_LAYOUT_DEFAULTS', serialize(
70
  array(
71
    'enabled' => FALSE,
72
    'enclosingTag' => 'ul',
73
    'entryEnclosingTag' => 'li',
74
    'glue' => ' ',
75
  )));
76

    
77
define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
78
define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
79
define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
80
    array(
81
        'show' => 0,
82
        'maxextend' => 184,
83
        'media_uri_query' => '',
84
        'custom_placeholder_image_on' => 0,
85
        'custom_placeholder_image_fid' => ''
86
    )
87
  )
88
);
89

    
90
/**
91
 * @todo document this function
92
 */
93
function get_taxon_tabs_list() {
94
  return array(
95
    0 => 'General',
96
    1 => 'Synonymy',
97
    2 => 'Images',
98
    3 => 'Specimens',
99
    4 => 'Keys',
100
  );
101
}
102

    
103
$taxon_tab_options = get_taxon_tabs_list();
104
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
105

    
106
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
107

    
108
/**
109
 * @todo document this function.
110
 */
111
function get_taxon_options_list() {
112
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
113
  foreach ($taxon_tab_options as $key => $value) {
114
    $taxon_tab_options[$key] = t($key);
115
  }
116
  return $taxon_tab_options;
117

    
118
}
119

    
120
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
121
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
122
  array(
123
      'ZoologicalName' => array(
124
        'namePart' => array('name' => TRUE),
125
        'nameAuthorPart' => array('name' => TRUE),
126
        'referencePart' => array('authors' => TRUE),
127
        'microreferencePart' => array('microreference' => TRUE),
128
        'statusPart' => array('status' => TRUE),
129
        'descriptionPart' => array('description' => TRUE),
130
      ),
131
      'BotanicalName'=> array(
132
        'namePart' => array('name' => TRUE),
133
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
134
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
135
        'statusPart' => array('status' => TRUE),
136
        'descriptionPart' => array('description' => TRUE),
137
      ),
138
     '#DEFAULT' => array(
139
        'namePart' => array(
140
            'name' => TRUE
141
        ),
142
        'nameAuthorPart' => array(
143
            'name' => TRUE,
144
            'authors' => TRUE
145
        ),
146
        'referencePart' => array(
147
            'reference' => TRUE
148
        ),
149
        'microreferencePart' => array(
150
            'microreference' => TRUE,
151
        ),
152
        'statusPart' => array(
153
            'status' => TRUE,
154
        ),
155
        'descriptionPart' => array(
156
            'description' => TRUE,
157
        ),
158
      )
159
    )
160
  )
161
);
162
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
163
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
164
   array (
165
     'taxon_page_title,polytomousKey'=> array(
166
          'namePart' => array('#uri' => TRUE),
167
        ),
168
      'taxon_page_synonymy,related_taxon'=> array(
169
          'nameAuthorPart' => array('#uri' => TRUE),
170
          'referencePart' => TRUE,
171
          'statusPart' => TRUE,
172
          'descriptionPart' => TRUE,
173
        ),
174
      'acceptedFor,typedesignations,list_of_taxa' => array(
175
          'nameAuthorPart' => array('#uri' => TRUE),
176
          'referencePart' => TRUE,
177
        ),
178
      '#DEFAULT' => array(
179
          'nameAuthorPart' => array('#uri' => TRUE),
180
          'referencePart' => TRUE,
181
       )
182
    )
183
));
184

    
185
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
186
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
187
    // to unset a default enntry set the value to 0
188
    array(
189
      'doTaxa'=>'doTaxa',
190
      'doSynonyms' => 'doSynonyms',
191
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
192
      'doMisappliedNames' => 'doMisappliedNames'
193
    )
194
  )
195
);
196

    
197
/* Gallery variables. */
198
$gallery_settings = array(
199
    "cdm_dataportal_show_taxon_thumbnails" => 1,
200
    "cdm_dataportal_show_synonym_thumbnails" => 0,
201
    "cdm_dataportal_show_thumbnail_captions" => 1,
202
    "cdm_dataportal_media_maxextend" => 120,
203
    "cdm_dataportal_media_cols" => 3,
204
    "cdm_dataportal_media_maxRows" => 1,
205
);
206

    
207
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
208
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
209
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
210
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
211
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
212
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
213
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
214
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
215
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
216
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
217
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
218
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
219
/**
220
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
221
 * the snonymy.
222
 *
223
 * @var string
224
 */
225
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
226
/**
227
 * The drupal variable for the configuration of the information aggregation along
228
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
229
 *    - direct: the uuids of the taxon relationship types to take into account in invers
230
 *      direction.
231
 *    - invers: the uuids of the taxon relationship types to take into account in direct
232
 *      direction.
233
 *
234
 * @var String
235
 */
236
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
237
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
238
    array(
239
        'direct'=>array(),
240
        'invers'=>array()
241
     )
242
   ));
243
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
244
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
245
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
246

    
247
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
248
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
249
    array(
250
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
251
        'includeOccurrences' => 0,
252
        'includeTaxonNameDescriptions' => 0
253
     )
254
  ));
255

    
256
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
257
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
258
  // needs to be merged with user setting by drupal_array_merge_deep()
259
  'width' => 512, // optimum size for OSM layers is 512
260
  'height' => 512 / 2, // optimum size for OSM layers 256
261
  'bbox' => '', // empty to allow automatic zooming to extend
262
  'show_labels' => FALSE,
263
  'caption' => '',
264
  'distribution_opacity' => '0.5',
265
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
266
  'image_map' => array(
267
    'base_layer' => '', // none, formerly this was cyprusdivs
268
    'bg_color' => '1874CD',
269
    'layer_style' => 'ffffff,606060,,',
270
  ),
271
  'openlayers' => array(
272
    'base_layers' =>  array(
273
      // A layer MUST NOT BE SET in the defaults,
274
      // otherwise it can not be overidden by the user settings:
275
      // 'osgeo_vmap0' => 'osgeo_vmap0',
276
      // it is sufficient to define the preferred layer,
277
      // since it will automatically be enabled:
278
      'PREFERRED' => 'osgeo_vmap0'),
279
     'custom_wms_base_layer' => array(
280
            'name' => NULL,
281
            'url' => NULL,
282
            'params' =>  NULL,
283
            'projection' => NULL,
284
            'proj4js_def' => NULL,
285
            'max_extent' => NULL,
286
            'units' => NULL
287
     ),
288
    'show_layer_switcher' => TRUE,
289
    'display_outside_max_extent' => FALSE
290
  ),
291
  'legend' => array(
292
    'show' => TRUE,
293
    'opacity' => '0.5',
294
    'font_size' => 10,
295
    'font_style' => FALSE,
296
    'icon_width' => 35,
297
    'icon_height' => 15
298
  )
299
)));
300

    
301
/**
302
 * Merges the named array variable with the array of defaults.
303
 *
304
 * @param string $variable_name
305
 *     The variable name
306
 * @param string | array $default
307
 *     The array containing the default values either as array or serialized as string.
308
 *     Unserialization is cared for if nessecary
309
 * @return array
310
 *     The merged array as returnd by drupal_array_merge_deep()
311
 */
312
function get_array_variable_merged($variable_name, $default){
313

    
314
    // unserialize if nessecary
315
    if(!is_array($default)){
316
      $default = unserialize($default);
317
    }
318
    $variable = variable_get($variable_name, array());
319
    return drupal_array_merge_deep($default, $variable);
320
}
321

    
322
/**
323
 * @todo document this function.
324
 */
325
function getGallerySettings($gallery_config_form_name) {
326
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
327
}
328

    
329
/**
330
 * Returns the string representation of the default tab.
331
 *
332
 * @param bool $returnTabIndex
333
 *   Defaults to FALSE, if set true this function will return the index number
334
 *   of the default tab. (used to supply default values to form elements).
335
 */
336
function get_default_taxon_tab($returnTabIndex = FALSE) {
337

    
338
  global $user;
339
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
340
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
341
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
342
  // Get the user value if the used has chosen to overwrite the system settings.
343
  $user_tab_on = variable_get($user_tab_active, FALSE);
344
  if ($user_tab_on) {
345
    $user_value = variable_get($user_tab, 0);
346
    $index_value = $user_value;
347
    // Get the system value.
348
  }
349
  else {
350
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
351
    $index_value = $system_value;
352
  }
353

    
354
  // Return the index value or the string representation.
355
  if ($returnTabIndex) {
356
    return $index_value;
357
  }
358
  else {
359
    return ($values[$index_value]);
360
  }
361

    
362
}
363

    
364
/**
365
 * @todo Please document this function.
366
 * @see http://drupal.org/node/1354
367
 */
368
function cdm_dataportal_menu_admin(&$items) {
369
  // Display section on admin/config page.
370
  $items['admin/config/cdm_dataportal'] = array(
371
    'title' => 'CDM Dataportal',
372
    'description' => 'Settings for the CDM DataPortal.',
373
    'position' => 'right',
374
    'weight' => 10,
375
    'page callback' => 'system_admin_menu_block_page',
376
    'access arguments' => array('administer cdm_dataportal'),
377
    'file' => 'system.admin.inc',
378
    'file path' => drupal_get_path('module', 'system'),
379
  );
380
  $items['admin/config/cdm_dataportal/settings'] = array(
381
    'title' => 'Settings',
382
    'description' => 'Settings for the CDM DataPortal.',
383
    'weight' => 0,
384
    'page callback' => 'drupal_get_form',
385
    'page arguments' => array('cdm_settings_general'),
386
    'access arguments' => array('administer cdm_dataportal'),
387
    'type' => MENU_NORMAL_ITEM,
388
  );
389
  $items['admin/config/cdm_dataportal/settings/general'] = array(
390
    'title' => 'General',
391
    'description' => 'General',
392
    'weight' => 0,
393
    'page callback' => 'drupal_get_form',
394
    'page arguments' => array('cdm_settings_general'),
395
    'access arguments' => array('administer cdm_dataportal'),
396
    'type' => MENU_DEFAULT_LOCAL_TASK,
397
  );
398

    
399
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
400
    'title' => 'Cache',
401
    'description' => 'Cache',
402
    'access arguments' => array('administer cdm_dataportal'),
403
    'page callback' => 'drupal_get_form',
404
    'page arguments' => array('cdm_settings_cache'),
405
    'weight' => 10,
406
    'type' => MENU_LOCAL_TASK,
407
  );
408

    
409
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
410
    'title' => 'Geo & Map',
411
    'description' => 'Geo & Map',
412
    'access arguments' => array('administer cdm_dataportal'),
413
    'page callback' => 'drupal_get_form',
414
    'page arguments' => array('cdm_settings_geo'),
415
    'weight' => 1,
416
    'type' => MENU_LOCAL_TASK,
417
  );
418

    
419
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
420
    'title' => 'Layout',
421
    'description' => 'Configure and adjust the layout of your DataPortal ',
422
    'access arguments' => array('administer cdm_dataportal'),
423
    'page callback' => 'drupal_get_form',
424
    'page arguments' => array('cdm_settings_layout'),
425
    'weight' => 2,
426
    'type' => MENU_LOCAL_TASK,
427
  );
428

    
429
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
430
    'title' => 'Taxon',
431
    'description' => 'Configure and adjust the layout of your DataPortal ',
432
    'access arguments' => array('administer cdm_dataportal'),
433
    'page callback' => 'drupal_get_form',
434
    'page arguments' => array('cdm_settings_layout_taxon'),
435
    'weight' => 1,
436
    'type' => MENU_LOCAL_TASK,
437
  );
438
  /*
439
  $items[] = array(
440
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
441
  'title' => t('Synonymy'),
442
  'description' => t('Configure and adjust the layout of your DataPortal '),
443
  'access' => user_access('administer cdm_dataportal'),
444
  'callback' => 'drupal_get_form',
445
  'callback arguments' => array('cdm_settings_layout_synonymy'),
446
  'weight' => 1,
447
  'type' => MENU_LOCAL_TASK,
448
  );
449

    
450
  $items[] = array(
451
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
452
  'title' => t('Specimens'),
453
  'description' => t('Configure and adjust the layout of your DataPortal '),
454
  'access' => user_access('administer cdm_dataportal'),
455
  'callback' => 'drupal_get_form',
456
  'callback arguments' => array('cdm_settings_layout_specimens'),
457
  'weight' => 1,
458
  'type' => MENU_LOCAL_TASK,
459
  );
460
  */
461
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
462
    'title' => 'Search',
463
    'description' => 'Configure and adjust the layout of your DataPortal ',
464
    'access arguments' => array('administer cdm_dataportal'),
465
    'page callback' => 'drupal_get_form',
466
    'page arguments' => array('cdm_settings_layout_search'),
467
    'weight' => 2,
468
    'type' => MENU_LOCAL_TASK,
469
  );
470

    
471
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
472
    'title' => 'Media',
473
    'description' => 'Configure and adjust the layout of your DataPortal ',
474
    'access arguments' => array('administer cdm_dataportal'),
475
    'page callback' => 'drupal_get_form',
476
    'page arguments' => array('cdm_settings_layout_media'),
477
    'weight' => 3,
478
    'type' => MENU_LOCAL_TASK,
479
  );
480

    
481
}
482

    
483
/**
484
 * @todo document this function.
485
 */
486
function cdm_help_general_cache() {
487
  $form = array();
488
  $form['cache_help'] = array(
489
    '#type' => 'fieldset',
490
    '#title' => t('Help'),
491
    '#collapsible' => TRUE,
492
    '#collapsed' => TRUE,
493
  );
494
  $form['cache_help']['test'] = array('#value' => t('probando'));
495
  return drupal_render($form);
496
  $res = array();
497
  $res['default'] = drupal_render($help);
498
  return $res;
499
}
500

    
501
/**
502
 * Configures the settings form for the CDM-API module.
503
 *
504
 * @return array
505
 *   Drupal settings form.
506
 */
507
function cdm_settings_general() {
508

    
509
  $form['cdm_webservice'] = array(
510
    '#type' => 'fieldset',
511
    '#title' => t('CDM Server'),
512
    '#collapsible' => FALSE,
513
    '#collapsed' => FALSE,
514
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
515
        CDM data base to the web via RESTful web services and thus is the source of the data
516
        to be displayed by a CDM DataPotal.'),
517
  );
518

    
519
  $form['cdm_webservice']['cdm_webservice_url'] = array(
520
    '#type' => 'textfield',
521
    '#title' => t('CDM web service URL') . ':',
522
    '#description' => t('This is the URL to the CDM-Server exposing your data
523
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
524
    '#default_value' => variable_get('cdm_webservice_url', NULL),
525
  );
526

    
527
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
528
    '#type' => 'markup',
529
    '#markup' => '<b>Debug CDM Web Service:</b> The web service debug box has completely been replaced '
530
      . 'by  the ' . l('CDM web service debug block', 'admin/structure/block/manage/cdm_api/cdm_ws_debug/configure')
531
      . '. It is usually only visible for administrative roles like <i>administrator</i> and <i>CDM admin</i>'
532
  );
533

    
534
  $form['cdm_webservice']['freetext_index'] = array(
535
    '#type' => 'fieldset',
536
    '#title' => t('Freetext index'),
537
    '#collapsible' => FALSE,
538
    '#collapsed' => FALSE,
539
  );
540

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

    
553
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
554
  $trigger_link_options = array(
555
    'attributes' => array(
556
      'class' => 'index-trigger',
557
    ),
558
  );
559
  $form['cdm_webservice']['freetext_index']['operations'] = array(
560
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
561
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
562
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
563
      ))
564
    . '<div id="index-progress"></div></div>',
565
  );
566
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
567

    
568
  $form['cdm_webservice']['proxy'] = array(
569
    '#type' => 'fieldset',
570
    '#title' => t('Proxy'),
571
    '#collapsible' => TRUE,
572
    '#collapsed' => TRUE,
573
  );
574

    
575
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
576
    '#type' => 'textfield',
577
    '#title' => t('Proxy URL') . ':',
578
    '#description' => t('If this proxy url is set the cdm api tries
579
    to connect the web service over the given proxy server.
580
    Otherwise proxy usage is deactivated.'),
581
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
582
  );
583

    
584
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
585
    '#type' => 'textfield',
586
    '#title' => t('Proxy port') . ':',
587
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
588
  );
589

    
590
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
591
    '#type' => 'textfield',
592
    '#title' => t('Login') . ':',
593
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
594
  );
595

    
596
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
597
    '#type' => 'textfield',
598
    '#title' => t('Password') . ':',
599
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
600
  );
601

    
602
  // TODO: settings are still incomplete, compare with
603
  // trunk/dataportal/inc/config_default.php.inc.
604
  $form['taxon_tree'] = array(
605
    '#type' => 'fieldset',
606
    '#title' => t('Taxon Tree'),
607
    '#collapsible' => FALSE,
608
    '#collapsed' => TRUE,
609
    '#description' => t('<p>When you explore your collection, you can navigate
610
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
611
      able to navigate through your collection the
612
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
613
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
614
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
615
      </a></p>'),
616
  );
617

    
618
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
619
    '#type' => 'select',
620
    '#title' => t('Available classifications') . ':',
621
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
622
    '#options' => cdm_get_taxontrees_as_options(),
623
    '#description' => t('Select the default taxa classification for your
624
      <em>taxon tree</em>, the other classifications will be also available but
625
      with a manual user change.'),
626
  );
627

    
628
  $form['taxon_tree']['taxontree_ranklimit'] = array(
629
    '#type' => 'select',
630
    '#title' => t('Rank of highest displayed taxon') . ':',
631
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
632
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
633
    '#options' => cdm_rankVocabulary_as_option(),
634
    '#description' => t('This is the rank of the highest displayed taxon in the
635
      <em>taxon tree</em>. You can select here which rank should be at the top
636
      level of the tree structure.'),
637
  );
638

    
639
  $form['aggregation'] = array(
640
      '#type' => 'fieldset',
641
      '#title' => t('Aggregation of data'),
642
      '#collapsible' => FALSE,
643
      '#description' => t("This section covers the different aspects of aggregating information.
644
          <p>
645
          </p>"),
646

    
647
  );
648

    
649
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
650
      '#type' => 'checkboxes',
651
      '#title' => 'Taxon media filter',
652
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
653
      '#options' => array(
654
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
655
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
656
          'includeOccurrences' => 'Media related to specimens and occurrences',
657
      ),
658
      '#description' => 'This filter configures which images should be taken into account.',
659
  );
660

    
661
  $form['aggregation']['notice'] = array(
662
      '#markup' => '<strong>NOTICE:</strong> The below aggregation settings can slow down the data portal, so you may want to sensibly apply these setting and you may also
663
          want to make use of the caching capabilities of the dataportal.',
664
  );
665

    
666
  $form['aggregation']['media_aggregation'] = array(
667
      '#type' => 'fieldset',
668
      '#title' => t('Media aggregation'),
669
      '#collapsible' => FALSE,
670
      '#collapsed' => TRUE,
671
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
672

    
673
  );
674
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
675
      '#type' => 'select',
676
      '#title' => t('Aggregation of taxon pictures') . ':',
677
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
678
      '#options' => array(
679
          0 => "Show only pictures of the current taxon",
680
          1 => "Include pictures of taxonomic children",
681
      ),
682
      '#description' => t("Choose whether to include the images of the taxonomic children. This will affect the <em>Images</em> tab and image tumbnails like in the search results."),
683
  );
684

    
685
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
686
      '#type' => 'fieldset',
687
      '#attributes' => array('class'=>array('clearfix')),
688
      '#title' => t('Aggregation via taxon relationsships'),
689
      '#collapsible' => TRUE,
690
      '#collapsed' => TRUE,
691
      '#tree' => TRUE,
692
      '#description' => t('Information on taxa will be aggregated along the below chosen
693
          taxon relation ships. This will affect images and occurrences (specimens).
694
          Taxon relation ships are directed and point form one taxon to another. The taxon
695
          relationships to be taken into accunt can therefore configured for the direct direction
696
          and for the inverse.'),
697
  );
698

    
699
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
700
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
701

    
702
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
703
      '#type' => 'checkboxes',
704
      '#title' => t('Direct'),
705
      '#options' => $taxonRelationshipTypeOptions,
706
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
707
  );
708
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
709
      '#type' => 'checkboxes',
710
      '#title' => t('Invers'),
711
      '#options' => $taxonRelationshipTypeOptions,
712
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
713
  );
714

    
715
  // ----------------------
716
  $form['cdm_js_devel_mode'] = array(
717
      '#type' => 'checkbox',
718
      '#title' => 'Java-script developer mode',
719
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
720
      '#description' => 'In production envirionments the java script libraries
721
      the cdm_dataportal is making use of are compressed and optimized. This
722
      is good for performance but a caveat if you need to debug java-script. When the
723
      java-script developer mode is enabled the uncompressed and commented developer
724
      versions of java-script libraries will be used where possible.
725
      <br/><strong>Do not use this option in production!</strong>'
726
  );
727

    
728
  // Comment @WA: D7 form api does not support reset buttons,
729
  // so to mimic the D5 reset button we add one like this.
730
  $form['actions']['reset'] = array(
731
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
732
    '#weight' => 1000,
733
  );
734

    
735
  return system_settings_form($form);
736
}
737

    
738

    
739
/**
740
 * LAYOUT settings
741
 * @return unknown_type
742
 *   todo
743
 */
744
function cdm_settings_layout() {
745

    
746
  $form = array();
747

    
748
  $form['about'] = array(
749
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
750
      layout. If you want to configure the specific sites layout visit the
751
      respective configuration site for taxon, search or media.') . '</p>',
752
  );
753

    
754
  // ---- footnotes --- //
755
  $form['footnotes'] = array(
756
    '#type' => 'fieldset',
757
    '#title' => t('Footnotes'),
758
    '#collapsible' => FALSE,
759
    '#collapsed' => FALSE,
760
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
761
      media or distribution areas may have annotations or footnotes. When the
762
      footnotes are enabled they will be visible (if they exist).'),
763
  );
764

    
765
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
766
    '#type' => 'checkbox',
767
    '#title' => t('Do not show footnotes'),
768
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
769
    '#description' => t('Check this if you do not want to show any footnotes'),
770
  );
771

    
772
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
773
    '#type' => 'checkbox',
774
    '#title' => t('Do not show annotations footnotes'),
775
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
776
    '#description' => t('Check this if you do not want to show annotation footnotes'),
777
  );
778

    
779
  $annotationTypeOptions = cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE);
780
  // Additional option for the NULL case.
781
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
782
  $form['footnotes']['annotations_types_as_footnotes'] = array(
783
    '#type' => 'checkboxes',
784
    '#title' => t('Annotation types as footnotes'),
785
    '#description' => t("Only annotations of the selected type will be displayed
786
       as footnotes. You may want to turn 'technical annotations' off."),
787
    '#options' => $annotationTypeOptions,
788
  );
789
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
790
  if (!empty($annotationsTypesAsFootnotes)) {
791
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
792
  }
793

    
794
  // --- Advanced Search --- //
795
  $form['asearch'] = array(
796
      '#type' => 'fieldset',
797
      '#title' => t('Advanced search'),
798
      '#collapsible' => FALSE,
799
      '#collapsed' => FALSE,
800
  );
801
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
802
      '#type' => 'checkbox',
803
      '#title' => t('Show advanced search link'),
804
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
805
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
806
  );
807

    
808
  // ---- Taxon Name Rendering --- //
809
  $form['taxon_name'] = array(
810
      '#type' => 'fieldset',
811
      '#title' => t('Taxon name display'),
812
      '#collapsible' => TRUE,
813
      '#collapsed' => TRUE,
814
      '#description' => t('The display of taxon names is configured by two parts.'
815
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
816
          . 'The name parts are defined in the <stong>part definitions</strong>'),
817
  );
818

    
819
  drupal_add_js(
820
      'jQuery(document).ready( function( ) {
821
         // pretty print json
822
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
823
         var obj = JSON.parse(json_text);
824
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
825

    
826
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
827
         obj = JSON.parse(json_text);
828
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
829
       });'
830
      ,array(
831
          'type' => 'inline',
832
          'scope' => 'footer'
833
      )
834
  );
835

    
836
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
837

    
838
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
839
      '#type' => 'textarea',
840
      '#title' => t('Part definitions'),
841
      '#element_validate' => array('form_element_validate_json'),
842
      '#default_value' =>  json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions)),
843
      '#description' => '
844
          <p>
845
          (Clearing the text area will reset it to the default)
846
          </p>
847
          <p>
848
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
849
          </p>
850
          <p>
851
           A full taxon name plus additional information can consist of the following elements:
852
          <ul>
853
             <li>name: the taxon name inclugin rank nbut without author</li>
854
             <li>authors:  The authors of a reference, also used in taxon names</li>
855
             <li>reference: the nomenclatural reference,</li>
856
             <li>microreference:  Volume, page number etc.</li>
857
             <li>status:  The nomenclatural status of a name</li>
858
             <li>description: name descriptions like protologues etc ...</li>
859
          </ul>
860
          </p>
861
          <p>
862
           These elements are combined in the part definitions array to from the specific parts to be rendered.
863
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
864
           Usually the following parts are formed:
865
          <ul>
866
            <li>namePart: the name and rank (in example: "Lapsana communis")</li>
867
            <li>authorshipPart: the author (in example: "L.")</li>
868
            <li>nameAuthorPart: the combination of name and author part (in example: "Lapsana communis L.").</li>
869
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
870
               be combined when a link to the taxon is rendered.</li>
871
            <li>referencePart: the nomencaltural reference (in example: "Sp. Pl. 1753")</li>
872
            <li>microreferencePart: usually the page number (in example ": 811.")</li>
873
            <li>statusPart: the nomenclatorical status</li>
874
            <li>descriptionPart: name descriptions like protologues etc ...</li>
875
          </ul>
876
          </p>
877
          <p>
878
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
879
           specific parts part definitions:
880
          <ul>
881
            <li>BotanicalName</li>
882
            <li>ZoologicalName</li>
883
            <li>#DEFAULT: covers ViralNames and other NonViralNames
884
          </ul>
885
           An example:
886
          <pre>
887
           {
888
            "ZoologicalName": {
889
              "namePart": {
890
                "name": true
891
              },
892
              "referencePart": {
893
                "authors": true
894
              },
895
              "microreferencePart": {
896
                "microreference": true
897
              },
898
              "statusPart": {
899
                "status": true
900
              },
901
              "descriptionPart": {
902
                "description": true
903
              }
904
            },
905
            "BotanicalName": {
906
              "namePart": {
907
                "name": true,
908
                "authors": true
909
              },
910
              "referencePart": {
911
                "reference": true,
912
                "microreference": true
913
              },
914
              "statusPart": {
915
                "status": true
916
              },
917
              "descriptionPart": {
918
                "description": true
919
              }
920
            }
921
          }
922
           </pre>',
923
  );
924

    
925
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
926

    
927
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
928
      '#type' => 'textarea',
929
      '#title' => t('Name render templates'),
930
      '#element_validate' => array('form_element_validate_json'),
931
      '#default_value' =>  json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates)),
932
      '#description' => '
933
          <p>
934
          (Clearing the text area will reset it to the default)
935
          </p>
936
          <p>
937
          The render templates array contains one or more name render templates to be used within the page areas identified by the
938
          render path. The render path is used as key of the array sub subelements whereas the name render template array is set as value.
939
          The following render Path keys are curretly recognized:
940
          <ul>
941
            <li>list_of_taxa:</li>
942
            <li>acceptedFor:</li>
943
            <li>taxon_page_synonymy</li>
944
            <li>typedesignations</li>
945
            <li>taxon_page_title</li>
946
            <li>polytomousKey</li>
947
            <li>na: name + authorship</li>
948
            <li>nar:name + authorship + reference</li>
949
            <li>#DEFAULT</li>
950
          </ul>
951
          A single render template can be used for multiple render paths. In this case the according key of the render templates
952
          array element should be a comma separated list of render paths, without any whitespace!.
953
          </p>
954
          <p>
955
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
956
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
957
          <p>
958
          The value of the render template element must be set to TRUE in order to let this part being rendered.
959
          The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
960
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
961
          links if the paramters $nameLink or $refenceLink are given to the name render function
962
          (this is hard coded and cannot be configured here).',
963
  );
964

    
965
  // @WA: D7 form api does not support reset buttons,
966
  // so to mimic the D5 reset button we add one like this.
967
  $form['actions']['reset'] = array(
968
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
969
    '#weight' => 1000,
970
  );
971

    
972
  $form['#submit'] = array('submit_json_as_php_array');
973
  // #json_elements especially defined for submit_json_as_php_array()
974
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
975
  return system_settings_form($form);
976
}
977

    
978

    
979
/**
980
 * @todo Please document this function.
981
 * @see http://drupal.org/node/1354
982
 */
983
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
984
  $form[$form_name] = array(
985
    '#type' => 'fieldset',
986
    '#title' => t($form_title),
987
    '#collapsible' => TRUE,
988
    '#collapsed' => $collapsed,
989
    '#tree' => TRUE,
990
    '#description' => t($form_description),
991
  );
992

    
993
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
994
  $gallery_settings = variable_get($form_name, $default_values);
995
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
996
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
997
    /*
998
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
999
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1000
    '#type' => 'textfield',
1001
    '#title' => t('Search Page Size'),
1002
    '#default_value' => $test,
1003
    '#description' => t('Number of Names to display per page in search results.')
1004
    );
1005
    */
1006
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1007
      '#type' => 'checkbox',
1008
      '#title' => t('Show media thumbnails for accepted taxa'),
1009
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1010
    );
1011

    
1012
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1013
      '#type' => 'checkbox',
1014
      '#title' => t('Show media thumbnails for synonyms'),
1015
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1016
      '#description' => '',
1017
    );
1018
  }
1019

    
1020
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1021
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1022
    '#type' => 'checkbox',
1023
    '#title' => t('Show captions under thumbnails'),
1024
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1025
    '#description' => '',
1026
  );
1027

    
1028
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1029
    '#type' => 'textfield',
1030
    '#title' => t('Thumbnail size') . ':',
1031
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1032
    '#description' => t('Select the size of each individual thumbnail.'),
1033
  );
1034

    
1035
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1036
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1037
      '#type' => 'textfield',
1038
      '#title' => t('Number of columns') . ':',
1039
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1040
      '#description' => t('Group the thumbnails in columns: select how many
1041
        columns the gallery should display.'),
1042
    );
1043
  }
1044

    
1045
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1046
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1047
      '#type' => 'textfield',
1048
      '#title' => t('Maximum number of rows') . ':',
1049
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1050
      '#description' => t('You can group the thumbnails in rows, select in how
1051
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1052
        If you want an unlimited number of rows please set to 0.'),
1053
    );
1054
  }
1055

    
1056
  return $form;
1057
}
1058

    
1059
/**
1060
 * @todo document this function.
1061
 */
1062
function cdm_settings_layout_taxon() {
1063
  $collapsed = FALSE;
1064
  $form = array();
1065

    
1066
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1067

    
1068
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1069
      '#type' => 'checkbox',
1070
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1071
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1072
      '#description' => t('<p>If checked the link to search results is rendered at
1073
       the top of the taxon site. Clicking on the link the last search performed
1074
       is rendered again.</p>'),
1075
  );
1076

    
1077
  // --------- TABBED TAXON ------- //
1078
  $form['taxon_tabs'] = array(
1079
    '#type' => 'fieldset',
1080
    '#title' => t('Taxon tabs'),
1081
    '#collapsible' => TRUE,
1082
    '#collapsed' => FALSE,
1083
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1084
      be splitted in four diferent tabs; General, Synonymy, Images and
1085
      Specimens. If the taxon has no information for any of the tabs/sections
1086
      such tab will be not displayed.'),
1087
  );
1088

    
1089
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1090
    '#type' => 'checkbox',
1091
    '#title' => t('Tabbed taxon page'),
1092
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1093
    '#description' => t('<p>If selected split the taxon page into individual
1094
      tabs for description, images, synonymy and specimens. If not the taxon
1095
      data is rendered as a long single page without tabs.</p>'),
1096
  );
1097

    
1098
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1099
    '#type' => 'checkboxes',
1100
    '#title' => t('Tabs visibility options') . ':',
1101
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1102
    '#options' => get_taxon_options_list(),
1103
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1104
  );
1105

    
1106
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1107
    '#type' => 'select',
1108
    '#title' => t('Default tab to display') . ':',
1109
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1110
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1111
    '#description' => t('<p>Select the default tab to display when visiting a
1112
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1113
      <strong>Note:</strong> After performing a search and clicking in any
1114
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1115
      taxon and not the above selected tab.'),
1116
  );
1117

    
1118
  /* ======  TAXON_PROFILE ====== */
1119
  $form['taxon_profile'] = array(
1120
    '#type' => 'fieldset',
1121
    '#title' => t('Taxon profile (tab)'),
1122
    '#description' => t('<p>This section covers the settings related to the taxon
1123
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1124
    '#collapsible' => TRUE,
1125
    '#collapsed' => TRUE,
1126
  );
1127

    
1128
  // ---- PROFILE PICTURE ----//
1129

    
1130
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1131
    '#type' => 'fieldset',
1132
    '#tree' => TRUE,
1133
    '#title' => t('Taxon profile picture'),
1134
    '#collapsible' => TRUE,
1135
    '#collapsed' => FALSE,
1136
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1137
  );
1138

    
1139
  //FIXME migrate variables:
1140
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1141
  // FIXME
1142
  //  eanable file modul in profile and in update
1143

    
1144
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1145
  /*
1146
   * 'show' => 1,
1147
   * 'maxextend' => 184,
1148
   * 'media_uri_query' => ''
1149
   * 'custom_placeholder_image_on' => 1,
1150
   * 'custom_placeholder_image_fid' => ''
1151
   */
1152
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1153
    '#type' => 'checkbox',
1154
    '#title' => t('Enable profil picture'),
1155
    '#description' => t('Show the profil picture.'),
1156
    '#default_value' => $taxon_profile_image_settings['show'],
1157
  );
1158

    
1159
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1160
      '#type' => 'textfield',
1161
      '#tree' => TRUE,
1162
      '#title' => t('Profil picture maximum extend'),
1163
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1164
      '#field_suffix' => 'px',
1165
      '#maxlength' => 4,
1166
      '#size' => 4,
1167
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1168
  );
1169

    
1170
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1171
      '#type' => 'textfield',
1172
      '#tree' => TRUE,
1173
      '#title' => t('Additional URI query parameter'),
1174
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1175
      '#maxlength' => 1024,
1176
      '#size' => 60,
1177
      '#description' => t('Additional query parameters to be used when requesting for the '
1178
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1179
          . 'The query parameters will be appendend to the uri of the media representation part'
1180
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1181
  );
1182

    
1183
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1184
      '#type' => 'checkbox',
1185
      '#title' => t('Use a custom placeholder image'),
1186
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1187
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1188
  );
1189

    
1190
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1191
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1192
        '#type' => 'managed_file',
1193
        '#title' => t('Custom placeholder image file'),
1194
        '#progress_indicator' => 'bar',
1195
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1196
    //       '#name' => 'custom_placeholder_image',
1197
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1198
    );
1199

    
1200
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1201
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1202
      $url = file_create_url($profile_image_file->uri);
1203
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1204
                '#type' => 'item',
1205
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1206
      );
1207
    }
1208
  } else {
1209
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1210
        '#type' => 'hidden',
1211
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1212
    );
1213
  }
1214

    
1215

    
1216

    
1217
  $options = cdm_rankVocabulary_as_option();
1218
  array_unshift($options, '-- DISABLED --');
1219
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1220
    '#type' => 'select',
1221
    '#title' => t('Hide profile picture for higher ranks') . ':',
1222
    '#default_value' => variable_get('image_hide_rank', '0'),
1223
    '#options' => $options,
1224
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1225
  );
1226

    
1227
  // -- MEDIA THUMBNAILS -- //
1228
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1229
  $form_title = 'Taxon Profile Images';
1230
  $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>';
1231
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1232

    
1233
  // ---- FEATURE TREE ---- //
1234
  $form['taxon_profile']['feature_trees'] = array(
1235
    '#type' => 'fieldset',
1236
    '#title' => t('Features'),
1237
    '#collapsible' => TRUE,
1238
    '#collapsed' => FALSE,
1239
    '#description' => t("This section covers settings related to the taxon's
1240
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1241
      features such as description, distribution, common names, etc. that Drupal
1242
      will render at the taxon profile page."),
1243
  );
1244
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1245
  $saved_uuid = variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1246
  if(!isset($featureTrees['options'][$saved_uuid])) {
1247
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1248
  }
1249
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
1250
    '#type' => 'radios',
1251
    '#title' => t('Taxon profile sections') . ':',
1252
    '#default_value' => $saved_uuid,
1253
    '#options' =>  $featureTrees['options'],
1254
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1255
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1256
    '#description' => t('Select the Feature Tree to be displayed at the taxon
1257
      profile. Click "Show Details" to see the Feature Tree elements.'
1258
    ),
1259
  );
1260
  $featureTrees = cdm_get_featureTrees_as_options();
1261
  $saved_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1262
  if(!isset($featureTrees['options'][$saved_uuid])) {
1263
    $saved_uuid = NULL;
1264
  }
1265
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
1266
    '#type' => 'radios',
1267
    '#title' => t('Natural language representation of structured descriptions') . ':',
1268
    '#default_value' => $saved_uuid,
1269
    '#options' => $featureTrees['options'],
1270
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1271
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1272
    '#description' => t('Taxon descriptions can be stored in a highly structured
1273
      form. The feature tree selected here will be used to generate textual
1274
      representation in natural language.'
1275
    ),
1276
  );
1277

    
1278
  // ---- LAYOUT PER FEATURE ---- //
1279
  $feature_tree = get_profile_featureTree();
1280
  if (isset($feature_tree->root->childNodes)) {
1281

    
1282
    $form_feature_list_layout = array(
1283
      '#title' => t('Taxon profile layout'),
1284
      '#collapsible' => TRUE,
1285
      '#collapsed' => FALSE,
1286
      '#type' => 'fieldset',
1287
      '#description' => t('Will be available in a future release.'),
1288
    );
1289

    
1290
    $feature_list_layout_settings_disabled = TRUE;
1291
    foreach ($feature_tree->root->childNodes as $featureNode) {
1292

    
1293
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1294
        // Must not exceed 45 characters !!!
1295
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1296

    
1297
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1298
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1299

    
1300
        $form_feature_list_layout[$subform_id] = array(
1301
          '#tree' => TRUE,
1302
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1303
          '#collapsible' => FALSE,
1304
          '#collapsed' => FALSE,
1305
          '#type' => 'fieldset',
1306
          '#description' => t(''),
1307
        );
1308

    
1309
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1310
          '#type' => 'checkbox',
1311
          '#title' => t('Enable'),
1312
          '#default_value' => $settings['enabled'],
1313
          '#description' => t('Enable user defined layout for this feature'),
1314
        );
1315

    
1316
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1317
          '#type' => 'textfield',
1318
          '#title' => t('Enclosing tag'),
1319
          '#disabled' => !$settings['enabled'],
1320
          '#default_value' => $settings['enclosingTag'],
1321
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1322
        );
1323

    
1324
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1325
          '#type' => 'textfield',
1326
          '#title' => t('Entry enclosing tag'),
1327
          '#disabled' => !$settings['enabled'],
1328
          '#default_value' => $settings['entryEnclosingTag'],
1329
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1330
        );
1331

    
1332
        $form_feature_list_layout[$subform_id]['glue'] = array(
1333
          '#type' => 'textfield',
1334
          '#title' => t('Glue'),
1335
          '#disabled' => !$settings['enabled'],
1336
          '#default_value' => $settings['glue'],
1337
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1338
        );
1339

    
1340
      }
1341

    
1342
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1343
    }
1344
  }
1345

    
1346
  // ---- DISTRIBUTION LAYOUT ---- //
1347
  $form['taxon_profile']['distribution_layout'] = array(
1348
    '#title' => t('Distribution'),
1349
    '#collapsible' => TRUE,
1350
    '#collapsed' => FALSE,
1351
    '#type' => 'fieldset',
1352
    '#description' => t('Select if you want to sort or not the distribution text
1353
      located below the distribution map.'),
1354
  );
1355

    
1356
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1357
    '#type' => 'radios',
1358
    '#title' => t('Sort') . ':',
1359
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1360
    '#options' => array(
1361
      'NO_SORT' => t('Standard (No sort)'),
1362
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1363
    ),
1364
  );
1365

    
1366
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1367
    '#type' => 'checkbox',
1368
    '#title' => t('Show TextData elements on top of the map'),
1369
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1370
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1371
      elements on top of the map. Otherwise all <code>TextData</code>
1372
      distribution elements will be listed below the other area elements.
1373
      This option is useful if you need to have descriptive texts for each
1374
      distribution map.'),
1375
  );
1376

    
1377

    
1378
  /* ====== SYNONYMY ====== */
1379
  $form['taxon_synonymy'] = array(
1380
    '#type' => 'fieldset',
1381
    '#title' => t('Taxon synonymy (tab)'),
1382
    '#collapsible' => TRUE,
1383
    '#collapsed' => TRUE,
1384
    '#description' => t('This section covers the settings related to the taxon
1385
      <strong>synonymy</strong> tab.'),
1386
  );
1387

    
1388
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1389
    '#type' => 'checkbox',
1390
    '#title' => t('Show accepted taxon on top of the synonymy'),
1391
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1392
    '#description' => t('If checked, the first homotypic taxon is a repetition
1393
      of the accepted taxon most likely with the full nomenclatural reference
1394
      (depending on the currently chosen theme).'),
1395
  );
1396

    
1397
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1398
    '#type' => 'checkbox',
1399
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1400
      coming from a synonym link.'),
1401
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1402
    '#description' => t('Check this if after doing a search and clicking on a
1403
      synonym you want to see the "accept of" text for the accepted synonym.'),
1404
  );
1405

    
1406
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1407
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1408
    '#type' => 'checkboxes',
1409
    '#title' => t('Display name relationships') . ':',
1410
    '#default_value' => variable_get('name_relationships_to_show', 0),
1411
    '#options' => $nameRelationshipTypeOptions,
1412
    '#description' => t('Select the name relationships you want to show for the
1413
      accepted taxa.'),
1414
  );
1415

    
1416
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1417
    '#type' => 'checkbox',
1418
    '#title' => t('Show taxon relations ships of accepted taxon'),
1419
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1420
    '#description' => t('If this option is enabled the synonymy will show the
1421
      below selected taxon relationships of accepted taxa.'),
1422
  );
1423

    
1424
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1425
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1426
    '#type' => 'checkboxes',
1427
    '#title' => t('Taxon relationship types') . ':',
1428
    '#description' => t('Only taxon relationships of the selected type will be
1429
      displayed'),
1430
    '#options' => $taxonRelationshipTypeOptions,
1431
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1432
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1433
  );
1434

    
1435
  // ====== SPECIMENS ====== //
1436
  $form['taxon_specimens'] = array(
1437
    '#type' => 'fieldset',
1438
    '#title' => t('Taxon specimens (tab)'),
1439
    '#collapsible' => TRUE,
1440
    '#collapsed' => TRUE,
1441
    '#description' => t('This section covers the settings related to the taxon
1442
      <strong>specimens</strong> tab.'),
1443
  );
1444

    
1445
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1446
  $saved_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1447
  if(!isset($featureTrees['options'][$saved_uuid])) {
1448
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1449
  }
1450
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1451
      '#type' => 'radios',
1452
      '#title' => t('Specimen description feature tree') . ':',
1453
      '#default_value' => $saved_uuid,
1454
      '#options' =>  $featureTrees['options'],
1455
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1456
      '#options_suffixes' => $featureTrees['treeRepresentations'],
1457
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1458
      ),
1459
  );
1460

    
1461
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1462
  $form_title = t('Specimen media');
1463
  $form_description = t('Specimens may have media which is displayed at the
1464
     Specimen tab/section as a gallery. It is possible to configure the
1465
     thumbnails gallery here, however for configuring how a single media should
1466
     be displayed please go to !url.</p>',
1467
     array(
1468
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1469
     ));
1470
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1471

    
1472
  // --- MEDIA GALLERY ---- //
1473
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1474
  $form_title = 'Media gallery (tab)';
1475
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1476
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1477
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1478
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1479
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1480
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1481
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1482

    
1483
  // Comment @WA: D7 form api does not support reset buttons,
1484
  // so to mimic the D5 reset button we add one like this.
1485
  $form['actions']['reset'] = array(
1486
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1487
    '#weight' => 1000,
1488
  );
1489
  return system_settings_form($form);
1490
}
1491

    
1492
/**
1493
 * @todo document this function.
1494
 */
1495
function cdm_settings_layout_search() {
1496

    
1497
  $form = array();
1498

    
1499
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
1500

    
1501
  $form['search_settings'] = array(
1502
    '#type' => 'fieldset',
1503
    '#title' => t('Taxa Search'),
1504
    '#collapsible' => FALSE,
1505
    '#collapsed' => FALSE,
1506
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1507
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1508
         where they can write the text to be searched. You can find Drupal block configuration
1509
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1510
  );
1511

    
1512
  $form['search_settings']['simple_search_ignore_classification'] = array(
1513
      '#type' => 'checkbox',
1514
      '#title' => t('Ignore the chosen classification in simple search'),
1515
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
1516
      '#description' => t('The simple search, which can be executed via the search block,
1517
          will by default search on all classifications. Remove the tick if you want your
1518
          portal to search on the classification selected in the classification browser
1519
          selector.'),
1520
  );
1521

    
1522
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1523
    '#type' => 'textfield',
1524
    '#title' => t('Results per page') . ':',
1525
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1526
    '#description' => t('Number of results to display per page.'),
1527
  );
1528

    
1529
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
1530
  $form['search_settings']['cdm_search_taxa_mode'] = array(
1531
      '#type' => 'checkboxes',
1532
      '#title' => 'Search mode',
1533
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
1534
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
1535
          for the advance search form and the behaviour of the simple search form which always will behave according to the
1536
          defaults set here.',
1537
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
1538
      '#default_value' => $search_mode_default
1539
      );
1540

    
1541
  // --- SEARCH TAXA GALLERY ---- //
1542
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1543
  $collapsed = FALSE;
1544
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1545
  $form_title = 'Taxa Search thumbnails';
1546
  $form_description = 'Search results may show thumbnails. ';
1547
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1548

    
1549
  // Comment @WA: D7 form api does not support reset buttons,
1550
  // so to mimic the D5 reset button we add one like this.
1551
  $form['actions']['reset'] = array(
1552
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1553
    '#weight' => 1000,
1554
  );
1555
  return system_settings_form($form);
1556
}
1557

    
1558
/**
1559
 * @todo document this function.
1560
 */
1561
function cdm_settings_layout_media() {
1562

    
1563
  $form = array();
1564

    
1565
  $form['media_settings'] = array(
1566
    '#type' => 'fieldset',
1567
    '#title' => t('Media settings'),
1568
    '#collapsible' => FALSE,
1569
    '#collapsed' => FALSE,
1570
    '#description' => 'This section covers layout settings for media pages.'
1571
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
1572
  );
1573

    
1574
  $form['media_settings']['image_gallery_viewer'] = array(
1575
    '#type' => 'select',
1576
    '#title' => t('Image viewer') . ':',
1577
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1578
    '#options' => array(
1579
      'default' => t('Standard image viewer'),
1580
      'fsi' => t('FSI viewer (requires FSI server!)'),
1581
    ),
1582
  );
1583

    
1584
  // --- MEDIA GALLERY ---- //
1585
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1586
  $form_title = 'Standard viewer';
1587
  $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>';
1588
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1589
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1590

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

    
1600
/**
1601
 * GEOSERVICE and Map settings.
1602
 */
1603
function cdm_settings_geo($form, &$form_state) {
1604

    
1605
  $current_geoserver_settings = get_edit_map_service_settings();
1606
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
1607
  // The default layer must always be enabled
1608
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
1609
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
1610

    
1611
  $form = array();
1612

    
1613
  $dummy_distribution_query = NULL;
1614
  if($map_distribution['map_type'] != 1){
1615
    // we need to apply a dummy query since the map serice requires for image maps
1616
    // at least as and ad to be defined
1617
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
1618
  }
1619
  $form['map_preview'] = array(
1620
      '#type' => 'fieldset',
1621
      '#tree' => FALSE,
1622
      '#title' => t('Map preview'),
1623
      '#collapsible' => FALSE,
1624
      '#description' => 'The preview of the map'
1625
       . ($dummy_distribution_query != null ?
1626
           ' may not be accurate in case if image maps, please check the map display in the taxon pages.':
1627
           '.<br/>Hold down Strg and drag with your mouse to select a bbox to zoom to. <br/>The bbox of the visible area of the map is always displayed below the map.')
1628
  );
1629
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL,
1630
      array(
1631
          'move' => "this.cdmOpenlayersMap.printInfo",
1632
          '#execute' => "this.cdmOpenlayersMap.printInfo"
1633
      )
1634
  );
1635

    
1636

    
1637
  /*
1638
   * GEO SERVER
1639
   */
1640
  $form['edit_map_server'] = array(
1641
    '#type' => 'fieldset',
1642
    '#tree' => true,
1643
    '#title' => t('EDIT map service'),
1644
    '#collapsible' => TRUE,
1645
    '#collapsed' => TRUE,
1646
    '#description' => t('Configuration and selection of your geo server.
1647
      The Geo Server is responsible for generating the maps.'),
1648
  );
1649

    
1650
  $form['edit_map_server']['base_uri'] = array(
1651
    '#type' => 'select',
1652
    '#title' => t('EDIT map service') . ':',
1653
    '#default_value' => $current_geoserver_settings['base_uri'],
1654
    '#options' => unserialize(EDIT_MAPSERVER_URI),
1655
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
1656
  );
1657
  $form['edit_map_server']['version'] = array(
1658
      '#type' => 'select',
1659
      '#title' => t('Version') . ':',
1660
      '#default_value' => $current_geoserver_settings['version'],
1661
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
1662
      '#description' => t('The version of the EDIT map services'),
1663
  );
1664

    
1665
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1666
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1667
  $form['gmap_api_key'] = array(
1668
      '#type' => 'textfield',
1669
      '#title' => t('Google maps API key') . ':',
1670
      '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1671
      '#description' => t('If you want to use the Google Maps Layer, a key is
1672
      needed. If you need a key, visit
1673
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
1674
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
1675
      is the default key for the localhost (127.0.0.1).',
1676
      array('!localhostkey' => $localhostkey)),
1677
  );
1678

    
1679

    
1680
  /*
1681
   * MAP SETTINGS
1682
   */
1683

    
1684
  $form[CDM_MAP_DISTRIBUTION] = array(
1685
    '#type' => 'fieldset',
1686
    '#tree' => TRUE,
1687
    '#title' => t('Maps settings'),
1688
    '#collapsible' => TRUE,
1689
    '#collapsed' => TRUE,
1690
    '#description' => t('General configuration for all map types.'),
1691
  );
1692

    
1693
  /*
1694
   * settings for the distribution map are used also for specimens map!!!!
1695
   */
1696

    
1697
  $form[CDM_MAP_DISTRIBUTION]['width'] = array(
1698
    '#type' => 'textfield',
1699
    '#title' => 'Width',
1700
    '#default_value' => $map_distribution['width'],
1701
    '#maxlength' => 4,
1702
    '#size' => 4,
1703
    '#description' => 'Width of the map. To allow OSM baselayers to zoom out to the full extend of the world the map width must be
1704
      a multiple of 256px since the osm tiles from tile.openstreetmap.org have a size of 256px x 256px and frational zoom
1705
      levels are not possible in this case.',
1706
  );
1707
  $form[CDM_MAP_DISTRIBUTION]['height'] = array(
1708
      '#type' => 'textfield',
1709
      '#title' => 'Height',
1710
      '#default_value' => $map_distribution['height'],
1711
      '#maxlength' => 4,
1712
      '#size' => 4,
1713
      '#description' => 'Height of the map. Depending on the chosen base layer you may want to choose the height equal
1714
      to the width or half of the width. Any other aspect ratio is also possible if desired.',
1715
  );
1716

    
1717
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
1718
    '#type' => 'textfield',
1719
    '#title' => 'Bounding box',
1720
    '#default_value' => $map_distribution['bbox'],
1721
    '#description' => t('The bounding box defines the area to be initially displayed in maps.
1722
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
1723
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
1724
      <strong>TIP: </strong>You can use the map preview above to choose a bbox from the map. Maybe you need to change the map type to OpeLayers.
1725
      Hold down Strg and drag with your mouse to select a bbox to zoom to. The bbox of the visible area of the map is always displayed
1726
      below the map from where you can copy the bbox string.</p>'),
1727
  );
1728

    
1729
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
1730
    '#type' => 'checkbox',
1731
    '#title' => 'Display area labels',
1732
    '#default_value' => $map_distribution['show_labels'],
1733
    '#description' => t('The map will show name labels of the areas'),
1734
  );
1735

    
1736
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
1737
    '#type' => 'textfield',
1738
    '#title' => 'Map caption',
1739
    '#default_value' => $map_distribution['caption'],
1740
    '#description' => t('The caption will be shown below the map.'),
1741
  );
1742

    
1743
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
1744
    '#type' => 'textfield',
1745
    '#title' => 'Distribution layer opacity',
1746
    '#default_value' => $map_distribution['distribution_opacity'],
1747
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1748
                           fully visible, while a value near to 0.0 will be not much visible.'),
1749
  );
1750

    
1751
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
1752
    '#type' => 'radios',
1753
    '#title' => 'Map types',
1754
    '#options' => array(
1755
      1 => "OpenLayers dynamic map viewer",
1756
      0 => "Plain image",
1757
    ),
1758
    '#default_value' => $map_distribution['map_type'],
1759
    '#description' => 'Two different map types are available :
1760
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
1761
      which allows zooming and panning. If enabled you can configure the default layer
1762
      (background of your maps) below.</li>
1763
      <li><em>Plain image</em>: The map will be static non interactive
1764
      image.</li></ul>',
1765
  );
1766
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
1767

    
1768

    
1769
  // --- Plain Image Settings --- //
1770
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
1771
    '#type' => 'fieldset',
1772
    '#title' => 'Plain image map settings',
1773
    '#tree' => TRUE,
1774
    '#collapsible' => TRUE,
1775
    '#collapsed' => $open_layers_is_enabled,
1776
    '#description' => 'The settings in this section are still expertimental
1777
      and can only be used with the EDIT map service version 1.1 or above.',
1778
  );
1779
  $edit_mapserver_version = get_edit_map_service_version_number();
1780
  if ($edit_mapserver_version < 1.1) {
1781
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">' . t("The chosen EDIT map service version ($edit_mapserver_version) is too low, it must be at least 1.1") . '</div>'
1782
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
1783
  }
1784

    
1785
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
1786
    '#type' => 'textfield',
1787
    '#title' => 'Background layer',
1788
    '#default_value' => $map_distribution['image_map']['base_layer'],
1789
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
1790
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
1791
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
1792
    )),
1793
  );
1794

    
1795
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
1796
    '#type' => 'textfield',
1797
    '#title' => 'Background color',
1798
    '#default_value' => $map_distribution['image_map']['bg_color'],
1799
  );
1800

    
1801
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
1802
    '#type' => 'textfield',
1803
    '#title' => 'Background layer style',
1804
     // Only line color by now.
1805
    '#default_value' => $map_distribution['image_map']['layer_style'],
1806
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
1807
  );
1808

    
1809
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
1810
      '#type' => 'textfield',
1811
      '#title' => 'Projection',
1812
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
1813
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
1814
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
1815
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
1816
  );
1817

    
1818

    
1819
  // --- OpenLayers Settings --- //
1820
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
1821
    '#type' => 'fieldset',
1822
    '#title' => 'OpenLayers settings',
1823
    '#tree' => TRUE,
1824
    '#collapsible' => TRUE,
1825
    '#collapsed' => !$open_layers_is_enabled,
1826
    '#description' => '',
1827
  );
1828

    
1829

    
1830
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
1831
      '#type' => 'checkbox',
1832
      '#title' => 'Display outside max extent',
1833
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
1834
      '#description' => t('Allows the map to display parts of the layers which are outside
1835
         the max extent if the aspect ratio of the map and of the baselayer
1836
         are not equal.'),
1837
  );
1838

    
1839
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
1840
      '#type' => 'checkbox',
1841
      '#title' => 'Show Layer Switcher',
1842
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
1843
      '#description' => 'The Layer Switcher control displays a table of contents
1844
      for the map.  This allows the user interface to switch between
1845
      base layers and to show or hide overlays.  By default the switcher is
1846
      shown minimized on the right edge of the map, the user may expand it
1847
      by clicking on the handle.',
1848
  );
1849

    
1850
  if (!$open_layers_is_enabled) {
1851
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
1852
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
1853
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
1854
  }
1855

    
1856
  $baselayer_options = array(
1857
    /*
1858
   NOTICE: must correspond to the layers defined in
1859
   js/openlayers_,ap.js#getLayersByName()
1860
   */
1861
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
1862
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
1863
    // all others EPSG:900913
1864
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
1865
    'edit-etopo1' => "ETOPO1 Global Relief Model",
1866
    'mapnik' => 'OpenStreetMap',
1867
    'mapquest_open' => "MapQuest",
1868
    'mapquest_sat' => "MapQuest Sattelite",
1869
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
1870
    'gmap' => 'Google Streets',
1871
    'gsat' => 'Google Satellite',
1872
    'ghyb' => 'Google Hybrid',
1873
//     'veroad' => 'Virtual Earth Roads',
1874
//     'veaer' => 'Virtual Earth Aerial',
1875
//     'vehyb' => 'Virtual Earth Hybrid',
1876
    // 'yahoo' => 'Yahoo Street',
1877
    // 'yahoosat' => 'Yahoo Satellite',
1878
    // 'yahoohyb' => 'Yahoo Hybrid',
1879
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
1880
  );
1881

    
1882
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
1883
    '#type' => 'checkboxes_preferred',
1884
    '#title' => 'Base Layers',
1885
    '#options' => $baselayer_options,
1886
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
1887
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
1888
  );
1889

    
1890
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
1891
      '#type' => 'fieldset',
1892
      '#title' => 'Custom WMS base layer',
1893
      '#tree' => TRUE,
1894
      '#collapsible' => FALSE,
1895
      '#collapsed' => FALSE,
1896
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
1897
  );
1898

    
1899
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
1900
      '#type' => 'textfield',
1901
      '#title' => 'Layer name',
1902
      // Only line color by now.
1903
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
1904
      '#description' => 'A arbitrary name for the layer.',
1905
  );
1906
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
1907
      '#type' => 'textfield',
1908
      '#title' => 'WMS url',
1909
      // Only line color by now.
1910
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
1911
      '#description' => 'Base url for the WMS (e.g.  http://wms.jpl.nasa.gov/wms.cgi)'
1912
  );
1913
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
1914
      '#type' => 'textarea',
1915
      '#title' => 'WMS parameters',
1916
      '#element_validate' => array('form_element_validate_json'),
1917
      // Only line color by now.
1918
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
1919
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON.'
1920
  );
1921
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
1922
      '#type' => 'textfield',
1923
      '#title' => 'Projection',
1924
      // Only line color by now.
1925
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
1926
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
1927
  );
1928
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
1929
      '#type' => 'textfield',
1930
      '#title' => 'proj4js definition',
1931
      // Only line color by now.
1932
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
1933
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
1934
            The definitions for
1935
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
1936
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
1937
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
1938
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
1939
            choose to display the proj4js definition string.
1940
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
1941
            <pre>
1942
+a         Semimajor radius of the ellipsoid axis
1943
+alpha     ? Used with Oblique Mercator and possibly a few others
1944
+axis      Axis orientation (new in 4.8.0)
1945
+b         Semiminor radius of the ellipsoid axis
1946
+datum     Datum name (see `proj -ld`)
1947
+ellps     Ellipsoid name (see `proj -le`)
1948
+k         Scaling factor (old name)
1949
+k_0       Scaling factor (new name)
1950
+lat_0     Latitude of origin
1951
+lat_1     Latitude of first standard parallel
1952
+lat_2     Latitude of second standard parallel
1953
+lat_ts    Latitude of true scale
1954
+lon_0     Central meridian
1955
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
1956
+lon_wrap  Center longitude to use for wrapping (see below)
1957
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
1958
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
1959
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
1960
+pm        Alternate prime meridian (typically a city name, see below)
1961
+proj      Projection name (see `proj -l`)
1962
+south     Denotes southern hemisphere UTM zone
1963
+to_meter  Multiplier to convert map units to 1.0m
1964
+towgs84   3 or 7 term datum transform parameters (see below)
1965
+units     meters, US survey feet, etc.
1966
+vto_meter vertical conversion to meters.
1967
+vunits    vertical units.
1968
+x_0       False easting
1969
+y_0       False northing
1970
+zone      UTM zone
1971
            </pre>
1972
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
1973
  );
1974
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
1975
      '#type' => 'textfield',
1976
      '#title' => 'Maximum extent',
1977
      // Only line color by now.
1978
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
1979
      '#description' => 'The maximum extent of the map as boundin box in the units of the map.'
1980
  );
1981
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
1982
      '#type' => 'textfield',
1983
      '#title' => 'Units',
1984
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
1985
      '#description' => 'The layer map units.  Defaults to null.  Possible values are ‘degrees’ (or ‘dd’), ‘m’, ‘ft’, ‘km’, ‘mi’, ‘inches’.  Normally taken from the projection.  Only required if both map and layers do not define a projection, or if they define a projection which does not define units.'
1986
  );
1987

    
1988
  /*
1989
   * Map Legend
1990
   */
1991
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
1992
    '#type' => 'fieldset',
1993
    '#title' => 'Map legend',
1994
    '#tree' => TRUE,
1995
    '#collapsible' => TRUE,
1996
    '#collapsed' => TRUE,
1997
    '#description' => 'Configure the maps legend.',
1998
  );
1999

    
2000
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2001
    '#type' => 'checkbox',
2002
    '#title' => 'Display a map legend',
2003
    '#default_value' => $map_distribution['legend']['show'],
2004
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2005
  );
2006

    
2007
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2008
    '#type' => 'textfield',
2009
    '#title' => 'Legend opacity',
2010
    '#default_value' => $map_distribution['legend']['opacity'],
2011
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2012
                         to 0.0 will be not much visible.',
2013
  );
2014

    
2015
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2016
    '#type' => 'textfield',
2017
    '#title' => 'Font size',
2018
    '#default_value' => $map_distribution['legend']['font_size'],
2019
    '#description' => 'Font size in pixels.',
2020
  );
2021

    
2022
  $fontStyles = array(
2023
    0 => "plane",
2024
    1 => "italic",
2025
  );
2026
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2027
    '#type' => 'select',
2028
    '#title' => 'Available font styles',
2029
    '#default_value' => $map_distribution['legend']['font_style'],
2030
    '#options' => $fontStyles,
2031
    '#description' => 'Select a font style for the map legend.',
2032
  );
2033

    
2034
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2035
    '#type' => 'textfield',
2036
    '#title' => 'Icon width',
2037
    '#default_value' => $map_distribution['legend']['icon_width'],
2038
    '#description' => 'Legend icon width in pixels.',
2039
  );
2040
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2041
    '#type' => 'textfield',
2042
    '#title' => 'Icon height',
2043
    '#default_value' => $map_distribution['legend']['icon_height'],
2044
    '#description' => 'Legend icon height in pixels.',
2045
  );
2046

    
2047
  // @WA: D7 form api does not support reset buttons,
2048
  // so to mimic the D5 reset button we add one like this.
2049
  $form['actions']['reset'] = array(
2050
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2051
    '#weight' => 1000,
2052
  );
2053

    
2054
  return system_settings_form($form);
2055
}
2056

    
2057
/**
2058
 * @todo document this function.
2059
 */
2060
function cdm_settings_cache() {
2061

    
2062
  $form = array();
2063

    
2064
  $form['cache_settings'] = array(
2065
    '#type' => 'fieldset',
2066
    '#title' => t('Cache Settings'),
2067
    '#collapsible' => FALSE,
2068
    '#collapsed' => FALSE,
2069
    '#description' => t('<p>When caching is enabled all single taxon sites are
2070
      stored in an internal drupal cache doing the portal response of taxa pages
2071
      faster. This is possible because the sites are loaded from the cache and
2072
      are not created from scratch.</p>'),
2073
  );
2074

    
2075
  $form['cache_settings']['cdm_webservice_cache'] = array(
2076
    '#type' => 'checkbox',
2077
    '#title' => t('<strong>Enable caching</strong>'),
2078
    '#options' => cdm_help_general_cache(),
2079
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2080
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2081
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2082
       application the changes will be not visible till the cache is erased.
2083
       Therefore developers should deactived this feature when they are working
2084
       on the CDM Dataportal Module.</p>'),
2085
  );
2086

    
2087
  $form['cache_settings']['cdm_run_cache'] = array(
2088
    '#markup' => cdm_view_cache_site(),
2089
  );
2090

    
2091
  // @WA: D7 form api does not support reset buttons,
2092
  // so to mimic the D5 reset button we add one like this.
2093
  $form['actions']['reset'] = array(
2094
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2095
    '#weight' => 1000,
2096
  );
2097
  return system_settings_form($form);
2098
}
2099

    
2100
/**
2101
 * Walk and cache all taxon pages.
2102
 */
2103
function cdm_view_cache_site() {
2104

    
2105
  $out = '';
2106

    
2107
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2108

    
2109
  $request_params = array();
2110
  $request_params['class'] = "Taxon";
2111

    
2112
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2113
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2114
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2115

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

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

    
2125
  // Comment @WA: A form within a form is not valid html and not needed here.
2126
  // Also, it would be recommended just to include this part of the form in the
2127
  // rest of the form array in cdm_settings_cache().
2128
  // $out .= '<form id="cache_site">';
2129
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2130
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2131
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2132
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2133
  // $out .= '</form>';
2134
  $out .= '</div>';
2135
  /*
2136
  foreach($taxonPager->records as $taxon){
2137
    cdm_dataportal_taxon_view($uuid);
2138
  }
2139
  */
2140
  return $out;
2141
}
2142

    
2143

    
2144
function cdm_settings_layout_taxon_submit($form, &$form_state){
2145
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2146
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2147
    if(is_object($file)){
2148
      $file->status = FILE_STATUS_PERMANENT;
2149
      file_save($file);
2150
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2151
    }
2152
  }
2153
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2154
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2155
    // we first need to set the variable to persist the changes setting
2156
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
2157
    menu_rebuild();
2158
  }
2159
}
2160

    
2161
function cdm_settings_layout_search_submit($form, &$form_state){
2162
  // the visibility of media thumbnails also affects the ui of the search results
2163
  // so reset the according session variable
2164
  //    1. in order to give the user immediate
2165
  //       feedback on potential setting changes
2166
  //    2. let refresh the default if it has changed
2167
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2168
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
2169
  }
2170
}
2171

    
2172
/**
2173
 * Form validation handler for cdm_settings_general
2174
 *
2175
 * Comment @WA: currently this handler is not used.
2176
 * It seems partly for cdm_settings_general en partly for cdm_settings_cache?
2177
 * Then you can change the name into cdm_settings_general_validate() or
2178
 * cdm_settings_cache_validate().
2179
 * But cdm_api_secref_cache_clear is not doing anything (yet)?
2180
 */
2181
function cdm_settings_general_validate($form, &$form_state) {
2182

    
2183
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2184
    $form_state['values']['cdm_webservice_url'] .= '/';
2185
  }
2186

    
2187
}
2188

    
2189
/**
2190
 * Form validation handler for cdm_settings_cache
2191
 */
2192
function cdm_settings_cache_validate($form, &$form_state) {
2193
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2194
    cache_clear_all(NULL, 'cache_cdm_ws');
2195
    // Better clear secref_cache since I can not be sure if the cache has not
2196
    // be used during this response.
2197
    cdm_api_secref_cache_clear();
2198
  }
2199

    
2200
}
2201

    
2202
/**
2203
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
2204
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
2205
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
2206
 *  - version: the version, e.g.: v1.1
2207
 *
2208
 * @return array
2209
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
2210
 */
2211
function get_edit_map_service_settings() {
2212

    
2213
  $settings = variable_get('edit_map_server', array(
2214
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
2215
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
2216
      )
2217
  );
2218
  // replace old non tree like settings by default
2219
  // TODO to be removed after release 3.1.5
2220
  if(!is_array($settings)){
2221
    variable_del('edit_map_server');
2222
    return get_edit_map_service_settings();
2223
  }
2224

    
2225
  return $settings;
2226
}
2227

    
2228
/**
2229
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2230
 *
2231
 * @return string
2232
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2233
 */
2234
function get_edit_map_service_full_uri() {
2235
  $settings = get_edit_map_service_settings();
2236
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
2237
}
2238

    
2239

    
2240
/**
2241
 * Returns the version number of the currently selected edit mapserver as a float
2242
 *
2243
 * @return float
2244
 *   The version number of the currently selected edit mapserver as a float.
2245
 *   Returns 0 on error.
2246
 */
2247
function get_edit_map_service_version_number() {
2248

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

    
2251
  $settings = get_edit_map_service_settings();
2252
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
2253
  if (isset($matches[1])) {
2254
    // Convert string to float.
2255
    $version = 1 + $matches[1][0] - 1;
2256
    return $version;
2257
  }
2258
  else {
2259
    // Report error.
2260
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
2261
        array(
2262
          '!version' => $settings['version'],
2263
          'warning')
2264
        )
2265
      );
2266
    return 0;
2267
  }
2268
}
2269

    
2270
/**
2271
 * Returns the array of selected items in a options array
2272
 *
2273
 * @param array $options
2274
 *   An options array as generated by a form element like checkoxes, select ...,
2275
 */
2276
function get_selection($options) {
2277
  $selection = array();
2278
  foreach ($options as $key=>$val) {
2279
    if (!empty($val)) {
2280
      $selection[] = $val;
2281
    }
2282
  }
2283
  return $selection;
2284
}
2285

    
2286

    
2287
/**
2288
 * Implements hook_element_info().
2289
 *
2290
 * Allows modules to declare their own Form API element types and specify their default values.
2291
 *
2292
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
2293
 */
2294
function cdm_dataportal_element_info() {
2295
  $type['checkboxes_preferred'] = array(
2296
    '#input' => TRUE,
2297
    '#process' => array('checkboxes_preferred_expand'),
2298
    '#after_build' => array('checkboxes_preferred_after_build'),
2299
    '#theme' => array('checkboxes_preferred'),
2300
    // '#theme_wrapper' => array('form_element'),
2301
  );
2302
  return $type;
2303
}
2304

    
2305
/**
2306
 * #process callback function for the custom form element type 'checkbox_preferred'
2307
 *
2308
 *
2309
 */
2310
function checkboxes_preferred_expand($element, &$form_state, $form) {
2311

    
2312
  // First of all create checkboxes for each of the elements
2313
  $element = form_process_checkboxes($element);
2314

    
2315
  // compose the element name
2316
  $parents = array();
2317
  array_deep_copy($element['#parents'], $parents);
2318
  $parents[count($parents) -1 ] .= '_preferred';
2319
  $element_name = $parents[0];
2320
  for ($i=1; $i < count($parents); $i++){
2321
    $element_name .= '[' . $parents[$i] . ']';
2322
  }
2323

    
2324
  $children = element_children($element);
2325

    
2326
  $element['table_start'] = array(
2327
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
2328
    '#weight' => -1,
2329
  );
2330

    
2331
  // prepare first part each of the table rows which contains the row label
2332
  $weight = 0;
2333
  foreach ($children as $key) {
2334
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
2335
    $element[$key]['#weight'] = $weight;
2336
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
2337
    $element[$key]['#suffix'] = '</td>';
2338
    unset($element[$key]['#title']);
2339
    $weight += 2;
2340
  }
2341
  $weight = 0;
2342

    
2343
  // add a radio button to each of the checkboxes, the
2344
  // check boxes have already been created at the beginning
2345
  // of this function
2346
  if (count($element['#options']) > 0) {
2347
    foreach ($element['#options'] as $key => $choice) {
2348
      if (!isset($element[$key . '_preferred'])) {
2349
        $element[$key . '_preferred'] = array(
2350
          '#type' => 'radio',
2351
          '#name' => $element_name,
2352
          '#return_value' => check_plain($key),
2353
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
2354
          '#attributes' => $element['#attributes'],
2355
          '#parents' => $element['#parents'],
2356
          // '#spawned' => TRUE,
2357
          '#weight' => $weight + 1,
2358
          '#prefix' => '<td>',        // add a prefix to start a new table cell
2359
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
2360
        );
2361
      }
2362
      $weight += 2;
2363
    }
2364
  }
2365

    
2366
  // end the table
2367
  $element['table_end'] = array(
2368
    '#markup' => '</table>',
2369
    '#weight' => $weight++,
2370
  );
2371

    
2372
  return $element;
2373
}
2374

    
2375
/**
2376
 * Theme function for the custom form field 'checkboxes_preferred'.
2377
 */
2378
function theme_checkboxes_preferred($variables) {
2379
  $element = $variables['element'];
2380
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
2381
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
2382
  $out .= drupal_render_children($element);
2383
  $out .= '<div class="description">' . $element['#description'] . '</div>';
2384
  $out .= '</div>';
2385
  return $out;
2386
}
2387

    
2388
/**
2389
 * Callback for checkboxes preferred for widget which will
2390
 * be called after the form or element is built. The call
2391
 * back is configured in the form element by setting it as
2392
 * #after_build parameter.
2393
 *
2394
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
2395
 *
2396
 * @param $element
2397
 *   Nested array of form elements that comprise the form.
2398
 * @param $form_state
2399
 *   A keyed array containing the current state of the form.
2400
 *   This includes the current persistent storage data for the form.
2401
 *   Additional information, like the sanitized $_POST data,
2402
 *   is also accumulated here in $form_state['input']
2403
 *
2404
 * @return the modified form array
2405
 */
2406
function checkboxes_preferred_after_build($element, &$form_state) {
2407

    
2408
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
2409

    
2410
  if ($_POST && count($_POST) > 0) {
2411
    // TODO use  $form_state['input'] instead of POST !!!
2412
    // First pass of form processing.
2413
    $parents = array();
2414
    array_deep_copy($element['#parents'], $parents);
2415
    $parents[count($parents) - 1] .= '_preferred';
2416
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
2417
    $element['#value']['PREFERRED'] = $preferred_layer;
2418
//     $form_state[$parent_id] = $element['#value'];
2419
//     $form_state['values']['baselayers'] = $element['#value'];
2420
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
2421
    $form_state_element_values = $element['#value'];
2422
  }
2423
  else {
2424
    // Second pass of form processing.
2425
    $preferred_layer = $element['#value']['PREFERRED'];
2426
  }
2427

    
2428
  // Also set the chosen value (not sure if this is good Drupal style ....).
2429
  foreach ($children = element_children($element) as $key) {
2430
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
2431
      $element[$key]['#value'] = $preferred_layer;
2432
    }
2433
  }
2434
  // The default layer must always be enabled.
2435
  $element[$preferred_layer]['#value'] = $preferred_layer;
2436

    
2437
  return $element;
2438
}
2439

    
2440
function radios_prepare_options_suffix(&$elements){
2441

    
2442
  $childrenKeys = element_children($elements);
2443
  foreach($childrenKeys as $key){
2444
    if(!is_array($elements[$key]['#theme_wrappers'])){
2445
      $elements[$key]['#theme_wrappers'] = array();
2446
    }
2447
    if(isset($elements['#options_suffixes'][$key])){
2448
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
2449
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
2450
    }
2451
  }
2452
  return $elements;
2453

    
2454
}
2455

    
2456
/**
2457
 * TODO
2458
 * @param unknown $variables
2459
 */
2460
function theme_radio_options_suffix($variables) {
2461
  $element = $variables['element'];
2462
  if(isset($element['#options_suffix'])) {
2463
    $element['#children'] .= $element['#options_suffix'];
2464
  }
2465
  return $element['#children'];
2466
}
2467

    
2468

    
2469
/**
2470
 * Element validate callback for text field and arrays containing json.
2471
 *
2472
 * @param $element
2473
 *   The form element to validate
2474
 * @param $form_state
2475
 *   A keyed array containing the current state of the form.
2476
 * @param $form
2477
 *   Nested array of form elements that comprise the form.
2478
 */
2479
function form_element_validate_json($element, &$form_state, $form) {
2480
   if (!empty($element['#value'])) {
2481
     json_decode($element['#value']);
2482
     if(json_last_error() != JSON_ERROR_NONE){
2483
       form_error($element, t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title'])) . l('JSONLint', 'http://jsonlint.com/'));
2484
     }
2485
   }
2486
}
2487

    
2488
/**
2489
 * Form submission handler for textareas and textfields containing JSON.
2490
 *
2491
 * The contained JSON will be converted into an php array
2492
 * or object and will be stored in the variables as such.
2493
 *
2494
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2495
 *
2496
 * @param $form
2497
 *   Nested array of form elements that comprise the form.
2498
 * @param $form_state
2499
 *   A keyed array containing the current state of the form.
2500
 *
2501
 */
2502
function submit_json_as_php_array($form, &$form_state) {
2503
  if (is_array($form['#json_elements'])) {
2504
    foreach ($form['#json_elements'] as $element){
2505
      if (trim($form_state['values'][$element])) {
2506
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
2507
      } else {
2508
        $form_state['values'][$element] = NULL;
2509
      }
2510
    }
2511
  }
2512
}
(14-14/14)