Project

General

Profile

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

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

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

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

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

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

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

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

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

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

    
84

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

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

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

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

    
113
}
114

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

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

    
220
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
221
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
222
    array(
223
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
224
        'includeOccurrences' => 0,
225
        'includeTaxonNameDescriptions' => 0
226
     )
227
  ));
228

    
229
/**
230
 * @todo document this function.
231
 */
232
function getGallerySettings($gallery_config_form_name) {
233
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
234
  return variable_get($gallery_config_form_name, $default_values);
235
}
236

    
237
/**
238
 * Returns the string representation of the default tab.
239
 *
240
 * @param bool $returnTabIndex
241
 *   Defaults to FALSE, if set true this function will return the index number
242
 *   of the default tab. (used to supply default values to form elements).
243
 */
244
function get_default_taxon_tab($returnTabIndex = FALSE) {
245

    
246
  global $user;
247
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
248
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
249
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
250
  // Get the user value if the used has chosen to overwrite the system settings.
251
  $user_tab_on = variable_get($user_tab_active, FALSE);
252
  if ($user_tab_on) {
253
    $user_value = variable_get($user_tab, 0);
254
    $index_value = $user_value;
255
    // Get the system value.
256
  }
257
  else {
258
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
259
    $index_value = $system_value;
260
  }
261

    
262
  // Return the index value or the string representation.
263
  if ($returnTabIndex) {
264
    return $index_value;
265
  }
266
  else {
267
    return ($values[$index_value]);
268
  }
269

    
270
}
271

    
272
/**
273
 * @todo Please document this function.
274
 * @see http://drupal.org/node/1354
275
 */
276
function cdm_dataportal_menu_admin(&$items) {
277
  // Display section on admin/config page.
278
  $items['admin/config/cdm_dataportal'] = array(
279
    'title' => 'CDM Dataportal',
280
    'description' => 'Settings for the CDM DataPortal.',
281
    'position' => 'right',
282
    'weight' => 10,
283
    'page callback' => 'system_admin_menu_block_page',
284
    'access arguments' => array('administer cdm_dataportal'),
285
    'file' => 'system.admin.inc',
286
    'file path' => drupal_get_path('module', 'system'),
287
  );
288
  $items['admin/config/cdm_dataportal/settings'] = array(
289
    'title' => 'Settings',
290
    'description' => 'Settings for the CDM DataPortal.',
291
    'weight' => 0,
292
    'page callback' => 'drupal_get_form',
293
    'page arguments' => array('cdm_settings_general'),
294
    'access arguments' => array('administer cdm_dataportal'),
295
    'type' => MENU_NORMAL_ITEM,
296
  );
297
  $items['admin/config/cdm_dataportal/settings/general'] = array(
298
    'title' => 'General',
299
    'description' => 'General',
300
    'weight' => 0,
301
    'page callback' => 'drupal_get_form',
302
    'page arguments' => array('cdm_settings_general'),
303
    'access arguments' => array('administer cdm_dataportal'),
304
    'type' => MENU_DEFAULT_LOCAL_TASK,
305
  );
306

    
307
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
308
    'title' => 'Cache',
309
    'description' => 'Cache',
310
    'access arguments' => array('administer cdm_dataportal'),
311
    'page callback' => 'drupal_get_form',
312
    'page arguments' => array('cdm_settings_cache'),
313
    'weight' => 10,
314
    'type' => MENU_LOCAL_TASK,
315
  );
316

    
317
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
318
    'title' => 'Geo & Map',
319
    'description' => 'Geo & Map',
320
    'access arguments' => array('administer cdm_dataportal'),
321
    'page callback' => 'drupal_get_form',
322
    'page arguments' => array('cdm_settings_geo'),
323
    'weight' => 1,
324
    'type' => MENU_LOCAL_TASK,
325
  );
326

    
327
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
328
    'title' => 'Layout',
329
    'description' => 'Configure and adjust the layout of your DataPortal ',
330
    'access arguments' => array('administer cdm_dataportal'),
331
    'page callback' => 'drupal_get_form',
332
    'page arguments' => array('cdm_settings_layout'),
333
    'weight' => 2,
334
    'type' => MENU_LOCAL_TASK,
335
  );
336

    
337
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
338
    'title' => 'Taxon',
339
    'description' => 'Configure and adjust the layout of your DataPortal ',
340
    'access arguments' => array('administer cdm_dataportal'),
341
    'page callback' => 'drupal_get_form',
342
    'page arguments' => array('cdm_settings_layout_taxon'),
343
    'weight' => 1,
344
    'type' => MENU_LOCAL_TASK,
345
  );
346
  /*
347
  $items[] = array(
348
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
349
  'title' => t('Synonymy'),
350
  'description' => t('Configure and adjust the layout of your DataPortal '),
351
  'access' => user_access('administer cdm_dataportal'),
352
  'callback' => 'drupal_get_form',
353
  'callback arguments' => array('cdm_settings_layout_synonymy'),
354
  'weight' => 1,
355
  'type' => MENU_LOCAL_TASK,
356
  );
357

    
358
  $items[] = array(
359
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
360
  'title' => t('Specimens'),
361
  'description' => t('Configure and adjust the layout of your DataPortal '),
362
  'access' => user_access('administer cdm_dataportal'),
363
  'callback' => 'drupal_get_form',
364
  'callback arguments' => array('cdm_settings_layout_specimens'),
365
  'weight' => 1,
366
  'type' => MENU_LOCAL_TASK,
367
  );
368
  */
369
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
370
    'title' => 'Search',
371
    'description' => 'Configure and adjust the layout of your DataPortal ',
372
    'access arguments' => array('administer cdm_dataportal'),
373
    'page callback' => 'drupal_get_form',
374
    'page arguments' => array('cdm_settings_layout_search'),
375
    'weight' => 2,
376
    'type' => MENU_LOCAL_TASK,
377
  );
378

    
379
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
380
    'title' => 'Media',
381
    'description' => 'Configure and adjust the layout of your DataPortal ',
382
    'access arguments' => array('administer cdm_dataportal'),
383
    'page callback' => 'drupal_get_form',
384
    'page arguments' => array('cdm_settings_layout_media'),
385
    'weight' => 3,
386
    'type' => MENU_LOCAL_TASK,
387
  );
388

    
389
}
390

    
391
/**
392
 * @todo document this function.
393
 */
394
function cdm_help_general_cache() {
395
  $form = array();
396
  $form['cache_help'] = array(
397
    '#type' => 'fieldset',
398
    '#title' => t('Help'),
399
    '#collapsible' => TRUE,
400
    '#collapsed' => TRUE,
401
  );
402
  $form['cache_help']['test'] = array('#value' => t('probando'));
403
  return drupal_render($form);
404
  $res = array();
405
  $res['default'] = drupal_render($help);
406
  return $res;
407
}
408

    
409
/**
410
 * Configures the settings form for the CDM-API module.
411
 *
412
 * @return array
413
 *   Drupal settings form.
414
 */
415
function cdm_settings_general() {
416

    
417
  $form['cdm_webservice'] = array(
418
    '#type' => 'fieldset',
419
    '#title' => t('CDM Server'),
420
    '#collapsible' => FALSE,
421
    '#collapsed' => FALSE,
422
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
423
        CDM data base to the web via RESTful web services and thus is the source of the data
424
        to be displayed by a CDM DataPotal.'),
425
  );
426

    
427
  $form['cdm_webservice']['cdm_webservice_url'] = array(
428
    '#type' => 'textfield',
429
    '#title' => t('CDM web service URL') . ':',
430
    '#description' => t('This is the URL to the CDM-Server exposing your data
431
      e.g. <em>"http://localhost:8080/cichorieae/"</em> The URL <strong>must end
432
      with a slash</strong> character!'),
433
    '#default_value' => variable_get('cdm_webservice_url', NULL),
434
  );
435

    
436
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
437
    '#type' => 'checkbox',
438
    '#title' => t('<b>Debug CDM Web Service</b>'),
439
    '#default_value' => variable_get('cdm_webservice_debug', 1),
440
    '#description' => t('The black web service debug box will appear at the top
441
      of each page. When clicked it toggles open and provides a list of all HTTP
442
      requests which have been made while building of this page.<br />
443
      <strong>Note:</strong> this is a feature dedicated to developers. It will
444
      only be visible when logged in and if the user has suffucicient rights to
445
      see this debug box.'),
446
  );
447

    
448
  $form['cdm_webservice']['freetext_index'] = array(
449
    '#type' => 'fieldset',
450
    '#title' => t('Freetext index'),
451
    '#collapsible' => FALSE,
452
    '#collapsed' => FALSE,
453
  );
454

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

    
467
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
468
  $trigger_link_options = array(
469
    'attributes' => array(
470
      'class' => 'index-trigger',
471
    ),
472
  );
473
  $form['cdm_webservice']['freetext_index']['operations'] = array(
474
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
475
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
476
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
477
      ))
478
    . '<div id="index-progress"></div></div>',
479
  );
480
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
481

    
482
  $form['cdm_webservice']['proxy'] = array(
483
    '#type' => 'fieldset',
484
    '#title' => t('Proxy'),
485
    '#collapsible' => TRUE,
486
    '#collapsed' => TRUE,
487
  );
488

    
489
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
490
    '#type' => 'textfield',
491
    '#title' => t('Proxy URL') . ':',
492
    '#description' => t('If this proxy url is set the cdm api tries
493
    to connect the web service over the given proxy server.
494
    Otherwise proxy usage is deactivated.'),
495
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
496
  );
497

    
498
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
499
    '#type' => 'textfield',
500
    '#title' => t('Proxy port') . ':',
501
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
502
  );
503

    
504
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
505
    '#type' => 'textfield',
506
    '#title' => t('Login') . ':',
507
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
508
  );
509

    
510
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
511
    '#type' => 'textfield',
512
    '#title' => t('Password') . ':',
513
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
514
  );
515

    
516
  // TODO: settings are still incomplete, compare with
517
  // trunk/dataportal/inc/config_default.php.inc.
518
  $form['taxon_tree'] = array(
519
    '#type' => 'fieldset',
520
    '#title' => t('Taxon Tree'),
521
    '#collapsible' => FALSE,
522
    '#collapsed' => TRUE,
523
    '#description' => t('<p>When you explore your collection, you can navigate
524
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
525
      able to navigate through your collection the
526
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
527
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
528
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
529
      </a></p>'),
530
  );
531

    
532
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
533
    '#type' => 'select',
534
    '#title' => t('Available classifications') . ':',
535
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
536
    '#options' => cdm_get_taxontrees_as_options(),
537
    '#description' => t('Select the default taxa classification for your
538
      <em>taxon tree</em>, the other classifications will be also available but
539
      with a manual user change.'),
540
  );
541

    
542
  $form['taxon_tree']['taxontree_ranklimit'] = array(
543
    '#type' => 'select',
544
    '#title' => t('Rank of highest displayed taxon') . ':',
545
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
546
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
547
    '#options' => cdm_rankVocabulary_as_option(),
548
    '#description' => t('This is the rank of the highest displayed taxon in the
549
      <em>taxon tree</em>. You can select here which rank should be at the top
550
      level of the tree structure.'),
551
  );
552

    
553
  $form['aggregation'] = array(
554
      '#type' => 'fieldset',
555
      '#title' => t('Aggregation of data'),
556
      '#collapsible' => FALSE,
557
      '#description' => t("This section covers the different aspects of aggregating information.
558
          <p>
559
          </p>"),
560

    
561
  );
562

    
563
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
564
      '#type' => 'checkboxes',
565
      '#title' => 'Taxon media filter',
566
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
567
      '#options' => array(
568
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
569
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
570
          'includeOccurrences' => 'Media related to specimens and occurrences',
571
      ),
572
      '#description' => 'This filter configures which images should be taken into account.',
573
  );
574

    
575
  $form['aggregation']['notice'] = array(
576
      '#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
577
          want to make use of the caching capabilities of the dataportal.',
578
  );
579

    
580
  $form['aggregation']['media_aggregation'] = array(
581
      '#type' => 'fieldset',
582
      '#title' => t('Media aggregation'),
583
      '#collapsible' => FALSE,
584
      '#collapsed' => TRUE,
585
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
586

    
587
  );
588
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
589
      '#type' => 'select',
590
      '#title' => t('Aggregation of taxon pictures') . ':',
591
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
592
      '#options' => array(
593
          0 => "Show only pictures of the current taxon",
594
          1 => "Include pictures of taxonomic children",
595
      ),
596
      '#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."),
597
  );
598

    
599
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
600
      '#type' => 'fieldset',
601
      '#attributes' => array('class'=>array('clearfix')),
602
      '#title' => t('Aggregation via taxon relationsships'),
603
      '#collapsible' => TRUE,
604
      '#collapsed' => TRUE,
605
      '#tree' => TRUE,
606
      '#description' => t('Information on taxa will be aggregated along the below chosen
607
          taxon relation ships. This will affect images and occurrences (specimens).
608
          Taxon relation ships are directed and point form one taxon to another. The taxon
609
          relationships to be taken into accunt can therefore configured for the direct direction
610
          and for the inverse.'),
611
  );
612

    
613
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
614
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
615

    
616
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
617
      '#type' => 'checkboxes',
618
      '#title' => t('Direct'),
619
      '#options' => $taxonRelationshipTypeOptions,
620
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
621
  );
622
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
623
      '#type' => 'checkboxes',
624
      '#title' => t('Invers'),
625
      '#options' => $taxonRelationshipTypeOptions,
626
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
627
  );
628

    
629
  // Comment @WA: D7 form api does not support reset buttons,
630
  // so to mimic the D5 reset button we add one like this.
631
  $form['actions']['reset'] = array(
632
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
633
    '#weight' => 1000,
634
  );
635

    
636
  return system_settings_form($form);
637
}
638

    
639

    
640
/**
641
 * LAYOUT settings
642
 * @return unknown_type
643
 *   todo
644
 */
645
function cdm_settings_layout() {
646

    
647
  $form = array();
648

    
649
  $form['about'] = array(
650
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
651
      layout. If you want to configure the specific sites layout visit the
652
      respective configuration site for taxon, search or media.') . '</p>',
653
  );
654

    
655
  // ---- footnotes --- //
656
  $form['footnotes'] = array(
657
    '#type' => 'fieldset',
658
    '#title' => t('Footnotes'),
659
    '#collapsible' => FALSE,
660
    '#collapsed' => FALSE,
661
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
662
      media or distribution areas may have annotations or footnotes. When the
663
      footnotes are enabled they will be visible (if they exist).'),
664
  );
665

    
666
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
667
    '#type' => 'checkbox',
668
    '#title' => t('Do not show footnotes'),
669
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
670
    '#description' => t('Check this if you do not want to show any footnotes'),
671
  );
672

    
673
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
674
    '#type' => 'checkbox',
675
    '#title' => t('Do not show annotations footnotes'),
676
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
677
    '#description' => t('Check this if you do not want to show annotation footnotes'),
678
  );
679

    
680
  $annotationTypeOptions = cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE);
681
  // Additional option for the NULL case.
682
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
683
  $form['footnotes']['annotations_types_as_footnotes'] = array(
684
    '#type' => 'checkboxes',
685
    '#title' => t('Annotation types as footnotes'),
686
    '#description' => t("Only annotations of the selected type will be displayed
687
       as footnotes. You may want to turn 'technical annotations' off."),
688
    '#options' => $annotationTypeOptions,
689
  );
690
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
691
  if (!empty($annotationsTypesAsFootnotes)) {
692
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
693
  }
694

    
695
  // --- Advanced Search --- //
696
  $form['asearch'] = array(
697
      '#type' => 'fieldset',
698
      '#title' => t('Advanced search'),
699
      '#collapsible' => FALSE,
700
      '#collapsed' => FALSE,
701
  );
702
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
703
      '#type' => 'checkbox',
704
      '#title' => t('Show advanced search link'),
705
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
706
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
707
  );
708

    
709
  // ---- Taxon Name Rendering --- //
710
  $form['taxon_name'] = array(
711
      '#type' => 'fieldset',
712
      '#title' => t('Taxon name display'),
713
      '#collapsible' => TRUE,
714
      '#collapsed' => TRUE,
715
      '#description' => t('The display of taxon names is configured by two parts.'
716
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
717
          . 'The name parts are defined in the <stong>part definitions</strong>'),
718
  );
719

    
720
  drupal_add_js(
721
      'jQuery(document).ready( function( ) {
722
         // pretty print json
723
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
724
         var obj = JSON.parse(json_text);
725
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
726

    
727
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
728
         obj = JSON.parse(json_text);
729
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
730
       });'
731
      ,array(
732
          'type' => 'inline',
733
          'scope' => 'footer'
734
      )
735
  );
736

    
737
  //TODO remove after all portals are using the settings
738
  $default_part_definitions = theme('get_partDefinition', array());
739
  if(!is_array($default_part_definitions)) {
740
    $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
741
  }
742

    
743
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
744
      '#type' => 'textarea',
745
      '#title' => t('Part definitions'),
746
      '#element_validate' => array('form_element_validate_json'),
747
      '#default_value' =>  json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions)),
748
      '#description' => '
749
          <p>
750
          (Clearing the text area will reset it to the default)
751
          </p>
752
          <p>
753
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
754
          </p>
755
          <p>
756
           A full taxon name plus additional information can consist of the following elements:
757
          <ul>
758
             <li>name: the taxon name inclugin rank nbut without author</li>
759
             <li>authors:  The authors of a reference, also used in taxon names</li>
760
             <li>reference: the nomenclatural reference,</li>
761
             <li>microreference:  Volume, page number etc.</li>
762
             <li>status:  The nomenclatural status of a name</li>
763
             <li>description: name descriptions like protologues etc ...</li>
764
          </ul>
765
          </p>
766
          <p>
767
           These elements are combined in the part definitions array to from the specific parts to be rendered.
768
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
769
           Usually the following parts are formed:
770
          <ul>
771
            <li>namePart: the name and rank (in example: "Lapsana communis")</li>
772
            <li>authorshipPart: the author (in example: "L.")</li>
773
            <li>nameAuthorPart: the combination of name and author part (in example: "Lapsana communis L.").</li>
774
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
775
               be combined when a link to the taxon is rendered.</li>
776
            <li>referencePart: the nomencaltural reference (in example: "Sp. Pl. 1753")</li>
777
            <li>microreferencePart: usually the page number (in example ": 811.")</li>
778
            <li>statusPart: the nomenclatorical status</li>
779
            <li>descriptionPart: name descriptions like protologues etc ...</li>
780
          </ul>
781
          </p>
782
          <p>
783
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
784
           specific parts part definitions:
785
          <ul>
786
            <li>BotanicalName</li>
787
            <li>ZoologicalName</li>
788
            <li>#DEFAULT: covers ViralNames and other NonViralNames
789
          </ul>
790
           An example:
791
          <pre>
792
           {
793
            "ZoologicalName": {
794
              "namePart": {
795
                "name": true
796
              },
797
              "referencePart": {
798
                "authors": true
799
              },
800
              "microreferencePart": {
801
                "microreference": true
802
              },
803
              "statusPart": {
804
                "status": true
805
              },
806
              "descriptionPart": {
807
                "description": true
808
              }
809
            },
810
            "BotanicalName": {
811
              "namePart": {
812
                "name": true,
813
                "authors": true
814
              },
815
              "referencePart": {
816
                "reference": true,
817
                "microreference": true
818
              },
819
              "statusPart": {
820
                "status": true
821
              },
822
              "descriptionPart": {
823
                "description": true
824
              }
825
            }
826
          }
827
           </pre>',
828
  );
829

    
830
  //TODO remove after all portals are using the settings
831
  $default_render_templates = theme('get_nameRenderTemplate', array());
832
  if(!is_array($default_render_templates)) {
833
    $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
834
  }
835

    
836
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
837
      '#type' => 'textarea',
838
      '#title' => t('Name render templates'),
839
      '#element_validate' => array('form_element_validate_json'),
840
      '#default_value' =>  json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates)),
841
      '#description' => '
842
          <p>
843
          (Clearing the text area will reset it to the default)
844
          </p>
845
          <p>
846
          The render templates array contains one or more name render templates to be used within the page areas identified by the
847
          render path. The render path is used as key of the array sub subelements whereas the name render template array is set as value.
848
          The following render Path keys are curretly recognized:
849
          <ul>
850
            <li>list_of_taxa:</li>
851
            <li>acceptedFor:</li>
852
            <li>taxon_page_synonymy</li>
853
            <li>typedesignations</li>
854
            <li>taxon_page_title</li>
855
            <li>polytomousKey</li>
856
            <li>na: name + authorship</li>
857
            <li>nar:name + authorship + reference</li>
858
            <li>#DEFAULT</li>
859
          </ul>
860
          A single render template can be used for multiple render paths. In this case the according key of the render templates
861
          array element should be a comma separated list of render paths, without any whitespace!.
862
          </p>
863
          <p>
864
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
865
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
866
          <p>
867
          The value of the render template element must be set to TRUE in order to let this part being rendered.
868
          The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
869
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
870
          links if the paramters $nameLink or $refenceLink are given to the name render function
871
          (this is hard coded and cannot be configured here).',
872
  );
873

    
874
  // @WA: D7 form api does not support reset buttons,
875
  // so to mimic the D5 reset button we add one like this.
876
  $form['actions']['reset'] = array(
877
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
878
    '#weight' => 1000,
879
  );
880

    
881
  $form['#submit'] = array('submit_json_as_php_array');
882
  // #json_elements especially defined for submit_json_as_php_array()
883
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
884
  return system_settings_form($form);
885
}
886

    
887

    
888
/**
889
 * @todo Please document this function.
890
 * @see http://drupal.org/node/1354
891
 */
892
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
893
  $form[$form_name] = array(
894
    '#type' => 'fieldset',
895
    '#title' => t($form_title),
896
    '#collapsible' => TRUE,
897
    '#collapsed' => $collapsed,
898
    '#tree' => TRUE,
899
    '#description' => t($form_description),
900
  );
901

    
902
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
903
  $gallery_settings = variable_get($form_name, $default_values);
904
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
905
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
906
    /*
907
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
908
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
909
    '#type' => 'textfield',
910
    '#title' => t('Search Page Size'),
911
    '#default_value' => $test,
912
    '#description' => t('Number of Names to display per page in search results.')
913
    );
914
    */
915
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
916
      '#type' => 'checkbox',
917
      '#title' => t('Show media thumbnails for accepted taxa'),
918
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
919
    );
920

    
921
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
922
      '#type' => 'checkbox',
923
      '#title' => t('Show media thumbnails for synonyms'),
924
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
925
      '#description' => '',
926
    );
927
  }
928

    
929
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
930
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
931
    '#type' => 'checkbox',
932
    '#title' => t('Show captions under thumbnails'),
933
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
934
    '#description' => '',
935
  );
936

    
937
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
938
    '#type' => 'textfield',
939
    '#title' => t('Thumbnail size') . ':',
940
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
941
    '#description' => t('Select the size of each individual thumbnail.'),
942
  );
943

    
944
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
945
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
946
      '#type' => 'textfield',
947
      '#title' => t('Number of columns') . ':',
948
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
949
      '#description' => t('Group the thumbnails in columns: select how many
950
        columns the gallery should display.'),
951
    );
952
  }
953

    
954
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
955
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
956
      '#type' => 'textfield',
957
      '#title' => t('Maximum number of rows') . ':',
958
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
959
      '#description' => t('You can group the thumbnails in rows, select in how
960
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
961
        If you want an unlimited number of rows please set to 0.'),
962
    );
963
  }
964

    
965
  return $form;
966
}
967

    
968
/**
969
 * @todo document this function.
970
 */
971
function cdm_settings_layout_taxon() {
972
  $collapsed = FALSE;
973
  $form = array();
974

    
975
  // --------- TABBED TAXON ------- //
976
  $form['taxon_tabs'] = array(
977
    '#type' => 'fieldset',
978
    '#title' => t('Taxon tabs'),
979
    '#collapsible' => TRUE,
980
    '#collapsed' => FALSE,
981
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
982
      be splitted in four diferent tabs; General, Synonymy, Images and
983
      Specimens. If the taxon has no information for any of the tabs/sections
984
      such tab will be not displayed.'),
985
  );
986

    
987
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
988
    '#type' => 'checkbox',
989
    '#title' => t('Tabbed taxon page'),
990
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
991
    '#description' => t('<p>If selected split the taxon page into individual
992
      tabs for description, images, synonymy and specimens. If not the taxon
993
      data is rendered as a long single page without tabs.</p>'),
994
  );
995

    
996
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
997
    '#type' => 'checkboxes',
998
    '#title' => t('Tabs visibility options') . ':',
999
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1000
    '#options' => get_taxon_options_list(),
1001
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1002
  );
1003

    
1004
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1005
    '#type' => 'select',
1006
    '#title' => t('Default tab to display') . ':',
1007
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1008
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1009
    '#description' => t('<p>Select the default tab to display when visiting a
1010
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1011
      <strong>Note:</strong> After performing a search and clicking in any
1012
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1013
      taxon and not the above selected tab.'),
1014
  );
1015

    
1016
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1017
    '#type' => 'checkbox',
1018
    '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1019
    '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1020
    '#description' => t('<p>If checked the link to search results is rendered at
1021
       the top of the taxon site. Clicking on the link the last search performed
1022
       is rendered again.</p>'),
1023
  );
1024

    
1025
  /* ======  TAXON_PROFILE ====== */
1026
  $form['taxon_profile'] = array(
1027
    '#type' => 'fieldset',
1028
    '#title' => t('Taxon profile (tab)'),
1029
    '#description' => t('<p>This section covers the settings related to the taxon
1030
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1031
    '#collapsible' => TRUE,
1032
    '#collapsed' => TRUE,
1033
  );
1034

    
1035
  // ---- PROFILE PICTURE ----//
1036
  $form['taxon_profile']['picture'] = array(
1037
    '#type' => 'fieldset',
1038
    '#title' => t('Taxon profile picture'),
1039
    '#collapsible' => TRUE,
1040
    '#collapsed' => FALSE,
1041
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1042
  );
1043

    
1044
  $form['taxon_profile']['picture']['cdm_dataportal_show_default_image'] = array(
1045
    '#type' => 'checkbox',
1046
    '#title' => t('Enable profil picture'),
1047
    '#default_value' => variable_get('cdm_dataportal_show_default_image', FALSE),
1048
    '#description' => t('Show the profil picture.'),
1049
  );
1050

    
1051
  $options = cdm_rankVocabulary_as_option();
1052
  array_unshift($options, '-- DISABLED --');
1053
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1054
    '#type' => 'select',
1055
    '#title' => t('Hide profile picture for higher ranks') . ':',
1056
    '#default_value' => variable_get('image_hide_rank', '0'),
1057
    '#options' => $options,
1058
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1059
  );
1060

    
1061
  // -- MEDIA THUMBNAILS -- //
1062
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1063
  $form_title = 'Taxon Profile Images';
1064
  $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>';
1065
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1066

    
1067
  // ---- FEATURE TREE ---- //
1068
  $form['taxon_profile']['feature_trees'] = array(
1069
    '#type' => 'fieldset',
1070
    '#title' => t('Features'),
1071
    '#collapsible' => TRUE,
1072
    '#collapsed' => FALSE,
1073
    '#description' => t("This section covers settings related to the taxon's
1074
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1075
      features such as description, distribution, common names, etc. that Drupal
1076
      will render at the taxon profile page."),
1077
  );
1078
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1079
  $saved_uuid = variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1080
  if(!isset($featureTrees['options'][$saved_uuid])) {
1081
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1082
  }
1083
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
1084
    '#type' => 'radios',
1085
    '#title' => t('Taxon profile sections') . ':',
1086
    '#default_value' => $saved_uuid,
1087
    '#options' =>  $featureTrees['options'],
1088
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1089
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1090
    '#description' => t('Select the Feature Tree to be displayed at the taxon
1091
      profile. Click "Show Details" to see the Feature Tree elements.'
1092
    ),
1093
  );
1094
  $featureTrees = cdm_get_featureTrees_as_options();
1095
  $saved_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1096
  if(!isset($featureTrees['options'][$saved_uuid])) {
1097
    $saved_uuid = NULL;
1098
  }
1099
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
1100
    '#type' => 'radios',
1101
    '#title' => t('Natural language representation of structured descriptions') . ':',
1102
    '#default_value' => $saved_uuid,
1103
    '#options' => $featureTrees['options'],
1104
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1105
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1106
    '#description' => t('Taxon descriptions can be stored in a highly structured
1107
      form. The feature tree selected here will be used to generate textual
1108
      representation in natural language.'
1109
    ),
1110
  );
1111

    
1112
  // ---- LAYOUT PER FEATURE ---- //
1113
  $feature_tree = get_profile_featureTree();
1114
  if (isset($feature_tree->root->children)) {
1115

    
1116
    $form_feature_list_layout = array(
1117
      '#title' => t('Taxon profile layout'),
1118
      '#collapsible' => TRUE,
1119
      '#collapsed' => FALSE,
1120
      '#type' => 'fieldset',
1121
      '#description' => t('Will be available in a future release.'),
1122
    );
1123

    
1124
    $feature_list_layout_settings_disabled = TRUE;
1125
    foreach ($feature_tree->root->children as $featureNode) {
1126

    
1127
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1128
        // Must not exceed 45 characters !!!
1129
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1130

    
1131
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1132
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1133

    
1134
        $form_feature_list_layout[$subform_id] = array(
1135
          '#tree' => TRUE,
1136
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1137
          '#collapsible' => FALSE,
1138
          '#collapsed' => FALSE,
1139
          '#type' => 'fieldset',
1140
          '#description' => t(''),
1141
        );
1142

    
1143
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1144
          '#type' => 'checkbox',
1145
          '#title' => t('Enable'),
1146
          '#default_value' => $settings['enabled'],
1147
          '#description' => t('Enable user defined layout for this feature'),
1148
        );
1149

    
1150
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1151
          '#type' => 'textfield',
1152
          '#title' => t('Enclosing tag'),
1153
          '#disabled' => !$settings['enabled'],
1154
          '#default_value' => $settings['enclosingTag'],
1155
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1156
        );
1157

    
1158
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1159
          '#type' => 'textfield',
1160
          '#title' => t('Entry enclosing tag'),
1161
          '#disabled' => !$settings['enabled'],
1162
          '#default_value' => $settings['entryEnclosingTag'],
1163
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1164
        );
1165

    
1166
        $form_feature_list_layout[$subform_id]['glue'] = array(
1167
          '#type' => 'textfield',
1168
          '#title' => t('Glue'),
1169
          '#disabled' => !$settings['enabled'],
1170
          '#default_value' => $settings['glue'],
1171
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1172
        );
1173

    
1174
      }
1175

    
1176
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1177
    }
1178
  }
1179

    
1180
  // ---- DISTRIBUTION LAYOUT ---- //
1181
  $form['taxon_profile']['distribution_layout'] = array(
1182
    '#title' => t('Distribution'),
1183
    '#collapsible' => TRUE,
1184
    '#collapsed' => FALSE,
1185
    '#type' => 'fieldset',
1186
    '#description' => t('Select if you want to sort or not the distribution text
1187
      located below the distribution map.'),
1188
  );
1189

    
1190
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1191
    '#type' => 'radios',
1192
    '#title' => t('Sort') . ':',
1193
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1194
    '#options' => array(
1195
      'NO_SORT' => t('Standard (No sort)'),
1196
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1197
    ),
1198
  );
1199

    
1200
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1201
    '#type' => 'checkbox',
1202
    '#title' => t('Show TextData elements on top of the map'),
1203
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1204
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1205
      elements on top of the map. Otherwise all <code>TextData</code>
1206
      distribution elements will be listed below the other area elements.
1207
      This option is useful if you need to have descriptive texts for each
1208
      distribution map.'),
1209
  );
1210

    
1211

    
1212
  /* ====== SYNONYMY ====== */
1213
  $form['taxon_synonymy'] = array(
1214
    '#type' => 'fieldset',
1215
    '#title' => t('Taxon synonymy (tab)'),
1216
    '#collapsible' => TRUE,
1217
    '#collapsed' => TRUE,
1218
    '#description' => t('This section covers the settings related to the taxon
1219
      <strong>synonymy</strong> tab.'),
1220
  );
1221

    
1222
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1223
    '#type' => 'checkbox',
1224
    '#title' => t('Show accepted taxon on top of the synonymy'),
1225
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1226
    '#description' => t('If checked, the first homotypic taxon is a repetition
1227
      of the accepted taxon most likely with the full nomenclatural reference
1228
      (depending on the currently chosen theme).'),
1229
  );
1230

    
1231
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1232
    '#type' => 'checkbox',
1233
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1234
      coming from a synonym link.'),
1235
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1236
    '#description' => t('Check this if after doing a search and clicking on a
1237
      synonym you want to see the "accept of" text for the accepted synonym.'),
1238
  );
1239

    
1240
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1241
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1242
    '#type' => 'checkboxes',
1243
    '#title' => t('Display name relationships') . ':',
1244
    '#default_value' => variable_get('name_relationships_to_show', 0),
1245
    '#options' => $nameRelationshipTypeOptions,
1246
    '#description' => t('Select the name relationships you want to show for the
1247
      accepted taxa.'),
1248
  );
1249

    
1250
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1251
    '#type' => 'checkbox',
1252
    '#title' => t('Show taxon relations ships of accepted taxon'),
1253
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1254
    '#description' => t('If this option is enabled the synonymy will show the
1255
      below selected taxon relationships of accepted taxa.'),
1256
  );
1257

    
1258
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1259
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1260
    '#type' => 'checkboxes',
1261
    '#title' => t('Taxon relationship types') . ':',
1262
    '#description' => t('Only taxon relationships of the selected type will be
1263
      displayed'),
1264
    '#options' => $taxonRelationshipTypeOptions,
1265
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1266
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1267
  );
1268

    
1269
  // ====== SPECIMENS ====== //
1270
  $form['taxon_specimens'] = array(
1271
    '#type' => 'fieldset',
1272
    '#title' => t('Taxon specimens (tab)'),
1273
    '#collapsible' => TRUE,
1274
    '#collapsed' => TRUE,
1275
    '#description' => t('This section covers the settings related to the taxon
1276
      <strong>specimens</strong> tab.'),
1277
  );
1278

    
1279
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1280
  $saved_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1281
  if(!isset($featureTrees['options'][$saved_uuid])) {
1282
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1283
  }
1284
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1285
      '#type' => 'radios',
1286
      '#title' => t('Specimen description feature tree') . ':',
1287
      '#default_value' => $saved_uuid,
1288
      '#options' =>  $featureTrees['options'],
1289
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1290
      '#options_suffixes' => $featureTrees['treeRepresentations'],
1291
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1292
      ),
1293
  );
1294

    
1295
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1296
  $form_title = t('Specimen media');
1297
  $form_description = t('Specimens may have media which is displayed at the
1298
     Specimen tab/section as a gallery. It is possible to configure the
1299
     thumbnails gallery here, however for configuring how a single media should
1300
     be displayed please go to !url.</p>',
1301
     array(
1302
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1303
     ));
1304
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1305

    
1306
  // --- MEDIA GALLERY ---- //
1307
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1308
  $form_title = 'Media gallery (tab)';
1309
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1310
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1311
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1312
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1313
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1314
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1315
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1316

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

    
1326
/**
1327
 * @todo document this function.
1328
 */
1329
function cdm_settings_layout_search() {
1330

    
1331
  $form = array();
1332

    
1333
  $form['search_settings'] = array(
1334
    '#type' => 'fieldset',
1335
    '#title' => t('Taxa Search'),
1336
    '#collapsible' => FALSE,
1337
    '#collapsed' => FALSE,
1338
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1339
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1340
         where they can write the text to be searched. You can find Drupal block configuration
1341
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1342
  );
1343

    
1344
  $form['search_settings']['simple_search_ignore_classification'] = array(
1345
      '#type' => 'checkbox',
1346
      '#title' => t('Ignore the chosen classification in simple search'),
1347
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
1348
      '#description' => t('The simple search, which can be executed via the search block,
1349
          will by default search on all classifications. Remove the tick if you want your
1350
          portal to search on the classification selected in the classification browser
1351
          selector.'),
1352
  );
1353

    
1354
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1355
    '#type' => 'textfield',
1356
    '#title' => t('Results per page') . ':',
1357
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1358
    '#description' => t('Number of results to display per page.'),
1359
  );
1360

    
1361
  $form['search_settings']['cdm_search_taxa'] = array(
1362
    '#type' => 'checkbox',
1363
    '#title' => t('Sets the default value of <em>Search for accepted taxa</em> in the advanced search form.'),
1364
    '#default_value' => variable_get('cdm_search_taxa', 1),
1365
    '#description' => t('<p>If checked the <em>Search for accepted taxa </em> option will be enabled in the advanced form.</p>'),
1366
  );
1367

    
1368
  $form['search_settings']['cdm_search_synonyms'] = array(
1369
    '#type' => 'checkbox',
1370
    '#title' => t('Sets the default value of <em>Search for synonyms</em> in the advanced search form.'),
1371
    '#default_value' => variable_get('cdm_search_synonyms', 1),
1372
    '#description' => t('<p>If checked the <em>Search for synonyms</em> option will be enabled in the advanced form.</p>'),
1373
  );
1374

    
1375
  $form['search_settings']['cdm_search_common_names'] = array(
1376
    '#type' => 'checkbox',
1377
    '#title' => t('Sets the default value of <em>Search for common names</em> in the advanced search form.'),
1378
    '#default_value' => variable_get('cdm_search_common_names', 0),
1379
    '#description' => t('<p>If checked the <em>Search for common names</em> option will be enabled in the advanced form.</p>'),
1380
  );
1381

    
1382
  $form['search_settings']['cdm_search_use_default_values'] = array(
1383
    '#type' => 'checkbox',
1384
    '#title' => t('Sets use of default values in the advanced search form.'),
1385
    '#default_value' => variable_get('cdm_search_use_default_values', 1),
1386
    '#description' => t('<p>If checked the defqult values set abovewill be used for the search.</p>'),
1387
  );
1388

    
1389

    
1390
  // --- SEARCH TAXA GALLERY ---- //
1391
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1392
  $collapsed = FALSE;
1393
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1394
  $form_title = 'Taxa Search thumbnails';
1395
  $form_description = 'Search results may show thumbnails. ';
1396
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1397

    
1398
  // Comment @WA: D7 form api does not support reset buttons,
1399
  // so to mimic the D5 reset button we add one like this.
1400
  $form['actions']['reset'] = array(
1401
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1402
    '#weight' => 1000,
1403
  );
1404
  return system_settings_form($form);
1405
}
1406

    
1407
/**
1408
 * @todo document this function.
1409
 */
1410
function cdm_settings_layout_media() {
1411

    
1412
  $form = array();
1413

    
1414
  $form['media_settings'] = array(
1415
    '#type' => 'fieldset',
1416
    '#title' => t('Media settings'),
1417
    '#collapsible' => FALSE,
1418
    '#collapsed' => FALSE,
1419
    '#description' => 'This section covers layout settings for media pages.'
1420
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
1421
  );
1422

    
1423
  $form['media_settings']['image_gallery_viewer'] = array(
1424
    '#type' => 'select',
1425
    '#title' => t('Image viewer') . ':',
1426
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1427
    '#options' => array(
1428
      'default' => t('Standard image viewer'),
1429
      'fsi' => t('FSI viewer (requires FSI server!)'),
1430
    ),
1431
  );
1432

    
1433
  // --- MEDIA GALLERY ---- //
1434
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1435
  $form_title = 'Standard viewer';
1436
  $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>';
1437
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1438
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1439

    
1440
  // @WA: D7 form api does not support reset buttons,
1441
  // so to mimic the D5 reset button we add one like this.
1442
  $form['actions']['reset'] = array(
1443
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1444
    '#weight' => 1000,
1445
  );
1446
  return system_settings_form($form);
1447
}
1448

    
1449
/**
1450
 * GEOSERVICE and Map settings.
1451
 */
1452
function cdm_settings_geo($form, &$form_state) {
1453

    
1454
  $form = array();
1455

    
1456
  /*
1457
  GEO SERVER
1458
  */
1459
  $form['edit_map_server'] = array(
1460
    '#type' => 'fieldset',
1461
    '#tree' => true,
1462
    '#title' => t('EDIT map service'),
1463
    '#collapsible' => TRUE,
1464
    '#collapsed' => TRUE,
1465
    '#description' => t('Configuration and selection of your geo server.
1466
      The Geo Server is responsible for generating the maps.'),
1467
  );
1468

    
1469
  $current_geoserver_settings = get_edit_map_service_settings();
1470

    
1471
  $form['edit_map_server']['base_uri'] = array(
1472
    '#type' => 'select',
1473
    '#title' => t('EDIT map service') . ':',
1474
    '#default_value' => $current_geoserver_settings['base_uri'],
1475
    '#options' => unserialize(EDIT_MAPSERVER_URI),
1476
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
1477
  );
1478
  $form['edit_map_server']['version'] = array(
1479
      '#type' => 'select',
1480
      '#title' => t('Version') . ':',
1481
      '#default_value' => $current_geoserver_settings['version'],
1482
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
1483
      '#description' => t('The version of the EDIT map services'),
1484
  );
1485

    
1486
  /*
1487
  MAP SETTINGS
1488
  */
1489
  $form['map_settings'] = array(
1490
    '#type' => 'fieldset',
1491
    '#title' => t('Maps settings'),
1492
    '#collapsible' => TRUE,
1493
    '#collapsed' => TRUE,
1494
    '#description' => t('General configuration for all map types.'),
1495
  );
1496

    
1497
  $form['map_settings']['cdm_dataportal_geoservice_display_width'] = array(
1498
    '#type' => 'textfield',
1499
    '#title' => t('Maps width') . ':',
1500
    '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
1501
    '#description' => t('Choose the width of your maps, the height will always
1502
      be the half of the width. A value of 500 means the size will be 500 pixels
1503
      width and 250 pixels height.'),
1504
  );
1505

    
1506
  $form['map_settings']['cdm_dataportal_geoservice_bounding_box'] = array(
1507
    '#type' => 'textfield',
1508
    '#title' => t('Fixed bounding box') . ':',
1509
    '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
1510
    '#description' => t('Define surrounding of area to be displayed in maps.
1511
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
1512
      to let the map <strong>automatically zoom</strong> to the distribution
1513
      area.'),
1514
  );
1515

    
1516
  $form['map_settings']['cdm_dataportal_geoservice_labels_on'] = array(
1517
    '#type' => 'checkbox',
1518
    '#title' => '<b>' . t('Display area labels') . '</b>',
1519
    '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
1520
    '#description' => t('Check this if you like area names to be displayed in the maps. DOES IT WORK???? '),
1521
  );
1522

    
1523
  $form['map_settings']['cdm_dataportal_geoservice_map_caption'] = array(
1524
    '#type' => 'textfield',
1525
    '#title' => t('Map caption') . ':',
1526
    '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
1527
    '#description' => t('Define a caption for the map.'),
1528
  );
1529

    
1530
  $form['map_settings']['cdm_dataportal_geoservice_distributionOpacity'] = array(
1531
    '#type' => 'textfield',
1532
    '#title' => t('Distribution layer opacity') . ':',
1533
    '#default_value' => variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5'),
1534
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1535
                           fully visible, while a value near to 0.0 will be not much visible.'),
1536
  );
1537

    
1538
  $form['map_settings']['cdm_dataportal_map_openlayers'] = array(
1539
    '#type' => 'radios',
1540
    '#title' => t('Map Viewer') . ':',
1541
    '#options' => array(
1542
      1 => "OpenLayers dynamic mapviewer",
1543
      0 => "Plain image",
1544
    ),
1545
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1546
    '#description' => t('You can choose from two different map viewers:
1547
      <ul><li><em>OpenLayers</em> displays the maps in an interactive viewer
1548
      which allows zooming and panning. If not enabled the maps will consist
1549
      on a static image. If enabled you can configure the default layer
1550
      (background of your maps) below. Only one of them will be rendered.</li>
1551
      <li><em>Plain image</em> displays the map as a plain non interactive
1552
      image.</li></ul>'),
1553
  );
1554

    
1555
  $openLayersEnabled = variable_get('cdm_dataportal_map_openlayers', 1) == 1;
1556

    
1557

    
1558
  // --- Plain Image Settings --- //
1559
  $form['map_image'] = array(
1560
    '#type' => 'fieldset',
1561
    '#title' => t('Plain image map settings'),
1562
    '#collapsible' => TRUE,
1563
    '#collapsed' => $openLayersEnabled,
1564
    '#description' => t('The settings in this section are still expertimental
1565
      and can only be used with the EDIT map service version 1.1 or above.'),
1566
  );
1567

    
1568
  $edit_mapserver_version = get_edit_map_service_version_number();
1569
  if ($edit_mapserver_version < 1.1) {
1570
    $form['map_image']['#description'] = '<div class="messages warning">' . t("The selected EDIT map service version has to small version number: $edit_mapserver_version") . '</div>'
1571
      . $form['map_image']['#description'];
1572
  }
1573

    
1574
  $form['map_image']['map_base_layer'] = array(
1575
    '#type' => 'textfield',
1576
    '#title' => t('Background layer') . ':',
1577
    '#default_value' => variable_get('map_base_layer', 'cyprusdivs'),
1578
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
1579
      '!url1' => l(t('deegree-csw'), 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
1580
      '!url2' => l(t('geoserver layers'), 'http://edit.africamuseum.be/geoserver/web/'), // http://edit.africamuseum.be/geoserver/rest/layers
1581
    )),
1582
  );
1583

    
1584
  $form['map_image']['map_bg_color'] = array(
1585
    '#type' => 'textfield',
1586
    '#title' => t('Background color') . ':',
1587
    '#default_value' => variable_get('map_bg_color', '1874CD'),
1588
  );
1589

    
1590
  $form['map_image']['map_base_layer_style'] = array(
1591
    '#type' => 'textfield',
1592
    '#title' => t('Background layer area style') . ':',
1593
     // Only line color by now.
1594
    '#default_value' => variable_get('map_base_layer_style', 'ffffff,606060,,'),
1595
    '#description' => t('Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}'),
1596
  );
1597

    
1598

    
1599
  // --- OpenLayers Settings --- //
1600
  $form['openlayers'] = array(
1601
    '#type' => 'fieldset',
1602
    '#title' => t('OpenLayers settings'),
1603
    '#collapsible' => TRUE,
1604
    '#collapsed' => !$openLayersEnabled,
1605
    '#description' => '',
1606
  );
1607

    
1608
  if (!$openLayersEnabled) {
1609
    $form['openlayers']['#description'] = '<div class="messages warning">' . t('The Openlayers viewer is currently not enabled! (see section Maps settings above )') . '</div>'
1610
      . $form['openlayers']['#description'];
1611
  }
1612

    
1613
  $baselayer_options = array(
1614
    /*
1615
   NOTICE: must correspond to the layers defined in
1616
   js/openlayers_,ap.js#getLayersByName()
1617
   */
1618
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
1619
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
1620
    // all others EPSG:900913
1621
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
1622
    'edit-etopo1' => "ETOPO1 Global Relief Model",
1623
    'mapnik' => 'OpenStreetMap',
1624
    'osmarender' => 'OpenStreetMap (Tiles@home)',
1625
    'gmap' => 'Google Streets',
1626
    'gsat' => 'Google Satellite',
1627
    'ghyb' => 'Google Hybrid',
1628
    'veroad' => 'Virtual Earth Roads',
1629
    'veaer' => 'Virtual Earth Aerial',
1630
    'vehyb' => 'Virtual Earth Hybrid',
1631
    // 'yahoo' => 'Yahoo Street',
1632
    // 'yahoosat' => 'Yahoo Satellite',
1633
    // 'yahoohyb' => 'Yahoo Hybrid',
1634
  );
1635

    
1636
  $form['openlayers']['baselayers'] = array(
1637
    '#type' => 'checkboxes_preferred',
1638
    '#title' => t('Base Layers') . ':',
1639
    '#options' => $baselayer_options,
1640
    '#default_value' => variable_get('baselayers', array('metacarta_vmap0' => "metacarta_vmap0", 'PREFERRED' => 'metacarta_vmap0')),
1641
    '#description' => t('Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.'),
1642
  );
1643

    
1644
  // cdm_dataportal_geoservice_showLayerSwitcher
1645
  $form['openlayers']['cdm_dataportal_geoservice_showLayerSwitcher'] = array(
1646
    '#type' => 'checkbox',
1647
    '#title' => '<b>' . t('Show Layer Switcher') . '</b>',
1648
    '#default_value' => variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE),
1649
    '#description' => t('
1650
      The Layer Switcher control displays a table of contents
1651
      for the map.  This allows the user interface to switch between
1652
      BaseLayers and to show or hide Overlays.  By default the switcher is
1653
      shown minimized on the right edge of the map, the user may expand it
1654
      by clicking on the handle.'
1655
    ),
1656
  );
1657

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

    
1672
  $form['cdm_dataportal_geoservice_map_legend'] = array(
1673
    '#type' => 'fieldset',
1674
    '#title' => t('Map legend'),
1675
    '#collapsible' => TRUE,
1676
    '#collapsed' => TRUE,
1677
    '#description' => t('Configure the maps legend.'),
1678
  );
1679

    
1680
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
1681
    '#type' => 'checkbox',
1682
    '#title' => '<b>' . t('Display a map legend') . '</b>',
1683
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
1684
    '#description' => t('Check this if you like a legend to be displayed with the maps.'),
1685
  );
1686

    
1687
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legendOpacity'] = array(
1688
    '#type' => 'textfield',
1689
    '#title' => t('Legend opacity'),
1690
    '#default_value' => variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'),
1691
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
1692
                         to 0.0 will be not much visible.'),
1693
  );
1694

    
1695
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
1696
    '#type' => 'textfield',
1697
    '#title' => t('Font size'),
1698
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
1699
    '#description' => t('Font size in pixels.'),
1700
  );
1701

    
1702
  $fontStyles = array(
1703
    0 => "plane",
1704
    1 => "italic",
1705
  );
1706
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
1707
    '#type' => 'select',
1708
    '#title' => t('Available font styles'),
1709
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', FALSE),
1710
    '#options' => $fontStyles,
1711
    '#description' => t('Select a font style for the map legend.'),
1712
  );
1713

    
1714
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
1715
    '#type' => 'textfield',
1716
    '#title' => t('Legend icon width'),
1717
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
1718
    '#description' => t('Legend icon width in pixels.'),
1719
  );
1720
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
1721
    '#type' => 'textfield',
1722
    '#title' => t('Legend icon height'),
1723
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
1724
    '#description' => t('Legend icon height in pixels.'),
1725
  );
1726

    
1727
  // @WA: D7 form api does not support reset buttons,
1728
  // so to mimic the D5 reset button we add one like this.
1729
  $form['actions']['reset'] = array(
1730
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1731
    '#weight' => 1000,
1732
  );
1733

    
1734
  return system_settings_form($form);
1735
}
1736

    
1737
/**
1738
 * @todo document this function.
1739
 */
1740
function cdm_settings_cache() {
1741

    
1742
  $form = array();
1743

    
1744
  $form['cache_settings'] = array(
1745
    '#type' => 'fieldset',
1746
    '#title' => t('Cache Settings'),
1747
    '#collapsible' => FALSE,
1748
    '#collapsed' => FALSE,
1749
    '#description' => t('<p>When caching is enabled all single taxon sites are
1750
      stored in an internal drupal cache doing the portal response of taxa pages
1751
      faster. This is possible because the sites are loaded from the cache and
1752
      are not created from scratch.</p>'),
1753
  );
1754

    
1755
  $form['cache_settings']['cdm_webservice_cache'] = array(
1756
    '#type' => 'checkbox',
1757
    '#title' => t('<strong>Enable caching</strong>'),
1758
    '#options' => cdm_help_general_cache(),
1759
    '#default_value' => variable_get('cdm_webservice_cache', 1),
1760
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
1761
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
1762
       application the changes will be not visible till the cache is erased.
1763
       Therefore developers should deactived this feature when they are working
1764
       on the CDM Dataportal Module.</p>'),
1765
  );
1766

    
1767
  $form['cache_settings']['cdm_run_cache'] = array(
1768
    '#markup' => cdm_view_cache_site(),
1769
  );
1770

    
1771
  // @WA: D7 form api does not support reset buttons,
1772
  // so to mimic the D5 reset button we add one like this.
1773
  $form['actions']['reset'] = array(
1774
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1775
    '#weight' => 1000,
1776
  );
1777
  return system_settings_form($form);
1778
}
1779

    
1780
/**
1781
 * Walk and cache all taxon pages.
1782
 */
1783
function cdm_view_cache_site() {
1784

    
1785
  $out = '';
1786

    
1787
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
1788

    
1789
  $request_params = array();
1790
  $request_params['class'] = "Taxon";
1791

    
1792
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
1793
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
1794
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
1795

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

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

    
1805
  // Comment @WA: A form within a form is not valid html and not needed here.
1806
  // Also, it would be recommended just to include this part of the form in the
1807
  // rest of the form array in cdm_settings_cache().
1808
  // $out .= '<form id="cache_site">';
1809
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
1810
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
1811
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
1812
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
1813
  // $out .= '</form>';
1814
  $out .= '</div>';
1815
  /*
1816
  foreach($taxonPager->records as $taxon){
1817
    cdm_dataportal_taxon_view($uuid);
1818
  }
1819
  */
1820
  return $out;
1821
}
1822

    
1823
/**
1824
 * Form validation handler for ?
1825
 *
1826
 * Comment @WA: currently this handler is not used.
1827
 * It seems partly for cdm_settings_general en partly for cdm_settings_cache?
1828
 * Then you can change the name into cdm_settings_general_validate() or
1829
 * cdm_settings_cache_validate().
1830
 * But cdm_api_secref_cache_clear is not doing anything (yet)?
1831
 */
1832
function cdm_settings_validate($form, &$form_state) {
1833

    
1834
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
1835
    // form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
1836
    $form_state['values']['cdm_webservice_url'] .= '/';
1837
  }
1838

    
1839
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
1840
    cache_clear_all(NULL, 'cache_cdm_ws');
1841
    // Better clear secref_cache since I can not be sure if the cache has not
1842
    // be used during this response.
1843
    cdm_api_secref_cache_clear();
1844
  }
1845
}
1846

    
1847
/**
1848
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
1849
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
1850
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
1851
 *  - version: the version, e.g.: v1.1
1852
 *
1853
 * @return array
1854
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
1855
 */
1856
function get_edit_map_service_settings() {
1857

    
1858
  $settings = variable_get('edit_map_server', array(
1859
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
1860
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
1861
      )
1862
  );
1863
  // replace old non tree like settings by default
1864
  // TODO to be removed after release 3.1.5
1865
  if(!is_array($settings)){
1866
    variable_del('edit_map_server');
1867
    return get_edit_map_service_settings();
1868
  }
1869

    
1870
  return $settings;
1871
}
1872

    
1873
/**
1874
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
1875
 *
1876
 * @return string
1877
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
1878
 */
1879
function get_edit_map_service_full_uri() {
1880
  $settings = get_edit_map_service_settings();
1881
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
1882
}
1883

    
1884

    
1885
/**
1886
 * Returns the version number of the currently selected edit mapserver as a float
1887
 *
1888
 * @return float
1889
 *   The version number of the currently selected edit mapserver as a float.
1890
 *   Returns 0 on error.
1891
 */
1892
function get_edit_map_service_version_number() {
1893

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

    
1896
  $settings = get_edit_map_service_settings();
1897
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
1898
  if (isset($matches[1])) {
1899
    // Convert string to float.
1900
    $version = 1 + $matches[1][0] - 1;
1901
    return $version;
1902
  }
1903
  else {
1904
    // Report error.
1905
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
1906
        array(
1907
          '!version' => $settings['version'],
1908
          'warning')
1909
        )
1910
      );
1911
    return 0;
1912
  }
1913
}
1914

    
1915
/**
1916
 * Returns the array of selected items in a options array
1917
 *
1918
 * @param array $options
1919
 *   An options array as generated by a form element like checkoxes, select ...,
1920
 */
1921
function get_selection($options) {
1922
  $selection = array();
1923
  foreach ($options as $key=>$val) {
1924
    if (!empty($val)) {
1925
      $selection[] = $val;
1926
    }
1927
  }
1928
  return $selection;
1929
}
1930

    
1931

    
1932
/**
1933
 * Implements hook_element_info().
1934
 *
1935
 * Allows modules to declare their own Form API element types and specify their default values.
1936
 *
1937
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
1938
 */
1939
function cdm_dataportal_element_info() {
1940
  $type['checkboxes_preferred'] = array(
1941
    '#input' => TRUE,
1942
    '#process' => array('checkboxes_preferred_expand'),
1943
    '#after_build' => array('checkboxes_preferred_after_build'),
1944
    '#theme' => array('checkboxes_preferred'),
1945
    // '#theme_wrapper' => array('form_element'),
1946
  );
1947
  return $type;
1948
}
1949

    
1950
/**
1951
 * #process callback function for the custom form element type 'checkbox_preferred'
1952
 *
1953
 *
1954
 */
1955
function checkboxes_preferred_expand($element, &$form_state, $form) {
1956

    
1957
  // First of all create checkboxes for each of the elements
1958
  $element = form_process_checkboxes($element);
1959

    
1960
  $children = element_children($element);
1961

    
1962
  $element['table_start'] = array(
1963
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
1964
    '#weight' => -1,
1965
  );
1966

    
1967
  // prepare first part each of the table rows which contains the row label
1968
  $weight = 0;
1969
  foreach ($children as $key) {
1970
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
1971
    $element[$key]['#weight'] = $weight;
1972
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
1973
    $element[$key]['#suffix'] = '</td>';
1974
    unset($element[$key]['#title']);
1975
    $weight += 2;
1976
  }
1977
  $weight = 0;
1978

    
1979
  // add a radio button to each of the checkboxes, the
1980
  // check boxes have already been created at the beginning
1981
  // of this function
1982
  if (count($element['#options']) > 0) {
1983
    foreach ($element['#options'] as $key => $choice) {
1984
      if (!isset($element[$key . '_preferred'])) {
1985
        $element[$key . '_preferred'] = array(
1986
          '#type' => 'radio',
1987
          '#name' => $element['#parents'][0] . '_preferred',
1988
          '#return_value' => check_plain($key),
1989
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
1990
          '#attributes' => $element['#attributes'],
1991
          '#parents' => $element['#parents'],
1992
          // '#spawned' => TRUE,
1993
          '#weight' => $weight + 1,
1994
          '#prefix' => '<td>',        // add a prefix to start a new table cell
1995
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
1996
        );
1997
      }
1998
      $weight += 2;
1999
    }
2000
  }
2001

    
2002
  // end the table
2003
  $element['table_end'] = array(
2004
    '#markup' => '</table>',
2005
    '#weight' => $weight++,
2006
  );
2007

    
2008
  return $element;
2009
}
2010

    
2011
/**
2012
 * Theme function for the custom form field 'checkboxes_preferred'.
2013
 */
2014
function theme_checkboxes_preferred($variables) {
2015
  $element = $variables['element'];
2016
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
2017
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
2018
  $out .= drupal_render_children($element);
2019
  $out .= '<div class="description">' . $element['#description'] . '</div>';
2020
  $out .= '</div>';
2021
  return $out;
2022
}
2023

    
2024
/**
2025
 * Callback for checkboxes preferred for widget which will
2026
 * be called after the form or element is built. The call
2027
 * back is configured in the form element by setting it as
2028
 * #after_build parameter.
2029
 *
2030
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
2031
 *
2032
 * @param $form
2033
 *   Nested array of form elements that comprise the form.
2034
 * @param $form_state
2035
 *   A keyed array containing the current state of the form.
2036
 *
2037
 * @return the modified form array
2038
 */
2039
function checkboxes_preferred_after_build($form, &$form_state) {
2040

    
2041
  $parent_id = $form['#parents'][0];
2042

    
2043
  if ($_POST && count($_POST) > 0) {
2044
    // First pass of form processing.
2045
    $preferred_layer = $_POST[$parent_id . '_preferred'];
2046
    $form['#value']['PREFERRED'] = $preferred_layer;
2047
    $form_state[$parent_id] = $form['#value'];
2048
    $form_state['values']['baselayers'] = $form['#value'];
2049
  }
2050
  else {
2051
    // Second pass of form processing.
2052
    $preferred_layer = $form['#value']['PREFERRED'];
2053
  }
2054

    
2055
  // Also set the chosen value (not sure if this is good Drupal style ....).
2056
  foreach ($children = element_children($form) as $key) {
2057
    if (!empty($form[$key]['#type']) && $form[$key]['#type'] == 'radio') {
2058
      $form[$key]['#value'] = $preferred_layer;
2059
    }
2060
  }
2061
  // The default layer must always be enabled.
2062
  $form[$preferred_layer]['#value'] = $preferred_layer;
2063

    
2064
  return $form;
2065
}
2066

    
2067
function radios_prepare_options_suffix(&$elements){
2068

    
2069
  $childrenKeys = element_children($elements);
2070
  foreach($childrenKeys as $key){
2071
    if(!is_array($elements[$key]['#theme_wrappers'])){
2072
      $elements[$key]['#theme_wrappers'] = array();
2073
    }
2074
    if(isset($elements['#options_suffixes'][$key])){
2075
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
2076
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
2077
    }
2078
  }
2079
  return $elements;
2080

    
2081
}
2082

    
2083
/**
2084
 * TODO
2085
 * @param unknown $variables
2086
 */
2087
function theme_radio_options_suffix($variables) {
2088
  $element = $variables['element'];
2089
  if(isset($element['#options_suffix'])) {
2090
    $element['#children'] .= $element['#options_suffix'];
2091
  }
2092
  return $element['#children'];
2093
}
2094

    
2095

    
2096
/**
2097
 * Element validate callback for text field and arrays containing json.
2098
 *
2099
 * @param $element
2100
 *   The form element to validate
2101
 * @param $form
2102
 *   Nested array of form elements that comprise the form.
2103
 * @param $form_state
2104
 *   A keyed array containing the current state of the form.
2105
 */
2106
function form_element_validate_json($element, &$form_state, $form) {
2107
   if (!empty($element['#value'])) {
2108
     json_decode($element['#value']);
2109
     if(json_last_error() != JSON_ERROR_NONE){
2110
       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/'));
2111
     }
2112
   }
2113
}
2114

    
2115
/**
2116
 * Form submission handler for textareas and textfields containing JSON.
2117
 *
2118
 * The contained JSON will be converted into an php array
2119
 * or object and will be stores in the variables as such.
2120
 *
2121
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2122
 *
2123
 * @param $form
2124
 *   Nested array of form elements that comprise the form.
2125
 * @param $form_state
2126
 *   A keyed array containing the current state of the form.
2127
 *
2128
 */
2129
function submit_json_as_php_array($form, &$form_state) {
2130
  if (is_array($form['#json_elements'])) {
2131
    foreach ($form['#json_elements'] as $element){
2132
      if (trim($form_state['values'][$element])) {
2133
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
2134
      } else {
2135
        $form_state['values'][$element] = NULL;
2136
      }
2137
    }
2138
  }
2139
}
(13-13/13)