Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / 7.x / modules / cdm_dataportal / settings.php @ 2bbc28c8

History | View | Annotate | Download (95.1 KB)

1
<?php
2
/**
3
 * @file
4
 * CDM Dataportal settings.
5
 */
6

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

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

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

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

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

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

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

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

    
84
define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
85
define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
86
define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
87
    array(
88
        'show' => 0,
89
        'maxextend' => 184,
90
        'media_uri_query' => '',
91
        'custom_placeholder_image_on' => 0,
92
        'custom_placeholder_image_fid' => ''
93
    )
94
  )
95
);
96

    
97
/**
98
 * @todo document this function
99
 */
100
function get_taxon_tabs_list() {
101
  return array(
102
    0 => 'General',
103
    1 => 'Synonymy',
104
    2 => 'Images',
105
    3 => 'Specimens',
106
    4 => 'Keys',
107
  );
108
}
109

    
110
$taxon_tab_options = get_taxon_tabs_list();
111
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
112

    
113
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
114

    
115
/**
116
 * @todo document this function.
117
 */
118
function get_taxon_options_list() {
119
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
120
  foreach ($taxon_tab_options as $key => $value) {
121
    $taxon_tab_options[$key] = t($key);
122
  }
123
  return $taxon_tab_options;
124

    
125
}
126

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

    
192
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
193
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
194
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
195
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
196
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
197
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
198
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
199
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
200
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
201
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
202
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
203
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
204
/**
205
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
206
 * the snonymy.
207
 *
208
 * @var string
209
 */
210
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
211
/**
212
 * The drupal variable for the configuration of the information aggregation along
213
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
214
 *    - direct: the uuids of the taxon relationship types to take into account in invers
215
 *      direction.
216
 *    - invers: the uuids of the taxon relationship types to take into account in direct
217
 *      direction.
218
 *
219
 * @var String
220
 */
221
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
222
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
223
    array(
224
        'direct'=>array(),
225
        'invers'=>array()
226
     )
227
   ));
228
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
229
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
230
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
231

    
232
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
233
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
234
    array(
235
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
236
        'includeOccurrences' => 0,
237
        'includeTaxonNameDescriptions' => 0
238
     )
239
  ));
240

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

    
285
/**
286
 * Merges the named array variable with the array of defaults.
287
 *
288
 * @param string $variable_name
289
 *     The variable name
290
 * @param string | array $default
291
 *     The array containing the default values either as array or serialized as string.
292
 *     Unserialization is cared for if nessecary
293
 * @return array
294
 *     The merged array as returnd by drupal_array_merge_deep()
295
 */
296
function get_array_variable_merged($variable_name, $default){
297

    
298
    // unserialize if nessecary
299
    if(!is_array($default)){
300
      $default = unserialize($default);
301
    }
302
    $variable = variable_get($variable_name, array());
303
    return drupal_array_merge_deep($default, $variable);
304
}
305

    
306
/**
307
 * @todo document this function.
308
 */
309
function getGallerySettings($gallery_config_form_name) {
310
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
311
}
312

    
313
/**
314
 * Returns the string representation of the default tab.
315
 *
316
 * @param bool $returnTabIndex
317
 *   Defaults to FALSE, if set true this function will return the index number
318
 *   of the default tab. (used to supply default values to form elements).
319
 */
320
function get_default_taxon_tab($returnTabIndex = FALSE) {
321

    
322
  global $user;
323
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
324
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
325
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
326
  // Get the user value if the used has chosen to overwrite the system settings.
327
  $user_tab_on = variable_get($user_tab_active, FALSE);
328
  if ($user_tab_on) {
329
    $user_value = variable_get($user_tab, 0);
330
    $index_value = $user_value;
331
    // Get the system value.
332
  }
333
  else {
334
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
335
    $index_value = $system_value;
336
  }
337

    
338
  // Return the index value or the string representation.
339
  if ($returnTabIndex) {
340
    return $index_value;
341
  }
342
  else {
343
    return ($values[$index_value]);
344
  }
345

    
346
}
347

    
348
/**
349
 * @todo Please document this function.
350
 * @see http://drupal.org/node/1354
351
 */
352
function cdm_dataportal_menu_admin(&$items) {
353
  // Display section on admin/config page.
354
  $items['admin/config/cdm_dataportal'] = array(
355
    'title' => 'CDM Dataportal',
356
    'description' => 'Settings for the CDM DataPortal.',
357
    'position' => 'right',
358
    'weight' => 10,
359
    'page callback' => 'system_admin_menu_block_page',
360
    'access arguments' => array('administer cdm_dataportal'),
361
    'file' => 'system.admin.inc',
362
    'file path' => drupal_get_path('module', 'system'),
363
  );
364
  $items['admin/config/cdm_dataportal/settings'] = array(
365
    'title' => 'Settings',
366
    'description' => 'Settings for the CDM DataPortal.',
367
    'weight' => 0,
368
    'page callback' => 'drupal_get_form',
369
    'page arguments' => array('cdm_settings_general'),
370
    'access arguments' => array('administer cdm_dataportal'),
371
    'type' => MENU_NORMAL_ITEM,
372
  );
373
  $items['admin/config/cdm_dataportal/settings/general'] = array(
374
    'title' => 'General',
375
    'description' => 'General',
376
    'weight' => 0,
377
    'page callback' => 'drupal_get_form',
378
    'page arguments' => array('cdm_settings_general'),
379
    'access arguments' => array('administer cdm_dataportal'),
380
    'type' => MENU_DEFAULT_LOCAL_TASK,
381
  );
382

    
383
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
384
    'title' => 'Cache',
385
    'description' => 'Cache',
386
    'access arguments' => array('administer cdm_dataportal'),
387
    'page callback' => 'drupal_get_form',
388
    'page arguments' => array('cdm_settings_cache'),
389
    'weight' => 10,
390
    'type' => MENU_LOCAL_TASK,
391
  );
392

    
393
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
394
    'title' => 'Geo & Map',
395
    'description' => 'Geo & Map',
396
    'access arguments' => array('administer cdm_dataportal'),
397
    'page callback' => 'drupal_get_form',
398
    'page arguments' => array('cdm_settings_geo'),
399
    'weight' => 1,
400
    'type' => MENU_LOCAL_TASK,
401
  );
402

    
403
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
404
    'title' => 'Layout',
405
    'description' => 'Configure and adjust the layout of your DataPortal ',
406
    'access arguments' => array('administer cdm_dataportal'),
407
    'page callback' => 'drupal_get_form',
408
    'page arguments' => array('cdm_settings_layout'),
409
    'weight' => 2,
410
    'type' => MENU_LOCAL_TASK,
411
  );
412

    
413
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
414
    'title' => 'Taxon',
415
    'description' => 'Configure and adjust the layout of your DataPortal ',
416
    'access arguments' => array('administer cdm_dataportal'),
417
    'page callback' => 'drupal_get_form',
418
    'page arguments' => array('cdm_settings_layout_taxon'),
419
    'weight' => 1,
420
    'type' => MENU_LOCAL_TASK,
421
  );
422
  /*
423
  $items[] = array(
424
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
425
  'title' => t('Synonymy'),
426
  'description' => t('Configure and adjust the layout of your DataPortal '),
427
  'access' => user_access('administer cdm_dataportal'),
428
  'callback' => 'drupal_get_form',
429
  'callback arguments' => array('cdm_settings_layout_synonymy'),
430
  'weight' => 1,
431
  'type' => MENU_LOCAL_TASK,
432
  );
433

434
  $items[] = array(
435
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
436
  'title' => t('Specimens'),
437
  'description' => t('Configure and adjust the layout of your DataPortal '),
438
  'access' => user_access('administer cdm_dataportal'),
439
  'callback' => 'drupal_get_form',
440
  'callback arguments' => array('cdm_settings_layout_specimens'),
441
  'weight' => 1,
442
  'type' => MENU_LOCAL_TASK,
443
  );
444
  */
445
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
446
    'title' => 'Search',
447
    'description' => 'Configure and adjust the layout of your DataPortal ',
448
    'access arguments' => array('administer cdm_dataportal'),
449
    'page callback' => 'drupal_get_form',
450
    'page arguments' => array('cdm_settings_layout_search'),
451
    'weight' => 2,
452
    'type' => MENU_LOCAL_TASK,
453
  );
454

    
455
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
456
    'title' => 'Media',
457
    'description' => 'Configure and adjust the layout of your DataPortal ',
458
    'access arguments' => array('administer cdm_dataportal'),
459
    'page callback' => 'drupal_get_form',
460
    'page arguments' => array('cdm_settings_layout_media'),
461
    'weight' => 3,
462
    'type' => MENU_LOCAL_TASK,
463
  );
464

    
465
}
466

    
467
/**
468
 * @todo document this function.
469
 */
470
function cdm_help_general_cache() {
471
  $form = array();
472
  $form['cache_help'] = array(
473
    '#type' => 'fieldset',
474
    '#title' => t('Help'),
475
    '#collapsible' => TRUE,
476
    '#collapsed' => TRUE,
477
  );
478
  $form['cache_help']['test'] = array('#value' => t('probando'));
479
  return drupal_render($form);
480
  $res = array();
481
  $res['default'] = drupal_render($help);
482
  return $res;
483
}
484

    
485
/**
486
 * Configures the settings form for the CDM-API module.
487
 *
488
 * @return array
489
 *   Drupal settings form.
490
 */
491
function cdm_settings_general() {
492

    
493
  $form['cdm_webservice'] = array(
494
    '#type' => 'fieldset',
495
    '#title' => t('CDM Server'),
496
    '#collapsible' => FALSE,
497
    '#collapsed' => FALSE,
498
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
499
        CDM data base to the web via RESTful web services and thus is the source of the data
500
        to be displayed by a CDM DataPotal.'),
501
  );
502

    
503
  $form['cdm_webservice']['cdm_webservice_url'] = array(
504
    '#type' => 'textfield',
505
    '#title' => t('CDM web service URL') . ':',
506
    '#description' => t('This is the URL to the CDM-Server exposing your data
507
      e.g. <em>"http://localhost:8080/cichorieae/"</em> The URL <strong>must end
508
      with a slash</strong> character!'),
509
    '#default_value' => variable_get('cdm_webservice_url', NULL),
510
  );
511

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

    
519
  $form['cdm_webservice']['freetext_index'] = array(
520
    '#type' => 'fieldset',
521
    '#title' => t('Freetext index'),
522
    '#collapsible' => FALSE,
523
    '#collapsed' => FALSE,
524
  );
525

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

    
538
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
539
  $trigger_link_options = array(
540
    'attributes' => array(
541
      'class' => 'index-trigger',
542
    ),
543
  );
544
  $form['cdm_webservice']['freetext_index']['operations'] = array(
545
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
546
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
547
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
548
      ))
549
    . '<div id="index-progress"></div></div>',
550
  );
551
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
552

    
553
  $form['cdm_webservice']['proxy'] = array(
554
    '#type' => 'fieldset',
555
    '#title' => t('Proxy'),
556
    '#collapsible' => TRUE,
557
    '#collapsed' => TRUE,
558
  );
559

    
560
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
561
    '#type' => 'textfield',
562
    '#title' => t('Proxy URL') . ':',
563
    '#description' => t('If this proxy url is set the cdm api tries
564
    to connect the web service over the given proxy server.
565
    Otherwise proxy usage is deactivated.'),
566
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
567
  );
568

    
569
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
570
    '#type' => 'textfield',
571
    '#title' => t('Proxy port') . ':',
572
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
573
  );
574

    
575
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
576
    '#type' => 'textfield',
577
    '#title' => t('Login') . ':',
578
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
579
  );
580

    
581
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
582
    '#type' => 'textfield',
583
    '#title' => t('Password') . ':',
584
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
585
  );
586

    
587
  // TODO: settings are still incomplete, compare with
588
  // trunk/dataportal/inc/config_default.php.inc.
589
  $form['taxon_tree'] = array(
590
    '#type' => 'fieldset',
591
    '#title' => t('Taxon Tree'),
592
    '#collapsible' => FALSE,
593
    '#collapsed' => TRUE,
594
    '#description' => t('<p>When you explore your collection, you can navigate
595
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
596
      able to navigate through your collection the
597
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
598
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
599
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
600
      </a></p>'),
601
  );
602

    
603
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
604
    '#type' => 'select',
605
    '#title' => t('Available classifications') . ':',
606
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
607
    '#options' => cdm_get_taxontrees_as_options(),
608
    '#description' => t('Select the default taxa classification for your
609
      <em>taxon tree</em>, the other classifications will be also available but
610
      with a manual user change.'),
611
  );
612

    
613
  $form['taxon_tree']['taxontree_ranklimit'] = array(
614
    '#type' => 'select',
615
    '#title' => t('Rank of highest displayed taxon') . ':',
616
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
617
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
618
    '#options' => cdm_rankVocabulary_as_option(),
619
    '#description' => t('This is the rank of the highest displayed taxon in the
620
      <em>taxon tree</em>. You can select here which rank should be at the top
621
      level of the tree structure.'),
622
  );
623

    
624
  $form['aggregation'] = array(
625
      '#type' => 'fieldset',
626
      '#title' => t('Aggregation of data'),
627
      '#collapsible' => FALSE,
628
      '#description' => t("This section covers the different aspects of aggregating information.
629
          <p>
630
          </p>"),
631

    
632
  );
633

    
634
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
635
      '#type' => 'checkboxes',
636
      '#title' => 'Taxon media filter',
637
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
638
      '#options' => array(
639
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
640
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
641
          'includeOccurrences' => 'Media related to specimens and occurrences',
642
      ),
643
      '#description' => 'This filter configures which images should be taken into account.',
644
  );
645

    
646
  $form['aggregation']['notice'] = array(
647
      '#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
648
          want to make use of the caching capabilities of the dataportal.',
649
  );
650

    
651
  $form['aggregation']['media_aggregation'] = array(
652
      '#type' => 'fieldset',
653
      '#title' => t('Media aggregation'),
654
      '#collapsible' => FALSE,
655
      '#collapsed' => TRUE,
656
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
657

    
658
  );
659
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
660
      '#type' => 'select',
661
      '#title' => t('Aggregation of taxon pictures') . ':',
662
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
663
      '#options' => array(
664
          0 => "Show only pictures of the current taxon",
665
          1 => "Include pictures of taxonomic children",
666
      ),
667
      '#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."),
668
  );
669

    
670
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
671
      '#type' => 'fieldset',
672
      '#attributes' => array('class'=>array('clearfix')),
673
      '#title' => t('Aggregation via taxon relationsships'),
674
      '#collapsible' => TRUE,
675
      '#collapsed' => TRUE,
676
      '#tree' => TRUE,
677
      '#description' => t('Information on taxa will be aggregated along the below chosen
678
          taxon relation ships. This will affect images and occurrences (specimens).
679
          Taxon relation ships are directed and point form one taxon to another. The taxon
680
          relationships to be taken into accunt can therefore configured for the direct direction
681
          and for the inverse.'),
682
  );
683

    
684
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
685
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
686

    
687
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
688
      '#type' => 'checkboxes',
689
      '#title' => t('Direct'),
690
      '#options' => $taxonRelationshipTypeOptions,
691
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
692
  );
693
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
694
      '#type' => 'checkboxes',
695
      '#title' => t('Invers'),
696
      '#options' => $taxonRelationshipTypeOptions,
697
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
698
  );
699

    
700
  // Comment @WA: D7 form api does not support reset buttons,
701
  // so to mimic the D5 reset button we add one like this.
702
  $form['actions']['reset'] = array(
703
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
704
    '#weight' => 1000,
705
  );
706

    
707
  return system_settings_form($form);
708
}
709

    
710

    
711
/**
712
 * LAYOUT settings
713
 * @return unknown_type
714
 *   todo
715
 */
716
function cdm_settings_layout() {
717

    
718
  $form = array();
719

    
720
  $form['about'] = array(
721
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
722
      layout. If you want to configure the specific sites layout visit the
723
      respective configuration site for taxon, search or media.') . '</p>',
724
  );
725

    
726
  // ---- footnotes --- //
727
  $form['footnotes'] = array(
728
    '#type' => 'fieldset',
729
    '#title' => t('Footnotes'),
730
    '#collapsible' => FALSE,
731
    '#collapsed' => FALSE,
732
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
733
      media or distribution areas may have annotations or footnotes. When the
734
      footnotes are enabled they will be visible (if they exist).'),
735
  );
736

    
737
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
738
    '#type' => 'checkbox',
739
    '#title' => t('Do not show footnotes'),
740
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
741
    '#description' => t('Check this if you do not want to show any footnotes'),
742
  );
743

    
744
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
745
    '#type' => 'checkbox',
746
    '#title' => t('Do not show annotations footnotes'),
747
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
748
    '#description' => t('Check this if you do not want to show annotation footnotes'),
749
  );
750

    
751
  $annotationTypeOptions = cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE);
752
  // Additional option for the NULL case.
753
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
754
  $form['footnotes']['annotations_types_as_footnotes'] = array(
755
    '#type' => 'checkboxes',
756
    '#title' => t('Annotation types as footnotes'),
757
    '#description' => t("Only annotations of the selected type will be displayed
758
       as footnotes. You may want to turn 'technical annotations' off."),
759
    '#options' => $annotationTypeOptions,
760
  );
761
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
762
  if (!empty($annotationsTypesAsFootnotes)) {
763
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
764
  }
765

    
766
  // --- Advanced Search --- //
767
  $form['asearch'] = array(
768
      '#type' => 'fieldset',
769
      '#title' => t('Advanced search'),
770
      '#collapsible' => FALSE,
771
      '#collapsed' => FALSE,
772
  );
773
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
774
      '#type' => 'checkbox',
775
      '#title' => t('Show advanced search link'),
776
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
777
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
778
  );
779

    
780
  // ---- Taxon Name Rendering --- //
781
  $form['taxon_name'] = array(
782
      '#type' => 'fieldset',
783
      '#title' => t('Taxon name display'),
784
      '#collapsible' => TRUE,
785
      '#collapsed' => TRUE,
786
      '#description' => t('The display of taxon names is configured by two parts.'
787
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
788
          . 'The name parts are defined in the <stong>part definitions</strong>'),
789
  );
790

    
791
  drupal_add_js(
792
      'jQuery(document).ready( function( ) {
793
         // pretty print json
794
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
795
         var obj = JSON.parse(json_text);
796
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
797

798
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
799
         obj = JSON.parse(json_text);
800
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
801
       });'
802
      ,array(
803
          'type' => 'inline',
804
          'scope' => 'footer'
805
      )
806
  );
807

    
808
  //TODO remove after all portals are using the settings
809
  $default_part_definitions = theme('get_partDefinition', array());
810
  if(!is_array($default_part_definitions)) {
811
    $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
812
  }
813

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

    
901
  //TODO remove after all portals are using the settings
902
  $default_render_templates = theme('get_nameRenderTemplate', array());
903
  if(!is_array($default_render_templates)) {
904
    $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
905
  }
906

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

    
945
  // @WA: D7 form api does not support reset buttons,
946
  // so to mimic the D5 reset button we add one like this.
947
  $form['actions']['reset'] = array(
948
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
949
    '#weight' => 1000,
950
  );
951

    
952
  $form['#submit'] = array('submit_json_as_php_array');
953
  // #json_elements especially defined for submit_json_as_php_array()
954
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
955
  return system_settings_form($form);
956
}
957

    
958

    
959
/**
960
 * @todo Please document this function.
961
 * @see http://drupal.org/node/1354
962
 */
963
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
964
  $form[$form_name] = array(
965
    '#type' => 'fieldset',
966
    '#title' => t($form_title),
967
    '#collapsible' => TRUE,
968
    '#collapsed' => $collapsed,
969
    '#tree' => TRUE,
970
    '#description' => t($form_description),
971
  );
972

    
973
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
974
  $gallery_settings = variable_get($form_name, $default_values);
975
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
976
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
977
    /*
978
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
979
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
980
    '#type' => 'textfield',
981
    '#title' => t('Search Page Size'),
982
    '#default_value' => $test,
983
    '#description' => t('Number of Names to display per page in search results.')
984
    );
985
    */
986
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
987
      '#type' => 'checkbox',
988
      '#title' => t('Show media thumbnails for accepted taxa'),
989
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
990
    );
991

    
992
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
993
      '#type' => 'checkbox',
994
      '#title' => t('Show media thumbnails for synonyms'),
995
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
996
      '#description' => '',
997
    );
998
  }
999

    
1000
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1001
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1002
    '#type' => 'checkbox',
1003
    '#title' => t('Show captions under thumbnails'),
1004
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1005
    '#description' => '',
1006
  );
1007

    
1008
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1009
    '#type' => 'textfield',
1010
    '#title' => t('Thumbnail size') . ':',
1011
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1012
    '#description' => t('Select the size of each individual thumbnail.'),
1013
  );
1014

    
1015
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1016
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1017
      '#type' => 'textfield',
1018
      '#title' => t('Number of columns') . ':',
1019
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1020
      '#description' => t('Group the thumbnails in columns: select how many
1021
        columns the gallery should display.'),
1022
    );
1023
  }
1024

    
1025
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1026
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1027
      '#type' => 'textfield',
1028
      '#title' => t('Maximum number of rows') . ':',
1029
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1030
      '#description' => t('You can group the thumbnails in rows, select in how
1031
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1032
        If you want an unlimited number of rows please set to 0.'),
1033
    );
1034
  }
1035

    
1036
  return $form;
1037
}
1038

    
1039
/**
1040
 * @todo document this function.
1041
 */
1042
function cdm_settings_layout_taxon() {
1043
  $collapsed = FALSE;
1044
  $form = array();
1045

    
1046
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1047

    
1048
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1049
      '#type' => 'checkbox',
1050
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1051
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1052
      '#description' => t('<p>If checked the link to search results is rendered at
1053
       the top of the taxon site. Clicking on the link the last search performed
1054
       is rendered again.</p>'),
1055
  );
1056

    
1057
  // --------- TABBED TAXON ------- //
1058
  $form['taxon_tabs'] = array(
1059
    '#type' => 'fieldset',
1060
    '#title' => t('Taxon tabs'),
1061
    '#collapsible' => TRUE,
1062
    '#collapsed' => FALSE,
1063
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1064
      be splitted in four diferent tabs; General, Synonymy, Images and
1065
      Specimens. If the taxon has no information for any of the tabs/sections
1066
      such tab will be not displayed.'),
1067
  );
1068

    
1069
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1070
    '#type' => 'checkbox',
1071
    '#title' => t('Tabbed taxon page'),
1072
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1073
    '#description' => t('<p>If selected split the taxon page into individual
1074
      tabs for description, images, synonymy and specimens. If not the taxon
1075
      data is rendered as a long single page without tabs.</p>'),
1076
  );
1077

    
1078
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1079
    '#type' => 'checkboxes',
1080
    '#title' => t('Tabs visibility options') . ':',
1081
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1082
    '#options' => get_taxon_options_list(),
1083
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1084
  );
1085

    
1086
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1087
    '#type' => 'select',
1088
    '#title' => t('Default tab to display') . ':',
1089
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1090
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1091
    '#description' => t('<p>Select the default tab to display when visiting a
1092
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1093
      <strong>Note:</strong> After performing a search and clicking in any
1094
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1095
      taxon and not the above selected tab.'),
1096
  );
1097

    
1098
  /* ======  TAXON_PROFILE ====== */
1099
  $form['taxon_profile'] = array(
1100
    '#type' => 'fieldset',
1101
    '#title' => t('Taxon profile (tab)'),
1102
    '#description' => t('<p>This section covers the settings related to the taxon
1103
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1104
    '#collapsible' => TRUE,
1105
    '#collapsed' => TRUE,
1106
  );
1107

    
1108
  // ---- PROFILE PICTURE ----//
1109

    
1110
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1111
    '#type' => 'fieldset',
1112
    '#tree' => TRUE,
1113
    '#title' => t('Taxon profile picture'),
1114
    '#collapsible' => TRUE,
1115
    '#collapsed' => FALSE,
1116
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1117
  );
1118

    
1119
  //FIXME migrate variables:
1120
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1121
  // FIXME
1122
  //  eanable file modul in profile and in update
1123

    
1124
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1125
  /*
1126
   * 'show' => 1,
1127
   * 'maxextend' => 184,
1128
   * 'media_uri_query' => ''
1129
   * 'custom_placeholder_image_on' => 1,
1130
   * 'custom_placeholder_image_fid' => ''
1131
   */
1132
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1133
    '#type' => 'checkbox',
1134
    '#title' => t('Enable profil picture'),
1135
    '#description' => t('Show the profil picture.'),
1136
    '#default_value' => $taxon_profile_image_settings['show'],
1137
  );
1138

    
1139
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1140
      '#type' => 'textfield',
1141
      '#tree' => TRUE,
1142
      '#title' => t('Profil picture maximum extend'),
1143
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1144
      '#field_suffix' => 'px',
1145
      '#maxlength' => 4,
1146
      '#size' => 4,
1147
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1148
  );
1149

    
1150
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1151
      '#type' => 'textfield',
1152
      '#tree' => TRUE,
1153
      '#title' => t('Additional URI query parameter'),
1154
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1155
      '#maxlength' => 1024,
1156
      '#size' => 60,
1157
      '#description' => t('Additional query parameters to be used when requesting for the '
1158
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1159
          . 'The query parameters will be appendend to the uri of the media representation part'
1160
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1161
  );
1162

    
1163
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1164
      '#type' => 'checkbox',
1165
      '#title' => t('Use a custom placeholder image'),
1166
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1167
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1168
  );
1169

    
1170
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1171
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1172
        '#type' => 'managed_file',
1173
        '#title' => t('Custom placeholder image file'),
1174
        '#progress_indicator' => 'bar',
1175
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1176
    //       '#name' => 'custom_placeholder_image',
1177
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1178
    );
1179

    
1180
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1181
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1182
      $url = file_create_url($profile_image_file->uri);
1183
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1184
                '#type' => 'item',
1185
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1186
      );
1187
    }
1188
  } else {
1189
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1190
        '#type' => 'hidden',
1191
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1192
    );
1193
  }
1194

    
1195

    
1196

    
1197
  $options = cdm_rankVocabulary_as_option();
1198
  array_unshift($options, '-- DISABLED --');
1199
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1200
    '#type' => 'select',
1201
    '#title' => t('Hide profile picture for higher ranks') . ':',
1202
    '#default_value' => variable_get('image_hide_rank', '0'),
1203
    '#options' => $options,
1204
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1205
  );
1206

    
1207
  // -- MEDIA THUMBNAILS -- //
1208
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1209
  $form_title = 'Taxon Profile Images';
1210
  $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>';
1211
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1212

    
1213
  // ---- FEATURE TREE ---- //
1214
  $form['taxon_profile']['feature_trees'] = array(
1215
    '#type' => 'fieldset',
1216
    '#title' => t('Features'),
1217
    '#collapsible' => TRUE,
1218
    '#collapsed' => FALSE,
1219
    '#description' => t("This section covers settings related to the taxon's
1220
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1221
      features such as description, distribution, common names, etc. that Drupal
1222
      will render at the taxon profile page."),
1223
  );
1224
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1225
  $saved_uuid = variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1226
  if(!isset($featureTrees['options'][$saved_uuid])) {
1227
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1228
  }
1229
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
1230
    '#type' => 'radios',
1231
    '#title' => t('Taxon profile sections') . ':',
1232
    '#default_value' => $saved_uuid,
1233
    '#options' =>  $featureTrees['options'],
1234
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1235
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1236
    '#description' => t('Select the Feature Tree to be displayed at the taxon
1237
      profile. Click "Show Details" to see the Feature Tree elements.'
1238
    ),
1239
  );
1240
  $featureTrees = cdm_get_featureTrees_as_options();
1241
  $saved_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1242
  if(!isset($featureTrees['options'][$saved_uuid])) {
1243
    $saved_uuid = NULL;
1244
  }
1245
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
1246
    '#type' => 'radios',
1247
    '#title' => t('Natural language representation of structured descriptions') . ':',
1248
    '#default_value' => $saved_uuid,
1249
    '#options' => $featureTrees['options'],
1250
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1251
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1252
    '#description' => t('Taxon descriptions can be stored in a highly structured
1253
      form. The feature tree selected here will be used to generate textual
1254
      representation in natural language.'
1255
    ),
1256
  );
1257

    
1258
  // ---- LAYOUT PER FEATURE ---- //
1259
  $feature_tree = get_profile_featureTree();
1260
  if (isset($feature_tree->root->children)) {
1261

    
1262
    $form_feature_list_layout = array(
1263
      '#title' => t('Taxon profile layout'),
1264
      '#collapsible' => TRUE,
1265
      '#collapsed' => FALSE,
1266
      '#type' => 'fieldset',
1267
      '#description' => t('Will be available in a future release.'),
1268
    );
1269

    
1270
    $feature_list_layout_settings_disabled = TRUE;
1271
    foreach ($feature_tree->root->children as $featureNode) {
1272

    
1273
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1274
        // Must not exceed 45 characters !!!
1275
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1276

    
1277
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1278
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1279

    
1280
        $form_feature_list_layout[$subform_id] = array(
1281
          '#tree' => TRUE,
1282
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1283
          '#collapsible' => FALSE,
1284
          '#collapsed' => FALSE,
1285
          '#type' => 'fieldset',
1286
          '#description' => t(''),
1287
        );
1288

    
1289
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1290
          '#type' => 'checkbox',
1291
          '#title' => t('Enable'),
1292
          '#default_value' => $settings['enabled'],
1293
          '#description' => t('Enable user defined layout for this feature'),
1294
        );
1295

    
1296
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1297
          '#type' => 'textfield',
1298
          '#title' => t('Enclosing tag'),
1299
          '#disabled' => !$settings['enabled'],
1300
          '#default_value' => $settings['enclosingTag'],
1301
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1302
        );
1303

    
1304
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1305
          '#type' => 'textfield',
1306
          '#title' => t('Entry enclosing tag'),
1307
          '#disabled' => !$settings['enabled'],
1308
          '#default_value' => $settings['entryEnclosingTag'],
1309
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1310
        );
1311

    
1312
        $form_feature_list_layout[$subform_id]['glue'] = array(
1313
          '#type' => 'textfield',
1314
          '#title' => t('Glue'),
1315
          '#disabled' => !$settings['enabled'],
1316
          '#default_value' => $settings['glue'],
1317
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1318
        );
1319

    
1320
      }
1321

    
1322
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1323
    }
1324
  }
1325

    
1326
  // ---- DISTRIBUTION LAYOUT ---- //
1327
  $form['taxon_profile']['distribution_layout'] = array(
1328
    '#title' => t('Distribution'),
1329
    '#collapsible' => TRUE,
1330
    '#collapsed' => FALSE,
1331
    '#type' => 'fieldset',
1332
    '#description' => t('Select if you want to sort or not the distribution text
1333
      located below the distribution map.'),
1334
  );
1335

    
1336
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1337
    '#type' => 'radios',
1338
    '#title' => t('Sort') . ':',
1339
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1340
    '#options' => array(
1341
      'NO_SORT' => t('Standard (No sort)'),
1342
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1343
    ),
1344
  );
1345

    
1346
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1347
    '#type' => 'checkbox',
1348
    '#title' => t('Show TextData elements on top of the map'),
1349
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1350
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1351
      elements on top of the map. Otherwise all <code>TextData</code>
1352
      distribution elements will be listed below the other area elements.
1353
      This option is useful if you need to have descriptive texts for each
1354
      distribution map.'),
1355
  );
1356

    
1357

    
1358
  /* ====== SYNONYMY ====== */
1359
  $form['taxon_synonymy'] = array(
1360
    '#type' => 'fieldset',
1361
    '#title' => t('Taxon synonymy (tab)'),
1362
    '#collapsible' => TRUE,
1363
    '#collapsed' => TRUE,
1364
    '#description' => t('This section covers the settings related to the taxon
1365
      <strong>synonymy</strong> tab.'),
1366
  );
1367

    
1368
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1369
    '#type' => 'checkbox',
1370
    '#title' => t('Show accepted taxon on top of the synonymy'),
1371
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1372
    '#description' => t('If checked, the first homotypic taxon is a repetition
1373
      of the accepted taxon most likely with the full nomenclatural reference
1374
      (depending on the currently chosen theme).'),
1375
  );
1376

    
1377
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1378
    '#type' => 'checkbox',
1379
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1380
      coming from a synonym link.'),
1381
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1382
    '#description' => t('Check this if after doing a search and clicking on a
1383
      synonym you want to see the "accept of" text for the accepted synonym.'),
1384
  );
1385

    
1386
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1387
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1388
    '#type' => 'checkboxes',
1389
    '#title' => t('Display name relationships') . ':',
1390
    '#default_value' => variable_get('name_relationships_to_show', 0),
1391
    '#options' => $nameRelationshipTypeOptions,
1392
    '#description' => t('Select the name relationships you want to show for the
1393
      accepted taxa.'),
1394
  );
1395

    
1396
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1397
    '#type' => 'checkbox',
1398
    '#title' => t('Show taxon relations ships of accepted taxon'),
1399
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1400
    '#description' => t('If this option is enabled the synonymy will show the
1401
      below selected taxon relationships of accepted taxa.'),
1402
  );
1403

    
1404
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1405
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1406
    '#type' => 'checkboxes',
1407
    '#title' => t('Taxon relationship types') . ':',
1408
    '#description' => t('Only taxon relationships of the selected type will be
1409
      displayed'),
1410
    '#options' => $taxonRelationshipTypeOptions,
1411
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1412
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1413
  );
1414

    
1415
  // ====== SPECIMENS ====== //
1416
  $form['taxon_specimens'] = array(
1417
    '#type' => 'fieldset',
1418
    '#title' => t('Taxon specimens (tab)'),
1419
    '#collapsible' => TRUE,
1420
    '#collapsed' => TRUE,
1421
    '#description' => t('This section covers the settings related to the taxon
1422
      <strong>specimens</strong> tab.'),
1423
  );
1424

    
1425
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1426
  $saved_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1427
  if(!isset($featureTrees['options'][$saved_uuid])) {
1428
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1429
  }
1430
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1431
      '#type' => 'radios',
1432
      '#title' => t('Specimen description feature tree') . ':',
1433
      '#default_value' => $saved_uuid,
1434
      '#options' =>  $featureTrees['options'],
1435
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1436
      '#options_suffixes' => $featureTrees['treeRepresentations'],
1437
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1438
      ),
1439
  );
1440

    
1441
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1442
  $form_title = t('Specimen media');
1443
  $form_description = t('Specimens may have media which is displayed at the
1444
     Specimen tab/section as a gallery. It is possible to configure the
1445
     thumbnails gallery here, however for configuring how a single media should
1446
     be displayed please go to !url.</p>',
1447
     array(
1448
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1449
     ));
1450
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1451

    
1452
  // --- MEDIA GALLERY ---- //
1453
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1454
  $form_title = 'Media gallery (tab)';
1455
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1456
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1457
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1458
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1459
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1460
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1461
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1462

    
1463
  // Comment @WA: D7 form api does not support reset buttons,
1464
  // so to mimic the D5 reset button we add one like this.
1465
  $form['actions']['reset'] = array(
1466
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1467
    '#weight' => 1000,
1468
  );
1469
  return system_settings_form($form);
1470
}
1471

    
1472
/**
1473
 * @todo document this function.
1474
 */
1475
function cdm_settings_layout_search() {
1476

    
1477
  $form = array();
1478

    
1479
  $form['search_settings'] = array(
1480
    '#type' => 'fieldset',
1481
    '#title' => t('Taxa Search'),
1482
    '#collapsible' => FALSE,
1483
    '#collapsed' => FALSE,
1484
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1485
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1486
         where they can write the text to be searched. You can find Drupal block configuration
1487
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1488
  );
1489

    
1490
  $form['search_settings']['simple_search_ignore_classification'] = array(
1491
      '#type' => 'checkbox',
1492
      '#title' => t('Ignore the chosen classification in simple search'),
1493
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
1494
      '#description' => t('The simple search, which can be executed via the search block,
1495
          will by default search on all classifications. Remove the tick if you want your
1496
          portal to search on the classification selected in the classification browser
1497
          selector.'),
1498
  );
1499

    
1500
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1501
    '#type' => 'textfield',
1502
    '#title' => t('Results per page') . ':',
1503
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1504
    '#description' => t('Number of results to display per page.'),
1505
  );
1506

    
1507
  $form['search_settings']['cdm_search_taxa'] = array(
1508
    '#type' => 'checkbox',
1509
    '#title' => t('Sets the default value of <em>Search for accepted taxa</em> in the advanced search form.'),
1510
    '#default_value' => variable_get('cdm_search_taxa', 1),
1511
    '#description' => t('<p>If checked the <em>Search for accepted taxa </em> option will be enabled in the advanced form.</p>'),
1512
  );
1513

    
1514
  $form['search_settings']['cdm_search_synonyms'] = array(
1515
    '#type' => 'checkbox',
1516
    '#title' => t('Sets the default value of <em>Search for synonyms</em> in the advanced search form.'),
1517
    '#default_value' => variable_get('cdm_search_synonyms', 1),
1518
    '#description' => t('<p>If checked the <em>Search for synonyms</em> option will be enabled in the advanced form.</p>'),
1519
  );
1520

    
1521
  $form['search_settings']['cdm_search_common_names'] = array(
1522
    '#type' => 'checkbox',
1523
    '#title' => t('Sets the default value of <em>Search for common names</em> in the advanced search form.'),
1524
    '#default_value' => variable_get('cdm_search_common_names', 0),
1525
    '#description' => t('<p>If checked the <em>Search for common names</em> option will be enabled in the advanced form.</p>'),
1526
  );
1527

    
1528
  $form['search_settings']['cdm_search_use_default_values'] = array(
1529
    '#type' => 'checkbox',
1530
    '#title' => t('Sets use of default values in the advanced search form.'),
1531
    '#default_value' => variable_get('cdm_search_use_default_values', 1),
1532
    '#description' => t('<p>If checked the defqult values set abovewill be used for the search.</p>'),
1533
  );
1534

    
1535

    
1536
  // --- SEARCH TAXA GALLERY ---- //
1537
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1538
  $collapsed = FALSE;
1539
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1540
  $form_title = 'Taxa Search thumbnails';
1541
  $form_description = 'Search results may show thumbnails. ';
1542
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1543

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

    
1553
/**
1554
 * @todo document this function.
1555
 */
1556
function cdm_settings_layout_media() {
1557

    
1558
  $form = array();
1559

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

    
1569
  $form['media_settings']['image_gallery_viewer'] = array(
1570
    '#type' => 'select',
1571
    '#title' => t('Image viewer') . ':',
1572
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1573
    '#options' => array(
1574
      'default' => t('Standard image viewer'),
1575
      'fsi' => t('FSI viewer (requires FSI server!)'),
1576
    ),
1577
  );
1578

    
1579
  // --- MEDIA GALLERY ---- //
1580
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1581
  $form_title = 'Standard viewer';
1582
  $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>';
1583
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1584
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1585

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

    
1595
/**
1596
 * GEOSERVICE and Map settings.
1597
 */
1598
function cdm_settings_geo($form, &$form_state) {
1599

    
1600
  $current_geoserver_settings = get_edit_map_service_settings();
1601
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
1602

    
1603
  $form = array();
1604

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

    
1628

    
1629
  /*
1630
   * GEO SERVER
1631
   */
1632
  $form['edit_map_server'] = array(
1633
    '#type' => 'fieldset',
1634
    '#tree' => true,
1635
    '#title' => t('EDIT map service'),
1636
    '#collapsible' => TRUE,
1637
    '#collapsed' => TRUE,
1638
    '#description' => t('Configuration and selection of your geo server.
1639
      The Geo Server is responsible for generating the maps.'),
1640
  );
1641

    
1642
  $form['edit_map_server']['base_uri'] = array(
1643
    '#type' => 'select',
1644
    '#title' => t('EDIT map service') . ':',
1645
    '#default_value' => $current_geoserver_settings['base_uri'],
1646
    '#options' => unserialize(EDIT_MAPSERVER_URI),
1647
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
1648
  );
1649
  $form['edit_map_server']['version'] = array(
1650
      '#type' => 'select',
1651
      '#title' => t('Version') . ':',
1652
      '#default_value' => $current_geoserver_settings['version'],
1653
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
1654
      '#description' => t('The version of the EDIT map services'),
1655
  );
1656

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

    
1671

    
1672
  /*
1673
   * MAP SETTINGS
1674
   */
1675

    
1676
  $form[CDM_MAP_DISTRIBUTION] = array(
1677
    '#type' => 'fieldset',
1678
    '#tree' => TRUE,
1679
    '#title' => t('Maps settings'),
1680
    '#collapsible' => TRUE,
1681
    '#collapsed' => TRUE,
1682
    '#description' => t('General configuration for all map types.'),
1683
  );
1684

    
1685
  /*
1686
   * settings for the distribution map are used also for specimens map!!!!
1687
   */
1688

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

    
1709
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
1710
    '#type' => 'textfield',
1711
    '#title' => 'Bounding box',
1712
    '#default_value' => $map_distribution['bbox'],
1713
    '#description' => t('The bounding box defines the area to be initially displayed in maps.
1714
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
1715
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
1716
      <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.
1717
      Hold down Strg and drag with your mouse to select a bbox to zoom to. The bbox of the visisble area of the map is always displayed
1718
      below the map from where you can copy the bbox string.</p>'),
1719
  );
1720

    
1721
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
1722
    '#type' => 'checkbox',
1723
    '#title' => 'Display area labels',
1724
    '#default_value' => $map_distribution['show_labels'],
1725
    '#description' => t('The map will show name labels of the areas'),
1726
  );
1727

    
1728
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
1729
    '#type' => 'textfield',
1730
    '#title' => 'Map caption',
1731
    '#default_value' => $map_distribution['caption'],
1732
    '#description' => t('The caption will be shown below the map.'),
1733
  );
1734

    
1735
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
1736
    '#type' => 'textfield',
1737
    '#title' => 'Distribution layer opacity',
1738
    '#default_value' => $map_distribution['distribution_opacity'],
1739
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1740
                           fully visible, while a value near to 0.0 will be not much visible.'),
1741
  );
1742

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

    
1760

    
1761
  // --- Plain Image Settings --- //
1762
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
1763
    '#type' => 'fieldset',
1764
    '#title' => 'Plain image map settings',
1765
    '#tree' => TRUE,
1766
    '#collapsible' => TRUE,
1767
    '#collapsed' => $open_layers_is_enabled,
1768
    '#description' => 'The settings in this section are still expertimental
1769
      and can only be used with the EDIT map service version 1.1 or above.',
1770
  );
1771
  $edit_mapserver_version = get_edit_map_service_version_number();
1772
  if ($edit_mapserver_version < 1.1) {
1773
    $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>'
1774
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
1775
  }
1776

    
1777
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
1778
    '#type' => 'textfield',
1779
    '#title' => 'Background layer',
1780
    '#default_value' => $map_distribution['image_map']['base_layer'],
1781
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
1782
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
1783
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
1784
    )),
1785
  );
1786

    
1787
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
1788
    '#type' => 'textfield',
1789
    '#title' => 'Background color',
1790
    '#default_value' => $map_distribution['image_map']['bg_color'],
1791
  );
1792

    
1793
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
1794
    '#type' => 'textfield',
1795
    '#title' => 'Background layer style',
1796
     // Only line color by now.
1797
    '#default_value' => $map_distribution['image_map']['layer_style'],
1798
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
1799
  );
1800

    
1801

    
1802
  // --- OpenLayers Settings --- //
1803
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
1804
    '#type' => 'fieldset',
1805
    '#title' => 'OpenLayers settings',
1806
    '#tree' => TRUE,
1807
    '#collapsible' => TRUE,
1808
    '#collapsed' => !$open_layers_is_enabled,
1809
    '#description' => '',
1810
  );
1811

    
1812

    
1813
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
1814
      '#type' => 'checkbox',
1815
      '#title' => 'Display outside max extent',
1816
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
1817
      '#description' => t('Allows the map to display parts of the layers which are outside
1818
         the max extent if the aspect ratio of the map and of the baselayer
1819
         are not equal.'),
1820
  );
1821

    
1822
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
1823
      '#type' => 'checkbox',
1824
      '#title' => 'Show Layer Switcher',
1825
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
1826
      '#description' => 'The Layer Switcher control displays a table of contents
1827
      for the map.  This allows the user interface to switch between
1828
      base layers and to show or hide overlays.  By default the switcher is
1829
      shown minimized on the right edge of the map, the user may expand it
1830
      by clicking on the handle.',
1831
  );
1832

    
1833
  if (!$open_layers_is_enabled) {
1834
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
1835
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
1836
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
1837
  }
1838

    
1839
  $baselayer_options = array(
1840
    /*
1841
   NOTICE: must correspond to the layers defined in
1842
   js/openlayers_,ap.js#getLayersByName()
1843
   */
1844
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
1845
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
1846
    // all others EPSG:900913
1847
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
1848
    'edit-etopo1' => "ETOPO1 Global Relief Model",
1849
    'mapnik' => 'OpenStreetMap',
1850
    'mapquest_open' => "MapQuest",
1851
    'mapquest_sat' => "MapQuest Sattelite",
1852
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
1853
    'gmap' => 'Google Streets',
1854
    'gsat' => 'Google Satellite',
1855
    'ghyb' => 'Google Hybrid',
1856
//     'veroad' => 'Virtual Earth Roads',
1857
//     'veaer' => 'Virtual Earth Aerial',
1858
//     'vehyb' => 'Virtual Earth Hybrid',
1859
    // 'yahoo' => 'Yahoo Street',
1860
    // 'yahoosat' => 'Yahoo Satellite',
1861
    // 'yahoohyb' => 'Yahoo Hybrid',
1862
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
1863
  );
1864

    
1865
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
1866
    '#type' => 'checkboxes_preferred',
1867
    '#title' => 'Base Layers',
1868
    '#options' => $baselayer_options,
1869
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
1870
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
1871
  );
1872

    
1873
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
1874
      '#type' => 'fieldset',
1875
      '#title' => 'Custom WMS base layer',
1876
      '#tree' => TRUE,
1877
      '#collapsible' => FALSE,
1878
      '#collapsed' => FALSE,
1879
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
1880
  );
1881

    
1882
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
1883
      '#type' => 'textfield',
1884
      '#title' => 'Layer name',
1885
      // Only line color by now.
1886
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
1887
      '#description' => 'A arbitrary name for the layer.',
1888
  );
1889
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
1890
      '#type' => 'textfield',
1891
      '#title' => 'WMS url',
1892
      // Only line color by now.
1893
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
1894
      '#description' => 'Base url for the WMS (e.g.  http://wms.jpl.nasa.gov/wms.cgi)'
1895
  );
1896
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
1897
      '#type' => 'textarea',
1898
      '#title' => 'WMS parameters',
1899
      '#element_validate' => array('form_element_validate_json'),
1900
      // Only line color by now.
1901
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
1902
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON.'
1903
  );
1904
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
1905
      '#type' => 'textfield',
1906
      '#title' => 'Projection',
1907
      // Only line color by now.
1908
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
1909
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
1910
  );
1911
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
1912
      '#type' => 'textfield',
1913
      '#title' => 'Maximum extent',
1914
      // Only line color by now.
1915
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
1916
      '#description' => 'The maximum extent of the map as boundin box in the units of the map.'
1917
  );
1918
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
1919
      '#type' => 'textfield',
1920
      '#title' => 'Units',
1921
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
1922
      '#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.'
1923
  );
1924

    
1925
  /*
1926
   * Map Legend
1927
   */
1928
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
1929
    '#type' => 'fieldset',
1930
    '#title' => 'Map legend',
1931
    '#tree' => TRUE,
1932
    '#collapsible' => TRUE,
1933
    '#collapsed' => TRUE,
1934
    '#description' => 'Configure the maps legend.',
1935
  );
1936

    
1937
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
1938
    '#type' => 'checkbox',
1939
    '#title' => 'Display a map legend',
1940
    '#default_value' => $map_distribution['legend']['show'],
1941
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
1942
  );
1943

    
1944
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
1945
    '#type' => 'textfield',
1946
    '#title' => 'Legend opacity',
1947
    '#default_value' => $map_distribution['legend']['opacity'],
1948
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
1949
                         to 0.0 will be not much visible.',
1950
  );
1951

    
1952
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
1953
    '#type' => 'textfield',
1954
    '#title' => 'Font size',
1955
    '#default_value' => $map_distribution['legend']['font_size'],
1956
    '#description' => 'Font size in pixels.',
1957
  );
1958

    
1959
  $fontStyles = array(
1960
    0 => "plane",
1961
    1 => "italic",
1962
  );
1963
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
1964
    '#type' => 'select',
1965
    '#title' => 'Available font styles',
1966
    '#default_value' => $map_distribution['legend']['font_style'],
1967
    '#options' => $fontStyles,
1968
    '#description' => 'Select a font style for the map legend.',
1969
  );
1970

    
1971
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
1972
    '#type' => 'textfield',
1973
    '#title' => 'Icon width',
1974
    '#default_value' => $map_distribution['legend']['icon_width'],
1975
    '#description' => 'Legend icon width in pixels.',
1976
  );
1977
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
1978
    '#type' => 'textfield',
1979
    '#title' => 'Icon height',
1980
    '#default_value' => $map_distribution['legend']['icon_height'],
1981
    '#description' => 'Legend icon height in pixels.',
1982
  );
1983

    
1984
  // @WA: D7 form api does not support reset buttons,
1985
  // so to mimic the D5 reset button we add one like this.
1986
  $form['actions']['reset'] = array(
1987
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1988
    '#weight' => 1000,
1989
  );
1990

    
1991
  return system_settings_form($form);
1992
}
1993

    
1994
/**
1995
 * @todo document this function.
1996
 */
1997
function cdm_settings_cache() {
1998

    
1999
  $form = array();
2000

    
2001
  $form['cache_settings'] = array(
2002
    '#type' => 'fieldset',
2003
    '#title' => t('Cache Settings'),
2004
    '#collapsible' => FALSE,
2005
    '#collapsed' => FALSE,
2006
    '#description' => t('<p>When caching is enabled all single taxon sites are
2007
      stored in an internal drupal cache doing the portal response of taxa pages
2008
      faster. This is possible because the sites are loaded from the cache and
2009
      are not created from scratch.</p>'),
2010
  );
2011

    
2012
  $form['cache_settings']['cdm_webservice_cache'] = array(
2013
    '#type' => 'checkbox',
2014
    '#title' => t('<strong>Enable caching</strong>'),
2015
    '#options' => cdm_help_general_cache(),
2016
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2017
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2018
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2019
       application the changes will be not visible till the cache is erased.
2020
       Therefore developers should deactived this feature when they are working
2021
       on the CDM Dataportal Module.</p>'),
2022
  );
2023

    
2024
  $form['cache_settings']['cdm_run_cache'] = array(
2025
    '#markup' => cdm_view_cache_site(),
2026
  );
2027

    
2028
  // @WA: D7 form api does not support reset buttons,
2029
  // so to mimic the D5 reset button we add one like this.
2030
  $form['actions']['reset'] = array(
2031
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2032
    '#weight' => 1000,
2033
  );
2034
  return system_settings_form($form);
2035
}
2036

    
2037
/**
2038
 * Walk and cache all taxon pages.
2039
 */
2040
function cdm_view_cache_site() {
2041

    
2042
  $out = '';
2043

    
2044
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2045

    
2046
  $request_params = array();
2047
  $request_params['class'] = "Taxon";
2048

    
2049
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2050
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2051
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2052

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

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

    
2062
  // Comment @WA: A form within a form is not valid html and not needed here.
2063
  // Also, it would be recommended just to include this part of the form in the
2064
  // rest of the form array in cdm_settings_cache().
2065
  // $out .= '<form id="cache_site">';
2066
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2067
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2068
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2069
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2070
  // $out .= '</form>';
2071
  $out .= '</div>';
2072
  /*
2073
  foreach($taxonPager->records as $taxon){
2074
    cdm_dataportal_taxon_view($uuid);
2075
  }
2076
  */
2077
  return $out;
2078
}
2079

    
2080

    
2081
function cdm_settings_layout_taxon_submit($form, &$form_state){
2082
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2083
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2084
    if(is_object($file)){
2085
      $file->status = FILE_STATUS_PERMANENT;
2086
      file_save($file);
2087
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2088
    }
2089
  }
2090
}
2091

    
2092
/**
2093
 * Form validation handler for ?
2094
 *
2095
 * Comment @WA: currently this handler is not used.
2096
 * It seems partly for cdm_settings_general en partly for cdm_settings_cache?
2097
 * Then you can change the name into cdm_settings_general_validate() or
2098
 * cdm_settings_cache_validate().
2099
 * But cdm_api_secref_cache_clear is not doing anything (yet)?
2100
 */
2101
function cdm_settings_validate($form, &$form_state) {
2102

    
2103
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2104
    // form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
2105
    $form_state['values']['cdm_webservice_url'] .= '/';
2106
  }
2107

    
2108
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2109
    cache_clear_all(NULL, 'cache_cdm_ws');
2110
    // Better clear secref_cache since I can not be sure if the cache has not
2111
    // be used during this response.
2112
    cdm_api_secref_cache_clear();
2113
  }
2114
}
2115

    
2116
/**
2117
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
2118
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
2119
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
2120
 *  - version: the version, e.g.: v1.1
2121
 *
2122
 * @return array
2123
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
2124
 */
2125
function get_edit_map_service_settings() {
2126

    
2127
  $settings = variable_get('edit_map_server', array(
2128
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
2129
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
2130
      )
2131
  );
2132
  // replace old non tree like settings by default
2133
  // TODO to be removed after release 3.1.5
2134
  if(!is_array($settings)){
2135
    variable_del('edit_map_server');
2136
    return get_edit_map_service_settings();
2137
  }
2138

    
2139
  return $settings;
2140
}
2141

    
2142
/**
2143
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2144
 *
2145
 * @return string
2146
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2147
 */
2148
function get_edit_map_service_full_uri() {
2149
  $settings = get_edit_map_service_settings();
2150
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
2151
}
2152

    
2153

    
2154
/**
2155
 * Returns the version number of the currently selected edit mapserver as a float
2156
 *
2157
 * @return float
2158
 *   The version number of the currently selected edit mapserver as a float.
2159
 *   Returns 0 on error.
2160
 */
2161
function get_edit_map_service_version_number() {
2162

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

    
2165
  $settings = get_edit_map_service_settings();
2166
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
2167
  if (isset($matches[1])) {
2168
    // Convert string to float.
2169
    $version = 1 + $matches[1][0] - 1;
2170
    return $version;
2171
  }
2172
  else {
2173
    // Report error.
2174
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
2175
        array(
2176
          '!version' => $settings['version'],
2177
          'warning')
2178
        )
2179
      );
2180
    return 0;
2181
  }
2182
}
2183

    
2184
/**
2185
 * Returns the array of selected items in a options array
2186
 *
2187
 * @param array $options
2188
 *   An options array as generated by a form element like checkoxes, select ...,
2189
 */
2190
function get_selection($options) {
2191
  $selection = array();
2192
  foreach ($options as $key=>$val) {
2193
    if (!empty($val)) {
2194
      $selection[] = $val;
2195
    }
2196
  }
2197
  return $selection;
2198
}
2199

    
2200

    
2201
/**
2202
 * Implements hook_element_info().
2203
 *
2204
 * Allows modules to declare their own Form API element types and specify their default values.
2205
 *
2206
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
2207
 */
2208
function cdm_dataportal_element_info() {
2209
  $type['checkboxes_preferred'] = array(
2210
    '#input' => TRUE,
2211
    '#process' => array('checkboxes_preferred_expand'),
2212
    '#after_build' => array('checkboxes_preferred_after_build'),
2213
    '#theme' => array('checkboxes_preferred'),
2214
    // '#theme_wrapper' => array('form_element'),
2215
  );
2216
  return $type;
2217
}
2218

    
2219
/**
2220
 * #process callback function for the custom form element type 'checkbox_preferred'
2221
 *
2222
 *
2223
 */
2224
function checkboxes_preferred_expand($element, &$form_state, $form) {
2225

    
2226
  // First of all create checkboxes for each of the elements
2227
  $element = form_process_checkboxes($element);
2228

    
2229
  // compose the element name
2230
  $parents = array();
2231
  array_deep_copy($element['#parents'], $parents);
2232
  $parents[count($parents) -1 ] .= '_preferred';
2233
  $element_name = $parents[0];
2234
  for ($i=1; $i < count($parents); $i++){
2235
    $element_name .= '[' . $parents[$i] . ']';
2236
  }
2237

    
2238
  $children = element_children($element);
2239

    
2240
  $element['table_start'] = array(
2241
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
2242
    '#weight' => -1,
2243
  );
2244

    
2245
  // prepare first part each of the table rows which contains the row label
2246
  $weight = 0;
2247
  foreach ($children as $key) {
2248
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
2249
    $element[$key]['#weight'] = $weight;
2250
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
2251
    $element[$key]['#suffix'] = '</td>';
2252
    unset($element[$key]['#title']);
2253
    $weight += 2;
2254
  }
2255
  $weight = 0;
2256

    
2257
  // add a radio button to each of the checkboxes, the
2258
  // check boxes have already been created at the beginning
2259
  // of this function
2260
  if (count($element['#options']) > 0) {
2261
    foreach ($element['#options'] as $key => $choice) {
2262
      if (!isset($element[$key . '_preferred'])) {
2263
        $element[$key . '_preferred'] = array(
2264
          '#type' => 'radio',
2265
          '#name' => $element_name,
2266
          '#return_value' => check_plain($key),
2267
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
2268
          '#attributes' => $element['#attributes'],
2269
          '#parents' => $element['#parents'],
2270
          // '#spawned' => TRUE,
2271
          '#weight' => $weight + 1,
2272
          '#prefix' => '<td>',        // add a prefix to start a new table cell
2273
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
2274
        );
2275
      }
2276
      $weight += 2;
2277
    }
2278
  }
2279

    
2280
  // end the table
2281
  $element['table_end'] = array(
2282
    '#markup' => '</table>',
2283
    '#weight' => $weight++,
2284
  );
2285

    
2286
  return $element;
2287
}
2288

    
2289
/**
2290
 * Theme function for the custom form field 'checkboxes_preferred'.
2291
 */
2292
function theme_checkboxes_preferred($variables) {
2293
  $element = $variables['element'];
2294
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
2295
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
2296
  $out .= drupal_render_children($element);
2297
  $out .= '<div class="description">' . $element['#description'] . '</div>';
2298
  $out .= '</div>';
2299
  return $out;
2300
}
2301

    
2302
/**
2303
 * Callback for checkboxes preferred for widget which will
2304
 * be called after the form or element is built. The call
2305
 * back is configured in the form element by setting it as
2306
 * #after_build parameter.
2307
 *
2308
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
2309
 *
2310
 * @param $element
2311
 *   Nested array of form elements that comprise the form.
2312
 * @param $form_state
2313
 *   A keyed array containing the current state of the form.
2314
 *   This includes the current persistent storage data for the form.
2315
 *   Additional information, like the sanitized $_POST data,
2316
 *   is also accumulated here in $form_state['input']
2317
 *
2318
 * @return the modified form array
2319
 */
2320
function checkboxes_preferred_after_build($element, &$form_state) {
2321

    
2322
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
2323

    
2324
  if ($_POST && count($_POST) > 0) {
2325
    // TODO use  $form_state['input'] instead of POST !!!
2326
    // First pass of form processing.
2327
    $parents = array();
2328
    array_deep_copy($element['#parents'], $parents);
2329
    $parents[count($parents) - 1] .= '_preferred';
2330
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
2331
    $element['#value']['PREFERRED'] = $preferred_layer;
2332
//     $form_state[$parent_id] = $element['#value'];
2333
//     $form_state['values']['baselayers'] = $element['#value'];
2334
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
2335
    $form_state_element_values = $element['#value'];
2336
  }
2337
  else {
2338
    // Second pass of form processing.
2339
    $preferred_layer = $element['#value']['PREFERRED'];
2340
  }
2341

    
2342
  // Also set the chosen value (not sure if this is good Drupal style ....).
2343
  foreach ($children = element_children($element) as $key) {
2344
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
2345
      $element[$key]['#value'] = $preferred_layer;
2346
    }
2347
  }
2348
  // The default layer must always be enabled.
2349
  $element[$preferred_layer]['#value'] = $preferred_layer;
2350

    
2351
  return $element;
2352
}
2353

    
2354
function radios_prepare_options_suffix(&$elements){
2355

    
2356
  $childrenKeys = element_children($elements);
2357
  foreach($childrenKeys as $key){
2358
    if(!is_array($elements[$key]['#theme_wrappers'])){
2359
      $elements[$key]['#theme_wrappers'] = array();
2360
    }
2361
    if(isset($elements['#options_suffixes'][$key])){
2362
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
2363
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
2364
    }
2365
  }
2366
  return $elements;
2367

    
2368
}
2369

    
2370
/**
2371
 * TODO
2372
 * @param unknown $variables
2373
 */
2374
function theme_radio_options_suffix($variables) {
2375
  $element = $variables['element'];
2376
  if(isset($element['#options_suffix'])) {
2377
    $element['#children'] .= $element['#options_suffix'];
2378
  }
2379
  return $element['#children'];
2380
}
2381

    
2382

    
2383
/**
2384
 * Element validate callback for text field and arrays containing json.
2385
 *
2386
 * @param $element
2387
 *   The form element to validate
2388
 * @param $form_state
2389
 *   A keyed array containing the current state of the form.
2390
 * @param $form
2391
 *   Nested array of form elements that comprise the form.
2392
 */
2393
function form_element_validate_json($element, &$form_state, $form) {
2394
   if (!empty($element['#value'])) {
2395
     json_decode($element['#value']);
2396
     if(json_last_error() != JSON_ERROR_NONE){
2397
       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/'));
2398
     }
2399
   }
2400
}
2401

    
2402
/**
2403
 * Form submission handler for textareas and textfields containing JSON.
2404
 *
2405
 * The contained JSON will be converted into an php array
2406
 * or object and will be stored in the variables as such.
2407
 *
2408
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2409
 *
2410
 * @param $form
2411
 *   Nested array of form elements that comprise the form.
2412
 * @param $form_state
2413
 *   A keyed array containing the current state of the form.
2414
 *
2415
 */
2416
function submit_json_as_php_array($form, &$form_state) {
2417
  if (is_array($form['#json_elements'])) {
2418
    foreach ($form['#json_elements'] as $element){
2419
      if (trim($form_state['values'][$element])) {
2420
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
2421
      } else {
2422
        $form_state['values'][$element] = NULL;
2423
      }
2424
    }
2425
  }
2426
}
Add picture from clipboard (Maximum size: 40 MB)