Project

General

Profile

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

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

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

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

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

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

    
34

    
35

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

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

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

    
90
/**
91
 * Returns the array of implemented taxon page tabs.
92
 * The array has fixed integer keys which must not be changed.
93
 */
94
function get_taxon_tabs_list() {
95
  return array(
96
    0 => 'General',
97
    1 => 'Synonymy',
98
    2 => 'Images',
99
    3 => 'Specimens',
100
    4 => 'Keys',
101
  );
102
}
103

    
104
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
105
  array('general' => '-3', 'synonymy' => '-2', 'images' => '0', 'specimens' => '1', 'keys' => '3')
106
));
107

    
108
$taxon_tab_options = get_taxon_tabs_list();
109
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
110

    
111
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
112

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

    
123
}
124

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

    
190
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
191
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
192
    // to unset a default enntry set the value to 0
193
    array(
194
      'doTaxa'=>'doTaxa',
195
      'doSynonyms' => 'doSynonyms',
196
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
197
      'doMisappliedNames' => 'doMisappliedNames'
198
    )
199
  )
200
);
201

    
202
/* Gallery variables. */
203
$gallery_settings = array(
204
    "cdm_dataportal_show_taxon_thumbnails" => 1,
205
    "cdm_dataportal_show_synonym_thumbnails" => 0,
206
    "cdm_dataportal_show_thumbnail_captions" => 1,
207
    "cdm_dataportal_media_maxextend" => 120,
208
    "cdm_dataportal_media_cols" => 3,
209
    "cdm_dataportal_media_maxRows" => 1,
210
);
211

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

    
252
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
253
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
254
      array(
255
      'filter_rules' => array(
256
        'statusOrderPreference' => 0,
257
        'subAreaPreference' => 0,
258
      ),
259
      'hideMarkedAreas' => array()
260
     )
261
));
262

    
263

    
264
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
265
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
266
    array(
267
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
268
        'includeOccurrences' => 0,
269
        'includeTaxonNameDescriptions' => 0
270
     )
271
  ));
272

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

    
318
/**
319
 * Merges the named array variable with the array of defaults.
320
 *
321
 * IḾPORTANT: The array keys must be strings. When the keys are integers
322
 * the merging will not take place for these enties. Number keyed enties
323
 * are just appended to the result array.
324
 *
325
 * @param string $variable_name
326
 *     The variable name
327
 * @param string | array $default
328
 *     The array containing the default values either as array or serialized as string.
329
 *     Unserialization is cared for if nessecary
330
 * @return array
331
 *     The merged array as returnd by drupal_array_merge_deep()
332
 */
333
function get_array_variable_merged($variable_name, $default){
334

    
335
    // unserialize if nessecary
336
    if(!is_array($default)){
337
      $default = unserialize($default);
338
    }
339
    $variable = variable_get($variable_name, array());
340
    $result = drupal_array_merge_deep($default, $variable);
341
    return $result;
342
}
343

    
344
/**
345
 * @todo document this function.
346
 */
347
function getGallerySettings($gallery_config_form_name) {
348
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
349
}
350

    
351
/**
352
 * Returns the string representation of the default tab.
353
 *
354
 * @param bool $returnTabIndex
355
 *   Defaults to FALSE, if set true this function will return the index number
356
 *   of the default tab. (used to supply default values to form elements).
357
 */
358
function get_default_taxon_tab($returnTabIndex = FALSE) {
359

    
360
  global $user;
361
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
362
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
363
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
364
  // Get the user value if the used has chosen to overwrite the system settings.
365
  $user_tab_on = variable_get($user_tab_active, FALSE);
366
  if ($user_tab_on) {
367
    $user_value = variable_get($user_tab, 0);
368
    $index_value = $user_value;
369
    // Get the system value.
370
  }
371
  else {
372
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
373
    $index_value = $system_value;
374
  }
375

    
376
  // Return the index value or the string representation.
377
  if ($returnTabIndex) {
378
    return $index_value;
379
  }
380
  else {
381
    return ($values[$index_value]);
382
  }
383

    
384
}
385

    
386
/**
387
 * @todo Please document this function.
388
 * @see http://drupal.org/node/1354
389
 */
390
function cdm_dataportal_menu_admin(&$items) {
391
  // Display section on admin/config page.
392
  $items['admin/config/cdm_dataportal'] = array(
393
    'title' => 'CDM Dataportal',
394
    'description' => 'Settings for the CDM DataPortal.',
395
    'position' => 'right',
396
    'weight' => 10,
397
    'page callback' => 'system_admin_menu_block_page',
398
    'access arguments' => array('administer cdm_dataportal'),
399
    'file' => 'system.admin.inc',
400
    'file path' => drupal_get_path('module', 'system'),
401
  );
402
  $items['admin/config/cdm_dataportal/settings'] = array(
403
    'title' => 'Settings',
404
    'description' => 'Settings for the CDM DataPortal.',
405
    'weight' => 0,
406
    'page callback' => 'drupal_get_form',
407
    'page arguments' => array('cdm_settings_general'),
408
    'access arguments' => array('administer cdm_dataportal'),
409
    'type' => MENU_NORMAL_ITEM,
410
  );
411
  $items['admin/config/cdm_dataportal/settings/general'] = array(
412
    'title' => 'General',
413
    'description' => 'General',
414
    'weight' => 0,
415
    'page callback' => 'drupal_get_form',
416
    'page arguments' => array('cdm_settings_general'),
417
    'access arguments' => array('administer cdm_dataportal'),
418
    'type' => MENU_DEFAULT_LOCAL_TASK,
419
  );
420

    
421
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
422
    'title' => 'Cache',
423
    'description' => 'Cache',
424
    'access arguments' => array('administer cdm_dataportal'),
425
    'page callback' => 'drupal_get_form',
426
    'page arguments' => array('cdm_settings_cache'),
427
    'weight' => 10,
428
    'type' => MENU_LOCAL_TASK,
429
  );
430

    
431
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
432
    'title' => 'Geo & Map',
433
    'description' => 'Geo & Map',
434
    'access arguments' => array('administer cdm_dataportal'),
435
    'page callback' => 'drupal_get_form',
436
    'page arguments' => array('cdm_settings_geo'),
437
    'weight' => 1,
438
    'type' => MENU_LOCAL_TASK,
439
  );
440

    
441
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
442
    'title' => 'Layout',
443
    'description' => 'Configure and adjust the layout of your DataPortal ',
444
    'access arguments' => array('administer cdm_dataportal'),
445
    'page callback' => 'drupal_get_form',
446
    'page arguments' => array('cdm_settings_layout'),
447
    'weight' => 2,
448
    'type' => MENU_LOCAL_TASK,
449
  );
450

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

    
472
  $items[] = array(
473
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
474
  'title' => t('Specimens'),
475
  'description' => t('Configure and adjust the layout of your DataPortal '),
476
  'access' => user_access('administer cdm_dataportal'),
477
  'callback' => 'drupal_get_form',
478
  'callback arguments' => array('cdm_settings_layout_specimens'),
479
  'weight' => 1,
480
  'type' => MENU_LOCAL_TASK,
481
  );
482
  */
483
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
484
    'title' => 'Search',
485
    'description' => 'Configure and adjust the layout of your DataPortal ',
486
    'access arguments' => array('administer cdm_dataportal'),
487
    'page callback' => 'drupal_get_form',
488
    'page arguments' => array('cdm_settings_layout_search'),
489
    'weight' => 2,
490
    'type' => MENU_LOCAL_TASK,
491
  );
492

    
493
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
494
    'title' => 'Media',
495
    'description' => 'Configure and adjust the layout of your DataPortal ',
496
    'access arguments' => array('administer cdm_dataportal'),
497
    'page callback' => 'drupal_get_form',
498
    'page arguments' => array('cdm_settings_layout_media'),
499
    'weight' => 3,
500
    'type' => MENU_LOCAL_TASK,
501
  );
502

    
503
}
504

    
505
/**
506
 * @todo document this function.
507
 */
508
function cdm_help_general_cache() {
509
  $form = array();
510
  $form['cache_help'] = array(
511
    '#type' => 'fieldset',
512
    '#title' => t('Help'),
513
    '#collapsible' => TRUE,
514
    '#collapsed' => TRUE,
515
  );
516
  $form['cache_help']['test'] = array('#value' => t('probando'));
517
  return drupal_render($form);
518
  $res = array();
519
  $res['default'] = drupal_render($help);
520
  return $res;
521
}
522

    
523
/**
524
 * Configures the settings form for the CDM-API module.
525
 *
526
 * @return array
527
 *   Drupal settings form.
528
 */
529
function cdm_settings_general() {
530

    
531
  $form['cdm_webservice'] = array(
532
    '#type' => 'fieldset',
533
    '#title' => t('CDM Server'),
534
    '#collapsible' => FALSE,
535
    '#collapsed' => FALSE,
536
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
537
        CDM data base to the web via RESTful web services and thus is the source of the data
538
        to be displayed by a CDM DataPotal.'),
539
  );
540

    
541
  $form['cdm_webservice']['cdm_webservice_url'] = array(
542
    '#type' => 'textfield',
543
    '#title' => t('CDM web service URL') . ':',
544
    '#description' => t('This is the URL to the CDM-Server exposing your data
545
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
546
    '#default_value' => variable_get('cdm_webservice_url', NULL),
547
  );
548

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

    
556
  $form['cdm_webservice']['freetext_index'] = array(
557
    '#type' => 'fieldset',
558
    '#title' => t('Freetext index'),
559
    '#collapsible' => FALSE,
560
    '#collapsed' => FALSE,
561
  );
562

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

    
575
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
576
  $trigger_link_options = array(
577
    'attributes' => array(
578
      'class' => 'index-trigger',
579
    ),
580
  );
581
  $form['cdm_webservice']['freetext_index']['operations'] = array(
582
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
583
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
584
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
585
      ))
586
    . '<div id="index-progress"></div></div>',
587
  );
588
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
589

    
590
  $form['cdm_webservice']['proxy'] = array(
591
    '#type' => 'fieldset',
592
    '#title' => t('Proxy'),
593
    '#collapsible' => TRUE,
594
    '#collapsed' => TRUE,
595
  );
596

    
597
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
598
    '#type' => 'textfield',
599
    '#title' => t('Proxy URL') . ':',
600
    '#description' => t('If this proxy url is set the cdm api tries
601
    to connect the web service over the given proxy server.
602
    Otherwise proxy usage is deactivated.'),
603
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
604
  );
605

    
606
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
607
    '#type' => 'textfield',
608
    '#title' => t('Proxy port') . ':',
609
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
610
  );
611

    
612
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
613
    '#type' => 'textfield',
614
    '#title' => t('Login') . ':',
615
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
616
  );
617

    
618
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
619
    '#type' => 'textfield',
620
    '#title' => t('Password') . ':',
621
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
622
  );
623

    
624
  // TODO: settings are still incomplete, compare with
625
  // trunk/dataportal/inc/config_default.php.inc.
626
  $form['taxon_tree'] = array(
627
    '#type' => 'fieldset',
628
    '#title' => t('Taxon Tree'),
629
    '#collapsible' => FALSE,
630
    '#collapsed' => TRUE,
631
    '#description' => t('<p>When you explore your collection, you can navigate
632
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
633
      able to navigate through your collection the
634
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
635
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
636
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
637
      </a></p>'),
638
  );
639

    
640
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
641
    '#type' => 'select',
642
    '#title' => t('Available classifications') . ':',
643
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
644
    '#options' => cdm_get_taxontrees_as_options(),
645
    '#description' => t('Select the default taxa classification for your
646
      <em>taxon tree</em>, the other classifications will be also available but
647
      with a manual user change.'),
648
  );
649

    
650
  $form['taxon_tree']['taxontree_ranklimit'] = array(
651
    '#type' => 'select',
652
    '#title' => t('Rank of highest displayed taxon') . ':',
653
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
654
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
655
    '#options' => cdm_rankVocabulary_as_option(),
656
    '#description' => t('This is the rank of the highest displayed taxon in the
657
      <em>taxon tree</em>. You can select here which rank should be at the top
658
      level of the tree structure.'),
659
  );
660

    
661
  $form['distribution'] = array(
662
      '#type' => 'fieldset',
663
      '#title' => t('Distributions'),
664
      '#collapsible' => FALSE,
665
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
666
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
667
          '<p>
668
          </p>',
669
  );
670

    
671
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
672
      '#type' => 'fieldset',
673
      '#title' => 'Distribution filter',
674
      '#collapsible' => FALSE,
675
      '#collapsed' => FALSE,
676
      '#tree' => TRUE,
677
      '#description' => 'The Distribution filter offers the following options
678
      <ul>
679
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
680
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
681
      <li><strong>Marked area filter:</strong>Skip distributions where the area has a Marker with one of the specified MarkerTypes</li>
682
      </ul>'
683
  );
684

    
685
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
686
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
687
      '#type' => 'checkboxes',
688
      '#title' => 'Filter rules',
689
      '#default_value' => $cdm_distribution_filter['filter_rules'],
690
      '#options' => array(
691
          'statusOrderPreference' => 'Status order preference rule',
692
          'subAreaPreference' => 'Sub area preference rule'
693
      ),
694
  );
695

    
696
  $marker_type_options = cdm_terms_as_options( cdm_ws_fetch_all('term', array('class' => 'MarkerType' )) );
697
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hideMarkedAreas'] = array(
698
      '#type' => 'checkboxes',
699
      '#title' => 'Hide marked area filter',
700
      '#default_value' => $cdm_distribution_filter['hideMarkedAreas'],
701
      '#options' => $marker_type_options,
702
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
703
  );
704

    
705
  $form['aggregation'] = array(
706
      '#type' => 'fieldset',
707
      '#title' => t('Aggregation of data'),
708
      '#collapsible' => FALSE,
709
      '#description' => 'This section covers the different aspects of aggregating information.
710
          <p>
711
          </p>',
712
  );
713

    
714
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
715
      '#type' => 'checkboxes',
716
      '#title' => 'Taxon media filter',
717
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
718
      '#options' => array(
719
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
720
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
721
          'includeOccurrences' => 'Media related to specimens and occurrences',
722
      ),
723
      '#description' => 'This filter configures which images should be taken into account.',
724
  );
725

    
726
  $form['aggregation']['notice'] = array(
727
      '#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
728
          want to make use of the caching capabilities of the dataportal.',
729
  );
730

    
731
  $form['aggregation']['media_aggregation'] = array(
732
      '#type' => 'fieldset',
733
      '#title' => t('Media aggregation'),
734
      '#collapsible' => FALSE,
735
      '#collapsed' => TRUE,
736
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
737

    
738
  );
739
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
740
      '#type' => 'select',
741
      '#title' => t('Aggregation of taxon pictures') . ':',
742
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
743
      '#options' => array(
744
          0 => "Show only pictures of the current taxon",
745
          1 => "Include pictures of taxonomic children",
746
      ),
747
      '#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."),
748
  );
749

    
750
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
751
      '#type' => 'fieldset',
752
      '#attributes' => array('class'=>array('clearfix')),
753
      '#title' => t('Aggregation via taxon relationsships'),
754
      '#collapsible' => TRUE,
755
      '#collapsed' => TRUE,
756
      '#tree' => TRUE,
757
      '#description' => t('Information on taxa will be aggregated along the below chosen
758
          taxon relation ships. This will affect images and occurrences (specimens).
759
          Taxon relation ships are directed and point form one taxon to another. The taxon
760
          relationships to be taken into accunt can therefore configured for the direct direction
761
          and for the inverse.'),
762
  );
763

    
764
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
765
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
766

    
767
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
768
      '#type' => 'checkboxes',
769
      '#title' => t('Direct'),
770
      '#options' => $taxonRelationshipTypeOptions,
771
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
772
  );
773
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
774
      '#type' => 'checkboxes',
775
      '#title' => t('Invers'),
776
      '#options' => $taxonRelationshipTypeOptions,
777
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
778
  );
779

    
780
  // ----------------------
781
  $form['cdm_js_devel_mode'] = array(
782
      '#type' => 'checkbox',
783
      '#title' => 'Java-script developer mode',
784
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
785
      '#description' => 'In production envirionments the java script libraries
786
      the cdm_dataportal is making use of are compressed and optimized. This
787
      is good for performance but a caveat if you need to debug java-script. When the
788
      java-script developer mode is enabled the uncompressed and commented developer
789
      versions of java-script libraries will be used where possible.
790
      <br/><strong>Do not use this option in production!</strong>'
791
  );
792
  // ----------------------
793
  $form['cdm_debug_mode'] = array(
794
      '#type' => 'checkbox',
795
      '#title' => 'CDM page debug mode',
796
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
797
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
798
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
799
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
800
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
801
      The log is written by the drupal devel module function <code>dd()</code>.
802
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
803
  );
804

    
805
  // Comment @WA: D7 form api does not support reset buttons,
806
  // so to mimic the D5 reset button we add one like this.
807
  $form['actions']['reset'] = array(
808
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
809
    '#weight' => 1000,
810
  );
811

    
812
  return system_settings_form($form);
813
}
814

    
815

    
816
/**
817
 * LAYOUT settings
818
 * @return unknown_type
819
 *   todo
820
 */
821
function cdm_settings_layout() {
822

    
823
  $form = array();
824

    
825
  $form['about'] = array(
826
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
827
      layout. If you want to configure the specific sites layout visit the
828
      respective configuration site for taxon, search or media.') . '</p>',
829
  );
830

    
831
  // ---- footnotes --- //
832
  $form['footnotes'] = array(
833
    '#type' => 'fieldset',
834
    '#title' => t('Footnotes'),
835
    '#collapsible' => FALSE,
836
    '#collapsed' => FALSE,
837
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
838
      media or distribution areas may have annotations or footnotes. When the
839
      footnotes are enabled they will be visible (if they exist).'),
840
  );
841

    
842
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
843
    '#type' => 'checkbox',
844
    '#title' => t('Do not show footnotes'),
845
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
846
    '#description' => t('Check this if you do not want to show any footnotes'),
847
  );
848

    
849
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
850
    '#type' => 'checkbox',
851
    '#title' => t('Do not show annotations footnotes'),
852
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
853
    '#description' => t('Check this if you do not want to show annotation footnotes'),
854
  );
855

    
856
  $annotationTypeOptions = cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE);
857
  // Additional option for the NULL case.
858
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
859
  $form['footnotes']['annotations_types_as_footnotes'] = array(
860
    '#type' => 'checkboxes',
861
    '#title' => t('Annotation types as footnotes'),
862
    '#description' => t("Only annotations of the selected type will be displayed
863
       as footnotes. You may want to turn 'technical annotations' off."),
864
    '#options' => $annotationTypeOptions,
865
  );
866
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
867
  if (!empty($annotationsTypesAsFootnotes)) {
868
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
869
  }
870

    
871
  // --- Advanced Search --- //
872
  $form['asearch'] = array(
873
      '#type' => 'fieldset',
874
      '#title' => t('Advanced search'),
875
      '#collapsible' => FALSE,
876
      '#collapsed' => FALSE,
877
  );
878
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
879
      '#type' => 'checkbox',
880
      '#title' => t('Show advanced search link'),
881
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
882
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
883
  );
884

    
885
  // ---- Taxon Name Rendering --- //
886
  $form['taxon_name'] = array(
887
      '#type' => 'fieldset',
888
      '#title' => t('Taxon name display'),
889
      '#collapsible' => TRUE,
890
      '#collapsed' => TRUE,
891
      '#description' => t('The display of taxon names is configured by two parts.'
892
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
893
          . 'The name parts are defined in the <stong>part definitions</strong>'),
894
  );
895

    
896
  drupal_add_js(
897
      'jQuery(document).ready( function( ) {
898
         // pretty print json
899
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
900
         var obj = JSON.parse(json_text);
901
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
902

    
903
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
904
         obj = JSON.parse(json_text);
905
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
906
       });'
907
      ,array(
908
          'type' => 'inline',
909
          'scope' => 'footer'
910
      )
911
  );
912

    
913
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
914

    
915
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
916
      '#type' => 'textarea',
917
      '#title' => t('Part definitions'),
918
      '#element_validate' => array('form_element_validate_json'),
919
      '#default_value' =>  json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions)),
920
      '#description' => '
921
          <p>
922
          (Clearing the text area will reset it to the default)
923
          </p>
924
          <p>
925
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
926
          </p>
927
          <p>
928
           A full taxon name plus additional information can consist of the following elements:
929
          <ul>
930
             <li>name: the taxon name inclugin rank nbut without author</li>
931
             <li>authors:  The authors of a reference, also used in taxon names</li>
932
             <li>reference: the nomenclatural reference,</li>
933
             <li>microreference:  Volume, page number etc.</li>
934
             <li>status:  The nomenclatural status of a name</li>
935
             <li>description: name descriptions like protologues etc ...</li>
936
          </ul>
937
          </p>
938
          <p>
939
           These elements are combined in the part definitions array to from the specific parts to be rendered.
940
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
941
           Usually the following parts are formed:
942
          <ul>
943
            <li>namePart: the name and rank (in example: "Lapsana communis")</li>
944
            <li>authorshipPart: the author (in example: "L.")</li>
945
            <li>nameAuthorPart: the combination of name and author part (in example: "Lapsana communis L.").</li>
946
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
947
               be combined when a link to the taxon is rendered.</li>
948
            <li>referencePart: the nomencaltural reference (in example: "Sp. Pl. 1753")</li>
949
            <li>microreferencePart: usually the page number (in example ": 811.")</li>
950
            <li>statusPart: the nomenclatorical status</li>
951
            <li>descriptionPart: name descriptions like protologues etc ...</li>
952
          </ul>
953
          </p>
954
          <p>
955
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
956
           specific parts part definitions:
957
          <ul>
958
            <li>BotanicalName</li>
959
            <li>ZoologicalName</li>
960
            <li>#DEFAULT: covers ViralNames and other NonViralNames
961
          </ul>
962
           An example:
963
          <pre>
964
           {
965
            "ZoologicalName": {
966
              "namePart": {
967
                "name": true
968
              },
969
              "referencePart": {
970
                "authors": true
971
              },
972
              "microreferencePart": {
973
                "microreference": true
974
              },
975
              "statusPart": {
976
                "status": true
977
              },
978
              "descriptionPart": {
979
                "description": true
980
              }
981
            },
982
            "BotanicalName": {
983
              "namePart": {
984
                "name": true,
985
                "authors": true
986
              },
987
              "referencePart": {
988
                "reference": true,
989
                "microreference": true
990
              },
991
              "statusPart": {
992
                "status": true
993
              },
994
              "descriptionPart": {
995
                "description": true
996
              }
997
            }
998
          }
999
           </pre>',
1000
  );
1001

    
1002
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1003

    
1004
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1005
      '#type' => 'textarea',
1006
      '#title' => t('Name render templates'),
1007
      '#element_validate' => array('form_element_validate_json'),
1008
      '#default_value' =>  json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates)),
1009
      '#description' => '
1010
          <p>
1011
          (Clearing the text area will reset it to the default)
1012
          </p>
1013
          <p>
1014
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1015
          render path. The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1016
          The following render Path keys are curretly recognized:
1017
          <ul>
1018
            <li>list_of_taxa:</li>
1019
            <li>acceptedFor:</li>
1020
            <li>taxon_page_synonymy</li>
1021
            <li>typedesignations</li>
1022
            <li>taxon_page_title</li>
1023
            <li>polytomousKey</li>
1024
            <li>na: name + authorship</li>
1025
            <li>nar:name + authorship + reference</li>
1026
            <li>#DEFAULT</li>
1027
          </ul>
1028
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1029
          array element should be a comma separated list of render paths, without any whitespace!.
1030
          </p>
1031
          <p>
1032
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1033
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1034
          <p>
1035
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1036
          The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
1037
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1038
          links if the paramters $nameLink or $refenceLink are given to the name render function
1039
          (this is hard coded and cannot be configured here).',
1040
  );
1041

    
1042
  // @WA: D7 form api does not support reset buttons,
1043
  // so to mimic the D5 reset button we add one like this.
1044
  $form['actions']['reset'] = array(
1045
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1046
    '#weight' => 1000,
1047
  );
1048

    
1049
  $form['#submit'] = array('submit_json_as_php_array');
1050
  // #json_elements especially defined for submit_json_as_php_array()
1051
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1052
  return system_settings_form($form);
1053
}
1054

    
1055

    
1056
/**
1057
 * @todo Please document this function.
1058
 * @see http://drupal.org/node/1354
1059
 */
1060
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1061
  $form[$form_name] = array(
1062
    '#type' => 'fieldset',
1063
    '#title' => t($form_title),
1064
    '#collapsible' => TRUE,
1065
    '#collapsed' => $collapsed,
1066
    '#tree' => TRUE,
1067
    '#description' => t($form_description),
1068
  );
1069

    
1070
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1071
  $gallery_settings = variable_get($form_name, $default_values);
1072
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1073
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1074
    /*
1075
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1076
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1077
    '#type' => 'textfield',
1078
    '#title' => t('Search Page Size'),
1079
    '#default_value' => $test,
1080
    '#description' => t('Number of Names to display per page in search results.')
1081
    );
1082
    */
1083
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1084
      '#type' => 'checkbox',
1085
      '#title' => t('Show media thumbnails for accepted taxa'),
1086
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1087
    );
1088

    
1089
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1090
      '#type' => 'checkbox',
1091
      '#title' => t('Show media thumbnails for synonyms'),
1092
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1093
      '#description' => '',
1094
    );
1095
  }
1096

    
1097
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1098
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1099
    '#type' => 'checkbox',
1100
    '#title' => t('Show captions under thumbnails'),
1101
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1102
    '#description' => '',
1103
  );
1104

    
1105
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1106
    '#type' => 'textfield',
1107
    '#title' => t('Thumbnail size') . ':',
1108
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1109
    '#description' => t('Select the size of each individual thumbnail.'),
1110
  );
1111

    
1112
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1113
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1114
      '#type' => 'textfield',
1115
      '#title' => t('Number of columns') . ':',
1116
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1117
      '#description' => t('Group the thumbnails in columns: select how many
1118
        columns the gallery should display.'),
1119
    );
1120
  }
1121

    
1122
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1123
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1124
      '#type' => 'textfield',
1125
      '#title' => t('Maximum number of rows') . ':',
1126
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1127
      '#description' => t('You can group the thumbnails in rows, select in how
1128
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1129
        If you want an unlimited number of rows please set to 0.'),
1130
    );
1131
  }
1132

    
1133
  return $form;
1134
}
1135

    
1136
/**
1137
 * @todo document this function.
1138
 */
1139
function cdm_settings_layout_taxon() {
1140
  $collapsed = FALSE;
1141
  $form = array();
1142

    
1143
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1144

    
1145
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1146
      '#type' => 'checkbox',
1147
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1148
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1149
      '#description' => t('<p>If checked the link to search results is rendered at
1150
       the top of the taxon site. Clicking on the link the last search performed
1151
       is rendered again.</p>'),
1152
  );
1153

    
1154
  // --------- TABBED TAXON ------- //
1155
  $form['taxon_tabs'] = array(
1156
    '#type' => 'fieldset',
1157
    '#title' => t('Taxon tabs'),
1158
    '#collapsible' => TRUE,
1159
    '#collapsed' => FALSE,
1160
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1161
      be splitted in four diferent tabs; General, Synonymy, Images and
1162
      Specimens. If the taxon has no information for any of the tabs/sections
1163
      such tab will be not displayed.'),
1164
  );
1165

    
1166
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1167
    '#type' => 'checkbox',
1168
    '#title' => t('Tabbed taxon page'),
1169
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1170
    '#description' => t('<p>If selected split the taxon page into individual
1171
      tabs for description, images, synonymy and specimens. If not the taxon
1172
      data is rendered as a long single page without tabs.</p>'),
1173
  );
1174

    
1175
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1176
    '#type' => 'checkboxes',
1177
    '#title' => t('Tabs visibility options') . ':',
1178
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1179
    '#options' => get_taxon_options_list(),
1180
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1181
  );
1182

    
1183
  // WEIGHT
1184
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1185
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1186
      '#tree' => true
1187
  );
1188
  // Weights range from -delta to +delta, so delta should be at least half
1189
  // of the amount of tabs present.
1190
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1191
  foreach (get_taxon_tabs_list() as $label) {
1192
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1193
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1194
        '#title' => $label,
1195
        '#type'  => 'weight',
1196
        '#default_value' => $taxontabs_weights[$key],
1197
        '#delta' => $tab_weight_delta
1198
    );
1199
  }
1200

    
1201
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1202
    '#type' => 'select',
1203
    '#title' => t('Default tab to display') . ':',
1204
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1205
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1206
    '#description' => t('<p>Select the default tab to display when visiting a
1207
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1208
      <strong>Note:</strong> After performing a search and clicking in any
1209
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1210
      taxon and not the above selected tab.'),
1211
  );
1212

    
1213
  /* ======  TAXON_PROFILE ====== */
1214
  $form['taxon_profile'] = array(
1215
    '#type' => 'fieldset',
1216
    '#title' => t('Taxon profile (tab)'),
1217
    '#description' => t('<p>This section covers the settings related to the taxon
1218
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1219
    '#collapsible' => TRUE,
1220
    '#collapsed' => TRUE,
1221
  );
1222

    
1223
  // ---- PROFILE PICTURE ----//
1224

    
1225
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1226
    '#type' => 'fieldset',
1227
    '#tree' => TRUE,
1228
    '#title' => t('Taxon profile picture'),
1229
    '#collapsible' => TRUE,
1230
    '#collapsed' => FALSE,
1231
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1232
  );
1233

    
1234
  //FIXME migrate variables:
1235
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1236
  // FIXME
1237
  //  eanable file modul in profile and in update
1238

    
1239
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1240
  /*
1241
   * 'show' => 1,
1242
   * 'maxextend' => 184,
1243
   * 'media_uri_query' => ''
1244
   * 'custom_placeholder_image_on' => 1,
1245
   * 'custom_placeholder_image_fid' => ''
1246
   */
1247
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1248
    '#type' => 'checkbox',
1249
    '#title' => t('Enable profil picture'),
1250
    '#description' => t('Show the profil picture.'),
1251
    '#default_value' => $taxon_profile_image_settings['show'],
1252
  );
1253

    
1254
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1255
      '#type' => 'textfield',
1256
      '#tree' => TRUE,
1257
      '#title' => t('Profil picture maximum extend'),
1258
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1259
      '#field_suffix' => 'px',
1260
      '#maxlength' => 4,
1261
      '#size' => 4,
1262
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1263
  );
1264

    
1265
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1266
      '#type' => 'textfield',
1267
      '#tree' => TRUE,
1268
      '#title' => t('Additional URI query parameter'),
1269
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1270
      '#maxlength' => 1024,
1271
      '#size' => 60,
1272
      '#description' => t('Additional query parameters to be used when requesting for the '
1273
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1274
          . 'The query parameters will be appendend to the uri of the media representation part'
1275
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1276
  );
1277

    
1278
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1279
      '#type' => 'checkbox',
1280
      '#title' => t('Use a custom placeholder image'),
1281
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1282
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1283
  );
1284

    
1285
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1286
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1287
        '#type' => 'managed_file',
1288
        '#title' => t('Custom placeholder image file'),
1289
        '#progress_indicator' => 'bar',
1290
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1291
    //       '#name' => 'custom_placeholder_image',
1292
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1293
    );
1294

    
1295
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1296
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1297
      $url = file_create_url($profile_image_file->uri);
1298
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1299
                '#type' => 'item',
1300
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1301
      );
1302
    }
1303
  } else {
1304
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1305
        '#type' => 'hidden',
1306
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1307
    );
1308
  }
1309

    
1310

    
1311

    
1312
  $options = cdm_rankVocabulary_as_option();
1313
  array_unshift($options, '-- DISABLED --');
1314
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1315
    '#type' => 'select',
1316
    '#title' => t('Hide profile picture for higher ranks') . ':',
1317
    '#default_value' => variable_get('image_hide_rank', '0'),
1318
    '#options' => $options,
1319
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1320
  );
1321

    
1322
  // -- MEDIA THUMBNAILS -- //
1323
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1324
  $form_title = 'Taxon Profile Images';
1325
  $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>';
1326
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1327

    
1328
  // ---- FEATURE TREE ---- //
1329
  $form['taxon_profile']['feature_trees'] = array(
1330
    '#type' => 'fieldset',
1331
    '#title' => t('Features'),
1332
    '#collapsible' => TRUE,
1333
    '#collapsed' => FALSE,
1334
    '#description' => t("This section covers settings related to the taxon's
1335
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1336
      features such as description, distribution, common names, etc. that Drupal
1337
      will render at the taxon profile page."),
1338
  );
1339
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1340
  $saved_uuid = variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1341
  if(!isset($featureTrees['options'][$saved_uuid])) {
1342
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1343
  }
1344
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
1345
    '#type' => 'radios',
1346
    '#title' => t('Taxon profile sections') . ':',
1347
    '#default_value' => $saved_uuid,
1348
    '#options' =>  $featureTrees['options'],
1349
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1350
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1351
    '#description' => t('Select the Feature Tree to be displayed at the taxon
1352
      profile. Click "Show Details" to see the Feature Tree elements.'
1353
    ),
1354
  );
1355
  $featureTrees = cdm_get_featureTrees_as_options();
1356
  $saved_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1357
  if(!isset($featureTrees['options'][$saved_uuid])) {
1358
    $saved_uuid = NULL;
1359
  }
1360
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
1361
    '#type' => 'radios',
1362
    '#title' => t('Natural language representation of structured descriptions') . ':',
1363
    '#default_value' => $saved_uuid,
1364
    '#options' => $featureTrees['options'],
1365
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1366
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1367
    '#description' => t('Taxon descriptions can be stored in a highly structured
1368
      form. The feature tree selected here will be used to generate textual
1369
      representation in natural language.'
1370
    ),
1371
  );
1372

    
1373
  // ---- LAYOUT PER FEATURE ---- //
1374
  $feature_tree = get_profile_featureTree();
1375
  if (isset($feature_tree->root->childNodes)) {
1376

    
1377
    $form_feature_list_layout = array(
1378
      '#title' => t('Taxon profile layout'),
1379
      '#collapsible' => TRUE,
1380
      '#collapsed' => FALSE,
1381
      '#type' => 'fieldset',
1382
      '#description' => t('Will be available in a future release.'),
1383
    );
1384

    
1385
    $feature_list_layout_settings_disabled = TRUE;
1386
    foreach ($feature_tree->root->childNodes as $featureNode) {
1387

    
1388
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1389
        // Must not exceed 45 characters !!!
1390
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1391

    
1392
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1393
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1394

    
1395
        $form_feature_list_layout[$subform_id] = array(
1396
          '#tree' => TRUE,
1397
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1398
          '#collapsible' => FALSE,
1399
          '#collapsed' => FALSE,
1400
          '#type' => 'fieldset',
1401
          '#description' => t(''),
1402
        );
1403

    
1404
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1405
          '#type' => 'checkbox',
1406
          '#title' => t('Enable'),
1407
          '#default_value' => $settings['enabled'],
1408
          '#description' => t('Enable user defined layout for this feature'),
1409
        );
1410

    
1411
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1412
          '#type' => 'textfield',
1413
          '#title' => t('Enclosing tag'),
1414
          '#disabled' => !$settings['enabled'],
1415
          '#default_value' => $settings['enclosingTag'],
1416
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1417
        );
1418

    
1419
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1420
          '#type' => 'textfield',
1421
          '#title' => t('Entry enclosing tag'),
1422
          '#disabled' => !$settings['enabled'],
1423
          '#default_value' => $settings['entryEnclosingTag'],
1424
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1425
        );
1426

    
1427
        $form_feature_list_layout[$subform_id]['glue'] = array(
1428
          '#type' => 'textfield',
1429
          '#title' => t('Glue'),
1430
          '#disabled' => !$settings['enabled'],
1431
          '#default_value' => $settings['glue'],
1432
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1433
        );
1434

    
1435
      }
1436

    
1437
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1438
    }
1439
  }
1440

    
1441
  // ---- DISTRIBUTION LAYOUT ---- //
1442
  $form['taxon_profile']['distribution_layout'] = array(
1443
    '#title' => t('Distribution'),
1444
    '#collapsible' => TRUE,
1445
    '#collapsed' => FALSE,
1446
    '#type' => 'fieldset',
1447
    '#description' => t('Select if you want to sort or not the distribution text
1448
      located below the distribution map.'),
1449
  );
1450

    
1451
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1452
    '#type' => 'radios',
1453
    '#title' => t('Sort') . ':',
1454
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1455
    '#options' => array(
1456
      'NO_SORT' => t('Standard (No sort)'),
1457
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1458
    ),
1459
  );
1460

    
1461
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1462
    '#type' => 'checkbox',
1463
    '#title' => t('Show TextData elements on top of the map'),
1464
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1465
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1466
      elements on top of the map. Otherwise all <code>TextData</code>
1467
      distribution elements will be listed below the other area elements.
1468
      This option is useful if you need to have descriptive texts for each
1469
      distribution map.'),
1470
  );
1471

    
1472

    
1473
  /* ====== SYNONYMY ====== */
1474
  $form['taxon_synonymy'] = array(
1475
    '#type' => 'fieldset',
1476
    '#title' => t('Taxon synonymy (tab)'),
1477
    '#collapsible' => TRUE,
1478
    '#collapsed' => TRUE,
1479
    '#description' => t('This section covers the settings related to the taxon
1480
      <strong>synonymy</strong> tab.'),
1481
  );
1482

    
1483
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1484
    '#type' => 'checkbox',
1485
    '#title' => t('Show accepted taxon on top of the synonymy'),
1486
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1487
    '#description' => t('If checked, the first homotypic taxon is a repetition
1488
      of the accepted taxon most likely with the full nomenclatural reference
1489
      (depending on the currently chosen theme).'),
1490
  );
1491

    
1492
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1493
    '#type' => 'checkbox',
1494
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1495
      coming from a synonym link.'),
1496
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1497
    '#description' => t('Check this if after doing a search and clicking on a
1498
      synonym you want to see the "accept of" text for the accepted synonym.'),
1499
  );
1500

    
1501
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1502
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1503
    '#type' => 'checkboxes',
1504
    '#title' => t('Display name relationships') . ':',
1505
    '#default_value' => variable_get('name_relationships_to_show', 0),
1506
    '#options' => $nameRelationshipTypeOptions,
1507
    '#description' => t('Select the name relationships you want to show for the
1508
      accepted taxa.'),
1509
  );
1510

    
1511
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1512
    '#type' => 'checkbox',
1513
    '#title' => t('Show taxon relations ships of accepted taxon'),
1514
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1515
    '#description' => t('If this option is enabled the synonymy will show the
1516
      below selected taxon relationships of accepted taxa.'),
1517
  );
1518

    
1519
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1520
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1521
    '#type' => 'checkboxes',
1522
    '#title' => t('Taxon relationship types') . ':',
1523
    '#description' => t('Only taxon relationships of the selected type will be
1524
      displayed'),
1525
    '#options' => $taxonRelationshipTypeOptions,
1526
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1527
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1528
  );
1529

    
1530
  // ====== SPECIMENS ====== //
1531
  $form['taxon_specimens'] = array(
1532
    '#type' => 'fieldset',
1533
    '#title' => t('Taxon specimens (tab)'),
1534
    '#collapsible' => TRUE,
1535
    '#collapsed' => TRUE,
1536
    '#description' => t('This section covers the settings related to the taxon
1537
      <strong>specimens</strong> tab.'),
1538
  );
1539

    
1540
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1541
  $saved_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1542
  if(!isset($featureTrees['options'][$saved_uuid])) {
1543
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1544
  }
1545
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1546
      '#type' => 'radios',
1547
      '#title' => t('Specimen description feature tree') . ':',
1548
      '#default_value' => $saved_uuid,
1549
      '#options' =>  $featureTrees['options'],
1550
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1551
      '#options_suffixes' => $featureTrees['treeRepresentations'],
1552
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1553
      ),
1554
  );
1555

    
1556
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1557
  $form_title = t('Specimen media');
1558
  $form_description = t('Specimens may have media which is displayed at the
1559
     Specimen tab/section as a gallery. It is possible to configure the
1560
     thumbnails gallery here, however for configuring how a single media should
1561
     be displayed please go to !url.</p>',
1562
     array(
1563
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1564
     ));
1565
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1566

    
1567
  // --- MEDIA GALLERY ---- //
1568
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1569
  $form_title = 'Media gallery (tab)';
1570
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1571
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1572
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1573
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1574
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1575
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1576
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1577

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

    
1587
/**
1588
 * @todo document this function.
1589
 */
1590
function cdm_settings_layout_search() {
1591

    
1592
  $form = array();
1593

    
1594
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
1595

    
1596
  $form['search_settings'] = array(
1597
    '#type' => 'fieldset',
1598
    '#title' => t('Taxa Search'),
1599
    '#collapsible' => FALSE,
1600
    '#collapsed' => FALSE,
1601
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1602
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1603
         where they can write the text to be searched. You can find Drupal block configuration
1604
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1605
  );
1606

    
1607
  $form['search_settings']['simple_search_ignore_classification'] = array(
1608
      '#type' => 'checkbox',
1609
      '#title' => t('Ignore the chosen classification in simple search'),
1610
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
1611
      '#description' => t('The simple search, which can be executed via the search block,
1612
          will by default search on all classifications. Remove the tick if you want your
1613
          portal to search on the classification selected in the classification browser
1614
          selector.'),
1615
  );
1616

    
1617
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1618
    '#type' => 'textfield',
1619
    '#title' => t('Results per page') . ':',
1620
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1621
    '#description' => t('Number of results to display per page.'),
1622
  );
1623

    
1624
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
1625
  $form['search_settings']['cdm_search_taxa_mode'] = array(
1626
      '#type' => 'checkboxes',
1627
      '#title' => 'Search mode',
1628
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
1629
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
1630
          for the advance search form and the behaviour of the simple search form which always will behave according to the
1631
          defaults set here.',
1632
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
1633
      '#default_value' => $search_mode_default
1634
      );
1635

    
1636
  // --- SEARCH TAXA GALLERY ---- //
1637
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1638
  $collapsed = FALSE;
1639
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1640
  $form_title = 'Taxa Search thumbnails';
1641
  $form_description = 'Search results may show thumbnails. ';
1642
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1643

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

    
1653
/**
1654
 * @todo document this function.
1655
 */
1656
function cdm_settings_layout_media() {
1657

    
1658
  $form = array();
1659

    
1660
  $form['media_settings'] = array(
1661
    '#type' => 'fieldset',
1662
    '#title' => t('Media settings'),
1663
    '#collapsible' => FALSE,
1664
    '#collapsed' => FALSE,
1665
    '#description' => 'This section covers layout settings for media pages.'
1666
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
1667
  );
1668

    
1669
  $form['media_settings']['image_gallery_viewer'] = array(
1670
    '#type' => 'select',
1671
    '#title' => t('Image viewer') . ':',
1672
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1673
    '#options' => array(
1674
      'default' => t('Standard image viewer'),
1675
      'fsi' => t('FSI viewer (requires FSI server!)'),
1676
    ),
1677
  );
1678

    
1679
  // --- MEDIA GALLERY ---- //
1680
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1681
  $form_title = 'Standard viewer';
1682
  $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>';
1683
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1684
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1685

    
1686
  // @WA: D7 form api does not support reset buttons,
1687
  // so to mimic the D5 reset button we add one like this.
1688
  $form['actions']['reset'] = array(
1689
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1690
    '#weight' => 1000,
1691
  );
1692
  return system_settings_form($form);
1693
}
1694

    
1695
/**
1696
 * GEOSERVICE and Map settings.
1697
 */
1698
function cdm_settings_geo($form, &$form_state) {
1699

    
1700
  $current_geoserver_settings = get_edit_map_service_settings();
1701
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
1702
  // The default layer must always be enabled
1703
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
1704
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
1705

    
1706
  $form = array();
1707

    
1708
  $dummy_distribution_query = NULL;
1709
  if($map_distribution['map_type'] != 1){
1710
    // we need to apply a dummy query since the map serice requires for image maps
1711
    // at least as and ad to be defined
1712
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
1713
  }
1714
  $form['map_preview'] = array(
1715
      '#type' => 'fieldset',
1716
      '#tree' => FALSE,
1717
      '#title' => t('Map preview'),
1718
      '#collapsible' => FALSE,
1719
      '#description' => 'The preview of the map'
1720
       . ($dummy_distribution_query != null ?
1721
           ' may not be accurate in case if image maps, please check the map display in the taxon pages.':
1722
           '.<br/>Hold down Strg and drag with your mouse to select a bbox to zoom to. <br/>The bbox of the visible area of the map is always displayed below the map.')
1723
  );
1724
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL,
1725
      array(
1726
          'move' => "this.cdmOpenlayersMap.printInfo",
1727
          '#execute' => "this.cdmOpenlayersMap.printInfo"
1728
      )
1729
  );
1730

    
1731

    
1732
  /*
1733
   * GEO SERVER
1734
   */
1735
  $form['edit_map_server'] = array(
1736
    '#type' => 'fieldset',
1737
    '#tree' => true,
1738
    '#title' => t('EDIT map service'),
1739
    '#collapsible' => TRUE,
1740
    '#collapsed' => TRUE,
1741
    '#description' => t('Configuration and selection of your geo server.
1742
      The Geo Server is responsible for generating the maps.'),
1743
  );
1744

    
1745
  $form['edit_map_server']['base_uri'] = array(
1746
    '#type' => 'select',
1747
    '#title' => t('EDIT map service') . ':',
1748
    '#default_value' => $current_geoserver_settings['base_uri'],
1749
    '#options' => unserialize(EDIT_MAPSERVER_URI),
1750
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
1751
  );
1752
  $form['edit_map_server']['version'] = array(
1753
      '#type' => 'select',
1754
      '#title' => t('Version') . ':',
1755
      '#default_value' => $current_geoserver_settings['version'],
1756
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
1757
      '#description' => t('The version of the EDIT map services'),
1758
  );
1759

    
1760
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1761
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1762
  $form['gmap_api_key'] = array(
1763
      '#type' => 'textfield',
1764
      '#title' => t('Google maps API key') . ':',
1765
      '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1766
      '#description' => t('If you want to use the Google Maps Layer, a key is
1767
      needed. If you need a key, visit
1768
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
1769
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
1770
      is the default key for the localhost (127.0.0.1).',
1771
      array('!localhostkey' => $localhostkey)),
1772
  );
1773

    
1774

    
1775
  /*
1776
   * MAP SETTINGS
1777
   */
1778

    
1779
  $form[CDM_MAP_DISTRIBUTION] = array(
1780
    '#type' => 'fieldset',
1781
    '#tree' => TRUE,
1782
    '#title' => t('Maps settings'),
1783
    '#collapsible' => TRUE,
1784
    '#collapsed' => TRUE,
1785
    '#description' => t('General configuration for all map types.'),
1786
  );
1787

    
1788
  /*
1789
   * settings for the distribution map are used also for specimens map!!!!
1790
   */
1791

    
1792
  $form[CDM_MAP_DISTRIBUTION]['width'] = array(
1793
    '#type' => 'textfield',
1794
    '#title' => 'Width',
1795
    '#default_value' => $map_distribution['width'],
1796
    '#maxlength' => 4,
1797
    '#size' => 4,
1798
    '#description' => 'Width of the map. To allow OSM baselayers to zoom out to the full extend of the world the map width must be
1799
      a multiple of 256px since the osm tiles from tile.openstreetmap.org have a size of 256px x 256px and frational zoom
1800
      levels are not possible in this case.',
1801
  );
1802
  $form[CDM_MAP_DISTRIBUTION]['height'] = array(
1803
      '#type' => 'textfield',
1804
      '#title' => 'Height',
1805
      '#default_value' => $map_distribution['height'],
1806
      '#maxlength' => 4,
1807
      '#size' => 4,
1808
      '#description' => 'Height of the map. Depending on the chosen base layer you may want to choose the height equal
1809
      to the width or half of the width. Any other aspect ratio is also possible if desired.',
1810
  );
1811

    
1812
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
1813
    '#type' => 'textfield',
1814
    '#title' => 'Bounding box',
1815
    '#default_value' => $map_distribution['bbox'],
1816
    '#description' => t('The bounding box (left, bottom, right, top) defines the area to be initially displayed in maps.
1817
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
1818
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
1819
      <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.
1820
      Hold down Strg and drag with your mouse to select a bbox to zoom to. The bbox of the visible area of the map is always displayed
1821
      below the map from where you can copy the bbox string.</p>'),
1822
  );
1823

    
1824
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
1825
    '#type' => 'checkbox',
1826
    '#title' => 'Display area labels',
1827
    '#default_value' => $map_distribution['show_labels'],
1828
    '#description' => t('The map will show name labels of the areas'),
1829
  );
1830

    
1831
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
1832
    '#type' => 'textfield',
1833
    '#title' => 'Map caption',
1834
    '#default_value' => $map_distribution['caption'],
1835
    '#description' => t('The caption will be shown below the map.'),
1836
  );
1837

    
1838
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
1839
    '#type' => 'textfield',
1840
    '#title' => 'Distribution layer opacity',
1841
    '#default_value' => $map_distribution['distribution_opacity'],
1842
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1843
                           fully visible, while a value near to 0.0 will be not much visible.'),
1844
  );
1845

    
1846
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
1847
    '#type' => 'radios',
1848
    '#title' => 'Map types',
1849
    '#options' => array(
1850
      1 => "OpenLayers dynamic map viewer",
1851
      0 => "Plain image",
1852
    ),
1853
    '#default_value' => $map_distribution['map_type'],
1854
    '#description' => 'Two different map types are available :
1855
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
1856
      which allows zooming and panning. If enabled you can configure the default layer
1857
      (background of your maps) below.</li>
1858
      <li><em>Plain image</em>: The map will be static non interactive
1859
      image.</li></ul>',
1860
  );
1861
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
1862

    
1863

    
1864
  // --- Plain Image Settings --- //
1865
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
1866
    '#type' => 'fieldset',
1867
    '#title' => 'Plain image map settings',
1868
    '#tree' => TRUE,
1869
    '#collapsible' => TRUE,
1870
    '#collapsed' => $open_layers_is_enabled,
1871
    '#description' => 'The settings in this section are still expertimental
1872
      and can only be used with the EDIT map service version 1.1 or above.',
1873
  );
1874
  $edit_mapserver_version = get_edit_map_service_version_number();
1875
  if ($edit_mapserver_version < 1.1) {
1876
    $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>'
1877
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
1878
  }
1879

    
1880
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
1881
    '#type' => 'textfield',
1882
    '#title' => 'Background layer',
1883
    '#default_value' => $map_distribution['image_map']['base_layer'],
1884
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
1885
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
1886
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
1887
    )),
1888
  );
1889

    
1890
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
1891
    '#type' => 'textfield',
1892
    '#title' => 'Background color',
1893
    '#default_value' => $map_distribution['image_map']['bg_color'],
1894
  );
1895

    
1896
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
1897
    '#type' => 'textfield',
1898
    '#title' => 'Background layer style',
1899
     // Only line color by now.
1900
    '#default_value' => $map_distribution['image_map']['layer_style'],
1901
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
1902
  );
1903

    
1904
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
1905
      '#type' => 'textfield',
1906
      '#title' => 'Projection',
1907
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
1908
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
1909
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
1910
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
1911
  );
1912

    
1913

    
1914
  // --- OpenLayers Settings --- //
1915
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
1916
    '#type' => 'fieldset',
1917
    '#title' => 'OpenLayers settings',
1918
    '#tree' => TRUE,
1919
    '#collapsible' => TRUE,
1920
    '#collapsed' => !$open_layers_is_enabled,
1921
    '#description' => '',
1922
  );
1923

    
1924

    
1925
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
1926
      '#type' => 'checkbox',
1927
      '#title' => 'Display outside max extent',
1928
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
1929
      '#description' => t('Allows the map to display parts of the layers which are outside
1930
         the max extent if the aspect ratio of the map and of the baselayer
1931
         are not equal.'),
1932
  );
1933

    
1934

    
1935
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
1936
      '#type' => 'checkbox',
1937
      '#title' => 'Show Layer Switcher',
1938
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
1939
      '#description' => 'The Layer Switcher control displays a table of contents
1940
      for the map.  This allows the user interface to switch between
1941
      base layers and to show or hide overlays.  By default the switcher is
1942
      shown minimized on the right edge of the map, the user may expand it
1943
      by clicking on the handle.',
1944
  );
1945

    
1946
  if (!$open_layers_is_enabled) {
1947
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
1948
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
1949
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
1950
  }
1951

    
1952
  $baselayer_options = array(
1953
    /*
1954
   NOTICE: must correspond to the layers defined in
1955
   js/openlayers_,ap.js#getLayersByName()
1956
   */
1957
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
1958
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
1959
    // all others EPSG:900913
1960
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
1961
    'edit-etopo1' => "ETOPO1 Global Relief Model",
1962
    'mapnik' => 'OpenStreetMap',
1963
    'mapquest_open' => "MapQuest",
1964
    'mapquest_sat' => "MapQuest Sattelite",
1965
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
1966
    'gmap' => 'Google Streets',
1967
    'gsat' => 'Google Satellite',
1968
    'ghyb' => 'Google Hybrid',
1969
//     'veroad' => 'Virtual Earth Roads',
1970
//     'veaer' => 'Virtual Earth Aerial',
1971
//     'vehyb' => 'Virtual Earth Hybrid',
1972
    // 'yahoo' => 'Yahoo Street',
1973
    // 'yahoosat' => 'Yahoo Satellite',
1974
    // 'yahoohyb' => 'Yahoo Hybrid',
1975
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
1976
  );
1977

    
1978
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
1979
    '#type' => 'checkboxes_preferred',
1980
    '#title' => 'Base Layers',
1981
    '#options' => $baselayer_options,
1982
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
1983
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
1984
  );
1985

    
1986
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
1987
      '#type' => 'fieldset',
1988
      '#title' => 'Custom WMS base layer',
1989
      '#tree' => TRUE,
1990
      '#collapsible' => FALSE,
1991
      '#collapsed' => FALSE,
1992
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
1993
  );
1994

    
1995
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
1996
      '#type' => 'textfield',
1997
      '#title' => 'Layer name',
1998
      // Only line color by now.
1999
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2000
      '#description' => 'A arbitrary name for the layer.',
2001
  );
2002
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2003
      '#type' => 'textfield',
2004
      '#title' => 'WMS url',
2005
      // Only line color by now.
2006
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2007
      '#description' => 'Base url for the WMS (e.g.  http://wms.jpl.nasa.gov/wms.cgi)'
2008
  );
2009
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2010
      '#type' => 'textarea',
2011
      '#title' => 'WMS parameters',
2012
      '#element_validate' => array('form_element_validate_json'),
2013
      // Only line color by now.
2014
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2015
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2016
<pre> {
2017
  "Layers": "topp:em_tiny_jan2003",
2018
  "Format": "image/png",
2019
  "BGCOLOR": "0xe0faff"
2020
}
2021
</pre>'
2022
  );
2023
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2024
      '#type' => 'textfield',
2025
      '#title' => 'Projection',
2026
      // Only line color by now.
2027
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2028
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2029
  );
2030
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2031
      '#type' => 'textfield',
2032
      '#maxlength' => 256,
2033
      '#title' => 'proj4js definition',
2034
      // Only line color by now.
2035
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2036
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2037
            The definitions for
2038
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2039
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2040
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2041
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2042
            choose to display the proj4js definition string.
2043
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2044
            <pre>
2045
+a         Semimajor radius of the ellipsoid axis
2046
+alpha     ? Used with Oblique Mercator and possibly a few others
2047
+axis      Axis orientation (new in 4.8.0)
2048
+b         Semiminor radius of the ellipsoid axis
2049
+datum     Datum name (see `proj -ld`)
2050
+ellps     Ellipsoid name (see `proj -le`)
2051
+k         Scaling factor (old name)
2052
+k_0       Scaling factor (new name)
2053
+lat_0     Latitude of origin
2054
+lat_1     Latitude of first standard parallel
2055
+lat_2     Latitude of second standard parallel
2056
+lat_ts    Latitude of true scale
2057
+lon_0     Central meridian
2058
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
2059
+lon_wrap  Center longitude to use for wrapping (see below)
2060
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
2061
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
2062
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
2063
+pm        Alternate prime meridian (typically a city name, see below)
2064
+proj      Projection name (see `proj -l`)
2065
+south     Denotes southern hemisphere UTM zone
2066
+to_meter  Multiplier to convert map units to 1.0m
2067
+towgs84   3 or 7 term datum transform parameters (see below)
2068
+units     meters, US survey feet, etc.
2069
+vto_meter vertical conversion to meters.
2070
+vunits    vertical units.
2071
+x_0       False easting
2072
+y_0       False northing
2073
+zone      UTM zone
2074
            </pre>
2075
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
2076
  );
2077
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
2078
      '#type' => 'textfield',
2079
      '#title' => 'Maximum extent',
2080
      // Only line color by now.
2081
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
2082
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
2083
  );
2084
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
2085
      '#type' => 'textfield',
2086
      '#title' => 'Units',
2087
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
2088
      '#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.'
2089
  );
2090

    
2091
  /*
2092
   * Map Legend
2093
   */
2094
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2095
    '#type' => 'fieldset',
2096
    '#title' => 'Map legend',
2097
    '#tree' => TRUE,
2098
    '#collapsible' => TRUE,
2099
    '#collapsed' => TRUE,
2100
    '#description' => 'Configure the maps legend.',
2101
  );
2102

    
2103
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2104
    '#type' => 'checkbox',
2105
    '#title' => 'Display a map legend',
2106
    '#default_value' => $map_distribution['legend']['show'],
2107
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2108
  );
2109

    
2110
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2111
    '#type' => 'textfield',
2112
    '#title' => 'Legend opacity',
2113
    '#default_value' => $map_distribution['legend']['opacity'],
2114
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2115
                         to 0.0 will be not much visible.',
2116
  );
2117

    
2118
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2119
    '#type' => 'textfield',
2120
    '#title' => 'Font size',
2121
    '#default_value' => $map_distribution['legend']['font_size'],
2122
    '#description' => 'Font size in pixels.',
2123
  );
2124

    
2125
  $fontStyles = array(
2126
    0 => "plane",
2127
    1 => "italic",
2128
  );
2129
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2130
    '#type' => 'select',
2131
    '#title' => 'Available font styles',
2132
    '#default_value' => $map_distribution['legend']['font_style'],
2133
    '#options' => $fontStyles,
2134
    '#description' => 'Select a font style for the map legend.',
2135
  );
2136

    
2137
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2138
    '#type' => 'textfield',
2139
    '#title' => 'Icon width',
2140
    '#default_value' => $map_distribution['legend']['icon_width'],
2141
    '#description' => 'Legend icon width in pixels.',
2142
  );
2143
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2144
    '#type' => 'textfield',
2145
    '#title' => 'Icon height',
2146
    '#default_value' => $map_distribution['legend']['icon_height'],
2147
    '#description' => 'Legend icon height in pixels.',
2148
  );
2149

    
2150
  // @WA: D7 form api does not support reset buttons,
2151
  // so to mimic the D5 reset button we add one like this.
2152
  $form['actions']['reset'] = array(
2153
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2154
    '#weight' => 1000,
2155
  );
2156

    
2157
  return system_settings_form($form);
2158
}
2159

    
2160
/**
2161
 * @todo document this function.
2162
 */
2163
function cdm_settings_cache() {
2164

    
2165
  $form = array();
2166

    
2167
  $form['cache_settings'] = array(
2168
    '#type' => 'fieldset',
2169
    '#title' => t('Cache Settings'),
2170
    '#collapsible' => FALSE,
2171
    '#collapsed' => FALSE,
2172
    '#description' => t('<p>When caching is enabled all single taxon sites are
2173
      stored in an internal drupal cache doing the portal response of taxa pages
2174
      faster. This is possible because the sites are loaded from the cache and
2175
      are not created from scratch.</p>'),
2176
  );
2177

    
2178
  $form['cache_settings']['cdm_webservice_cache'] = array(
2179
    '#type' => 'checkbox',
2180
    '#title' => t('<strong>Enable caching</strong>'),
2181
    '#options' => cdm_help_general_cache(),
2182
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2183
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2184
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2185
       application the changes will be not visible till the cache is erased.
2186
       Therefore developers should deactived this feature when they are working
2187
       on the CDM Dataportal Module.</p>'),
2188
  );
2189

    
2190
  $form['cache_settings']['cdm_run_cache'] = array(
2191
    '#markup' => cdm_view_cache_site(),
2192
  );
2193

    
2194
  // @WA: D7 form api does not support reset buttons,
2195
  // so to mimic the D5 reset button we add one like this.
2196
  $form['actions']['reset'] = array(
2197
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2198
    '#weight' => 1000,
2199
  );
2200
  return system_settings_form($form);
2201
}
2202

    
2203
/**
2204
 * Walk and cache all taxon pages.
2205
 */
2206
function cdm_view_cache_site() {
2207

    
2208
  $out = '';
2209

    
2210
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2211

    
2212
  $request_params = array();
2213
  $request_params['class'] = "Taxon";
2214

    
2215
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2216
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2217
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2218

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

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

    
2228
  // Comment @WA: A form within a form is not valid html and not needed here.
2229
  // Also, it would be recommended just to include this part of the form in the
2230
  // rest of the form array in cdm_settings_cache().
2231
  // $out .= '<form id="cache_site">';
2232
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2233
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2234
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2235
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2236
  // $out .= '</form>';
2237
  $out .= '</div>';
2238
  /*
2239
  foreach($taxonPager->records as $taxon){
2240
    cdm_dataportal_taxon_view($uuid);
2241
  }
2242
  */
2243
  return $out;
2244
}
2245

    
2246

    
2247
function cdm_settings_layout_taxon_submit($form, &$form_state){
2248
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2249
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2250
    if(is_object($file)){
2251
      $file->status = FILE_STATUS_PERMANENT;
2252
      file_save($file);
2253
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2254
    }
2255
  }
2256
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2257
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2258
    // we first need to set the variable to persist the changes setting
2259
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
2260
    menu_rebuild();
2261
  }
2262
}
2263

    
2264
function cdm_settings_layout_search_submit($form, &$form_state){
2265
  // the visibility of media thumbnails also affects the ui of the search results
2266
  // so reset the according session variable
2267
  //    1. in order to give the user immediate
2268
  //       feedback on potential setting changes
2269
  //    2. let refresh the default if it has changed
2270
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2271
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
2272
  }
2273
}
2274

    
2275
/**
2276
 * Form validation handler for cdm_settings_general
2277
 *
2278
 * Comment @WA: currently this handler is not used.
2279
 * It seems partly for cdm_settings_general en partly for cdm_settings_cache?
2280
 * Then you can change the name into cdm_settings_general_validate() or
2281
 * cdm_settings_cache_validate().
2282
 * But cdm_api_secref_cache_clear is not doing anything (yet)?
2283
 */
2284
function cdm_settings_general_validate($form, &$form_state) {
2285

    
2286
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2287
    $form_state['values']['cdm_webservice_url'] .= '/';
2288
  }
2289

    
2290
}
2291

    
2292
/**
2293
 * Form validation handler for cdm_settings_cache
2294
 */
2295
function cdm_settings_cache_validate($form, &$form_state) {
2296
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2297
    cache_clear_all(NULL, 'cache_cdm_ws');
2298
    // Better clear secref_cache since I can not be sure if the cache has not
2299
    // be used during this response.
2300
    cdm_api_secref_cache_clear();
2301
  }
2302

    
2303
}
2304

    
2305
/**
2306
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
2307
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
2308
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
2309
 *  - version: the version, e.g.: v1.1
2310
 *
2311
 * @return array
2312
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
2313
 */
2314
function get_edit_map_service_settings() {
2315

    
2316
  $settings = variable_get('edit_map_server', array(
2317
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
2318
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
2319
      )
2320
  );
2321
  // replace old non tree like settings by default
2322
  // TODO to be removed after release 3.1.5
2323
  if(!is_array($settings)){
2324
    variable_del('edit_map_server');
2325
    return get_edit_map_service_settings();
2326
  }
2327

    
2328
  return $settings;
2329
}
2330

    
2331
/**
2332
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2333
 *
2334
 * @return string
2335
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2336
 */
2337
function get_edit_map_service_full_uri() {
2338
  $settings = get_edit_map_service_settings();
2339
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
2340
}
2341

    
2342

    
2343
/**
2344
 * Returns the version number of the currently selected edit mapserver as a float
2345
 *
2346
 * @return float
2347
 *   The version number of the currently selected edit mapserver as a float.
2348
 *   Returns 0 on error.
2349
 */
2350
function get_edit_map_service_version_number() {
2351

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

    
2354
  $settings = get_edit_map_service_settings();
2355
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
2356
  if (isset($matches[1])) {
2357
    // Convert string to float.
2358
    $version = 1 + $matches[1][0] - 1;
2359
    return $version;
2360
  }
2361
  else {
2362
    // Report error.
2363
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
2364
        array(
2365
          '!version' => $settings['version'],
2366
          'warning')
2367
        )
2368
      );
2369
    return 0;
2370
  }
2371
}
2372

    
2373
/**
2374
 * Returns the array of selected items in a options array
2375
 *
2376
 * @param array $options
2377
 *   An options array as generated by a form element like checkoxes, select ...,
2378
 */
2379
function get_selection($options) {
2380
  $selection = array();
2381
  foreach ($options as $key=>$val) {
2382
    if (!empty($val)) {
2383
      $selection[] = $val;
2384
    }
2385
  }
2386
  return $selection;
2387
}
2388

    
2389

    
2390
/**
2391
 * Implements hook_element_info().
2392
 *
2393
 * Allows modules to declare their own Form API element types and specify their default values.
2394
 *
2395
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
2396
 */
2397
function cdm_dataportal_element_info() {
2398
  $type['checkboxes_preferred'] = array(
2399
    '#input' => TRUE,
2400
    '#process' => array('checkboxes_preferred_expand'),
2401
    '#after_build' => array('checkboxes_preferred_after_build'),
2402
    '#theme' => array('checkboxes_preferred'),
2403
    // '#theme_wrapper' => array('form_element'),
2404
  );
2405
  return $type;
2406
}
2407

    
2408
/**
2409
 * #process callback function for the custom form element type 'checkbox_preferred'
2410
 *
2411
 *
2412
 */
2413
function checkboxes_preferred_expand($element, &$form_state, $form) {
2414

    
2415
  // First of all create checkboxes for each of the elements
2416
  $element = form_process_checkboxes($element);
2417

    
2418
  // compose the element name
2419
  $parents = array();
2420
  array_deep_copy($element['#parents'], $parents);
2421
  $parents[count($parents) -1 ] .= '_preferred';
2422
  $element_name = $parents[0];
2423
  for ($i=1; $i < count($parents); $i++){
2424
    $element_name .= '[' . $parents[$i] . ']';
2425
  }
2426

    
2427
  $children = element_children($element);
2428

    
2429
  $element['table_start'] = array(
2430
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
2431
    '#weight' => -1,
2432
  );
2433

    
2434
  // prepare first part each of the table rows which contains the row label
2435
  $weight = 0;
2436
  foreach ($children as $key) {
2437
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
2438
    $element[$key]['#weight'] = $weight;
2439
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
2440
    $element[$key]['#suffix'] = '</td>';
2441
    unset($element[$key]['#title']);
2442
    $weight += 2;
2443
  }
2444
  $weight = 0;
2445

    
2446
  // add a radio button to each of the checkboxes, the
2447
  // check boxes have already been created at the beginning
2448
  // of this function
2449
  if (count($element['#options']) > 0) {
2450
    foreach ($element['#options'] as $key => $choice) {
2451
      if (!isset($element[$key . '_preferred'])) {
2452
        $element[$key . '_preferred'] = array(
2453
          '#type' => 'radio',
2454
          '#name' => $element_name,
2455
          '#return_value' => check_plain($key),
2456
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
2457
          '#attributes' => $element['#attributes'],
2458
          '#parents' => $element['#parents'],
2459
          // '#spawned' => TRUE,
2460
          '#weight' => $weight + 1,
2461
          '#prefix' => '<td>',        // add a prefix to start a new table cell
2462
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
2463
        );
2464
      }
2465
      $weight += 2;
2466
    }
2467
  }
2468

    
2469
  // end the table
2470
  $element['table_end'] = array(
2471
    '#markup' => '</table>',
2472
    '#weight' => $weight++,
2473
  );
2474

    
2475
  return $element;
2476
}
2477

    
2478
/**
2479
 * Theme function for the custom form field 'checkboxes_preferred'.
2480
 */
2481
function theme_checkboxes_preferred($variables) {
2482
  $element = $variables['element'];
2483
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
2484
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
2485
  $out .= drupal_render_children($element);
2486
  $out .= '<div class="description">' . $element['#description'] . '</div>';
2487
  $out .= '</div>';
2488
  return $out;
2489
}
2490

    
2491
/**
2492
 * Callback for checkboxes preferred for widget which will
2493
 * be called after the form or element is built. The call
2494
 * back is configured in the form element by setting it as
2495
 * #after_build parameter.
2496
 *
2497
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
2498
 *
2499
 * @param $element
2500
 *   Nested array of form elements that comprise the form.
2501
 * @param $form_state
2502
 *   A keyed array containing the current state of the form.
2503
 *   This includes the current persistent storage data for the form.
2504
 *   Additional information, like the sanitized $_POST data,
2505
 *   is also accumulated here in $form_state['input']
2506
 *
2507
 * @return the modified form array
2508
 */
2509
function checkboxes_preferred_after_build($element, &$form_state) {
2510

    
2511
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
2512

    
2513
  if ($_POST && count($_POST) > 0) {
2514
    // TODO use  $form_state['input'] instead of POST !!!
2515
    // First pass of form processing.
2516
    $parents = array();
2517
    array_deep_copy($element['#parents'], $parents);
2518
    $parents[count($parents) - 1] .= '_preferred';
2519
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
2520
    $element['#value']['PREFERRED'] = $preferred_layer;
2521
//     $form_state[$parent_id] = $element['#value'];
2522
//     $form_state['values']['baselayers'] = $element['#value'];
2523
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
2524
    $form_state_element_values = $element['#value'];
2525
  }
2526
  else {
2527
    // Second pass of form processing.
2528
    $preferred_layer = $element['#value']['PREFERRED'];
2529
  }
2530

    
2531
  // Also set the chosen value (not sure if this is good Drupal style ....).
2532
  foreach ($children = element_children($element) as $key) {
2533
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
2534
      $element[$key]['#value'] = $preferred_layer;
2535
    }
2536
  }
2537
  // The default layer must always be enabled.
2538
  $element[$preferred_layer]['#value'] = $preferred_layer;
2539

    
2540
  return $element;
2541
}
2542

    
2543
function radios_prepare_options_suffix(&$elements){
2544

    
2545
  $childrenKeys = element_children($elements);
2546
  foreach($childrenKeys as $key){
2547
    if(!is_array($elements[$key]['#theme_wrappers'])){
2548
      $elements[$key]['#theme_wrappers'] = array();
2549
    }
2550
    if(isset($elements['#options_suffixes'][$key])){
2551
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
2552
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
2553
    }
2554
  }
2555
  return $elements;
2556

    
2557
}
2558

    
2559
/**
2560
 * TODO
2561
 * @param unknown $variables
2562
 */
2563
function theme_radio_options_suffix($variables) {
2564
  $element = $variables['element'];
2565
  if(isset($element['#options_suffix'])) {
2566
    $element['#children'] .= $element['#options_suffix'];
2567
  }
2568
  return $element['#children'];
2569
}
2570

    
2571

    
2572
/**
2573
 * Element validate callback for text field and arrays containing json.
2574
 *
2575
 * @param $element
2576
 *   The form element to validate
2577
 * @param $form_state
2578
 *   A keyed array containing the current state of the form.
2579
 * @param $form
2580
 *   Nested array of form elements that comprise the form.
2581
 */
2582
function form_element_validate_json($element, &$form_state, $form) {
2583
   if (!empty($element['#value'])) {
2584
     json_decode($element['#value']);
2585
     if(json_last_error() != JSON_ERROR_NONE){
2586
       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/'));
2587
     }
2588
   }
2589
}
2590

    
2591
/**
2592
 * Form submission handler for textareas and textfields containing JSON.
2593
 *
2594
 * The contained JSON will be converted into an php array
2595
 * or object and will be stored in the variables as such.
2596
 *
2597
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2598
 *
2599
 * @param $form
2600
 *   Nested array of form elements that comprise the form.
2601
 * @param $form_state
2602
 *   A keyed array containing the current state of the form.
2603
 *
2604
 */
2605
function submit_json_as_php_array($form, &$form_state) {
2606
  if (is_array($form['#json_elements'])) {
2607
    foreach ($form['#json_elements'] as $element){
2608
      if (trim($form_state['values'][$element])) {
2609
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
2610
      } else {
2611
        $form_state['values'][$element] = NULL;
2612
      }
2613
    }
2614
  }
2615
}
(14-14/14)