Project

General

Profile

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

    
274
/**
275
 * Merges the named array variable with the array of defaults.
276
 *
277
 * @param string $variable_name
278
 *     The variable name
279
 * @param string | array $default
280
 *     The array containing the default values either as array or serialized as string.
281
 *     Unserialization is cared for if nessecary
282
 * @return array
283
 *     The merged array as returnd by drupal_array_merge_deep()
284
 */
285
function get_array_variable_merged($variable_name, $default){
286

    
287
    // unserialize if nessecary
288
    if(!is_array($default)){
289
      $default = unserialize($default);
290
    }
291
    $variable = variable_get($variable_name, array());
292
    return drupal_array_merge_deep($default, $variable);
293
}
294

    
295
/**
296
 * @todo document this function.
297
 */
298
function getGallerySettings($gallery_config_form_name) {
299
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
300
}
301

    
302
/**
303
 * Returns the string representation of the default tab.
304
 *
305
 * @param bool $returnTabIndex
306
 *   Defaults to FALSE, if set true this function will return the index number
307
 *   of the default tab. (used to supply default values to form elements).
308
 */
309
function get_default_taxon_tab($returnTabIndex = FALSE) {
310

    
311
  global $user;
312
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
313
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
314
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
315
  // Get the user value if the used has chosen to overwrite the system settings.
316
  $user_tab_on = variable_get($user_tab_active, FALSE);
317
  if ($user_tab_on) {
318
    $user_value = variable_get($user_tab, 0);
319
    $index_value = $user_value;
320
    // Get the system value.
321
  }
322
  else {
323
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
324
    $index_value = $system_value;
325
  }
326

    
327
  // Return the index value or the string representation.
328
  if ($returnTabIndex) {
329
    return $index_value;
330
  }
331
  else {
332
    return ($values[$index_value]);
333
  }
334

    
335
}
336

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

    
372
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
373
    'title' => 'Cache',
374
    'description' => 'Cache',
375
    'access arguments' => array('administer cdm_dataportal'),
376
    'page callback' => 'drupal_get_form',
377
    'page arguments' => array('cdm_settings_cache'),
378
    'weight' => 10,
379
    'type' => MENU_LOCAL_TASK,
380
  );
381

    
382
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
383
    'title' => 'Geo & Map',
384
    'description' => 'Geo & Map',
385
    'access arguments' => array('administer cdm_dataportal'),
386
    'page callback' => 'drupal_get_form',
387
    'page arguments' => array('cdm_settings_geo'),
388
    'weight' => 1,
389
    'type' => MENU_LOCAL_TASK,
390
  );
391

    
392
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
393
    'title' => 'Layout',
394
    'description' => 'Configure and adjust the layout of your DataPortal ',
395
    'access arguments' => array('administer cdm_dataportal'),
396
    'page callback' => 'drupal_get_form',
397
    'page arguments' => array('cdm_settings_layout'),
398
    'weight' => 2,
399
    'type' => MENU_LOCAL_TASK,
400
  );
401

    
402
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
403
    'title' => 'Taxon',
404
    'description' => 'Configure and adjust the layout of your DataPortal ',
405
    'access arguments' => array('administer cdm_dataportal'),
406
    'page callback' => 'drupal_get_form',
407
    'page arguments' => array('cdm_settings_layout_taxon'),
408
    'weight' => 1,
409
    'type' => MENU_LOCAL_TASK,
410
  );
411
  /*
412
  $items[] = array(
413
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
414
  'title' => t('Synonymy'),
415
  'description' => t('Configure and adjust the layout of your DataPortal '),
416
  'access' => user_access('administer cdm_dataportal'),
417
  'callback' => 'drupal_get_form',
418
  'callback arguments' => array('cdm_settings_layout_synonymy'),
419
  'weight' => 1,
420
  'type' => MENU_LOCAL_TASK,
421
  );
422

    
423
  $items[] = array(
424
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
425
  'title' => t('Specimens'),
426
  'description' => t('Configure and adjust the layout of your DataPortal '),
427
  'access' => user_access('administer cdm_dataportal'),
428
  'callback' => 'drupal_get_form',
429
  'callback arguments' => array('cdm_settings_layout_specimens'),
430
  'weight' => 1,
431
  'type' => MENU_LOCAL_TASK,
432
  );
433
  */
434
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
435
    'title' => 'Search',
436
    'description' => 'Configure and adjust the layout of your DataPortal ',
437
    'access arguments' => array('administer cdm_dataportal'),
438
    'page callback' => 'drupal_get_form',
439
    'page arguments' => array('cdm_settings_layout_search'),
440
    'weight' => 2,
441
    'type' => MENU_LOCAL_TASK,
442
  );
443

    
444
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
445
    'title' => 'Media',
446
    'description' => 'Configure and adjust the layout of your DataPortal ',
447
    'access arguments' => array('administer cdm_dataportal'),
448
    'page callback' => 'drupal_get_form',
449
    'page arguments' => array('cdm_settings_layout_media'),
450
    'weight' => 3,
451
    'type' => MENU_LOCAL_TASK,
452
  );
453

    
454
}
455

    
456
/**
457
 * @todo document this function.
458
 */
459
function cdm_help_general_cache() {
460
  $form = array();
461
  $form['cache_help'] = array(
462
    '#type' => 'fieldset',
463
    '#title' => t('Help'),
464
    '#collapsible' => TRUE,
465
    '#collapsed' => TRUE,
466
  );
467
  $form['cache_help']['test'] = array('#value' => t('probando'));
468
  return drupal_render($form);
469
  $res = array();
470
  $res['default'] = drupal_render($help);
471
  return $res;
472
}
473

    
474
/**
475
 * Configures the settings form for the CDM-API module.
476
 *
477
 * @return array
478
 *   Drupal settings form.
479
 */
480
function cdm_settings_general() {
481

    
482
  $form['cdm_webservice'] = array(
483
    '#type' => 'fieldset',
484
    '#title' => t('CDM Server'),
485
    '#collapsible' => FALSE,
486
    '#collapsed' => FALSE,
487
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
488
        CDM data base to the web via RESTful web services and thus is the source of the data
489
        to be displayed by a CDM DataPotal.'),
490
  );
491

    
492
  $form['cdm_webservice']['cdm_webservice_url'] = array(
493
    '#type' => 'textfield',
494
    '#title' => t('CDM web service URL') . ':',
495
    '#description' => t('This is the URL to the CDM-Server exposing your data
496
      e.g. <em>"http://localhost:8080/cichorieae/"</em> The URL <strong>must end
497
      with a slash</strong> character!'),
498
    '#default_value' => variable_get('cdm_webservice_url', NULL),
499
  );
500

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

    
508
  $form['cdm_webservice']['freetext_index'] = array(
509
    '#type' => 'fieldset',
510
    '#title' => t('Freetext index'),
511
    '#collapsible' => FALSE,
512
    '#collapsed' => FALSE,
513
  );
514

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

    
527
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
528
  $trigger_link_options = array(
529
    'attributes' => array(
530
      'class' => 'index-trigger',
531
    ),
532
  );
533
  $form['cdm_webservice']['freetext_index']['operations'] = array(
534
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
535
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
536
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
537
      ))
538
    . '<div id="index-progress"></div></div>',
539
  );
540
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
541

    
542
  $form['cdm_webservice']['proxy'] = array(
543
    '#type' => 'fieldset',
544
    '#title' => t('Proxy'),
545
    '#collapsible' => TRUE,
546
    '#collapsed' => TRUE,
547
  );
548

    
549
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
550
    '#type' => 'textfield',
551
    '#title' => t('Proxy URL') . ':',
552
    '#description' => t('If this proxy url is set the cdm api tries
553
    to connect the web service over the given proxy server.
554
    Otherwise proxy usage is deactivated.'),
555
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
556
  );
557

    
558
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
559
    '#type' => 'textfield',
560
    '#title' => t('Proxy port') . ':',
561
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
562
  );
563

    
564
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
565
    '#type' => 'textfield',
566
    '#title' => t('Login') . ':',
567
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
568
  );
569

    
570
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
571
    '#type' => 'textfield',
572
    '#title' => t('Password') . ':',
573
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
574
  );
575

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

    
592
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
593
    '#type' => 'select',
594
    '#title' => t('Available classifications') . ':',
595
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
596
    '#options' => cdm_get_taxontrees_as_options(),
597
    '#description' => t('Select the default taxa classification for your
598
      <em>taxon tree</em>, the other classifications will be also available but
599
      with a manual user change.'),
600
  );
601

    
602
  $form['taxon_tree']['taxontree_ranklimit'] = array(
603
    '#type' => 'select',
604
    '#title' => t('Rank of highest displayed taxon') . ':',
605
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
606
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
607
    '#options' => cdm_rankVocabulary_as_option(),
608
    '#description' => t('This is the rank of the highest displayed taxon in the
609
      <em>taxon tree</em>. You can select here which rank should be at the top
610
      level of the tree structure.'),
611
  );
612

    
613
  $form['aggregation'] = array(
614
      '#type' => 'fieldset',
615
      '#title' => t('Aggregation of data'),
616
      '#collapsible' => FALSE,
617
      '#description' => t("This section covers the different aspects of aggregating information.
618
          <p>
619
          </p>"),
620

    
621
  );
622

    
623
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
624
      '#type' => 'checkboxes',
625
      '#title' => 'Taxon media filter',
626
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
627
      '#options' => array(
628
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
629
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
630
          'includeOccurrences' => 'Media related to specimens and occurrences',
631
      ),
632
      '#description' => 'This filter configures which images should be taken into account.',
633
  );
634

    
635
  $form['aggregation']['notice'] = array(
636
      '#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
637
          want to make use of the caching capabilities of the dataportal.',
638
  );
639

    
640
  $form['aggregation']['media_aggregation'] = array(
641
      '#type' => 'fieldset',
642
      '#title' => t('Media aggregation'),
643
      '#collapsible' => FALSE,
644
      '#collapsed' => TRUE,
645
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
646

    
647
  );
648
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
649
      '#type' => 'select',
650
      '#title' => t('Aggregation of taxon pictures') . ':',
651
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
652
      '#options' => array(
653
          0 => "Show only pictures of the current taxon",
654
          1 => "Include pictures of taxonomic children",
655
      ),
656
      '#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."),
657
  );
658

    
659
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
660
      '#type' => 'fieldset',
661
      '#attributes' => array('class'=>array('clearfix')),
662
      '#title' => t('Aggregation via taxon relationsships'),
663
      '#collapsible' => TRUE,
664
      '#collapsed' => TRUE,
665
      '#tree' => TRUE,
666
      '#description' => t('Information on taxa will be aggregated along the below chosen
667
          taxon relation ships. This will affect images and occurrences (specimens).
668
          Taxon relation ships are directed and point form one taxon to another. The taxon
669
          relationships to be taken into accunt can therefore configured for the direct direction
670
          and for the inverse.'),
671
  );
672

    
673
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
674
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
675

    
676
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
677
      '#type' => 'checkboxes',
678
      '#title' => t('Direct'),
679
      '#options' => $taxonRelationshipTypeOptions,
680
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
681
  );
682
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
683
      '#type' => 'checkboxes',
684
      '#title' => t('Invers'),
685
      '#options' => $taxonRelationshipTypeOptions,
686
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
687
  );
688

    
689
  // Comment @WA: D7 form api does not support reset buttons,
690
  // so to mimic the D5 reset button we add one like this.
691
  $form['actions']['reset'] = array(
692
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
693
    '#weight' => 1000,
694
  );
695

    
696
  return system_settings_form($form);
697
}
698

    
699

    
700
/**
701
 * LAYOUT settings
702
 * @return unknown_type
703
 *   todo
704
 */
705
function cdm_settings_layout() {
706

    
707
  $form = array();
708

    
709
  $form['about'] = array(
710
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
711
      layout. If you want to configure the specific sites layout visit the
712
      respective configuration site for taxon, search or media.') . '</p>',
713
  );
714

    
715
  // ---- footnotes --- //
716
  $form['footnotes'] = array(
717
    '#type' => 'fieldset',
718
    '#title' => t('Footnotes'),
719
    '#collapsible' => FALSE,
720
    '#collapsed' => FALSE,
721
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
722
      media or distribution areas may have annotations or footnotes. When the
723
      footnotes are enabled they will be visible (if they exist).'),
724
  );
725

    
726
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
727
    '#type' => 'checkbox',
728
    '#title' => t('Do not show footnotes'),
729
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
730
    '#description' => t('Check this if you do not want to show any footnotes'),
731
  );
732

    
733
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
734
    '#type' => 'checkbox',
735
    '#title' => t('Do not show annotations footnotes'),
736
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
737
    '#description' => t('Check this if you do not want to show annotation footnotes'),
738
  );
739

    
740
  $annotationTypeOptions = cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE);
741
  // Additional option for the NULL case.
742
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
743
  $form['footnotes']['annotations_types_as_footnotes'] = array(
744
    '#type' => 'checkboxes',
745
    '#title' => t('Annotation types as footnotes'),
746
    '#description' => t("Only annotations of the selected type will be displayed
747
       as footnotes. You may want to turn 'technical annotations' off."),
748
    '#options' => $annotationTypeOptions,
749
  );
750
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
751
  if (!empty($annotationsTypesAsFootnotes)) {
752
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
753
  }
754

    
755
  // --- Advanced Search --- //
756
  $form['asearch'] = array(
757
      '#type' => 'fieldset',
758
      '#title' => t('Advanced search'),
759
      '#collapsible' => FALSE,
760
      '#collapsed' => FALSE,
761
  );
762
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
763
      '#type' => 'checkbox',
764
      '#title' => t('Show advanced search link'),
765
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
766
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
767
  );
768

    
769
  // ---- Taxon Name Rendering --- //
770
  $form['taxon_name'] = array(
771
      '#type' => 'fieldset',
772
      '#title' => t('Taxon name display'),
773
      '#collapsible' => TRUE,
774
      '#collapsed' => TRUE,
775
      '#description' => t('The display of taxon names is configured by two parts.'
776
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
777
          . 'The name parts are defined in the <stong>part definitions</strong>'),
778
  );
779

    
780
  drupal_add_js(
781
      'jQuery(document).ready( function( ) {
782
         // pretty print json
783
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
784
         var obj = JSON.parse(json_text);
785
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
786

    
787
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
788
         obj = JSON.parse(json_text);
789
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
790
       });'
791
      ,array(
792
          'type' => 'inline',
793
          'scope' => 'footer'
794
      )
795
  );
796

    
797
  //TODO remove after all portals are using the settings
798
  $default_part_definitions = theme('get_partDefinition', array());
799
  if(!is_array($default_part_definitions)) {
800
    $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
801
  }
802

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

    
890
  //TODO remove after all portals are using the settings
891
  $default_render_templates = theme('get_nameRenderTemplate', array());
892
  if(!is_array($default_render_templates)) {
893
    $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
894
  }
895

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

    
934
  // @WA: D7 form api does not support reset buttons,
935
  // so to mimic the D5 reset button we add one like this.
936
  $form['actions']['reset'] = array(
937
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
938
    '#weight' => 1000,
939
  );
940

    
941
  $form['#submit'] = array('submit_json_as_php_array');
942
  // #json_elements especially defined for submit_json_as_php_array()
943
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
944
  return system_settings_form($form);
945
}
946

    
947

    
948
/**
949
 * @todo Please document this function.
950
 * @see http://drupal.org/node/1354
951
 */
952
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
953
  $form[$form_name] = array(
954
    '#type' => 'fieldset',
955
    '#title' => t($form_title),
956
    '#collapsible' => TRUE,
957
    '#collapsed' => $collapsed,
958
    '#tree' => TRUE,
959
    '#description' => t($form_description),
960
  );
961

    
962
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
963
  $gallery_settings = variable_get($form_name, $default_values);
964
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
965
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
966
    /*
967
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
968
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
969
    '#type' => 'textfield',
970
    '#title' => t('Search Page Size'),
971
    '#default_value' => $test,
972
    '#description' => t('Number of Names to display per page in search results.')
973
    );
974
    */
975
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
976
      '#type' => 'checkbox',
977
      '#title' => t('Show media thumbnails for accepted taxa'),
978
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
979
    );
980

    
981
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
982
      '#type' => 'checkbox',
983
      '#title' => t('Show media thumbnails for synonyms'),
984
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
985
      '#description' => '',
986
    );
987
  }
988

    
989
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
990
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
991
    '#type' => 'checkbox',
992
    '#title' => t('Show captions under thumbnails'),
993
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
994
    '#description' => '',
995
  );
996

    
997
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
998
    '#type' => 'textfield',
999
    '#title' => t('Thumbnail size') . ':',
1000
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1001
    '#description' => t('Select the size of each individual thumbnail.'),
1002
  );
1003

    
1004
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1005
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1006
      '#type' => 'textfield',
1007
      '#title' => t('Number of columns') . ':',
1008
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1009
      '#description' => t('Group the thumbnails in columns: select how many
1010
        columns the gallery should display.'),
1011
    );
1012
  }
1013

    
1014
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1015
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1016
      '#type' => 'textfield',
1017
      '#title' => t('Maximum number of rows') . ':',
1018
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1019
      '#description' => t('You can group the thumbnails in rows, select in how
1020
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1021
        If you want an unlimited number of rows please set to 0.'),
1022
    );
1023
  }
1024

    
1025
  return $form;
1026
}
1027

    
1028
/**
1029
 * @todo document this function.
1030
 */
1031
function cdm_settings_layout_taxon() {
1032
  $collapsed = FALSE;
1033
  $form = array();
1034

    
1035
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1036

    
1037
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1038
      '#type' => 'checkbox',
1039
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1040
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1041
      '#description' => t('<p>If checked the link to search results is rendered at
1042
       the top of the taxon site. Clicking on the link the last search performed
1043
       is rendered again.</p>'),
1044
  );
1045

    
1046
  // --------- TABBED TAXON ------- //
1047
  $form['taxon_tabs'] = array(
1048
    '#type' => 'fieldset',
1049
    '#title' => t('Taxon tabs'),
1050
    '#collapsible' => TRUE,
1051
    '#collapsed' => FALSE,
1052
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1053
      be splitted in four diferent tabs; General, Synonymy, Images and
1054
      Specimens. If the taxon has no information for any of the tabs/sections
1055
      such tab will be not displayed.'),
1056
  );
1057

    
1058
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1059
    '#type' => 'checkbox',
1060
    '#title' => t('Tabbed taxon page'),
1061
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1062
    '#description' => t('<p>If selected split the taxon page into individual
1063
      tabs for description, images, synonymy and specimens. If not the taxon
1064
      data is rendered as a long single page without tabs.</p>'),
1065
  );
1066

    
1067
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1068
    '#type' => 'checkboxes',
1069
    '#title' => t('Tabs visibility options') . ':',
1070
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1071
    '#options' => get_taxon_options_list(),
1072
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1073
  );
1074

    
1075
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1076
    '#type' => 'select',
1077
    '#title' => t('Default tab to display') . ':',
1078
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1079
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1080
    '#description' => t('<p>Select the default tab to display when visiting a
1081
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1082
      <strong>Note:</strong> After performing a search and clicking in any
1083
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1084
      taxon and not the above selected tab.'),
1085
  );
1086

    
1087
  /* ======  TAXON_PROFILE ====== */
1088
  $form['taxon_profile'] = array(
1089
    '#type' => 'fieldset',
1090
    '#title' => t('Taxon profile (tab)'),
1091
    '#description' => t('<p>This section covers the settings related to the taxon
1092
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1093
    '#collapsible' => TRUE,
1094
    '#collapsed' => TRUE,
1095
  );
1096

    
1097
  // ---- PROFILE PICTURE ----//
1098

    
1099
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1100
    '#type' => 'fieldset',
1101
    '#tree' => TRUE,
1102
    '#title' => t('Taxon profile picture'),
1103
    '#collapsible' => TRUE,
1104
    '#collapsed' => FALSE,
1105
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1106
  );
1107

    
1108
  //FIXME migrate variables:
1109
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1110
  // FIXME
1111
  //  eanable file modul in profile and in update
1112

    
1113
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1114
  /*
1115
   * 'show' => 1,
1116
   * 'maxextend' => 184,
1117
   * 'media_uri_query' => ''
1118
   * 'custom_placeholder_image_on' => 1,
1119
   * 'custom_placeholder_image_fid' => ''
1120
   */
1121
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1122
    '#type' => 'checkbox',
1123
    '#title' => t('Enable profil picture'),
1124
    '#description' => t('Show the profil picture.'),
1125
    '#default_value' => $taxon_profile_image_settings['show'],
1126
  );
1127

    
1128
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1129
      '#type' => 'textfield',
1130
      '#tree' => TRUE,
1131
      '#title' => t('Profil picture maximum extend'),
1132
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1133
      '#field_suffix' => 'px',
1134
      '#maxlength' => 4,
1135
      '#size' => 4,
1136
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1137
  );
1138

    
1139
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1140
      '#type' => 'textfield',
1141
      '#tree' => TRUE,
1142
      '#title' => t('Additional URI query parameter'),
1143
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1144
      '#maxlength' => 1024,
1145
      '#size' => 60,
1146
      '#description' => t('Additional query parameters to be used when requesting for the '
1147
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1148
          . 'The query parameters will be appendend to the uri of the media representation part'
1149
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1150
  );
1151

    
1152
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1153
      '#type' => 'checkbox',
1154
      '#title' => t('Use a custom placeholder image'),
1155
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1156
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1157
  );
1158

    
1159
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1160
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1161
        '#type' => 'managed_file',
1162
        '#title' => t('Custom placeholder image file'),
1163
        '#progress_indicator' => 'bar',
1164
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1165
    //       '#name' => 'custom_placeholder_image',
1166
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1167
    );
1168

    
1169
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1170
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1171
      $url = file_create_url($profile_image_file->uri);
1172
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1173
                '#type' => 'item',
1174
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1175
      );
1176
    }
1177
  } else {
1178
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1179
        '#type' => 'hidden',
1180
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1181
    );
1182
  }
1183

    
1184

    
1185

    
1186
  $options = cdm_rankVocabulary_as_option();
1187
  array_unshift($options, '-- DISABLED --');
1188
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1189
    '#type' => 'select',
1190
    '#title' => t('Hide profile picture for higher ranks') . ':',
1191
    '#default_value' => variable_get('image_hide_rank', '0'),
1192
    '#options' => $options,
1193
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1194
  );
1195

    
1196
  // -- MEDIA THUMBNAILS -- //
1197
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1198
  $form_title = 'Taxon Profile Images';
1199
  $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>';
1200
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1201

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

    
1247
  // ---- LAYOUT PER FEATURE ---- //
1248
  $feature_tree = get_profile_featureTree();
1249
  if (isset($feature_tree->root->children)) {
1250

    
1251
    $form_feature_list_layout = array(
1252
      '#title' => t('Taxon profile layout'),
1253
      '#collapsible' => TRUE,
1254
      '#collapsed' => FALSE,
1255
      '#type' => 'fieldset',
1256
      '#description' => t('Will be available in a future release.'),
1257
    );
1258

    
1259
    $feature_list_layout_settings_disabled = TRUE;
1260
    foreach ($feature_tree->root->children as $featureNode) {
1261

    
1262
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1263
        // Must not exceed 45 characters !!!
1264
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1265

    
1266
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1267
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1268

    
1269
        $form_feature_list_layout[$subform_id] = array(
1270
          '#tree' => TRUE,
1271
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1272
          '#collapsible' => FALSE,
1273
          '#collapsed' => FALSE,
1274
          '#type' => 'fieldset',
1275
          '#description' => t(''),
1276
        );
1277

    
1278
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1279
          '#type' => 'checkbox',
1280
          '#title' => t('Enable'),
1281
          '#default_value' => $settings['enabled'],
1282
          '#description' => t('Enable user defined layout for this feature'),
1283
        );
1284

    
1285
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1286
          '#type' => 'textfield',
1287
          '#title' => t('Enclosing tag'),
1288
          '#disabled' => !$settings['enabled'],
1289
          '#default_value' => $settings['enclosingTag'],
1290
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1291
        );
1292

    
1293
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1294
          '#type' => 'textfield',
1295
          '#title' => t('Entry enclosing tag'),
1296
          '#disabled' => !$settings['enabled'],
1297
          '#default_value' => $settings['entryEnclosingTag'],
1298
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1299
        );
1300

    
1301
        $form_feature_list_layout[$subform_id]['glue'] = array(
1302
          '#type' => 'textfield',
1303
          '#title' => t('Glue'),
1304
          '#disabled' => !$settings['enabled'],
1305
          '#default_value' => $settings['glue'],
1306
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1307
        );
1308

    
1309
      }
1310

    
1311
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1312
    }
1313
  }
1314

    
1315
  // ---- DISTRIBUTION LAYOUT ---- //
1316
  $form['taxon_profile']['distribution_layout'] = array(
1317
    '#title' => t('Distribution'),
1318
    '#collapsible' => TRUE,
1319
    '#collapsed' => FALSE,
1320
    '#type' => 'fieldset',
1321
    '#description' => t('Select if you want to sort or not the distribution text
1322
      located below the distribution map.'),
1323
  );
1324

    
1325
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1326
    '#type' => 'radios',
1327
    '#title' => t('Sort') . ':',
1328
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1329
    '#options' => array(
1330
      'NO_SORT' => t('Standard (No sort)'),
1331
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1332
    ),
1333
  );
1334

    
1335
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1336
    '#type' => 'checkbox',
1337
    '#title' => t('Show TextData elements on top of the map'),
1338
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1339
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1340
      elements on top of the map. Otherwise all <code>TextData</code>
1341
      distribution elements will be listed below the other area elements.
1342
      This option is useful if you need to have descriptive texts for each
1343
      distribution map.'),
1344
  );
1345

    
1346

    
1347
  /* ====== SYNONYMY ====== */
1348
  $form['taxon_synonymy'] = array(
1349
    '#type' => 'fieldset',
1350
    '#title' => t('Taxon synonymy (tab)'),
1351
    '#collapsible' => TRUE,
1352
    '#collapsed' => TRUE,
1353
    '#description' => t('This section covers the settings related to the taxon
1354
      <strong>synonymy</strong> tab.'),
1355
  );
1356

    
1357
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1358
    '#type' => 'checkbox',
1359
    '#title' => t('Show accepted taxon on top of the synonymy'),
1360
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1361
    '#description' => t('If checked, the first homotypic taxon is a repetition
1362
      of the accepted taxon most likely with the full nomenclatural reference
1363
      (depending on the currently chosen theme).'),
1364
  );
1365

    
1366
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1367
    '#type' => 'checkbox',
1368
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1369
      coming from a synonym link.'),
1370
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1371
    '#description' => t('Check this if after doing a search and clicking on a
1372
      synonym you want to see the "accept of" text for the accepted synonym.'),
1373
  );
1374

    
1375
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1376
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1377
    '#type' => 'checkboxes',
1378
    '#title' => t('Display name relationships') . ':',
1379
    '#default_value' => variable_get('name_relationships_to_show', 0),
1380
    '#options' => $nameRelationshipTypeOptions,
1381
    '#description' => t('Select the name relationships you want to show for the
1382
      accepted taxa.'),
1383
  );
1384

    
1385
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1386
    '#type' => 'checkbox',
1387
    '#title' => t('Show taxon relations ships of accepted taxon'),
1388
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1389
    '#description' => t('If this option is enabled the synonymy will show the
1390
      below selected taxon relationships of accepted taxa.'),
1391
  );
1392

    
1393
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1394
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1395
    '#type' => 'checkboxes',
1396
    '#title' => t('Taxon relationship types') . ':',
1397
    '#description' => t('Only taxon relationships of the selected type will be
1398
      displayed'),
1399
    '#options' => $taxonRelationshipTypeOptions,
1400
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1401
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1402
  );
1403

    
1404
  // ====== SPECIMENS ====== //
1405
  $form['taxon_specimens'] = array(
1406
    '#type' => 'fieldset',
1407
    '#title' => t('Taxon specimens (tab)'),
1408
    '#collapsible' => TRUE,
1409
    '#collapsed' => TRUE,
1410
    '#description' => t('This section covers the settings related to the taxon
1411
      <strong>specimens</strong> tab.'),
1412
  );
1413

    
1414
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1415
  $saved_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1416
  if(!isset($featureTrees['options'][$saved_uuid])) {
1417
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1418
  }
1419
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1420
      '#type' => 'radios',
1421
      '#title' => t('Specimen description feature tree') . ':',
1422
      '#default_value' => $saved_uuid,
1423
      '#options' =>  $featureTrees['options'],
1424
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1425
      '#options_suffixes' => $featureTrees['treeRepresentations'],
1426
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1427
      ),
1428
  );
1429

    
1430
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1431
  $form_title = t('Specimen media');
1432
  $form_description = t('Specimens may have media which is displayed at the
1433
     Specimen tab/section as a gallery. It is possible to configure the
1434
     thumbnails gallery here, however for configuring how a single media should
1435
     be displayed please go to !url.</p>',
1436
     array(
1437
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1438
     ));
1439
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1440

    
1441
  // --- MEDIA GALLERY ---- //
1442
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1443
  $form_title = 'Media gallery (tab)';
1444
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1445
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1446
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1447
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1448
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1449
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1450
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1451

    
1452
  // Comment @WA: D7 form api does not support reset buttons,
1453
  // so to mimic the D5 reset button we add one like this.
1454
  $form['actions']['reset'] = array(
1455
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1456
    '#weight' => 1000,
1457
  );
1458
  return system_settings_form($form);
1459
}
1460

    
1461
/**
1462
 * @todo document this function.
1463
 */
1464
function cdm_settings_layout_search() {
1465

    
1466
  $form = array();
1467

    
1468
  $form['search_settings'] = array(
1469
    '#type' => 'fieldset',
1470
    '#title' => t('Taxa Search'),
1471
    '#collapsible' => FALSE,
1472
    '#collapsed' => FALSE,
1473
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1474
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1475
         where they can write the text to be searched. You can find Drupal block configuration
1476
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1477
  );
1478

    
1479
  $form['search_settings']['simple_search_ignore_classification'] = array(
1480
      '#type' => 'checkbox',
1481
      '#title' => t('Ignore the chosen classification in simple search'),
1482
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
1483
      '#description' => t('The simple search, which can be executed via the search block,
1484
          will by default search on all classifications. Remove the tick if you want your
1485
          portal to search on the classification selected in the classification browser
1486
          selector.'),
1487
  );
1488

    
1489
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1490
    '#type' => 'textfield',
1491
    '#title' => t('Results per page') . ':',
1492
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1493
    '#description' => t('Number of results to display per page.'),
1494
  );
1495

    
1496
  $form['search_settings']['cdm_search_taxa'] = array(
1497
    '#type' => 'checkbox',
1498
    '#title' => t('Sets the default value of <em>Search for accepted taxa</em> in the advanced search form.'),
1499
    '#default_value' => variable_get('cdm_search_taxa', 1),
1500
    '#description' => t('<p>If checked the <em>Search for accepted taxa </em> option will be enabled in the advanced form.</p>'),
1501
  );
1502

    
1503
  $form['search_settings']['cdm_search_synonyms'] = array(
1504
    '#type' => 'checkbox',
1505
    '#title' => t('Sets the default value of <em>Search for synonyms</em> in the advanced search form.'),
1506
    '#default_value' => variable_get('cdm_search_synonyms', 1),
1507
    '#description' => t('<p>If checked the <em>Search for synonyms</em> option will be enabled in the advanced form.</p>'),
1508
  );
1509

    
1510
  $form['search_settings']['cdm_search_common_names'] = array(
1511
    '#type' => 'checkbox',
1512
    '#title' => t('Sets the default value of <em>Search for common names</em> in the advanced search form.'),
1513
    '#default_value' => variable_get('cdm_search_common_names', 0),
1514
    '#description' => t('<p>If checked the <em>Search for common names</em> option will be enabled in the advanced form.</p>'),
1515
  );
1516

    
1517
  $form['search_settings']['cdm_search_use_default_values'] = array(
1518
    '#type' => 'checkbox',
1519
    '#title' => t('Sets use of default values in the advanced search form.'),
1520
    '#default_value' => variable_get('cdm_search_use_default_values', 1),
1521
    '#description' => t('<p>If checked the defqult values set abovewill be used for the search.</p>'),
1522
  );
1523

    
1524

    
1525
  // --- SEARCH TAXA GALLERY ---- //
1526
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1527
  $collapsed = FALSE;
1528
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1529
  $form_title = 'Taxa Search thumbnails';
1530
  $form_description = 'Search results may show thumbnails. ';
1531
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1532

    
1533
  // Comment @WA: D7 form api does not support reset buttons,
1534
  // so to mimic the D5 reset button we add one like this.
1535
  $form['actions']['reset'] = array(
1536
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1537
    '#weight' => 1000,
1538
  );
1539
  return system_settings_form($form);
1540
}
1541

    
1542
/**
1543
 * @todo document this function.
1544
 */
1545
function cdm_settings_layout_media() {
1546

    
1547
  $form = array();
1548

    
1549
  $form['media_settings'] = array(
1550
    '#type' => 'fieldset',
1551
    '#title' => t('Media settings'),
1552
    '#collapsible' => FALSE,
1553
    '#collapsed' => FALSE,
1554
    '#description' => 'This section covers layout settings for media pages.'
1555
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
1556
  );
1557

    
1558
  $form['media_settings']['image_gallery_viewer'] = array(
1559
    '#type' => 'select',
1560
    '#title' => t('Image viewer') . ':',
1561
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1562
    '#options' => array(
1563
      'default' => t('Standard image viewer'),
1564
      'fsi' => t('FSI viewer (requires FSI server!)'),
1565
    ),
1566
  );
1567

    
1568
  // --- MEDIA GALLERY ---- //
1569
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1570
  $form_title = 'Standard viewer';
1571
  $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>';
1572
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1573
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1574

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

    
1584
/**
1585
 * GEOSERVICE and Map settings.
1586
 */
1587
function cdm_settings_geo($form, &$form_state) {
1588

    
1589
  $current_geoserver_settings = get_edit_map_service_settings();
1590
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
1591

    
1592
  $form = array();
1593

    
1594
  $dummy_distribution_query = NULL;
1595
  if($map_distribution['map_type'] != 1){
1596
    // we need to apply a dummy query since the map serice requires for image maps
1597
    // at least as and ad to be defined
1598
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
1599
  }
1600
  $form['map_preview'] = array(
1601
      '#type' => 'fieldset',
1602
      '#tree' => FALSE,
1603
      '#title' => t('Map preview'),
1604
      '#collapsible' => FALSE,
1605
      '#description' => 'The preview of the map'
1606
       . ($dummy_distribution_query != null ? ' may not be accurate in case if image maps, please check the map display in the taxon pages.': '.')
1607
  );
1608
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL,
1609
      array(
1610
          'move' => "this.cdmOpenlayersMap.printInfo",
1611
          '#execute' => "this.cdmOpenlayersMap.printInfo"
1612
      )
1613
  );
1614

    
1615

    
1616
  /*
1617
   * GEO SERVER
1618
   */
1619
  $form['edit_map_server'] = array(
1620
    '#type' => 'fieldset',
1621
    '#tree' => true,
1622
    '#title' => t('EDIT map service'),
1623
    '#collapsible' => TRUE,
1624
    '#collapsed' => TRUE,
1625
    '#description' => t('Configuration and selection of your geo server.
1626
      The Geo Server is responsible for generating the maps.'),
1627
  );
1628

    
1629
  $form['edit_map_server']['base_uri'] = array(
1630
    '#type' => 'select',
1631
    '#title' => t('EDIT map service') . ':',
1632
    '#default_value' => $current_geoserver_settings['base_uri'],
1633
    '#options' => unserialize(EDIT_MAPSERVER_URI),
1634
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
1635
  );
1636
  $form['edit_map_server']['version'] = array(
1637
      '#type' => 'select',
1638
      '#title' => t('Version') . ':',
1639
      '#default_value' => $current_geoserver_settings['version'],
1640
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
1641
      '#description' => t('The version of the EDIT map services'),
1642
  );
1643

    
1644
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1645
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1646
  $form['gmap_api_key'] = array(
1647
      '#type' => 'textfield',
1648
      '#title' => t('Google maps API key') . ':',
1649
      '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1650
      '#description' => t('If you want to use the Google Maps Layer, a key is
1651
      needed. If you need a key, visit
1652
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
1653
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
1654
      is the default key for the localhost (127.0.0.1).',
1655
      array('!localhostkey' => $localhostkey)),
1656
  );
1657

    
1658

    
1659
  /*
1660
   * MAP SETTINGS
1661
   */
1662

    
1663
  $form[CDM_MAP_DISTRIBUTION] = array(
1664
    '#type' => 'fieldset',
1665
    '#tree' => TRUE,
1666
    '#title' => t('Maps settings'),
1667
    '#collapsible' => TRUE,
1668
    '#collapsed' => TRUE,
1669
    '#description' => t('General configuration for all map types.'),
1670
  );
1671

    
1672
  /*
1673
   * settings for the distribution map are used also for specimens map!!!!
1674
   */
1675

    
1676
  $form[CDM_MAP_DISTRIBUTION]['width'] = array(
1677
    '#type' => 'textfield',
1678
    '#title' => 'Width',
1679
    '#default_value' => $map_distribution['width'],
1680
    '#maxlength' => 4,
1681
    '#size' => 4,
1682
    '#description' => 'Width of the map. To allow OSM baselayers to zoom out to the full extend of the world the map width must be
1683
      a multiple of 256px since the osm tiles from tile.openstreetmap.org have a size of 256px x 256px and frational zoom
1684
      levels are not possible in this case.',
1685
  );
1686
  $form[CDM_MAP_DISTRIBUTION]['height'] = array(
1687
      '#type' => 'textfield',
1688
      '#title' => 'Height',
1689
      '#default_value' => $map_distribution['height'],
1690
      '#maxlength' => 4,
1691
      '#size' => 4,
1692
      '#description' => 'Height of the map. Depending on the chosen base layer you may want to choose the height equal
1693
      to the width or half of the width. Any other aspect ratio is also possible if desired.',
1694
  );
1695

    
1696
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
1697
    '#type' => 'textfield',
1698
    '#title' => 'Bounding box',
1699
    '#default_value' => $map_distribution['bbox'],
1700
    '#description' => t('The bounding box defines the area to be initially displayed in maps.
1701
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
1702
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.'),
1703
  );
1704

    
1705
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
1706
    '#type' => 'checkbox',
1707
    '#title' => 'Display area labels',
1708
    '#default_value' => $map_distribution['show_labels'],
1709
    '#description' => t('The map will show name labels of the areas'),
1710
  );
1711

    
1712
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
1713
    '#type' => 'textfield',
1714
    '#title' => 'Map caption',
1715
    '#default_value' => $map_distribution['caption'],
1716
    '#description' => t('The caption will be shown below the map.'),
1717
  );
1718

    
1719
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
1720
    '#type' => 'textfield',
1721
    '#title' => 'Distribution layer opacity',
1722
    '#default_value' => $map_distribution['distribution_opacity'],
1723
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1724
                           fully visible, while a value near to 0.0 will be not much visible.'),
1725
  );
1726

    
1727
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
1728
    '#type' => 'radios',
1729
    '#title' => 'Map types',
1730
    '#options' => array(
1731
      1 => "OpenLayers dynamic map viewer",
1732
      0 => "Plain image",
1733
    ),
1734
    '#default_value' => $map_distribution['map_type'],
1735
    '#description' => 'Two different map types are available :
1736
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
1737
      which allows zooming and panning. If enabled you can configure the default layer
1738
      (background of your maps) below.</li>
1739
      <li><em>Plain image</em>: The map will be static non interactive
1740
      image.</li></ul>',
1741
  );
1742
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
1743

    
1744

    
1745
  // --- Plain Image Settings --- //
1746
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
1747
    '#type' => 'fieldset',
1748
    '#title' => 'Plain image map settings',
1749
    '#tree' => TRUE,
1750
    '#collapsible' => TRUE,
1751
    '#collapsed' => $open_layers_is_enabled,
1752
    '#description' => 'The settings in this section are still expertimental
1753
      and can only be used with the EDIT map service version 1.1 or above.',
1754
  );
1755
  $edit_mapserver_version = get_edit_map_service_version_number();
1756
  if ($edit_mapserver_version < 1.1) {
1757
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">' . t("The chosen EDIT map service version ($edit_mapserver_version) is too low, it must be at least 1.1") . '</div>'
1758
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
1759
  }
1760

    
1761
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
1762
    '#type' => 'textfield',
1763
    '#title' => 'Background layer',
1764
    '#default_value' => $map_distribution['image_map']['base_layer'],
1765
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
1766
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
1767
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
1768
    )),
1769
  );
1770

    
1771
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
1772
    '#type' => 'textfield',
1773
    '#title' => 'Background color',
1774
    '#default_value' => $map_distribution['image_map']['bg_color'],
1775
  );
1776

    
1777
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
1778
    '#type' => 'textfield',
1779
    '#title' => 'Background layer style',
1780
     // Only line color by now.
1781
    '#default_value' => $map_distribution['image_map']['layer_style'],
1782
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
1783
  );
1784

    
1785

    
1786
  // --- OpenLayers Settings --- //
1787
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
1788
    '#type' => 'fieldset',
1789
    '#title' => 'OpenLayers settings',
1790
    '#tree' => TRUE,
1791
    '#collapsible' => TRUE,
1792
    '#collapsed' => !$open_layers_is_enabled,
1793
    '#description' => '',
1794
  );
1795

    
1796
  if (!$open_layers_is_enabled) {
1797
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
1798
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
1799
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
1800
  }
1801

    
1802
  $baselayer_options = array(
1803
    /*
1804
   NOTICE: must correspond to the layers defined in
1805
   js/openlayers_,ap.js#getLayersByName()
1806
   */
1807
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
1808
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
1809
    // all others EPSG:900913
1810
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
1811
    'edit-etopo1' => "ETOPO1 Global Relief Model",
1812
    'mapnik' => 'OpenStreetMap',
1813
    'osmarender' => 'OpenStreetMap (Tiles@home)',
1814
    'gmap' => 'Google Streets',
1815
    'gsat' => 'Google Satellite',
1816
    'ghyb' => 'Google Hybrid',
1817
//     'veroad' => 'Virtual Earth Roads',
1818
//     'veaer' => 'Virtual Earth Aerial',
1819
//     'vehyb' => 'Virtual Earth Hybrid',
1820
    // 'yahoo' => 'Yahoo Street',
1821
    // 'yahoosat' => 'Yahoo Satellite',
1822
    // 'yahoohyb' => 'Yahoo Hybrid',
1823
  );
1824

    
1825
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
1826
    '#type' => 'checkboxes_preferred',
1827
    '#title' => 'Base Layers',
1828
    '#options' => $baselayer_options,
1829
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
1830
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
1831
  );
1832

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

    
1845
  /*
1846
   * Map Legend
1847
   */
1848
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
1849
    '#type' => 'fieldset',
1850
    '#title' => 'Map legend',
1851
    '#tree' => TRUE,
1852
    '#collapsible' => TRUE,
1853
    '#collapsed' => TRUE,
1854
    '#description' => 'Configure the maps legend.',
1855
  );
1856

    
1857
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
1858
    '#type' => 'checkbox',
1859
    '#title' => 'Display a map legend',
1860
    '#default_value' => $map_distribution['legend']['show'],
1861
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
1862
  );
1863

    
1864
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
1865
    '#type' => 'textfield',
1866
    '#title' => 'Legend opacity',
1867
    '#default_value' => $map_distribution['legend']['opacity'],
1868
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
1869
                         to 0.0 will be not much visible.',
1870
  );
1871

    
1872
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
1873
    '#type' => 'textfield',
1874
    '#title' => 'Font size',
1875
    '#default_value' => $map_distribution['legend']['font_size'],
1876
    '#description' => 'Font size in pixels.',
1877
  );
1878

    
1879
  $fontStyles = array(
1880
    0 => "plane",
1881
    1 => "italic",
1882
  );
1883
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
1884
    '#type' => 'select',
1885
    '#title' => 'Available font styles',
1886
    '#default_value' => $map_distribution['legend']['font_style'],
1887
    '#options' => $fontStyles,
1888
    '#description' => 'Select a font style for the map legend.',
1889
  );
1890

    
1891
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
1892
    '#type' => 'textfield',
1893
    '#title' => 'Icon width',
1894
    '#default_value' => $map_distribution['legend']['icon_width'],
1895
    '#description' => 'Legend icon width in pixels.',
1896
  );
1897
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
1898
    '#type' => 'textfield',
1899
    '#title' => 'Icon height',
1900
    '#default_value' => $map_distribution['legend']['icon_height'],
1901
    '#description' => 'Legend icon height in pixels.',
1902
  );
1903

    
1904
  // @WA: D7 form api does not support reset buttons,
1905
  // so to mimic the D5 reset button we add one like this.
1906
  $form['actions']['reset'] = array(
1907
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1908
    '#weight' => 1000,
1909
  );
1910

    
1911
  return system_settings_form($form);
1912
}
1913

    
1914
/**
1915
 * @todo document this function.
1916
 */
1917
function cdm_settings_cache() {
1918

    
1919
  $form = array();
1920

    
1921
  $form['cache_settings'] = array(
1922
    '#type' => 'fieldset',
1923
    '#title' => t('Cache Settings'),
1924
    '#collapsible' => FALSE,
1925
    '#collapsed' => FALSE,
1926
    '#description' => t('<p>When caching is enabled all single taxon sites are
1927
      stored in an internal drupal cache doing the portal response of taxa pages
1928
      faster. This is possible because the sites are loaded from the cache and
1929
      are not created from scratch.</p>'),
1930
  );
1931

    
1932
  $form['cache_settings']['cdm_webservice_cache'] = array(
1933
    '#type' => 'checkbox',
1934
    '#title' => t('<strong>Enable caching</strong>'),
1935
    '#options' => cdm_help_general_cache(),
1936
    '#default_value' => variable_get('cdm_webservice_cache', 1),
1937
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
1938
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
1939
       application the changes will be not visible till the cache is erased.
1940
       Therefore developers should deactived this feature when they are working
1941
       on the CDM Dataportal Module.</p>'),
1942
  );
1943

    
1944
  $form['cache_settings']['cdm_run_cache'] = array(
1945
    '#markup' => cdm_view_cache_site(),
1946
  );
1947

    
1948
  // @WA: D7 form api does not support reset buttons,
1949
  // so to mimic the D5 reset button we add one like this.
1950
  $form['actions']['reset'] = array(
1951
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1952
    '#weight' => 1000,
1953
  );
1954
  return system_settings_form($form);
1955
}
1956

    
1957
/**
1958
 * Walk and cache all taxon pages.
1959
 */
1960
function cdm_view_cache_site() {
1961

    
1962
  $out = '';
1963

    
1964
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
1965

    
1966
  $request_params = array();
1967
  $request_params['class'] = "Taxon";
1968

    
1969
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
1970
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
1971
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
1972

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

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

    
1982
  // Comment @WA: A form within a form is not valid html and not needed here.
1983
  // Also, it would be recommended just to include this part of the form in the
1984
  // rest of the form array in cdm_settings_cache().
1985
  // $out .= '<form id="cache_site">';
1986
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
1987
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
1988
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
1989
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
1990
  // $out .= '</form>';
1991
  $out .= '</div>';
1992
  /*
1993
  foreach($taxonPager->records as $taxon){
1994
    cdm_dataportal_taxon_view($uuid);
1995
  }
1996
  */
1997
  return $out;
1998
}
1999

    
2000

    
2001
function cdm_settings_layout_taxon_submit($form, &$form_state){
2002
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2003
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2004
    if(is_object($file)){
2005
      $file->status = FILE_STATUS_PERMANENT;
2006
      file_save($file);
2007
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2008
    }
2009
  }
2010
}
2011

    
2012
/**
2013
 * Form validation handler for ?
2014
 *
2015
 * Comment @WA: currently this handler is not used.
2016
 * It seems partly for cdm_settings_general en partly for cdm_settings_cache?
2017
 * Then you can change the name into cdm_settings_general_validate() or
2018
 * cdm_settings_cache_validate().
2019
 * But cdm_api_secref_cache_clear is not doing anything (yet)?
2020
 */
2021
function cdm_settings_validate($form, &$form_state) {
2022

    
2023
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2024
    // form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
2025
    $form_state['values']['cdm_webservice_url'] .= '/';
2026
  }
2027

    
2028
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2029
    cache_clear_all(NULL, 'cache_cdm_ws');
2030
    // Better clear secref_cache since I can not be sure if the cache has not
2031
    // be used during this response.
2032
    cdm_api_secref_cache_clear();
2033
  }
2034
}
2035

    
2036
/**
2037
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
2038
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
2039
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
2040
 *  - version: the version, e.g.: v1.1
2041
 *
2042
 * @return array
2043
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
2044
 */
2045
function get_edit_map_service_settings() {
2046

    
2047
  $settings = variable_get('edit_map_server', array(
2048
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
2049
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
2050
      )
2051
  );
2052
  // replace old non tree like settings by default
2053
  // TODO to be removed after release 3.1.5
2054
  if(!is_array($settings)){
2055
    variable_del('edit_map_server');
2056
    return get_edit_map_service_settings();
2057
  }
2058

    
2059
  return $settings;
2060
}
2061

    
2062
/**
2063
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2064
 *
2065
 * @return string
2066
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2067
 */
2068
function get_edit_map_service_full_uri() {
2069
  $settings = get_edit_map_service_settings();
2070
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
2071
}
2072

    
2073

    
2074
/**
2075
 * Returns the version number of the currently selected edit mapserver as a float
2076
 *
2077
 * @return float
2078
 *   The version number of the currently selected edit mapserver as a float.
2079
 *   Returns 0 on error.
2080
 */
2081
function get_edit_map_service_version_number() {
2082

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

    
2085
  $settings = get_edit_map_service_settings();
2086
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
2087
  if (isset($matches[1])) {
2088
    // Convert string to float.
2089
    $version = 1 + $matches[1][0] - 1;
2090
    return $version;
2091
  }
2092
  else {
2093
    // Report error.
2094
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
2095
        array(
2096
          '!version' => $settings['version'],
2097
          'warning')
2098
        )
2099
      );
2100
    return 0;
2101
  }
2102
}
2103

    
2104
/**
2105
 * Returns the array of selected items in a options array
2106
 *
2107
 * @param array $options
2108
 *   An options array as generated by a form element like checkoxes, select ...,
2109
 */
2110
function get_selection($options) {
2111
  $selection = array();
2112
  foreach ($options as $key=>$val) {
2113
    if (!empty($val)) {
2114
      $selection[] = $val;
2115
    }
2116
  }
2117
  return $selection;
2118
}
2119

    
2120

    
2121
/**
2122
 * Implements hook_element_info().
2123
 *
2124
 * Allows modules to declare their own Form API element types and specify their default values.
2125
 *
2126
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
2127
 */
2128
function cdm_dataportal_element_info() {
2129
  $type['checkboxes_preferred'] = array(
2130
    '#input' => TRUE,
2131
    '#process' => array('checkboxes_preferred_expand'),
2132
    '#after_build' => array('checkboxes_preferred_after_build'),
2133
    '#theme' => array('checkboxes_preferred'),
2134
    // '#theme_wrapper' => array('form_element'),
2135
  );
2136
  return $type;
2137
}
2138

    
2139
/**
2140
 * #process callback function for the custom form element type 'checkbox_preferred'
2141
 *
2142
 *
2143
 */
2144
function checkboxes_preferred_expand($element, &$form_state, $form) {
2145

    
2146
  // First of all create checkboxes for each of the elements
2147
  $element = form_process_checkboxes($element);
2148

    
2149
  // compose the element name
2150
  $parents = array();
2151
  array_deep_copy($element['#parents'], $parents);
2152
  $parents[count($parents) -1 ] .= '_preferred';
2153
  $element_name = $parents[0];
2154
  for ($i=1; $i < count($parents); $i++){
2155
    $element_name .= '[' . $parents[$i] . ']';
2156
  }
2157

    
2158
  $children = element_children($element);
2159

    
2160
  $element['table_start'] = array(
2161
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
2162
    '#weight' => -1,
2163
  );
2164

    
2165
  // prepare first part each of the table rows which contains the row label
2166
  $weight = 0;
2167
  foreach ($children as $key) {
2168
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
2169
    $element[$key]['#weight'] = $weight;
2170
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
2171
    $element[$key]['#suffix'] = '</td>';
2172
    unset($element[$key]['#title']);
2173
    $weight += 2;
2174
  }
2175
  $weight = 0;
2176

    
2177
  // add a radio button to each of the checkboxes, the
2178
  // check boxes have already been created at the beginning
2179
  // of this function
2180
  if (count($element['#options']) > 0) {
2181
    foreach ($element['#options'] as $key => $choice) {
2182
      if (!isset($element[$key . '_preferred'])) {
2183
        $element[$key . '_preferred'] = array(
2184
          '#type' => 'radio',
2185
          '#name' => $element_name,
2186
          '#return_value' => check_plain($key),
2187
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
2188
          '#attributes' => $element['#attributes'],
2189
          '#parents' => $element['#parents'],
2190
          // '#spawned' => TRUE,
2191
          '#weight' => $weight + 1,
2192
          '#prefix' => '<td>',        // add a prefix to start a new table cell
2193
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
2194
        );
2195
      }
2196
      $weight += 2;
2197
    }
2198
  }
2199

    
2200
  // end the table
2201
  $element['table_end'] = array(
2202
    '#markup' => '</table>',
2203
    '#weight' => $weight++,
2204
  );
2205

    
2206
  return $element;
2207
}
2208

    
2209
/**
2210
 * Theme function for the custom form field 'checkboxes_preferred'.
2211
 */
2212
function theme_checkboxes_preferred($variables) {
2213
  $element = $variables['element'];
2214
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
2215
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
2216
  $out .= drupal_render_children($element);
2217
  $out .= '<div class="description">' . $element['#description'] . '</div>';
2218
  $out .= '</div>';
2219
  return $out;
2220
}
2221

    
2222
/**
2223
 * Callback for checkboxes preferred for widget which will
2224
 * be called after the form or element is built. The call
2225
 * back is configured in the form element by setting it as
2226
 * #after_build parameter.
2227
 *
2228
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
2229
 *
2230
 * @param $element
2231
 *   Nested array of form elements that comprise the form.
2232
 * @param $form_state
2233
 *   A keyed array containing the current state of the form.
2234
 *   This includes the current persistent storage data for the form.
2235
 *   Additional information, like the sanitized $_POST data,
2236
 *   is also accumulated here in $form_state['input']
2237
 *
2238
 * @return the modified form array
2239
 */
2240
function checkboxes_preferred_after_build($element, &$form_state) {
2241

    
2242
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
2243

    
2244
  if ($_POST && count($_POST) > 0) {
2245
    // TODO use  $form_state['input'] instead of POST !!!
2246
    // First pass of form processing.
2247
    $parents = array();
2248
    array_deep_copy($element['#parents'], $parents);
2249
    $parents[count($parents) - 1] .= '_preferred';
2250
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
2251
    $element['#value']['PREFERRED'] = $preferred_layer;
2252
//     $form_state[$parent_id] = $element['#value'];
2253
//     $form_state['values']['baselayers'] = $element['#value'];
2254
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
2255
    $form_state_element_values = $element['#value'];
2256
  }
2257
  else {
2258
    // Second pass of form processing.
2259
    $preferred_layer = $element['#value']['PREFERRED'];
2260
  }
2261

    
2262
  // Also set the chosen value (not sure if this is good Drupal style ....).
2263
  foreach ($children = element_children($element) as $key) {
2264
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
2265
      $element[$key]['#value'] = $preferred_layer;
2266
    }
2267
  }
2268
  // The default layer must always be enabled.
2269
  $element[$preferred_layer]['#value'] = $preferred_layer;
2270

    
2271
  return $element;
2272
}
2273

    
2274
function radios_prepare_options_suffix(&$elements){
2275

    
2276
  $childrenKeys = element_children($elements);
2277
  foreach($childrenKeys as $key){
2278
    if(!is_array($elements[$key]['#theme_wrappers'])){
2279
      $elements[$key]['#theme_wrappers'] = array();
2280
    }
2281
    if(isset($elements['#options_suffixes'][$key])){
2282
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
2283
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
2284
    }
2285
  }
2286
  return $elements;
2287

    
2288
}
2289

    
2290
/**
2291
 * TODO
2292
 * @param unknown $variables
2293
 */
2294
function theme_radio_options_suffix($variables) {
2295
  $element = $variables['element'];
2296
  if(isset($element['#options_suffix'])) {
2297
    $element['#children'] .= $element['#options_suffix'];
2298
  }
2299
  return $element['#children'];
2300
}
2301

    
2302

    
2303
/**
2304
 * Element validate callback for text field and arrays containing json.
2305
 *
2306
 * @param $element
2307
 *   The form element to validate
2308
 * @param $form_state
2309
 *   A keyed array containing the current state of the form.
2310
 * @param $form
2311
 *   Nested array of form elements that comprise the form.
2312
 */
2313
function form_element_validate_json($element, &$form_state, $form) {
2314
   if (!empty($element['#value'])) {
2315
     json_decode($element['#value']);
2316
     if(json_last_error() != JSON_ERROR_NONE){
2317
       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/'));
2318
     }
2319
   }
2320
}
2321

    
2322
/**
2323
 * Form submission handler for textareas and textfields containing JSON.
2324
 *
2325
 * The contained JSON will be converted into an php array
2326
 * or object and will be stores in the variables as such.
2327
 *
2328
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2329
 *
2330
 * @param $form
2331
 *   Nested array of form elements that comprise the form.
2332
 * @param $form_state
2333
 *   A keyed array containing the current state of the form.
2334
 *
2335
 */
2336
function submit_json_as_php_array($form, &$form_state) {
2337
  if (is_array($form['#json_elements'])) {
2338
    foreach ($form['#json_elements'] as $element){
2339
      if (trim($form_state['values'][$element])) {
2340
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
2341
      } else {
2342
        $form_state['values'][$element] = NULL;
2343
      }
2344
    }
2345
  }
2346
}
(13-13/13)