Project

General

Profile

Download (87.5 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
define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
84
define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
85
    array(
86
        'show' => 0,
87
        'maxextend' => 184,
88
        'media_uri_query' => '',
89
        'custom_placeholder_image_on' => 0,
90
        'custom_placeholder_image_fid' => ''
91
    )
92
  )
93
);
94

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

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

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

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

    
123
}
124

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

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

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

    
239
/**
240
 * @todo document this function.
241
 */
242
function getGallerySettings($gallery_config_form_name) {
243
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
244
  return variable_get($gallery_config_form_name, $default_values);
245
}
246

    
247
/**
248
 * Returns the string representation of the default tab.
249
 *
250
 * @param bool $returnTabIndex
251
 *   Defaults to FALSE, if set true this function will return the index number
252
 *   of the default tab. (used to supply default values to form elements).
253
 */
254
function get_default_taxon_tab($returnTabIndex = FALSE) {
255

    
256
  global $user;
257
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
258
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
259
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
260
  // Get the user value if the used has chosen to overwrite the system settings.
261
  $user_tab_on = variable_get($user_tab_active, FALSE);
262
  if ($user_tab_on) {
263
    $user_value = variable_get($user_tab, 0);
264
    $index_value = $user_value;
265
    // Get the system value.
266
  }
267
  else {
268
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
269
    $index_value = $system_value;
270
  }
271

    
272
  // Return the index value or the string representation.
273
  if ($returnTabIndex) {
274
    return $index_value;
275
  }
276
  else {
277
    return ($values[$index_value]);
278
  }
279

    
280
}
281

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

    
317
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
318
    'title' => 'Cache',
319
    'description' => 'Cache',
320
    'access arguments' => array('administer cdm_dataportal'),
321
    'page callback' => 'drupal_get_form',
322
    'page arguments' => array('cdm_settings_cache'),
323
    'weight' => 10,
324
    'type' => MENU_LOCAL_TASK,
325
  );
326

    
327
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
328
    'title' => 'Geo & Map',
329
    'description' => 'Geo & Map',
330
    'access arguments' => array('administer cdm_dataportal'),
331
    'page callback' => 'drupal_get_form',
332
    'page arguments' => array('cdm_settings_geo'),
333
    'weight' => 1,
334
    'type' => MENU_LOCAL_TASK,
335
  );
336

    
337
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
338
    'title' => 'Layout',
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'),
343
    'weight' => 2,
344
    'type' => MENU_LOCAL_TASK,
345
  );
346

    
347
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
348
    'title' => 'Taxon',
349
    'description' => 'Configure and adjust the layout of your DataPortal ',
350
    'access arguments' => array('administer cdm_dataportal'),
351
    'page callback' => 'drupal_get_form',
352
    'page arguments' => array('cdm_settings_layout_taxon'),
353
    'weight' => 1,
354
    'type' => MENU_LOCAL_TASK,
355
  );
356
  /*
357
  $items[] = array(
358
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
359
  'title' => t('Synonymy'),
360
  'description' => t('Configure and adjust the layout of your DataPortal '),
361
  'access' => user_access('administer cdm_dataportal'),
362
  'callback' => 'drupal_get_form',
363
  'callback arguments' => array('cdm_settings_layout_synonymy'),
364
  'weight' => 1,
365
  'type' => MENU_LOCAL_TASK,
366
  );
367

    
368
  $items[] = array(
369
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
370
  'title' => t('Specimens'),
371
  'description' => t('Configure and adjust the layout of your DataPortal '),
372
  'access' => user_access('administer cdm_dataportal'),
373
  'callback' => 'drupal_get_form',
374
  'callback arguments' => array('cdm_settings_layout_specimens'),
375
  'weight' => 1,
376
  'type' => MENU_LOCAL_TASK,
377
  );
378
  */
379
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
380
    'title' => 'Search',
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_search'),
385
    'weight' => 2,
386
    'type' => MENU_LOCAL_TASK,
387
  );
388

    
389
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
390
    'title' => 'Media',
391
    'description' => 'Configure and adjust the layout of your DataPortal ',
392
    'access arguments' => array('administer cdm_dataportal'),
393
    'page callback' => 'drupal_get_form',
394
    'page arguments' => array('cdm_settings_layout_media'),
395
    'weight' => 3,
396
    'type' => MENU_LOCAL_TASK,
397
  );
398

    
399
}
400

    
401
/**
402
 * @todo document this function.
403
 */
404
function cdm_help_general_cache() {
405
  $form = array();
406
  $form['cache_help'] = array(
407
    '#type' => 'fieldset',
408
    '#title' => t('Help'),
409
    '#collapsible' => TRUE,
410
    '#collapsed' => TRUE,
411
  );
412
  $form['cache_help']['test'] = array('#value' => t('probando'));
413
  return drupal_render($form);
414
  $res = array();
415
  $res['default'] = drupal_render($help);
416
  return $res;
417
}
418

    
419
/**
420
 * Configures the settings form for the CDM-API module.
421
 *
422
 * @return array
423
 *   Drupal settings form.
424
 */
425
function cdm_settings_general() {
426

    
427
  $form['cdm_webservice'] = array(
428
    '#type' => 'fieldset',
429
    '#title' => t('CDM Server'),
430
    '#collapsible' => FALSE,
431
    '#collapsed' => FALSE,
432
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
433
        CDM data base to the web via RESTful web services and thus is the source of the data
434
        to be displayed by a CDM DataPotal.'),
435
  );
436

    
437
  $form['cdm_webservice']['cdm_webservice_url'] = array(
438
    '#type' => 'textfield',
439
    '#title' => t('CDM web service URL') . ':',
440
    '#description' => t('This is the URL to the CDM-Server exposing your data
441
      e.g. <em>"http://localhost:8080/cichorieae/"</em> The URL <strong>must end
442
      with a slash</strong> character!'),
443
    '#default_value' => variable_get('cdm_webservice_url', NULL),
444
  );
445

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

    
453
  $form['cdm_webservice']['freetext_index'] = array(
454
    '#type' => 'fieldset',
455
    '#title' => t('Freetext index'),
456
    '#collapsible' => FALSE,
457
    '#collapsed' => FALSE,
458
  );
459

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

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

    
487
  $form['cdm_webservice']['proxy'] = array(
488
    '#type' => 'fieldset',
489
    '#title' => t('Proxy'),
490
    '#collapsible' => TRUE,
491
    '#collapsed' => TRUE,
492
  );
493

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

    
503
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
504
    '#type' => 'textfield',
505
    '#title' => t('Proxy port') . ':',
506
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
507
  );
508

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

    
515
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
516
    '#type' => 'textfield',
517
    '#title' => t('Password') . ':',
518
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
519
  );
520

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

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

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

    
558
  $form['aggregation'] = array(
559
      '#type' => 'fieldset',
560
      '#title' => t('Aggregation of data'),
561
      '#collapsible' => FALSE,
562
      '#description' => t("This section covers the different aspects of aggregating information.
563
          <p>
564
          </p>"),
565

    
566
  );
567

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

    
580
  $form['aggregation']['notice'] = array(
581
      '#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
582
          want to make use of the caching capabilities of the dataportal.',
583
  );
584

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

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

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

    
618
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
619
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
620

    
621
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
622
      '#type' => 'checkboxes',
623
      '#title' => t('Direct'),
624
      '#options' => $taxonRelationshipTypeOptions,
625
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
626
  );
627
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
628
      '#type' => 'checkboxes',
629
      '#title' => t('Invers'),
630
      '#options' => $taxonRelationshipTypeOptions,
631
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
632
  );
633

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

    
641
  return system_settings_form($form);
642
}
643

    
644

    
645
/**
646
 * LAYOUT settings
647
 * @return unknown_type
648
 *   todo
649
 */
650
function cdm_settings_layout() {
651

    
652
  $form = array();
653

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

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

    
671
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
672
    '#type' => 'checkbox',
673
    '#title' => t('Do not show footnotes'),
674
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
675
    '#description' => t('Check this if you do not want to show any footnotes'),
676
  );
677

    
678
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
679
    '#type' => 'checkbox',
680
    '#title' => t('Do not show annotations footnotes'),
681
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
682
    '#description' => t('Check this if you do not want to show annotation footnotes'),
683
  );
684

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

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

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

    
725
  drupal_add_js(
726
      'jQuery(document).ready( function( ) {
727
         // pretty print json
728
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
729
         var obj = JSON.parse(json_text);
730
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
731

    
732
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
733
         obj = JSON.parse(json_text);
734
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
735
       });'
736
      ,array(
737
          'type' => 'inline',
738
          'scope' => 'footer'
739
      )
740
  );
741

    
742
  //TODO remove after all portals are using the settings
743
  $default_part_definitions = theme('get_partDefinition', array());
744
  if(!is_array($default_part_definitions)) {
745
    $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
746
  }
747

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

    
835
  //TODO remove after all portals are using the settings
836
  $default_render_templates = theme('get_nameRenderTemplate', array());
837
  if(!is_array($default_render_templates)) {
838
    $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
839
  }
840

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

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

    
886
  $form['#submit'] = array('submit_json_as_php_array');
887
  // #json_elements especially defined for submit_json_as_php_array()
888
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
889
  return system_settings_form($form);
890
}
891

    
892

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

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

    
926
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
927
      '#type' => 'checkbox',
928
      '#title' => t('Show media thumbnails for synonyms'),
929
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
930
      '#description' => '',
931
    );
932
  }
933

    
934
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
935
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
936
    '#type' => 'checkbox',
937
    '#title' => t('Show captions under thumbnails'),
938
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
939
    '#description' => '',
940
  );
941

    
942
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
943
    '#type' => 'textfield',
944
    '#title' => t('Thumbnail size') . ':',
945
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
946
    '#description' => t('Select the size of each individual thumbnail.'),
947
  );
948

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

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

    
970
  return $form;
971
}
972

    
973
/**
974
 * @todo document this function.
975
 */
976
function cdm_settings_layout_taxon() {
977
  $collapsed = FALSE;
978
  $form = array();
979

    
980
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
981

    
982
  $form['cdm_dataportal_show_back_to_search_results'] = array(
983
      '#type' => 'checkbox',
984
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
985
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
986
      '#description' => t('<p>If checked the link to search results is rendered at
987
       the top of the taxon site. Clicking on the link the last search performed
988
       is rendered again.</p>'),
989
  );
990

    
991
  // --------- TABBED TAXON ------- //
992
  $form['taxon_tabs'] = array(
993
    '#type' => 'fieldset',
994
    '#title' => t('Taxon tabs'),
995
    '#collapsible' => TRUE,
996
    '#collapsed' => FALSE,
997
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
998
      be splitted in four diferent tabs; General, Synonymy, Images and
999
      Specimens. If the taxon has no information for any of the tabs/sections
1000
      such tab will be not displayed.'),
1001
  );
1002

    
1003
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1004
    '#type' => 'checkbox',
1005
    '#title' => t('Tabbed taxon page'),
1006
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1007
    '#description' => t('<p>If selected split the taxon page into individual
1008
      tabs for description, images, synonymy and specimens. If not the taxon
1009
      data is rendered as a long single page without tabs.</p>'),
1010
  );
1011

    
1012
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1013
    '#type' => 'checkboxes',
1014
    '#title' => t('Tabs visibility options') . ':',
1015
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1016
    '#options' => get_taxon_options_list(),
1017
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1018
  );
1019

    
1020
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1021
    '#type' => 'select',
1022
    '#title' => t('Default tab to display') . ':',
1023
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1024
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1025
    '#description' => t('<p>Select the default tab to display when visiting a
1026
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1027
      <strong>Note:</strong> After performing a search and clicking in any
1028
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1029
      taxon and not the above selected tab.'),
1030
  );
1031

    
1032
  /* ======  TAXON_PROFILE ====== */
1033
  $form['taxon_profile'] = array(
1034
    '#type' => 'fieldset',
1035
    '#title' => t('Taxon profile (tab)'),
1036
    '#description' => t('<p>This section covers the settings related to the taxon
1037
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1038
    '#collapsible' => TRUE,
1039
    '#collapsed' => TRUE,
1040
  );
1041

    
1042
  // ---- PROFILE PICTURE ----//
1043

    
1044
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1045
    '#type' => 'fieldset',
1046
    '#tree' => TRUE,
1047
    '#title' => t('Taxon profile picture'),
1048
    '#collapsible' => TRUE,
1049
    '#collapsed' => FALSE,
1050
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1051
  );
1052

    
1053
  //FIXME migrate variables:
1054
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1055
  // FIXME
1056
  //  eanable file modul in profile and in update
1057

    
1058
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1059
  /*
1060
   * 'show' => 1,
1061
   * 'maxextend' => 184,
1062
   * 'media_uri_query' => ''
1063
   * 'custom_placeholder_image_on' => 1,
1064
   * 'custom_placeholder_image_fid' => ''
1065
   */
1066
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1067
    '#type' => 'checkbox',
1068
    '#title' => t('Enable profil picture'),
1069
    '#description' => t('Show the profil picture.'),
1070
    '#default_value' => $taxon_profile_image_settings['show'],
1071
  );
1072

    
1073
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1074
      '#type' => 'textfield',
1075
      '#tree' => TRUE,
1076
      '#title' => t('Profil picture maximum extend'),
1077
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1078
      '#field_suffix' => 'px',
1079
      '#maxlength' => 4,
1080
      '#size' => 4,
1081
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1082
  );
1083

    
1084
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1085
      '#type' => 'textfield',
1086
      '#tree' => TRUE,
1087
      '#title' => t('Additional URI query parameter'),
1088
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1089
      '#maxlength' => 1024,
1090
      '#size' => 60,
1091
      '#description' => t('Additional query parameters to be used when requesting for the '
1092
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1093
          . 'The query parameters will be appendend to the uri of the media representation part'
1094
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1095
  );
1096

    
1097
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1098
      '#type' => 'checkbox',
1099
      '#title' => t('Use a custom placeholder image'),
1100
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1101
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1102
  );
1103

    
1104
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1105
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1106
        '#type' => 'managed_file',
1107
        '#title' => t('Custom placeholder image file'),
1108
        '#progress_indicator' => 'bar',
1109
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1110
    //       '#name' => 'custom_placeholder_image',
1111
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1112
    );
1113

    
1114
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1115
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1116
      $url = file_create_url($profile_image_file->uri);
1117
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1118
                '#type' => 'item',
1119
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1120
      );
1121
    }
1122
  } else {
1123
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1124
        '#type' => 'hidden',
1125
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1126
    );
1127
  }
1128

    
1129

    
1130

    
1131
  $options = cdm_rankVocabulary_as_option();
1132
  array_unshift($options, '-- DISABLED --');
1133
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1134
    '#type' => 'select',
1135
    '#title' => t('Hide profile picture for higher ranks') . ':',
1136
    '#default_value' => variable_get('image_hide_rank', '0'),
1137
    '#options' => $options,
1138
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1139
  );
1140

    
1141
  // -- MEDIA THUMBNAILS -- //
1142
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1143
  $form_title = 'Taxon Profile Images';
1144
  $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>';
1145
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1146

    
1147
  // ---- FEATURE TREE ---- //
1148
  $form['taxon_profile']['feature_trees'] = array(
1149
    '#type' => 'fieldset',
1150
    '#title' => t('Features'),
1151
    '#collapsible' => TRUE,
1152
    '#collapsed' => FALSE,
1153
    '#description' => t("This section covers settings related to the taxon's
1154
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1155
      features such as description, distribution, common names, etc. that Drupal
1156
      will render at the taxon profile page."),
1157
  );
1158
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1159
  $saved_uuid = variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1160
  if(!isset($featureTrees['options'][$saved_uuid])) {
1161
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1162
  }
1163
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
1164
    '#type' => 'radios',
1165
    '#title' => t('Taxon profile sections') . ':',
1166
    '#default_value' => $saved_uuid,
1167
    '#options' =>  $featureTrees['options'],
1168
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1169
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1170
    '#description' => t('Select the Feature Tree to be displayed at the taxon
1171
      profile. Click "Show Details" to see the Feature Tree elements.'
1172
    ),
1173
  );
1174
  $featureTrees = cdm_get_featureTrees_as_options();
1175
  $saved_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1176
  if(!isset($featureTrees['options'][$saved_uuid])) {
1177
    $saved_uuid = NULL;
1178
  }
1179
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
1180
    '#type' => 'radios',
1181
    '#title' => t('Natural language representation of structured descriptions') . ':',
1182
    '#default_value' => $saved_uuid,
1183
    '#options' => $featureTrees['options'],
1184
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1185
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1186
    '#description' => t('Taxon descriptions can be stored in a highly structured
1187
      form. The feature tree selected here will be used to generate textual
1188
      representation in natural language.'
1189
    ),
1190
  );
1191

    
1192
  // ---- LAYOUT PER FEATURE ---- //
1193
  $feature_tree = get_profile_featureTree();
1194
  if (isset($feature_tree->root->children)) {
1195

    
1196
    $form_feature_list_layout = array(
1197
      '#title' => t('Taxon profile layout'),
1198
      '#collapsible' => TRUE,
1199
      '#collapsed' => FALSE,
1200
      '#type' => 'fieldset',
1201
      '#description' => t('Will be available in a future release.'),
1202
    );
1203

    
1204
    $feature_list_layout_settings_disabled = TRUE;
1205
    foreach ($feature_tree->root->children as $featureNode) {
1206

    
1207
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1208
        // Must not exceed 45 characters !!!
1209
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1210

    
1211
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1212
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1213

    
1214
        $form_feature_list_layout[$subform_id] = array(
1215
          '#tree' => TRUE,
1216
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1217
          '#collapsible' => FALSE,
1218
          '#collapsed' => FALSE,
1219
          '#type' => 'fieldset',
1220
          '#description' => t(''),
1221
        );
1222

    
1223
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1224
          '#type' => 'checkbox',
1225
          '#title' => t('Enable'),
1226
          '#default_value' => $settings['enabled'],
1227
          '#description' => t('Enable user defined layout for this feature'),
1228
        );
1229

    
1230
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1231
          '#type' => 'textfield',
1232
          '#title' => t('Enclosing tag'),
1233
          '#disabled' => !$settings['enabled'],
1234
          '#default_value' => $settings['enclosingTag'],
1235
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1236
        );
1237

    
1238
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1239
          '#type' => 'textfield',
1240
          '#title' => t('Entry enclosing tag'),
1241
          '#disabled' => !$settings['enabled'],
1242
          '#default_value' => $settings['entryEnclosingTag'],
1243
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1244
        );
1245

    
1246
        $form_feature_list_layout[$subform_id]['glue'] = array(
1247
          '#type' => 'textfield',
1248
          '#title' => t('Glue'),
1249
          '#disabled' => !$settings['enabled'],
1250
          '#default_value' => $settings['glue'],
1251
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1252
        );
1253

    
1254
      }
1255

    
1256
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1257
    }
1258
  }
1259

    
1260
  // ---- DISTRIBUTION LAYOUT ---- //
1261
  $form['taxon_profile']['distribution_layout'] = array(
1262
    '#title' => t('Distribution'),
1263
    '#collapsible' => TRUE,
1264
    '#collapsed' => FALSE,
1265
    '#type' => 'fieldset',
1266
    '#description' => t('Select if you want to sort or not the distribution text
1267
      located below the distribution map.'),
1268
  );
1269

    
1270
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1271
    '#type' => 'radios',
1272
    '#title' => t('Sort') . ':',
1273
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1274
    '#options' => array(
1275
      'NO_SORT' => t('Standard (No sort)'),
1276
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1277
    ),
1278
  );
1279

    
1280
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1281
    '#type' => 'checkbox',
1282
    '#title' => t('Show TextData elements on top of the map'),
1283
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1284
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1285
      elements on top of the map. Otherwise all <code>TextData</code>
1286
      distribution elements will be listed below the other area elements.
1287
      This option is useful if you need to have descriptive texts for each
1288
      distribution map.'),
1289
  );
1290

    
1291

    
1292
  /* ====== SYNONYMY ====== */
1293
  $form['taxon_synonymy'] = array(
1294
    '#type' => 'fieldset',
1295
    '#title' => t('Taxon synonymy (tab)'),
1296
    '#collapsible' => TRUE,
1297
    '#collapsed' => TRUE,
1298
    '#description' => t('This section covers the settings related to the taxon
1299
      <strong>synonymy</strong> tab.'),
1300
  );
1301

    
1302
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1303
    '#type' => 'checkbox',
1304
    '#title' => t('Show accepted taxon on top of the synonymy'),
1305
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1306
    '#description' => t('If checked, the first homotypic taxon is a repetition
1307
      of the accepted taxon most likely with the full nomenclatural reference
1308
      (depending on the currently chosen theme).'),
1309
  );
1310

    
1311
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1312
    '#type' => 'checkbox',
1313
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1314
      coming from a synonym link.'),
1315
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1316
    '#description' => t('Check this if after doing a search and clicking on a
1317
      synonym you want to see the "accept of" text for the accepted synonym.'),
1318
  );
1319

    
1320
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1321
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1322
    '#type' => 'checkboxes',
1323
    '#title' => t('Display name relationships') . ':',
1324
    '#default_value' => variable_get('name_relationships_to_show', 0),
1325
    '#options' => $nameRelationshipTypeOptions,
1326
    '#description' => t('Select the name relationships you want to show for the
1327
      accepted taxa.'),
1328
  );
1329

    
1330
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1331
    '#type' => 'checkbox',
1332
    '#title' => t('Show taxon relations ships of accepted taxon'),
1333
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1334
    '#description' => t('If this option is enabled the synonymy will show the
1335
      below selected taxon relationships of accepted taxa.'),
1336
  );
1337

    
1338
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1339
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1340
    '#type' => 'checkboxes',
1341
    '#title' => t('Taxon relationship types') . ':',
1342
    '#description' => t('Only taxon relationships of the selected type will be
1343
      displayed'),
1344
    '#options' => $taxonRelationshipTypeOptions,
1345
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1346
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1347
  );
1348

    
1349
  // ====== SPECIMENS ====== //
1350
  $form['taxon_specimens'] = array(
1351
    '#type' => 'fieldset',
1352
    '#title' => t('Taxon specimens (tab)'),
1353
    '#collapsible' => TRUE,
1354
    '#collapsed' => TRUE,
1355
    '#description' => t('This section covers the settings related to the taxon
1356
      <strong>specimens</strong> tab.'),
1357
  );
1358

    
1359
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1360
  $saved_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1361
  if(!isset($featureTrees['options'][$saved_uuid])) {
1362
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1363
  }
1364
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1365
      '#type' => 'radios',
1366
      '#title' => t('Specimen description feature tree') . ':',
1367
      '#default_value' => $saved_uuid,
1368
      '#options' =>  $featureTrees['options'],
1369
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1370
      '#options_suffixes' => $featureTrees['treeRepresentations'],
1371
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1372
      ),
1373
  );
1374

    
1375
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1376
  $form_title = t('Specimen media');
1377
  $form_description = t('Specimens may have media which is displayed at the
1378
     Specimen tab/section as a gallery. It is possible to configure the
1379
     thumbnails gallery here, however for configuring how a single media should
1380
     be displayed please go to !url.</p>',
1381
     array(
1382
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1383
     ));
1384
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1385

    
1386
  // --- MEDIA GALLERY ---- //
1387
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1388
  $form_title = 'Media gallery (tab)';
1389
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1390
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1391
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1392
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1393
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1394
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1395
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1396

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

    
1406
/**
1407
 * @todo document this function.
1408
 */
1409
function cdm_settings_layout_search() {
1410

    
1411
  $form = array();
1412

    
1413
  $form['search_settings'] = array(
1414
    '#type' => 'fieldset',
1415
    '#title' => t('Taxa Search'),
1416
    '#collapsible' => FALSE,
1417
    '#collapsed' => FALSE,
1418
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1419
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1420
         where they can write the text to be searched. You can find Drupal block configuration
1421
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1422
  );
1423

    
1424
  $form['search_settings']['simple_search_ignore_classification'] = array(
1425
      '#type' => 'checkbox',
1426
      '#title' => t('Ignore the chosen classification in simple search'),
1427
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
1428
      '#description' => t('The simple search, which can be executed via the search block,
1429
          will by default search on all classifications. Remove the tick if you want your
1430
          portal to search on the classification selected in the classification browser
1431
          selector.'),
1432
  );
1433

    
1434
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1435
    '#type' => 'textfield',
1436
    '#title' => t('Results per page') . ':',
1437
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1438
    '#description' => t('Number of results to display per page.'),
1439
  );
1440

    
1441
  $form['search_settings']['cdm_search_taxa'] = array(
1442
    '#type' => 'checkbox',
1443
    '#title' => t('Sets the default value of <em>Search for accepted taxa</em> in the advanced search form.'),
1444
    '#default_value' => variable_get('cdm_search_taxa', 1),
1445
    '#description' => t('<p>If checked the <em>Search for accepted taxa </em> option will be enabled in the advanced form.</p>'),
1446
  );
1447

    
1448
  $form['search_settings']['cdm_search_synonyms'] = array(
1449
    '#type' => 'checkbox',
1450
    '#title' => t('Sets the default value of <em>Search for synonyms</em> in the advanced search form.'),
1451
    '#default_value' => variable_get('cdm_search_synonyms', 1),
1452
    '#description' => t('<p>If checked the <em>Search for synonyms</em> option will be enabled in the advanced form.</p>'),
1453
  );
1454

    
1455
  $form['search_settings']['cdm_search_common_names'] = array(
1456
    '#type' => 'checkbox',
1457
    '#title' => t('Sets the default value of <em>Search for common names</em> in the advanced search form.'),
1458
    '#default_value' => variable_get('cdm_search_common_names', 0),
1459
    '#description' => t('<p>If checked the <em>Search for common names</em> option will be enabled in the advanced form.</p>'),
1460
  );
1461

    
1462
  $form['search_settings']['cdm_search_use_default_values'] = array(
1463
    '#type' => 'checkbox',
1464
    '#title' => t('Sets use of default values in the advanced search form.'),
1465
    '#default_value' => variable_get('cdm_search_use_default_values', 1),
1466
    '#description' => t('<p>If checked the defqult values set abovewill be used for the search.</p>'),
1467
  );
1468

    
1469

    
1470
  // --- SEARCH TAXA GALLERY ---- //
1471
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1472
  $collapsed = FALSE;
1473
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1474
  $form_title = 'Taxa Search thumbnails';
1475
  $form_description = 'Search results may show thumbnails. ';
1476
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1477

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

    
1487
/**
1488
 * @todo document this function.
1489
 */
1490
function cdm_settings_layout_media() {
1491

    
1492
  $form = array();
1493

    
1494
  $form['media_settings'] = array(
1495
    '#type' => 'fieldset',
1496
    '#title' => t('Media settings'),
1497
    '#collapsible' => FALSE,
1498
    '#collapsed' => FALSE,
1499
    '#description' => 'This section covers layout settings for media pages.'
1500
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
1501
  );
1502

    
1503
  $form['media_settings']['image_gallery_viewer'] = array(
1504
    '#type' => 'select',
1505
    '#title' => t('Image viewer') . ':',
1506
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1507
    '#options' => array(
1508
      'default' => t('Standard image viewer'),
1509
      'fsi' => t('FSI viewer (requires FSI server!)'),
1510
    ),
1511
  );
1512

    
1513
  // --- MEDIA GALLERY ---- //
1514
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1515
  $form_title = 'Standard viewer';
1516
  $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>';
1517
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1518
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1519

    
1520
  // @WA: D7 form api does not support reset buttons,
1521
  // so to mimic the D5 reset button we add one like this.
1522
  $form['actions']['reset'] = array(
1523
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1524
    '#weight' => 1000,
1525
  );
1526
  return system_settings_form($form);
1527
}
1528

    
1529
/**
1530
 * GEOSERVICE and Map settings.
1531
 */
1532
function cdm_settings_geo($form, &$form_state) {
1533

    
1534
  $form = array();
1535

    
1536
  /*
1537
  GEO SERVER
1538
  */
1539
  $form['edit_map_server'] = array(
1540
    '#type' => 'fieldset',
1541
    '#tree' => true,
1542
    '#title' => t('EDIT map service'),
1543
    '#collapsible' => TRUE,
1544
    '#collapsed' => TRUE,
1545
    '#description' => t('Configuration and selection of your geo server.
1546
      The Geo Server is responsible for generating the maps.'),
1547
  );
1548

    
1549
  $current_geoserver_settings = get_edit_map_service_settings();
1550

    
1551
  $form['edit_map_server']['base_uri'] = array(
1552
    '#type' => 'select',
1553
    '#title' => t('EDIT map service') . ':',
1554
    '#default_value' => $current_geoserver_settings['base_uri'],
1555
    '#options' => unserialize(EDIT_MAPSERVER_URI),
1556
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
1557
  );
1558
  $form['edit_map_server']['version'] = array(
1559
      '#type' => 'select',
1560
      '#title' => t('Version') . ':',
1561
      '#default_value' => $current_geoserver_settings['version'],
1562
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
1563
      '#description' => t('The version of the EDIT map services'),
1564
  );
1565

    
1566
  /*
1567
  MAP SETTINGS
1568
  */
1569
  $form['map_settings'] = array(
1570
    '#type' => 'fieldset',
1571
    '#title' => t('Maps settings'),
1572
    '#collapsible' => TRUE,
1573
    '#collapsed' => TRUE,
1574
    '#description' => t('General configuration for all map types.'),
1575
  );
1576

    
1577
  $form['map_settings']['cdm_dataportal_geoservice_display_width'] = array(
1578
    '#type' => 'textfield',
1579
    '#title' => t('Maps width') . ':',
1580
    '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
1581
    '#description' => t('Choose the width of your maps, the height will always
1582
      be the half of the width. A value of 500 means the size will be 500 pixels
1583
      width and 250 pixels height.'),
1584
  );
1585

    
1586
  $form['map_settings']['cdm_dataportal_geoservice_bounding_box'] = array(
1587
    '#type' => 'textfield',
1588
    '#title' => t('Fixed bounding box') . ':',
1589
    '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
1590
    '#description' => t('Define surrounding of area to be displayed in maps.
1591
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
1592
      to let the map <strong>automatically zoom</strong> to the distribution
1593
      area.'),
1594
  );
1595

    
1596
  $form['map_settings']['cdm_dataportal_geoservice_labels_on'] = array(
1597
    '#type' => 'checkbox',
1598
    '#title' => '<b>' . t('Display area labels') . '</b>',
1599
    '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
1600
    '#description' => t('Check this if you like area names to be displayed in the maps. DOES IT WORK???? '),
1601
  );
1602

    
1603
  $form['map_settings']['cdm_dataportal_geoservice_map_caption'] = array(
1604
    '#type' => 'textfield',
1605
    '#title' => t('Map caption') . ':',
1606
    '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
1607
    '#description' => t('Define a caption for the map.'),
1608
  );
1609

    
1610
  $form['map_settings']['cdm_dataportal_geoservice_distributionOpacity'] = array(
1611
    '#type' => 'textfield',
1612
    '#title' => t('Distribution layer opacity') . ':',
1613
    '#default_value' => variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5'),
1614
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1615
                           fully visible, while a value near to 0.0 will be not much visible.'),
1616
  );
1617

    
1618
  $form['map_settings']['cdm_dataportal_map_openlayers'] = array(
1619
    '#type' => 'radios',
1620
    '#title' => t('Map Viewer') . ':',
1621
    '#options' => array(
1622
      1 => "OpenLayers dynamic mapviewer",
1623
      0 => "Plain image",
1624
    ),
1625
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1626
    '#description' => t('You can choose from two different map viewers:
1627
      <ul><li><em>OpenLayers</em> displays the maps in an interactive viewer
1628
      which allows zooming and panning. If not enabled the maps will consist
1629
      on a static image. If enabled you can configure the default layer
1630
      (background of your maps) below. Only one of them will be rendered.</li>
1631
      <li><em>Plain image</em> displays the map as a plain non interactive
1632
      image.</li></ul>'),
1633
  );
1634

    
1635
  $openLayersEnabled = variable_get('cdm_dataportal_map_openlayers', 1) == 1;
1636

    
1637

    
1638
  // --- Plain Image Settings --- //
1639
  $form['map_image'] = array(
1640
    '#type' => 'fieldset',
1641
    '#title' => t('Plain image map settings'),
1642
    '#collapsible' => TRUE,
1643
    '#collapsed' => $openLayersEnabled,
1644
    '#description' => t('The settings in this section are still expertimental
1645
      and can only be used with the EDIT map service version 1.1 or above.'),
1646
  );
1647

    
1648
  $edit_mapserver_version = get_edit_map_service_version_number();
1649
  if ($edit_mapserver_version < 1.1) {
1650
    $form['map_image']['#description'] = '<div class="messages warning">' . t("The selected EDIT map service version has to small version number: $edit_mapserver_version") . '</div>'
1651
      . $form['map_image']['#description'];
1652
  }
1653

    
1654
  $form['map_image']['map_base_layer'] = array(
1655
    '#type' => 'textfield',
1656
    '#title' => t('Background layer') . ':',
1657
    '#default_value' => variable_get('map_base_layer', 'cyprusdivs'),
1658
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
1659
      '!url1' => l(t('deegree-csw'), 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
1660
      '!url2' => l(t('geoserver layers'), 'http://edit.africamuseum.be/geoserver/web/'), // http://edit.africamuseum.be/geoserver/rest/layers
1661
    )),
1662
  );
1663

    
1664
  $form['map_image']['map_bg_color'] = array(
1665
    '#type' => 'textfield',
1666
    '#title' => t('Background color') . ':',
1667
    '#default_value' => variable_get('map_bg_color', '1874CD'),
1668
  );
1669

    
1670
  $form['map_image']['map_base_layer_style'] = array(
1671
    '#type' => 'textfield',
1672
    '#title' => t('Background layer area style') . ':',
1673
     // Only line color by now.
1674
    '#default_value' => variable_get('map_base_layer_style', 'ffffff,606060,,'),
1675
    '#description' => t('Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}'),
1676
  );
1677

    
1678

    
1679
  // --- OpenLayers Settings --- //
1680
  $form['openlayers'] = array(
1681
    '#type' => 'fieldset',
1682
    '#title' => t('OpenLayers settings'),
1683
    '#collapsible' => TRUE,
1684
    '#collapsed' => !$openLayersEnabled,
1685
    '#description' => '',
1686
  );
1687

    
1688
  if (!$openLayersEnabled) {
1689
    $form['openlayers']['#description'] = '<div class="messages warning">' . t('The Openlayers viewer is currently not enabled! (see section Maps settings above )') . '</div>'
1690
      . $form['openlayers']['#description'];
1691
  }
1692

    
1693
  $baselayer_options = array(
1694
    /*
1695
   NOTICE: must correspond to the layers defined in
1696
   js/openlayers_,ap.js#getLayersByName()
1697
   */
1698
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
1699
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
1700
    // all others EPSG:900913
1701
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
1702
    'edit-etopo1' => "ETOPO1 Global Relief Model",
1703
    'mapnik' => 'OpenStreetMap',
1704
    'osmarender' => 'OpenStreetMap (Tiles@home)',
1705
    'gmap' => 'Google Streets',
1706
    'gsat' => 'Google Satellite',
1707
    'ghyb' => 'Google Hybrid',
1708
    'veroad' => 'Virtual Earth Roads',
1709
    'veaer' => 'Virtual Earth Aerial',
1710
    'vehyb' => 'Virtual Earth Hybrid',
1711
    // 'yahoo' => 'Yahoo Street',
1712
    // 'yahoosat' => 'Yahoo Satellite',
1713
    // 'yahoohyb' => 'Yahoo Hybrid',
1714
  );
1715

    
1716
  $form['openlayers']['baselayers'] = array(
1717
    '#type' => 'checkboxes_preferred',
1718
    '#title' => t('Base Layers') . ':',
1719
    '#options' => $baselayer_options,
1720
    '#default_value' => variable_get('baselayers', array('metacarta_vmap0' => "metacarta_vmap0", 'PREFERRED' => 'metacarta_vmap0')),
1721
    '#description' => t('Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.'),
1722
  );
1723

    
1724
  // cdm_dataportal_geoservice_showLayerSwitcher
1725
  $form['openlayers']['cdm_dataportal_geoservice_showLayerSwitcher'] = array(
1726
    '#type' => 'checkbox',
1727
    '#title' => '<b>' . t('Show Layer Switcher') . '</b>',
1728
    '#default_value' => variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE),
1729
    '#description' => t('
1730
      The Layer Switcher control displays a table of contents
1731
      for the map.  This allows the user interface to switch between
1732
      BaseLayers and to show or hide Overlays.  By default the switcher is
1733
      shown minimized on the right edge of the map, the user may expand it
1734
      by clicking on the handle.'
1735
    ),
1736
  );
1737

    
1738
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1739
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1740
  $form['openlayers']['gmap_api_key'] = array(
1741
    '#type' => 'textfield',
1742
    '#title' => t('Google maps API key') . ':',
1743
    '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1744
    '#description' => t('If you want to use the Google Maps Layer, a key is
1745
      needed. If you need a key, visit
1746
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
1747
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
1748
      is the default key for the localhost (127.0.0.1). The key in use is the
1749
      one above this text.', array('!localhostkey' => $localhostkey)),
1750
  );
1751

    
1752
  $form['cdm_dataportal_geoservice_map_legend'] = array(
1753
    '#type' => 'fieldset',
1754
    '#title' => t('Map legend'),
1755
    '#collapsible' => TRUE,
1756
    '#collapsed' => TRUE,
1757
    '#description' => t('Configure the maps legend.'),
1758
  );
1759

    
1760
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
1761
    '#type' => 'checkbox',
1762
    '#title' => '<b>' . t('Display a map legend') . '</b>',
1763
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
1764
    '#description' => t('Check this if you like a legend to be displayed with the maps.'),
1765
  );
1766

    
1767
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legendOpacity'] = array(
1768
    '#type' => 'textfield',
1769
    '#title' => t('Legend opacity'),
1770
    '#default_value' => variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'),
1771
    '#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
1772
                         to 0.0 will be not much visible.'),
1773
  );
1774

    
1775
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
1776
    '#type' => 'textfield',
1777
    '#title' => t('Font size'),
1778
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
1779
    '#description' => t('Font size in pixels.'),
1780
  );
1781

    
1782
  $fontStyles = array(
1783
    0 => "plane",
1784
    1 => "italic",
1785
  );
1786
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
1787
    '#type' => 'select',
1788
    '#title' => t('Available font styles'),
1789
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', FALSE),
1790
    '#options' => $fontStyles,
1791
    '#description' => t('Select a font style for the map legend.'),
1792
  );
1793

    
1794
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
1795
    '#type' => 'textfield',
1796
    '#title' => t('Legend icon width'),
1797
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
1798
    '#description' => t('Legend icon width in pixels.'),
1799
  );
1800
  $form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
1801
    '#type' => 'textfield',
1802
    '#title' => t('Legend icon height'),
1803
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
1804
    '#description' => t('Legend icon height in pixels.'),
1805
  );
1806

    
1807
  // @WA: D7 form api does not support reset buttons,
1808
  // so to mimic the D5 reset button we add one like this.
1809
  $form['actions']['reset'] = array(
1810
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1811
    '#weight' => 1000,
1812
  );
1813

    
1814
  return system_settings_form($form);
1815
}
1816

    
1817
/**
1818
 * @todo document this function.
1819
 */
1820
function cdm_settings_cache() {
1821

    
1822
  $form = array();
1823

    
1824
  $form['cache_settings'] = array(
1825
    '#type' => 'fieldset',
1826
    '#title' => t('Cache Settings'),
1827
    '#collapsible' => FALSE,
1828
    '#collapsed' => FALSE,
1829
    '#description' => t('<p>When caching is enabled all single taxon sites are
1830
      stored in an internal drupal cache doing the portal response of taxa pages
1831
      faster. This is possible because the sites are loaded from the cache and
1832
      are not created from scratch.</p>'),
1833
  );
1834

    
1835
  $form['cache_settings']['cdm_webservice_cache'] = array(
1836
    '#type' => 'checkbox',
1837
    '#title' => t('<strong>Enable caching</strong>'),
1838
    '#options' => cdm_help_general_cache(),
1839
    '#default_value' => variable_get('cdm_webservice_cache', 1),
1840
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
1841
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
1842
       application the changes will be not visible till the cache is erased.
1843
       Therefore developers should deactived this feature when they are working
1844
       on the CDM Dataportal Module.</p>'),
1845
  );
1846

    
1847
  $form['cache_settings']['cdm_run_cache'] = array(
1848
    '#markup' => cdm_view_cache_site(),
1849
  );
1850

    
1851
  // @WA: D7 form api does not support reset buttons,
1852
  // so to mimic the D5 reset button we add one like this.
1853
  $form['actions']['reset'] = array(
1854
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1855
    '#weight' => 1000,
1856
  );
1857
  return system_settings_form($form);
1858
}
1859

    
1860
/**
1861
 * Walk and cache all taxon pages.
1862
 */
1863
function cdm_view_cache_site() {
1864

    
1865
  $out = '';
1866

    
1867
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
1868

    
1869
  $request_params = array();
1870
  $request_params['class'] = "Taxon";
1871

    
1872
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
1873
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
1874
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
1875

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

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

    
1885
  // Comment @WA: A form within a form is not valid html and not needed here.
1886
  // Also, it would be recommended just to include this part of the form in the
1887
  // rest of the form array in cdm_settings_cache().
1888
  // $out .= '<form id="cache_site">';
1889
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
1890
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
1891
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
1892
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
1893
  // $out .= '</form>';
1894
  $out .= '</div>';
1895
  /*
1896
  foreach($taxonPager->records as $taxon){
1897
    cdm_dataportal_taxon_view($uuid);
1898
  }
1899
  */
1900
  return $out;
1901
}
1902

    
1903

    
1904
function cdm_settings_layout_taxon_submit($form, &$form_state){
1905
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
1906
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
1907
    if(is_object($file)){
1908
      $file->status = FILE_STATUS_PERMANENT;
1909
      file_save($file);
1910
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
1911
    }
1912
  }
1913
}
1914

    
1915
/**
1916
 * Form validation handler for ?
1917
 *
1918
 * Comment @WA: currently this handler is not used.
1919
 * It seems partly for cdm_settings_general en partly for cdm_settings_cache?
1920
 * Then you can change the name into cdm_settings_general_validate() or
1921
 * cdm_settings_cache_validate().
1922
 * But cdm_api_secref_cache_clear is not doing anything (yet)?
1923
 */
1924
function cdm_settings_validate($form, &$form_state) {
1925

    
1926
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
1927
    // form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
1928
    $form_state['values']['cdm_webservice_url'] .= '/';
1929
  }
1930

    
1931
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
1932
    cache_clear_all(NULL, 'cache_cdm_ws');
1933
    // Better clear secref_cache since I can not be sure if the cache has not
1934
    // be used during this response.
1935
    cdm_api_secref_cache_clear();
1936
  }
1937
}
1938

    
1939
/**
1940
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
1941
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
1942
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
1943
 *  - version: the version, e.g.: v1.1
1944
 *
1945
 * @return array
1946
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
1947
 */
1948
function get_edit_map_service_settings() {
1949

    
1950
  $settings = variable_get('edit_map_server', array(
1951
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
1952
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
1953
      )
1954
  );
1955
  // replace old non tree like settings by default
1956
  // TODO to be removed after release 3.1.5
1957
  if(!is_array($settings)){
1958
    variable_del('edit_map_server');
1959
    return get_edit_map_service_settings();
1960
  }
1961

    
1962
  return $settings;
1963
}
1964

    
1965
/**
1966
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
1967
 *
1968
 * @return string
1969
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
1970
 */
1971
function get_edit_map_service_full_uri() {
1972
  $settings = get_edit_map_service_settings();
1973
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
1974
}
1975

    
1976

    
1977
/**
1978
 * Returns the version number of the currently selected edit mapserver as a float
1979
 *
1980
 * @return float
1981
 *   The version number of the currently selected edit mapserver as a float.
1982
 *   Returns 0 on error.
1983
 */
1984
function get_edit_map_service_version_number() {
1985

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

    
1988
  $settings = get_edit_map_service_settings();
1989
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
1990
  if (isset($matches[1])) {
1991
    // Convert string to float.
1992
    $version = 1 + $matches[1][0] - 1;
1993
    return $version;
1994
  }
1995
  else {
1996
    // Report error.
1997
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
1998
        array(
1999
          '!version' => $settings['version'],
2000
          'warning')
2001
        )
2002
      );
2003
    return 0;
2004
  }
2005
}
2006

    
2007
/**
2008
 * Returns the array of selected items in a options array
2009
 *
2010
 * @param array $options
2011
 *   An options array as generated by a form element like checkoxes, select ...,
2012
 */
2013
function get_selection($options) {
2014
  $selection = array();
2015
  foreach ($options as $key=>$val) {
2016
    if (!empty($val)) {
2017
      $selection[] = $val;
2018
    }
2019
  }
2020
  return $selection;
2021
}
2022

    
2023

    
2024
/**
2025
 * Implements hook_element_info().
2026
 *
2027
 * Allows modules to declare their own Form API element types and specify their default values.
2028
 *
2029
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
2030
 */
2031
function cdm_dataportal_element_info() {
2032
  $type['checkboxes_preferred'] = array(
2033
    '#input' => TRUE,
2034
    '#process' => array('checkboxes_preferred_expand'),
2035
    '#after_build' => array('checkboxes_preferred_after_build'),
2036
    '#theme' => array('checkboxes_preferred'),
2037
    // '#theme_wrapper' => array('form_element'),
2038
  );
2039
  return $type;
2040
}
2041

    
2042
/**
2043
 * #process callback function for the custom form element type 'checkbox_preferred'
2044
 *
2045
 *
2046
 */
2047
function checkboxes_preferred_expand($element, &$form_state, $form) {
2048

    
2049
  // First of all create checkboxes for each of the elements
2050
  $element = form_process_checkboxes($element);
2051

    
2052
  $children = element_children($element);
2053

    
2054
  $element['table_start'] = array(
2055
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
2056
    '#weight' => -1,
2057
  );
2058

    
2059
  // prepare first part each of the table rows which contains the row label
2060
  $weight = 0;
2061
  foreach ($children as $key) {
2062
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
2063
    $element[$key]['#weight'] = $weight;
2064
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
2065
    $element[$key]['#suffix'] = '</td>';
2066
    unset($element[$key]['#title']);
2067
    $weight += 2;
2068
  }
2069
  $weight = 0;
2070

    
2071
  // add a radio button to each of the checkboxes, the
2072
  // check boxes have already been created at the beginning
2073
  // of this function
2074
  if (count($element['#options']) > 0) {
2075
    foreach ($element['#options'] as $key => $choice) {
2076
      if (!isset($element[$key . '_preferred'])) {
2077
        $element[$key . '_preferred'] = array(
2078
          '#type' => 'radio',
2079
          '#name' => $element['#parents'][0] . '_preferred',
2080
          '#return_value' => check_plain($key),
2081
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
2082
          '#attributes' => $element['#attributes'],
2083
          '#parents' => $element['#parents'],
2084
          // '#spawned' => TRUE,
2085
          '#weight' => $weight + 1,
2086
          '#prefix' => '<td>',        // add a prefix to start a new table cell
2087
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
2088
        );
2089
      }
2090
      $weight += 2;
2091
    }
2092
  }
2093

    
2094
  // end the table
2095
  $element['table_end'] = array(
2096
    '#markup' => '</table>',
2097
    '#weight' => $weight++,
2098
  );
2099

    
2100
  return $element;
2101
}
2102

    
2103
/**
2104
 * Theme function for the custom form field 'checkboxes_preferred'.
2105
 */
2106
function theme_checkboxes_preferred($variables) {
2107
  $element = $variables['element'];
2108
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
2109
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
2110
  $out .= drupal_render_children($element);
2111
  $out .= '<div class="description">' . $element['#description'] . '</div>';
2112
  $out .= '</div>';
2113
  return $out;
2114
}
2115

    
2116
/**
2117
 * Callback for checkboxes preferred for widget which will
2118
 * be called after the form or element is built. The call
2119
 * back is configured in the form element by setting it as
2120
 * #after_build parameter.
2121
 *
2122
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
2123
 *
2124
 * @param $form
2125
 *   Nested array of form elements that comprise the form.
2126
 * @param $form_state
2127
 *   A keyed array containing the current state of the form.
2128
 *
2129
 * @return the modified form array
2130
 */
2131
function checkboxes_preferred_after_build($form, &$form_state) {
2132

    
2133
  $parent_id = $form['#parents'][0];
2134

    
2135
  if ($_POST && count($_POST) > 0) {
2136
    // First pass of form processing.
2137
    $preferred_layer = $_POST[$parent_id . '_preferred'];
2138
    $form['#value']['PREFERRED'] = $preferred_layer;
2139
    $form_state[$parent_id] = $form['#value'];
2140
    $form_state['values']['baselayers'] = $form['#value'];
2141
  }
2142
  else {
2143
    // Second pass of form processing.
2144
    $preferred_layer = $form['#value']['PREFERRED'];
2145
  }
2146

    
2147
  // Also set the chosen value (not sure if this is good Drupal style ....).
2148
  foreach ($children = element_children($form) as $key) {
2149
    if (!empty($form[$key]['#type']) && $form[$key]['#type'] == 'radio') {
2150
      $form[$key]['#value'] = $preferred_layer;
2151
    }
2152
  }
2153
  // The default layer must always be enabled.
2154
  $form[$preferred_layer]['#value'] = $preferred_layer;
2155

    
2156
  return $form;
2157
}
2158

    
2159
function radios_prepare_options_suffix(&$elements){
2160

    
2161
  $childrenKeys = element_children($elements);
2162
  foreach($childrenKeys as $key){
2163
    if(!is_array($elements[$key]['#theme_wrappers'])){
2164
      $elements[$key]['#theme_wrappers'] = array();
2165
    }
2166
    if(isset($elements['#options_suffixes'][$key])){
2167
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
2168
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
2169
    }
2170
  }
2171
  return $elements;
2172

    
2173
}
2174

    
2175
/**
2176
 * TODO
2177
 * @param unknown $variables
2178
 */
2179
function theme_radio_options_suffix($variables) {
2180
  $element = $variables['element'];
2181
  if(isset($element['#options_suffix'])) {
2182
    $element['#children'] .= $element['#options_suffix'];
2183
  }
2184
  return $element['#children'];
2185
}
2186

    
2187

    
2188
/**
2189
 * Element validate callback for text field and arrays containing json.
2190
 *
2191
 * @param $element
2192
 *   The form element to validate
2193
 * @param $form
2194
 *   Nested array of form elements that comprise the form.
2195
 * @param $form_state
2196
 *   A keyed array containing the current state of the form.
2197
 */
2198
function form_element_validate_json($element, &$form_state, $form) {
2199
   if (!empty($element['#value'])) {
2200
     json_decode($element['#value']);
2201
     if(json_last_error() != JSON_ERROR_NONE){
2202
       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/'));
2203
     }
2204
   }
2205
}
2206

    
2207
/**
2208
 * Form submission handler for textareas and textfields containing JSON.
2209
 *
2210
 * The contained JSON will be converted into an php array
2211
 * or object and will be stores in the variables as such.
2212
 *
2213
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2214
 *
2215
 * @param $form
2216
 *   Nested array of form elements that comprise the form.
2217
 * @param $form_state
2218
 *   A keyed array containing the current state of the form.
2219
 *
2220
 */
2221
function submit_json_as_php_array($form, &$form_state) {
2222
  if (is_array($form['#json_elements'])) {
2223
    foreach ($form['#json_elements'] as $element){
2224
      if (trim($form_state['values'][$element])) {
2225
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
2226
      } else {
2227
        $form_state['values'][$element] = NULL;
2228
      }
2229
    }
2230
  }
2231
}
(13-13/13)