Project

General

Profile

Download (96.2 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?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 ba706bf0 Andreas Kohlbecker
/* ---- 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 d7abe39c Andreas Kohlbecker
      'v1.2_dev' => 'v1.2_dev',
66
      'v1.2' => 'v1.2',
67
      'v1.3_dev' => 'v1.3_dev'
68 ba706bf0 Andreas Kohlbecker
    )
69
  )
70
);
71
define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
72 d7abe39c Andreas Kohlbecker
define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
73 6657531f Andreas Kohlbecker
74
// --- Taxon profile settings --- /
75
define('LAYOUT_SETTING_PREFIX', 'layout_');
76
define('FEATURE_TREE_LAYOUT_DEFAULTS', serialize(
77
  array(
78
    'enabled' => FALSE,
79
    'enclosingTag' => 'ul',
80
    'entryEnclosingTag' => 'li',
81
    'glue' => ' ',
82
  )));
83
84 ba706bf0 Andreas Kohlbecker
define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
85 9c92cd84 Andreas Kohlbecker
define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
86
define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
87
    array(
88 0832bbb6 Andreas Kohlbecker
        'show' => 0,
89 9c92cd84 Andreas Kohlbecker
        'maxextend' => 184,
90 053a92ec Andreas Kohlbecker
        'media_uri_query' => '',
91 9c92cd84 Andreas Kohlbecker
        'custom_placeholder_image_on' => 0,
92
        'custom_placeholder_image_fid' => ''
93
    )
94
  )
95
);
96 ba706bf0 Andreas Kohlbecker
97 6657531f Andreas Kohlbecker
/**
98
 * @todo document this function
99
 */
100
function get_taxon_tabs_list() {
101
  return array(
102
    0 => 'General',
103
    1 => 'Synonymy',
104
    2 => 'Images',
105
    3 => 'Specimens',
106
    4 => 'Keys',
107
  );
108
}
109
110
$taxon_tab_options = get_taxon_tabs_list();
111
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
112
113
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
114
115
/**
116
 * @todo document this function.
117
 */
118
function get_taxon_options_list() {
119
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
120
  foreach ($taxon_tab_options as $key => $value) {
121
    $taxon_tab_options[$key] = t($key);
122
  }
123
  return $taxon_tab_options;
124
125
}
126
127 0f5f1c12 Andreas Kohlbecker
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
128
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
129
  array(
130
      'ZoologicalName' => array(
131 501347df Andreas Kohlbecker
        'namePart' => array('name' => TRUE),
132
        'nameAuthorPart' => array('name' => TRUE),
133
        'referencePart' => array('authors' => TRUE),
134
        'microreferencePart' => array('microreference' => TRUE),
135
        'statusPart' => array('status' => TRUE),
136
        'descriptionPart' => array('description' => TRUE),
137 0f5f1c12 Andreas Kohlbecker
      ),
138
      'BotanicalName'=> array(
139
        'namePart' => array('name' => TRUE),
140
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
141
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
142
        'statusPart' => array('status' => TRUE),
143
        'descriptionPart' => array('description' => TRUE),
144
      ),
145
     '#DEFAULT' => array(
146 501347df Andreas Kohlbecker
        'namePart' => array(
147
            'name' => TRUE
148
        ),
149
        'nameAuthorPart' => array(
150
            'name' => TRUE,
151
            'authors' => TRUE
152
        ),
153
        'referencePart' => array(
154
            'reference' => TRUE
155
        ),
156
        'microreferencePart' => array(
157
            'microreference' => TRUE,
158
        ),
159
        'statusPart' => array(
160
            'status' => TRUE,
161
        ),
162
        'descriptionPart' => array(
163
            'description' => TRUE,
164
        ),
165 0f5f1c12 Andreas Kohlbecker
      )
166
    )
167
  )
168
);
169
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
170
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
171 5972ca1a Andreas Kohlbecker
   array (
172
     'taxon_page_title,polytomousKey'=> array(
173
          'namePart' => array('#uri' => TRUE),
174
        ),
175
      'taxon_page_synonymy,related_taxon'=> array(
176
          'nameAuthorPart' => array('#uri' => TRUE),
177
          'referencePart' => TRUE,
178
          'statusPart' => TRUE,
179
          'descriptionPart' => TRUE,
180
        ),
181
      'acceptedFor,typedesignations,list_of_taxa' => array(
182
          'nameAuthorPart' => array('#uri' => TRUE),
183
          'referencePart' => TRUE,
184
        ),
185
      '#DEFAULT' => array(
186
          'nameAuthorPart' => array('#uri' => TRUE),
187
          'referencePart' => TRUE,
188
       )
189 0f5f1c12 Andreas Kohlbecker
    )
190
));
191
192 6657531f Andreas Kohlbecker
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
193
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
194
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
195
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
196
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
197
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
198
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
199
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
200
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
201
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
202
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
203
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
204 30f78c59 Andreas Kohlbecker
/**
205
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
206
 * the snonymy.
207
 *
208
 * @var string
209
 */
210 6657531f Andreas Kohlbecker
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
211 30f78c59 Andreas Kohlbecker
/**
212
 * The drupal variable for the configuration of the information aggregation along
213
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
214
 *    - direct: the uuids of the taxon relationship types to take into account in invers
215
 *      direction.
216
 *    - invers: the uuids of the taxon relationship types to take into account in direct
217
 *      direction.
218
 *
219
 * @var String
220
 */
221
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
222
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
223
    array(
224
        'direct'=>array(),
225
        'invers'=>array()
226
     )
227
   ));
228 6657531f Andreas Kohlbecker
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
229 bfb2b81a Andreas Kohlbecker
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
230 6657531f Andreas Kohlbecker
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
231
232 a950f2f9 Andreas Kohlbecker
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
233
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
234
    array(
235
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
236
        'includeOccurrences' => 0,
237
        'includeTaxonNameDescriptions' => 0
238
     )
239
  ));
240
241 cc3c9807 Andreas Kohlbecker
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
242
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
243
  // needs to be merged with user setting by drupal_array_merge_deep()
244
  'width' => 512, // optimum size for OSM layers is 512
245
  'height' => 512 / 2, // optimum size for OSM layers 256
246
  'bbox' => '', // empty to allow automatic zooming to extend
247
  'show_labels' => FALSE,
248
  'caption' => '',
249
  'distribution_opacity' => '0.5',
250
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
251
  'image_map' => array(
252
    'base_layer' => '', // none, formerly this was cyprusdivs
253
    'bg_color' => '1874CD',
254
    'layer_style' => 'ffffff,606060,,',
255
  ),
256
  'openlayers' => array(
257
    'base_layers' =>  array(
258
      // A layer MUST NOT BE SET in the defaults,
259
      // otherwise it can not be overidden by the user settings:
260
      // 'osgeo_vmap0' => 'osgeo_vmap0',
261
      // it is sufficient to define the preferred layer,
262
      // since it will automatically be enabled:
263
      'PREFERRED' => 'osgeo_vmap0'),
264 2bbc28c8 Andreas Kohlbecker
     'custom_wms_base_layer' => array(
265
            'name' => NULL,
266
            'url' => NULL,
267
            'params' =>  NULL,
268
            'projection' => NULL,
269
            'max_extent' => NULL,
270
            'units' => NULL
271
     ),
272
    'show_layer_switcher' => TRUE,
273
    'display_outside_max_extent' => FALSE
274 cc3c9807 Andreas Kohlbecker
  ),
275
  'legend' => array(
276
    'show' => TRUE,
277
    'opacity' => '0.5',
278
    'font_size' => 10,
279
    'font_style' => FALSE,
280
    'icon_width' => 35,
281
    'icon_height' => 15
282
  )
283
)));
284
285
/**
286
 * Merges the named array variable with the array of defaults.
287
 *
288
 * @param string $variable_name
289
 *     The variable name
290
 * @param string | array $default
291
 *     The array containing the default values either as array or serialized as string.
292
 *     Unserialization is cared for if nessecary
293
 * @return array
294
 *     The merged array as returnd by drupal_array_merge_deep()
295
 */
296
function get_array_variable_merged($variable_name, $default){
297
298
    // unserialize if nessecary
299
    if(!is_array($default)){
300
      $default = unserialize($default);
301
    }
302
    $variable = variable_get($variable_name, array());
303
    return drupal_array_merge_deep($default, $variable);
304
}
305
306 6657531f Andreas Kohlbecker
/**
307
 * @todo document this function.
308
 */
309
function getGallerySettings($gallery_config_form_name) {
310 cc3c9807 Andreas Kohlbecker
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
311 6657531f Andreas Kohlbecker
}
312
313
/**
314
 * Returns the string representation of the default tab.
315
 *
316
 * @param bool $returnTabIndex
317
 *   Defaults to FALSE, if set true this function will return the index number
318
 *   of the default tab. (used to supply default values to form elements).
319
 */
320
function get_default_taxon_tab($returnTabIndex = FALSE) {
321
322
  global $user;
323
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
324
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
325
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
326
  // Get the user value if the used has chosen to overwrite the system settings.
327
  $user_tab_on = variable_get($user_tab_active, FALSE);
328
  if ($user_tab_on) {
329
    $user_value = variable_get($user_tab, 0);
330
    $index_value = $user_value;
331
    // Get the system value.
332
  }
333
  else {
334
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
335
    $index_value = $system_value;
336
  }
337
338
  // Return the index value or the string representation.
339
  if ($returnTabIndex) {
340
    return $index_value;
341
  }
342
  else {
343
    return ($values[$index_value]);
344
  }
345
346
}
347
348
/**
349
 * @todo Please document this function.
350
 * @see http://drupal.org/node/1354
351
 */
352
function cdm_dataportal_menu_admin(&$items) {
353
  // Display section on admin/config page.
354
  $items['admin/config/cdm_dataportal'] = array(
355
    'title' => 'CDM Dataportal',
356
    'description' => 'Settings for the CDM DataPortal.',
357
    'position' => 'right',
358
    'weight' => 10,
359
    'page callback' => 'system_admin_menu_block_page',
360 e014414c Andreas Kohlbecker
    'access arguments' => array('administer cdm_dataportal'),
361 6657531f Andreas Kohlbecker
    'file' => 'system.admin.inc',
362
    'file path' => drupal_get_path('module', 'system'),
363
  );
364
  $items['admin/config/cdm_dataportal/settings'] = array(
365
    'title' => 'Settings',
366
    'description' => 'Settings for the CDM DataPortal.',
367
    'weight' => 0,
368
    'page callback' => 'drupal_get_form',
369
    'page arguments' => array('cdm_settings_general'),
370
    'access arguments' => array('administer cdm_dataportal'),
371
    'type' => MENU_NORMAL_ITEM,
372
  );
373
  $items['admin/config/cdm_dataportal/settings/general'] = array(
374
    'title' => 'General',
375
    'description' => 'General',
376
    'weight' => 0,
377
    'page callback' => 'drupal_get_form',
378
    'page arguments' => array('cdm_settings_general'),
379
    'access arguments' => array('administer cdm_dataportal'),
380
    'type' => MENU_DEFAULT_LOCAL_TASK,
381
  );
382
383
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
384
    'title' => 'Cache',
385
    'description' => 'Cache',
386
    'access arguments' => array('administer cdm_dataportal'),
387
    'page callback' => 'drupal_get_form',
388
    'page arguments' => array('cdm_settings_cache'),
389
    'weight' => 10,
390
    'type' => MENU_LOCAL_TASK,
391
  );
392
393
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
394
    'title' => 'Geo & Map',
395
    'description' => 'Geo & Map',
396
    'access arguments' => array('administer cdm_dataportal'),
397
    'page callback' => 'drupal_get_form',
398
    'page arguments' => array('cdm_settings_geo'),
399
    'weight' => 1,
400
    'type' => MENU_LOCAL_TASK,
401
  );
402
403
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
404
    'title' => 'Layout',
405
    'description' => 'Configure and adjust the layout of your DataPortal ',
406
    'access arguments' => array('administer cdm_dataportal'),
407
    'page callback' => 'drupal_get_form',
408
    'page arguments' => array('cdm_settings_layout'),
409
    'weight' => 2,
410
    'type' => MENU_LOCAL_TASK,
411
  );
412
413
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
414
    'title' => 'Taxon',
415
    'description' => 'Configure and adjust the layout of your DataPortal ',
416
    'access arguments' => array('administer cdm_dataportal'),
417
    'page callback' => 'drupal_get_form',
418
    'page arguments' => array('cdm_settings_layout_taxon'),
419
    'weight' => 1,
420
    'type' => MENU_LOCAL_TASK,
421
  );
422
  /*
423
  $items[] = array(
424
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
425
  'title' => t('Synonymy'),
426
  'description' => t('Configure and adjust the layout of your DataPortal '),
427
  'access' => user_access('administer cdm_dataportal'),
428
  'callback' => 'drupal_get_form',
429
  'callback arguments' => array('cdm_settings_layout_synonymy'),
430
  'weight' => 1,
431
  'type' => MENU_LOCAL_TASK,
432
  );
433
434
  $items[] = array(
435
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
436
  'title' => t('Specimens'),
437
  'description' => t('Configure and adjust the layout of your DataPortal '),
438
  'access' => user_access('administer cdm_dataportal'),
439
  'callback' => 'drupal_get_form',
440
  'callback arguments' => array('cdm_settings_layout_specimens'),
441
  'weight' => 1,
442
  'type' => MENU_LOCAL_TASK,
443
  );
444
  */
445
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
446
    'title' => 'Search',
447
    'description' => 'Configure and adjust the layout of your DataPortal ',
448
    'access arguments' => array('administer cdm_dataportal'),
449
    'page callback' => 'drupal_get_form',
450
    'page arguments' => array('cdm_settings_layout_search'),
451
    'weight' => 2,
452
    'type' => MENU_LOCAL_TASK,
453
  );
454
455
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
456
    'title' => 'Media',
457
    'description' => 'Configure and adjust the layout of your DataPortal ',
458
    'access arguments' => array('administer cdm_dataportal'),
459
    'page callback' => 'drupal_get_form',
460
    'page arguments' => array('cdm_settings_layout_media'),
461
    'weight' => 3,
462
    'type' => MENU_LOCAL_TASK,
463
  );
464 947c6a8d Andreas Kohlbecker
465 6657531f Andreas Kohlbecker
}
466
467
/**
468
 * @todo document this function.
469
 */
470
function cdm_help_general_cache() {
471
  $form = array();
472
  $form['cache_help'] = array(
473
    '#type' => 'fieldset',
474
    '#title' => t('Help'),
475
    '#collapsible' => TRUE,
476
    '#collapsed' => TRUE,
477
  );
478
  $form['cache_help']['test'] = array('#value' => t('probando'));
479
  return drupal_render($form);
480
  $res = array();
481
  $res['default'] = drupal_render($help);
482
  return $res;
483
}
484
485
/**
486
 * Configures the settings form for the CDM-API module.
487
 *
488
 * @return array
489
 *   Drupal settings form.
490
 */
491
function cdm_settings_general() {
492
493
  $form['cdm_webservice'] = array(
494
    '#type' => 'fieldset',
495
    '#title' => t('CDM Server'),
496
    '#collapsible' => FALSE,
497
    '#collapsed' => FALSE,
498 9438ad3a Andreas Kohlbecker
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
499
        CDM data base to the web via RESTful web services and thus is the source of the data
500
        to be displayed by a CDM DataPotal.'),
501 6657531f Andreas Kohlbecker
  );
502
503
  $form['cdm_webservice']['cdm_webservice_url'] = array(
504
    '#type' => 'textfield',
505
    '#title' => t('CDM web service URL') . ':',
506
    '#description' => t('This is the URL to the CDM-Server exposing your data
507 d1eb0a8c Andreas Kohlbecker
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
508 6657531f Andreas Kohlbecker
    '#default_value' => variable_get('cdm_webservice_url', NULL),
509
  );
510
511
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
512 17c3d760 Andreas Kohlbecker
    '#type' => 'markup',
513 6ab41d7b Andreas Kohlbecker
    '#markup' => '<b>Debug CDM Web Service:</b> The web service debug box has completely been replaced '
514
      . 'by  the ' . l('CDM web service debug block', 'admin/structure/block/manage/cdm_api/cdm_ws_debug/configure')
515 17c3d760 Andreas Kohlbecker
      . '. It is usually only visible for administrative roles like <i>administrator</i> and <i>CDM admin</i>'
516 6657531f Andreas Kohlbecker
  );
517
518
  $form['cdm_webservice']['freetext_index'] = array(
519
    '#type' => 'fieldset',
520
    '#title' => t('Freetext index'),
521
    '#collapsible' => FALSE,
522
    '#collapsed' => FALSE,
523
  );
524
525
  // Check the cdmserver port number and display a waring if it is not port 80
526
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
527
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
528
    $form['cdm_webservice']['freetext_index']['message'] = array(
529
      '#markup' => "<div class=\"description\">"
530
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'."
531
      . " Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server."
532
      . " You may want to contact the maintainer of the according CDM Server in order to solve this problem.", array('!port' => $portNumberMatch[1][0]))
533
      . "</div>",
534
    );
535
  };
536
537
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
538
  $trigger_link_options = array(
539
    'attributes' => array(
540
      'class' => 'index-trigger',
541
    ),
542
  );
543
  $form['cdm_webservice']['freetext_index']['operations'] = array(
544
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
545
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
546
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
547
      ))
548
    . '<div id="index-progress"></div></div>',
549
  );
550
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
551
552
  $form['cdm_webservice']['proxy'] = array(
553
    '#type' => 'fieldset',
554
    '#title' => t('Proxy'),
555
    '#collapsible' => TRUE,
556
    '#collapsed' => TRUE,
557
  );
558
559
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
560
    '#type' => 'textfield',
561
    '#title' => t('Proxy URL') . ':',
562
    '#description' => t('If this proxy url is set the cdm api tries
563
    to connect the web service over the given proxy server.
564
    Otherwise proxy usage is deactivated.'),
565
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
566
  );
567
568
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
569
    '#type' => 'textfield',
570
    '#title' => t('Proxy port') . ':',
571
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
572
  );
573
574
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
575
    '#type' => 'textfield',
576
    '#title' => t('Login') . ':',
577
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
578
  );
579
580
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
581
    '#type' => 'textfield',
582
    '#title' => t('Password') . ':',
583
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
584
  );
585
586
  // TODO: settings are still incomplete, compare with
587
  // trunk/dataportal/inc/config_default.php.inc.
588 9438ad3a Andreas Kohlbecker
  $form['taxon_tree'] = array(
589 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
590
    '#title' => t('Taxon Tree'),
591
    '#collapsible' => FALSE,
592
    '#collapsed' => TRUE,
593
    '#description' => t('<p>When you explore your collection, you can navigate
594
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
595
      able to navigate through your collection the
596
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
597
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
598
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
599
      </a></p>'),
600
  );
601
602 9438ad3a Andreas Kohlbecker
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
603 6657531f Andreas Kohlbecker
    '#type' => 'select',
604
    '#title' => t('Available classifications') . ':',
605
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
606
    '#options' => cdm_get_taxontrees_as_options(),
607
    '#description' => t('Select the default taxa classification for your
608
      <em>taxon tree</em>, the other classifications will be also available but
609
      with a manual user change.'),
610
  );
611
612 9438ad3a Andreas Kohlbecker
  $form['taxon_tree']['taxontree_ranklimit'] = array(
613 6657531f Andreas Kohlbecker
    '#type' => 'select',
614
    '#title' => t('Rank of highest displayed taxon') . ':',
615
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
616
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
617
    '#options' => cdm_rankVocabulary_as_option(),
618
    '#description' => t('This is the rank of the highest displayed taxon in the
619
      <em>taxon tree</em>. You can select here which rank should be at the top
620
      level of the tree structure.'),
621
  );
622
623 9438ad3a Andreas Kohlbecker
  $form['aggregation'] = array(
624
      '#type' => 'fieldset',
625
      '#title' => t('Aggregation of data'),
626
      '#collapsible' => FALSE,
627
      '#description' => t("This section covers the different aspects of aggregating information.
628
          <p>
629 ccde8251 Andreas Kohlbecker
          </p>"),
630 9438ad3a Andreas Kohlbecker
631
  );
632
633 ccde8251 Andreas Kohlbecker
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
634
      '#type' => 'checkboxes',
635
      '#title' => 'Taxon media filter',
636
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
637
      '#options' => array(
638
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
639
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
640
          'includeOccurrences' => 'Media related to specimens and occurrences',
641
      ),
642
      '#description' => 'This filter configures which images should be taken into account.',
643
  );
644
645
  $form['aggregation']['notice'] = array(
646 3a874294 Andreas Kohlbecker
      '#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
647 ccde8251 Andreas Kohlbecker
          want to make use of the caching capabilities of the dataportal.',
648
  );
649
650 9438ad3a Andreas Kohlbecker
  $form['aggregation']['media_aggregation'] = array(
651
      '#type' => 'fieldset',
652
      '#title' => t('Media aggregation'),
653
      '#collapsible' => FALSE,
654
      '#collapsed' => TRUE,
655
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
656
657
  );
658
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
659
      '#type' => 'select',
660
      '#title' => t('Aggregation of taxon pictures') . ':',
661
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
662
      '#options' => array(
663
          0 => "Show only pictures of the current taxon",
664
          1 => "Include pictures of taxonomic children",
665
      ),
666
      '#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."),
667
  );
668
669
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
670 30f78c59 Andreas Kohlbecker
      '#type' => 'fieldset',
671
      '#attributes' => array('class'=>array('clearfix')),
672 9438ad3a Andreas Kohlbecker
      '#title' => t('Aggregation via taxon relationsships'),
673 30f78c59 Andreas Kohlbecker
      '#collapsible' => TRUE,
674
      '#collapsed' => TRUE,
675
      '#tree' => TRUE,
676
      '#description' => t('Information on taxa will be aggregated along the below chosen
677
          taxon relation ships. This will affect images and occurrences (specimens).
678
          Taxon relation ships are directed and point form one taxon to another. The taxon
679
          relationships to be taken into accunt can therefore configured for the direct direction
680
          and for the inverse.'),
681
  );
682
683
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
684
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
685
686 9438ad3a Andreas Kohlbecker
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
687 30f78c59 Andreas Kohlbecker
      '#type' => 'checkboxes',
688
      '#title' => t('Direct'),
689
      '#options' => $taxonRelationshipTypeOptions,
690
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
691
  );
692 9438ad3a Andreas Kohlbecker
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
693 30f78c59 Andreas Kohlbecker
      '#type' => 'checkboxes',
694
      '#title' => t('Invers'),
695
      '#options' => $taxonRelationshipTypeOptions,
696
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
697
  );
698
699 5ea8b301 Andreas Kohlbecker
  // ----------------------
700
  $form['cdm_js_devel_mode'] = array(
701
      '#type' => 'checkbox',
702
      '#title' => 'Java-script developer mode',
703
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
704
      '#description' => 'In production envirionments the java script libraries
705
      the cdm_dataportal is making use of are compressed and optimized. This
706
      is good for performance but a caveat if you need to debug java-script. When the
707
      java-script developer mode is enabled the uncompressed and commented developer
708
      versions of java-script libraries will be used where possible.
709
      <br/><strong>Do not use this option in production!</strong>'
710
  );
711
712 6657531f Andreas Kohlbecker
  // Comment @WA: D7 form api does not support reset buttons,
713
  // so to mimic the D5 reset button we add one like this.
714
  $form['actions']['reset'] = array(
715
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
716
    '#weight' => 1000,
717
  );
718
719
  return system_settings_form($form);
720
}
721
722
723
/**
724
 * LAYOUT settings
725
 * @return unknown_type
726
 *   todo
727
 */
728
function cdm_settings_layout() {
729
730
  $form = array();
731 0f5f1c12 Andreas Kohlbecker
732
  $form['about'] = array(
733
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
734 6657531f Andreas Kohlbecker
      layout. If you want to configure the specific sites layout visit the
735 0f5f1c12 Andreas Kohlbecker
      respective configuration site for taxon, search or media.') . '</p>',
736 6657531f Andreas Kohlbecker
  );
737
738
  // ---- footnotes --- //
739 0f5f1c12 Andreas Kohlbecker
  $form['footnotes'] = array(
740 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
741
    '#title' => t('Footnotes'),
742
    '#collapsible' => FALSE,
743
    '#collapsed' => FALSE,
744
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
745
      media or distribution areas may have annotations or footnotes. When the
746
      footnotes are enabled they will be visible (if they exist).'),
747
  );
748
749 0f5f1c12 Andreas Kohlbecker
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
750 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
751
    '#title' => t('Do not show footnotes'),
752
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
753
    '#description' => t('Check this if you do not want to show any footnotes'),
754
  );
755
756 0f5f1c12 Andreas Kohlbecker
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
757 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
758
    '#title' => t('Do not show annotations footnotes'),
759
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
760
    '#description' => t('Check this if you do not want to show annotation footnotes'),
761
  );
762
763
  $annotationTypeOptions = cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE);
764
  // Additional option for the NULL case.
765
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
766 0f5f1c12 Andreas Kohlbecker
  $form['footnotes']['annotations_types_as_footnotes'] = array(
767 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
768
    '#title' => t('Annotation types as footnotes'),
769
    '#description' => t("Only annotations of the selected type will be displayed
770
       as footnotes. You may want to turn 'technical annotations' off."),
771
    '#options' => $annotationTypeOptions,
772
  );
773
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
774
  if (!empty($annotationsTypesAsFootnotes)) {
775 0f5f1c12 Andreas Kohlbecker
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
776 6657531f Andreas Kohlbecker
  }
777
778 0f5f1c12 Andreas Kohlbecker
  // --- Advanced Search --- //
779
  $form['asearch'] = array(
780
      '#type' => 'fieldset',
781
      '#title' => t('Advanced search'),
782
      '#collapsible' => FALSE,
783
      '#collapsed' => FALSE,
784
  );
785
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
786
      '#type' => 'checkbox',
787
      '#title' => t('Show advanced search link'),
788
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
789
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
790
  );
791
792
  // ---- Taxon Name Rendering --- //
793
  $form['taxon_name'] = array(
794
      '#type' => 'fieldset',
795
      '#title' => t('Taxon name display'),
796
      '#collapsible' => TRUE,
797
      '#collapsed' => TRUE,
798
      '#description' => t('The display of taxon names is configured by two parts.'
799
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
800
          . 'The name parts are defined in the <stong>part definitions</strong>'),
801
  );
802
803
  drupal_add_js(
804
      'jQuery(document).ready( function( ) {
805
         // pretty print json
806
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
807
         var obj = JSON.parse(json_text);
808
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
809
810
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
811
         obj = JSON.parse(json_text);
812
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
813
       });'
814
      ,array(
815
          'type' => 'inline',
816
          'scope' => 'footer'
817
      )
818 6657531f Andreas Kohlbecker
  );
819 0f5f1c12 Andreas Kohlbecker
820
  //TODO remove after all portals are using the settings
821
  $default_part_definitions = theme('get_partDefinition', array());
822
  if(!is_array($default_part_definitions)) {
823
    $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
824
  }
825
826
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
827
      '#type' => 'textarea',
828
      '#title' => t('Part definitions'),
829
      '#element_validate' => array('form_element_validate_json'),
830
      '#default_value' =>  json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions)),
831
      '#description' => '
832
          <p>
833
          (Clearing the text area will reset it to the default)
834
          </p>
835
          <p>
836
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
837
          </p>
838
          <p>
839
           A full taxon name plus additional information can consist of the following elements:
840
          <ul>
841
             <li>name: the taxon name inclugin rank nbut without author</li>
842
             <li>authors:  The authors of a reference, also used in taxon names</li>
843
             <li>reference: the nomenclatural reference,</li>
844
             <li>microreference:  Volume, page number etc.</li>
845
             <li>status:  The nomenclatural status of a name</li>
846
             <li>description: name descriptions like protologues etc ...</li>
847
          </ul>
848
          </p>
849
          <p>
850
           These elements are combined in the part definitions array to from the specific parts to be rendered.
851
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
852
           Usually the following parts are formed:
853
          <ul>
854
            <li>namePart: the name and rank (in example: "Lapsana communis")</li>
855
            <li>authorshipPart: the author (in example: "L.")</li>
856
            <li>nameAuthorPart: the combination of name and author part (in example: "Lapsana communis L.").</li>
857
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
858
               be combined when a link to the taxon is rendered.</li>
859
            <li>referencePart: the nomencaltural reference (in example: "Sp. Pl. 1753")</li>
860
            <li>microreferencePart: usually the page number (in example ": 811.")</li>
861
            <li>statusPart: the nomenclatorical status</li>
862
            <li>descriptionPart: name descriptions like protologues etc ...</li>
863
          </ul>
864
          </p>
865
          <p>
866
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
867
           specific parts part definitions:
868
          <ul>
869
            <li>BotanicalName</li>
870
            <li>ZoologicalName</li>
871
            <li>#DEFAULT: covers ViralNames and other NonViralNames
872
          </ul>
873
           An example:
874
          <pre>
875
           {
876
            "ZoologicalName": {
877
              "namePart": {
878
                "name": true
879
              },
880
              "referencePart": {
881 b5519d3a Andreas Kohlbecker
                "authors": true
882 0f5f1c12 Andreas Kohlbecker
              },
883
              "microreferencePart": {
884
                "microreference": true
885
              },
886
              "statusPart": {
887
                "status": true
888
              },
889
              "descriptionPart": {
890
                "description": true
891
              }
892
            },
893
            "BotanicalName": {
894
              "namePart": {
895
                "name": true,
896
                "authors": true
897
              },
898
              "referencePart": {
899
                "reference": true,
900
                "microreference": true
901
              },
902
              "statusPart": {
903
                "status": true
904
              },
905
              "descriptionPart": {
906
                "description": true
907
              }
908
            }
909
          }
910
           </pre>',
911
  );
912
913
  //TODO remove after all portals are using the settings
914
  $default_render_templates = theme('get_nameRenderTemplate', array());
915
  if(!is_array($default_render_templates)) {
916
    $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
917
  }
918
919
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
920
      '#type' => 'textarea',
921
      '#title' => t('Name render templates'),
922
      '#element_validate' => array('form_element_validate_json'),
923
      '#default_value' =>  json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates)),
924
      '#description' => '
925
          <p>
926
          (Clearing the text area will reset it to the default)
927
          </p>
928
          <p>
929
          The render templates array contains one or more name render templates to be used within the page areas identified by the
930
          render path. The render path is used as key of the array sub subelements whereas the name render template array is set as value.
931
          The following render Path keys are curretly recognized:
932
          <ul>
933 a950f2f9 Andreas Kohlbecker
            <li>list_of_taxa:</li>
934 0f5f1c12 Andreas Kohlbecker
            <li>acceptedFor:</li>
935
            <li>taxon_page_synonymy</li>
936
            <li>typedesignations</li>
937
            <li>taxon_page_title</li>
938
            <li>polytomousKey</li>
939
            <li>na: name + authorship</li>
940
            <li>nar:name + authorship + reference</li>
941
            <li>#DEFAULT</li>
942
          </ul>
943
          A single render template can be used for multiple render paths. In this case the according key of the render templates
944
          array element should be a comma separated list of render paths, without any whitespace!.
945
          </p>
946
          <p>
947
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
948
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
949
          <p>
950
          The value of the render template element must be set to TRUE in order to let this part being rendered.
951
          The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
952
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
953
          links if the paramters $nameLink or $refenceLink are given to the name render function
954
          (this is hard coded and cannot be configured here).',
955 6657531f Andreas Kohlbecker
  );
956
957
  // @WA: D7 form api does not support reset buttons,
958
  // so to mimic the D5 reset button we add one like this.
959
  $form['actions']['reset'] = array(
960
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
961
    '#weight' => 1000,
962
  );
963 0f5f1c12 Andreas Kohlbecker
964
  $form['#submit'] = array('submit_json_as_php_array');
965
  // #json_elements especially defined for submit_json_as_php_array()
966
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
967 6657531f Andreas Kohlbecker
  return system_settings_form($form);
968
}
969
970
971
/**
972
 * @todo Please document this function.
973
 * @see http://drupal.org/node/1354
974
 */
975
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
976
  $form[$form_name] = array(
977
    '#type' => 'fieldset',
978
    '#title' => t($form_title),
979
    '#collapsible' => TRUE,
980
    '#collapsed' => $collapsed,
981
    '#tree' => TRUE,
982
    '#description' => t($form_description),
983
  );
984
985
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
986
  $gallery_settings = variable_get($form_name, $default_values);
987
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
988
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
989
    /*
990
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
991
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
992
    '#type' => 'textfield',
993
    '#title' => t('Search Page Size'),
994
    '#default_value' => $test,
995
    '#description' => t('Number of Names to display per page in search results.')
996
    );
997
    */
998
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
999
      '#type' => 'checkbox',
1000
      '#title' => t('Show media thumbnails for accepted taxa'),
1001
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1002
    );
1003
1004
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1005
      '#type' => 'checkbox',
1006
      '#title' => t('Show media thumbnails for synonyms'),
1007
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1008
      '#description' => '',
1009
    );
1010
  }
1011
1012
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1013
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1014
    '#type' => 'checkbox',
1015
    '#title' => t('Show captions under thumbnails'),
1016
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1017
    '#description' => '',
1018
  );
1019
1020
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1021
    '#type' => 'textfield',
1022
    '#title' => t('Thumbnail size') . ':',
1023
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1024
    '#description' => t('Select the size of each individual thumbnail.'),
1025
  );
1026
1027
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1028
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1029
      '#type' => 'textfield',
1030
      '#title' => t('Number of columns') . ':',
1031
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1032
      '#description' => t('Group the thumbnails in columns: select how many
1033
        columns the gallery should display.'),
1034
    );
1035
  }
1036
1037
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1038
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1039
      '#type' => 'textfield',
1040
      '#title' => t('Maximum number of rows') . ':',
1041
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1042
      '#description' => t('You can group the thumbnails in rows, select in how
1043
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1044
        If you want an unlimited number of rows please set to 0.'),
1045
    );
1046
  }
1047
1048
  return $form;
1049
}
1050
1051
/**
1052
 * @todo document this function.
1053
 */
1054
function cdm_settings_layout_taxon() {
1055
  $collapsed = FALSE;
1056
  $form = array();
1057
1058 7df1be04 Andreas Kohlbecker
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1059
1060 d9c55e6c Andreas Kohlbecker
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1061
      '#type' => 'checkbox',
1062
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1063
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1064
      '#description' => t('<p>If checked the link to search results is rendered at
1065
       the top of the taxon site. Clicking on the link the last search performed
1066
       is rendered again.</p>'),
1067
  );
1068
1069 6657531f Andreas Kohlbecker
  // --------- TABBED TAXON ------- //
1070
  $form['taxon_tabs'] = array(
1071
    '#type' => 'fieldset',
1072
    '#title' => t('Taxon tabs'),
1073
    '#collapsible' => TRUE,
1074
    '#collapsed' => FALSE,
1075
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1076
      be splitted in four diferent tabs; General, Synonymy, Images and
1077
      Specimens. If the taxon has no information for any of the tabs/sections
1078
      such tab will be not displayed.'),
1079
  );
1080
1081
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1082
    '#type' => 'checkbox',
1083
    '#title' => t('Tabbed taxon page'),
1084
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1085
    '#description' => t('<p>If selected split the taxon page into individual
1086
      tabs for description, images, synonymy and specimens. If not the taxon
1087
      data is rendered as a long single page without tabs.</p>'),
1088
  );
1089
1090
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1091
    '#type' => 'checkboxes',
1092
    '#title' => t('Tabs visibility options') . ':',
1093
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1094
    '#options' => get_taxon_options_list(),
1095
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1096
  );
1097
1098
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1099
    '#type' => 'select',
1100
    '#title' => t('Default tab to display') . ':',
1101
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1102
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1103
    '#description' => t('<p>Select the default tab to display when visiting a
1104
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1105
      <strong>Note:</strong> After performing a search and clicking in any
1106
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1107
      taxon and not the above selected tab.'),
1108
  );
1109
1110
  /* ======  TAXON_PROFILE ====== */
1111
  $form['taxon_profile'] = array(
1112
    '#type' => 'fieldset',
1113
    '#title' => t('Taxon profile (tab)'),
1114 9438ad3a Andreas Kohlbecker
    '#description' => t('<p>This section covers the settings related to the taxon
1115 6657531f Andreas Kohlbecker
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1116
    '#collapsible' => TRUE,
1117
    '#collapsed' => TRUE,
1118
  );
1119
1120
  // ---- PROFILE PICTURE ----//
1121 9c92cd84 Andreas Kohlbecker
1122
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1123 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1124 9c92cd84 Andreas Kohlbecker
    '#tree' => TRUE,
1125 9438ad3a Andreas Kohlbecker
    '#title' => t('Taxon profile picture'),
1126 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
1127
    '#collapsed' => FALSE,
1128 9438ad3a Andreas Kohlbecker
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1129 6657531f Andreas Kohlbecker
  );
1130
1131 9c92cd84 Andreas Kohlbecker
  //FIXME migrate variables:
1132
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1133
  // FIXME
1134
  //  eanable file modul in profile and in update
1135
1136
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1137
  /*
1138
   * 'show' => 1,
1139
   * 'maxextend' => 184,
1140 053a92ec Andreas Kohlbecker
   * 'media_uri_query' => ''
1141 9c92cd84 Andreas Kohlbecker
   * 'custom_placeholder_image_on' => 1,
1142
   * 'custom_placeholder_image_fid' => ''
1143
   */
1144
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1145 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1146
    '#title' => t('Enable profil picture'),
1147
    '#description' => t('Show the profil picture.'),
1148 9c92cd84 Andreas Kohlbecker
    '#default_value' => $taxon_profile_image_settings['show'],
1149 6657531f Andreas Kohlbecker
  );
1150
1151 9c92cd84 Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1152 d9c55e6c Andreas Kohlbecker
      '#type' => 'textfield',
1153
      '#tree' => TRUE,
1154
      '#title' => t('Profil picture maximum extend'),
1155 9c92cd84 Andreas Kohlbecker
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1156 d9c55e6c Andreas Kohlbecker
      '#field_suffix' => 'px',
1157
      '#maxlength' => 4,
1158
      '#size' => 4,
1159
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1160
  );
1161
1162 053a92ec Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1163
      '#type' => 'textfield',
1164
      '#tree' => TRUE,
1165
      '#title' => t('Additional URI query parameter'),
1166
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1167
      '#maxlength' => 1024,
1168
      '#size' => 60,
1169
      '#description' => t('Additional query parameters to be used when requesting for the '
1170
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1171
          . 'The query parameters will be appendend to the uri of the media representation part'
1172
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1173
  );
1174
1175 9c92cd84 Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1176
      '#type' => 'checkbox',
1177
      '#title' => t('Use a custom placeholder image'),
1178 7df1be04 Andreas Kohlbecker
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1179 9c92cd84 Andreas Kohlbecker
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1180 7df1be04 Andreas Kohlbecker
  );
1181
1182 9c92cd84 Andreas Kohlbecker
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1183
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1184
        '#type' => 'managed_file',
1185
        '#title' => t('Custom placeholder image file'),
1186
        '#progress_indicator' => 'bar',
1187
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1188
    //       '#name' => 'custom_placeholder_image',
1189
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1190
    );
1191
1192
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1193
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1194
      $url = file_create_url($profile_image_file->uri);
1195
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1196
                '#type' => 'item',
1197
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1198
      );
1199
    }
1200
  } else {
1201
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1202
        '#type' => 'hidden',
1203
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1204
    );
1205
  }
1206
1207
1208
1209 6657531f Andreas Kohlbecker
  $options = cdm_rankVocabulary_as_option();
1210
  array_unshift($options, '-- DISABLED --');
1211
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1212
    '#type' => 'select',
1213 9438ad3a Andreas Kohlbecker
    '#title' => t('Hide profile picture for higher ranks') . ':',
1214 6657531f Andreas Kohlbecker
    '#default_value' => variable_get('image_hide_rank', '0'),
1215
    '#options' => $options,
1216 9438ad3a Andreas Kohlbecker
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1217 6657531f Andreas Kohlbecker
  );
1218
1219
  // -- MEDIA THUMBNAILS -- //
1220
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1221
  $form_title = 'Taxon Profile Images';
1222
  $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>';
1223
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1224
1225
  // ---- FEATURE TREE ---- //
1226 8127188a Alexander Oppermann
  $form['taxon_profile']['feature_trees'] = array(
1227 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1228
    '#title' => t('Features'),
1229
    '#collapsible' => TRUE,
1230
    '#collapsed' => FALSE,
1231
    '#description' => t("This section covers settings related to the taxon's
1232
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1233
      features such as description, distribution, common names, etc. that Drupal
1234
      will render at the taxon profile page."),
1235
  );
1236
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1237 854e1d99 Andreas Kohlbecker
  $saved_uuid = variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1238
  if(!isset($featureTrees['options'][$saved_uuid])) {
1239
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1240
  }
1241 6657531f Andreas Kohlbecker
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
1242
    '#type' => 'radios',
1243
    '#title' => t('Taxon profile sections') . ':',
1244 854e1d99 Andreas Kohlbecker
    '#default_value' => $saved_uuid,
1245 6657531f Andreas Kohlbecker
    '#options' =>  $featureTrees['options'],
1246 3f485c6d Andreas Kohlbecker
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1247
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1248 6657531f Andreas Kohlbecker
    '#description' => t('Select the Feature Tree to be displayed at the taxon
1249
      profile. Click "Show Details" to see the Feature Tree elements.'
1250
    ),
1251
  );
1252
  $featureTrees = cdm_get_featureTrees_as_options();
1253 854e1d99 Andreas Kohlbecker
  $saved_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1254
  if(!isset($featureTrees['options'][$saved_uuid])) {
1255
    $saved_uuid = NULL;
1256
  }
1257 6657531f Andreas Kohlbecker
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
1258
    '#type' => 'radios',
1259
    '#title' => t('Natural language representation of structured descriptions') . ':',
1260 854e1d99 Andreas Kohlbecker
    '#default_value' => $saved_uuid,
1261 6657531f Andreas Kohlbecker
    '#options' => $featureTrees['options'],
1262 3f485c6d Andreas Kohlbecker
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1263
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1264 6657531f Andreas Kohlbecker
    '#description' => t('Taxon descriptions can be stored in a highly structured
1265
      form. The feature tree selected here will be used to generate textual
1266
      representation in natural language.'
1267
    ),
1268
  );
1269
1270
  // ---- LAYOUT PER FEATURE ---- //
1271
  $feature_tree = get_profile_featureTree();
1272
  if (isset($feature_tree->root->children)) {
1273
1274
    $form_feature_list_layout = array(
1275
      '#title' => t('Taxon profile layout'),
1276
      '#collapsible' => TRUE,
1277
      '#collapsed' => FALSE,
1278
      '#type' => 'fieldset',
1279
      '#description' => t('Will be available in a future release.'),
1280
    );
1281
1282
    $feature_list_layout_settings_disabled = TRUE;
1283
    foreach ($feature_tree->root->children as $featureNode) {
1284
1285
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1286
        // Must not exceed 45 characters !!!
1287
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1288
1289
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1290
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1291
1292
        $form_feature_list_layout[$subform_id] = array(
1293
          '#tree' => TRUE,
1294
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1295
          '#collapsible' => FALSE,
1296
          '#collapsed' => FALSE,
1297
          '#type' => 'fieldset',
1298
          '#description' => t(''),
1299
        );
1300
1301
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1302
          '#type' => 'checkbox',
1303
          '#title' => t('Enable'),
1304
          '#default_value' => $settings['enabled'],
1305
          '#description' => t('Enable user defined layout for this feature'),
1306
        );
1307
1308
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1309
          '#type' => 'textfield',
1310
          '#title' => t('Enclosing tag'),
1311
          '#disabled' => !$settings['enabled'],
1312
          '#default_value' => $settings['enclosingTag'],
1313
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1314
        );
1315
1316
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1317
          '#type' => 'textfield',
1318
          '#title' => t('Entry enclosing tag'),
1319
          '#disabled' => !$settings['enabled'],
1320
          '#default_value' => $settings['entryEnclosingTag'],
1321
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1322
        );
1323
1324
        $form_feature_list_layout[$subform_id]['glue'] = array(
1325
          '#type' => 'textfield',
1326
          '#title' => t('Glue'),
1327
          '#disabled' => !$settings['enabled'],
1328
          '#default_value' => $settings['glue'],
1329
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1330
        );
1331
1332
      }
1333
1334
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1335
    }
1336
  }
1337
1338
  // ---- DISTRIBUTION LAYOUT ---- //
1339
  $form['taxon_profile']['distribution_layout'] = array(
1340
    '#title' => t('Distribution'),
1341
    '#collapsible' => TRUE,
1342
    '#collapsed' => FALSE,
1343
    '#type' => 'fieldset',
1344
    '#description' => t('Select if you want to sort or not the distribution text
1345
      located below the distribution map.'),
1346
  );
1347
1348
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1349
    '#type' => 'radios',
1350
    '#title' => t('Sort') . ':',
1351
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1352
    '#options' => array(
1353
      'NO_SORT' => t('Standard (No sort)'),
1354
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1355
    ),
1356
  );
1357
1358
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1359
    '#type' => 'checkbox',
1360
    '#title' => t('Show TextData elements on top of the map'),
1361
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1362
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1363
      elements on top of the map. Otherwise all <code>TextData</code>
1364
      distribution elements will be listed below the other area elements.
1365
      This option is useful if you need to have descriptive texts for each
1366
      distribution map.'),
1367
  );
1368
1369
1370
  /* ====== SYNONYMY ====== */
1371
  $form['taxon_synonymy'] = array(
1372
    '#type' => 'fieldset',
1373
    '#title' => t('Taxon synonymy (tab)'),
1374
    '#collapsible' => TRUE,
1375
    '#collapsed' => TRUE,
1376
    '#description' => t('This section covers the settings related to the taxon
1377 501347df Andreas Kohlbecker
      <strong>synonymy</strong> tab.'),
1378 6657531f Andreas Kohlbecker
  );
1379
1380
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1381
    '#type' => 'checkbox',
1382
    '#title' => t('Show accepted taxon on top of the synonymy'),
1383
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1384
    '#description' => t('If checked, the first homotypic taxon is a repetition
1385
      of the accepted taxon most likely with the full nomenclatural reference
1386
      (depending on the currently chosen theme).'),
1387
  );
1388
1389
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1390
    '#type' => 'checkbox',
1391
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1392
      coming from a synonym link.'),
1393
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1394
    '#description' => t('Check this if after doing a search and clicking on a
1395
      synonym you want to see the "accept of" text for the accepted synonym.'),
1396
  );
1397
1398
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1399 5014bf09 Andreas Kohlbecker
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1400 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
1401
    '#title' => t('Display name relationships') . ':',
1402
    '#default_value' => variable_get('name_relationships_to_show', 0),
1403
    '#options' => $nameRelationshipTypeOptions,
1404
    '#description' => t('Select the name relationships you want to show for the
1405
      accepted taxa.'),
1406
  );
1407
1408 5014bf09 Andreas Kohlbecker
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1409 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1410
    '#title' => t('Show taxon relations ships of accepted taxon'),
1411
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1412
    '#description' => t('If this option is enabled the synonymy will show the
1413
      below selected taxon relationships of accepted taxa.'),
1414
  );
1415
1416
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1417 5014bf09 Andreas Kohlbecker
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1418 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
1419
    '#title' => t('Taxon relationship types') . ':',
1420
    '#description' => t('Only taxon relationships of the selected type will be
1421
      displayed'),
1422
    '#options' => $taxonRelationshipTypeOptions,
1423
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1424
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1425
  );
1426
1427
  // ====== SPECIMENS ====== //
1428
  $form['taxon_specimens'] = array(
1429
    '#type' => 'fieldset',
1430
    '#title' => t('Taxon specimens (tab)'),
1431
    '#collapsible' => TRUE,
1432
    '#collapsed' => TRUE,
1433
    '#description' => t('This section covers the settings related to the taxon
1434
      <strong>specimens</strong> tab.'),
1435
  );
1436
1437 854e1d99 Andreas Kohlbecker
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1438
  $saved_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1439
  if(!isset($featureTrees['options'][$saved_uuid])) {
1440
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1441
  }
1442 bfb2b81a Andreas Kohlbecker
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1443
      '#type' => 'radios',
1444
      '#title' => t('Specimen description feature tree') . ':',
1445 854e1d99 Andreas Kohlbecker
      '#default_value' => $saved_uuid,
1446 bfb2b81a Andreas Kohlbecker
      '#options' =>  $featureTrees['options'],
1447 3f485c6d Andreas Kohlbecker
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1448
      '#options_suffixes' => $featureTrees['treeRepresentations'],
1449 bfb2b81a Andreas Kohlbecker
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1450
      ),
1451
  );
1452
1453 6657531f Andreas Kohlbecker
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1454
  $form_title = t('Specimen media');
1455
  $form_description = t('Specimens may have media which is displayed at the
1456
     Specimen tab/section as a gallery. It is possible to configure the
1457
     thumbnails gallery here, however for configuring how a single media should
1458
     be displayed please go to !url.</p>',
1459
     array(
1460
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1461
     ));
1462
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1463
1464
  // --- MEDIA GALLERY ---- //
1465
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1466
  $form_title = 'Media gallery (tab)';
1467
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1468
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1469
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1470
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1471
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1472
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1473
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1474
1475
  // Comment @WA: D7 form api does not support reset buttons,
1476
  // so to mimic the D5 reset button we add one like this.
1477
  $form['actions']['reset'] = array(
1478
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1479
    '#weight' => 1000,
1480
  );
1481
  return system_settings_form($form);
1482
}
1483
1484
/**
1485
 * @todo document this function.
1486
 */
1487
function cdm_settings_layout_search() {
1488
1489
  $form = array();
1490
1491
  $form['search_settings'] = array(
1492
    '#type' => 'fieldset',
1493
    '#title' => t('Taxa Search'),
1494 61b6ee11 Andreas Kohlbecker
    '#collapsible' => FALSE,
1495
    '#collapsed' => FALSE,
1496 6657531f Andreas Kohlbecker
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1497
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1498
         where they can write the text to be searched. You can find Drupal block configuration
1499
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1500
  );
1501
1502 61b6ee11 Andreas Kohlbecker
  $form['search_settings']['simple_search_ignore_classification'] = array(
1503
      '#type' => 'checkbox',
1504
      '#title' => t('Ignore the chosen classification in simple search'),
1505
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
1506
      '#description' => t('The simple search, which can be executed via the search block,
1507
          will by default search on all classifications. Remove the tick if you want your
1508
          portal to search on the classification selected in the classification browser
1509
          selector.'),
1510
  );
1511
1512 6657531f Andreas Kohlbecker
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1513
    '#type' => 'textfield',
1514
    '#title' => t('Results per page') . ':',
1515
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1516
    '#description' => t('Number of results to display per page.'),
1517
  );
1518
1519
  $form['search_settings']['cdm_search_taxa'] = array(
1520
    '#type' => 'checkbox',
1521
    '#title' => t('Sets the default value of <em>Search for accepted taxa</em> in the advanced search form.'),
1522
    '#default_value' => variable_get('cdm_search_taxa', 1),
1523
    '#description' => t('<p>If checked the <em>Search for accepted taxa </em> option will be enabled in the advanced form.</p>'),
1524
  );
1525
1526
  $form['search_settings']['cdm_search_synonyms'] = array(
1527
    '#type' => 'checkbox',
1528
    '#title' => t('Sets the default value of <em>Search for synonyms</em> in the advanced search form.'),
1529
    '#default_value' => variable_get('cdm_search_synonyms', 1),
1530
    '#description' => t('<p>If checked the <em>Search for synonyms</em> option will be enabled in the advanced form.</p>'),
1531
  );
1532
1533
  $form['search_settings']['cdm_search_common_names'] = array(
1534
    '#type' => 'checkbox',
1535
    '#title' => t('Sets the default value of <em>Search for common names</em> in the advanced search form.'),
1536
    '#default_value' => variable_get('cdm_search_common_names', 0),
1537
    '#description' => t('<p>If checked the <em>Search for common names</em> option will be enabled in the advanced form.</p>'),
1538
  );
1539
1540
  $form['search_settings']['cdm_search_use_default_values'] = array(
1541
    '#type' => 'checkbox',
1542
    '#title' => t('Sets use of default values in the advanced search form.'),
1543
    '#default_value' => variable_get('cdm_search_use_default_values', 1),
1544
    '#description' => t('<p>If checked the defqult values set abovewill be used for the search.</p>'),
1545
  );
1546
1547
1548
  // --- SEARCH TAXA GALLERY ---- //
1549
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1550
  $collapsed = FALSE;
1551
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1552
  $form_title = 'Taxa Search thumbnails';
1553
  $form_description = 'Search results may show thumbnails. ';
1554
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1555
1556
  // Comment @WA: D7 form api does not support reset buttons,
1557
  // so to mimic the D5 reset button we add one like this.
1558
  $form['actions']['reset'] = array(
1559
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1560
    '#weight' => 1000,
1561
  );
1562
  return system_settings_form($form);
1563
}
1564
1565
/**
1566
 * @todo document this function.
1567
 */
1568
function cdm_settings_layout_media() {
1569
1570
  $form = array();
1571
1572
  $form['media_settings'] = array(
1573
    '#type' => 'fieldset',
1574 a950f2f9 Andreas Kohlbecker
    '#title' => t('Media settings'),
1575
    '#collapsible' => FALSE,
1576 6657531f Andreas Kohlbecker
    '#collapsed' => FALSE,
1577 ccde8251 Andreas Kohlbecker
    '#description' => 'This section covers layout settings for media pages.'
1578
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
1579 6657531f Andreas Kohlbecker
  );
1580
1581
  $form['media_settings']['image_gallery_viewer'] = array(
1582
    '#type' => 'select',
1583
    '#title' => t('Image viewer') . ':',
1584
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1585
    '#options' => array(
1586
      'default' => t('Standard image viewer'),
1587
      'fsi' => t('FSI viewer (requires FSI server!)'),
1588
    ),
1589
  );
1590
1591
  // --- MEDIA GALLERY ---- //
1592
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1593
  $form_title = 'Standard viewer';
1594
  $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>';
1595
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1596
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1597
1598
  // @WA: D7 form api does not support reset buttons,
1599
  // so to mimic the D5 reset button we add one like this.
1600
  $form['actions']['reset'] = array(
1601
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1602
    '#weight' => 1000,
1603
  );
1604
  return system_settings_form($form);
1605
}
1606
1607
/**
1608
 * GEOSERVICE and Map settings.
1609
 */
1610 1d39ec64 w.addink
function cdm_settings_geo($form, &$form_state) {
1611 6657531f Andreas Kohlbecker
1612 cc3c9807 Andreas Kohlbecker
  $current_geoserver_settings = get_edit_map_service_settings();
1613
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
1614
1615 6657531f Andreas Kohlbecker
  $form = array();
1616
1617 cc3c9807 Andreas Kohlbecker
  $dummy_distribution_query = NULL;
1618
  if($map_distribution['map_type'] != 1){
1619
    // we need to apply a dummy query since the map serice requires for image maps
1620
    // at least as and ad to be defined
1621
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
1622
  }
1623 d2fd2a4c Andreas Kohlbecker
  $form['map_preview'] = array(
1624
      '#type' => 'fieldset',
1625
      '#tree' => FALSE,
1626
      '#title' => t('Map preview'),
1627
      '#collapsible' => FALSE,
1628 cc3c9807 Andreas Kohlbecker
      '#description' => 'The preview of the map'
1629 2bbc28c8 Andreas Kohlbecker
       . ($dummy_distribution_query != null ?
1630
           ' may not be accurate in case if image maps, please check the map display in the taxon pages.':
1631
           '.<br/>Hold down Strg and drag with your mouse to select a bbox to zoom to. <br/>The bbox of the visisble area of the map is always displayed below the map.')
1632 d2fd2a4c Andreas Kohlbecker
  );
1633 cc3c9807 Andreas Kohlbecker
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL,
1634 d2fd2a4c Andreas Kohlbecker
      array(
1635
          'move' => "this.cdmOpenlayersMap.printInfo",
1636
          '#execute' => "this.cdmOpenlayersMap.printInfo"
1637
      )
1638
  );
1639
1640 cc3c9807 Andreas Kohlbecker
1641 6657531f Andreas Kohlbecker
  /*
1642 d2fd2a4c Andreas Kohlbecker
   * GEO SERVER
1643
   */
1644 ba706bf0 Andreas Kohlbecker
  $form['edit_map_server'] = array(
1645 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1646 ba706bf0 Andreas Kohlbecker
    '#tree' => true,
1647
    '#title' => t('EDIT map service'),
1648 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
1649
    '#collapsed' => TRUE,
1650
    '#description' => t('Configuration and selection of your geo server.
1651
      The Geo Server is responsible for generating the maps.'),
1652
  );
1653
1654 ba706bf0 Andreas Kohlbecker
  $form['edit_map_server']['base_uri'] = array(
1655 6657531f Andreas Kohlbecker
    '#type' => 'select',
1656 ba706bf0 Andreas Kohlbecker
    '#title' => t('EDIT map service') . ':',
1657
    '#default_value' => $current_geoserver_settings['base_uri'],
1658
    '#options' => unserialize(EDIT_MAPSERVER_URI),
1659
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
1660 6657531f Andreas Kohlbecker
  );
1661 ba706bf0 Andreas Kohlbecker
  $form['edit_map_server']['version'] = array(
1662
      '#type' => 'select',
1663
      '#title' => t('Version') . ':',
1664
      '#default_value' => $current_geoserver_settings['version'],
1665
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
1666
      '#description' => t('The version of the EDIT map services'),
1667 6657531f Andreas Kohlbecker
  );
1668
1669 cc3c9807 Andreas Kohlbecker
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1670
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1671
  $form['gmap_api_key'] = array(
1672
      '#type' => 'textfield',
1673
      '#title' => t('Google maps API key') . ':',
1674
      '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1675
      '#description' => t('If you want to use the Google Maps Layer, a key is
1676
      needed. If you need a key, visit
1677
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
1678
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
1679
      is the default key for the localhost (127.0.0.1).',
1680
      array('!localhostkey' => $localhostkey)),
1681
  );
1682
1683
1684 6657531f Andreas Kohlbecker
  /*
1685 d2fd2a4c Andreas Kohlbecker
   * MAP SETTINGS
1686
   */
1687 cc3c9807 Andreas Kohlbecker
1688
  $form[CDM_MAP_DISTRIBUTION] = array(
1689 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1690 cc3c9807 Andreas Kohlbecker
    '#tree' => TRUE,
1691 6657531f Andreas Kohlbecker
    '#title' => t('Maps settings'),
1692
    '#collapsible' => TRUE,
1693
    '#collapsed' => TRUE,
1694
    '#description' => t('General configuration for all map types.'),
1695
  );
1696
1697 cc3c9807 Andreas Kohlbecker
  /*
1698
   * settings for the distribution map are used also for specimens map!!!!
1699
   */
1700
1701
  $form[CDM_MAP_DISTRIBUTION]['width'] = array(
1702 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
1703 cc3c9807 Andreas Kohlbecker
    '#title' => 'Width',
1704
    '#default_value' => $map_distribution['width'],
1705
    '#maxlength' => 4,
1706
    '#size' => 4,
1707
    '#description' => 'Width of the map. To allow OSM baselayers to zoom out to the full extend of the world the map width must be
1708 d2fd2a4c Andreas Kohlbecker
      a multiple of 256px since the osm tiles from tile.openstreetmap.org have a size of 256px x 256px and frational zoom
1709
      levels are not possible in this case.',
1710 6657531f Andreas Kohlbecker
  );
1711 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['height'] = array(
1712
      '#type' => 'textfield',
1713
      '#title' => 'Height',
1714
      '#default_value' => $map_distribution['height'],
1715
      '#maxlength' => 4,
1716
      '#size' => 4,
1717
      '#description' => 'Height of the map. Depending on the chosen base layer you may want to choose the height equal
1718
      to the width or half of the width. Any other aspect ratio is also possible if desired.',
1719
  );
1720 6657531f Andreas Kohlbecker
1721 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
1722 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
1723 cc3c9807 Andreas Kohlbecker
    '#title' => 'Bounding box',
1724
    '#default_value' => $map_distribution['bbox'],
1725
    '#description' => t('The bounding box defines the area to be initially displayed in maps.
1726 6657531f Andreas Kohlbecker
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
1727 2bbc28c8 Andreas Kohlbecker
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
1728
      <strong>TIP: </strong>You can use the map preview above to choose a bbox from the map. Maybe you need to change the map type to OpeLayers.
1729
      Hold down Strg and drag with your mouse to select a bbox to zoom to. The bbox of the visisble area of the map is always displayed
1730
      below the map from where you can copy the bbox string.</p>'),
1731 6657531f Andreas Kohlbecker
  );
1732
1733 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
1734 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1735 cc3c9807 Andreas Kohlbecker
    '#title' => 'Display area labels',
1736
    '#default_value' => $map_distribution['show_labels'],
1737
    '#description' => t('The map will show name labels of the areas'),
1738 6657531f Andreas Kohlbecker
  );
1739
1740 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
1741 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
1742 cc3c9807 Andreas Kohlbecker
    '#title' => 'Map caption',
1743
    '#default_value' => $map_distribution['caption'],
1744
    '#description' => t('The caption will be shown below the map.'),
1745 6657531f Andreas Kohlbecker
  );
1746
1747 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
1748 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
1749 cc3c9807 Andreas Kohlbecker
    '#title' => 'Distribution layer opacity',
1750
    '#default_value' => $map_distribution['distribution_opacity'],
1751 6657531f Andreas Kohlbecker
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
1752
                           fully visible, while a value near to 0.0 will be not much visible.'),
1753
  );
1754
1755 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
1756 6657531f Andreas Kohlbecker
    '#type' => 'radios',
1757 cc3c9807 Andreas Kohlbecker
    '#title' => 'Map types',
1758 6657531f Andreas Kohlbecker
    '#options' => array(
1759 cc3c9807 Andreas Kohlbecker
      1 => "OpenLayers dynamic map viewer",
1760 6657531f Andreas Kohlbecker
      0 => "Plain image",
1761
    ),
1762 cc3c9807 Andreas Kohlbecker
    '#default_value' => $map_distribution['map_type'],
1763
    '#description' => 'Two different map types are available :
1764
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
1765
      which allows zooming and panning. If enabled you can configure the default layer
1766
      (background of your maps) below.</li>
1767
      <li><em>Plain image</em>: The map will be static non interactive
1768
      image.</li></ul>',
1769 6657531f Andreas Kohlbecker
  );
1770 cc3c9807 Andreas Kohlbecker
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
1771 6657531f Andreas Kohlbecker
1772
1773
  // --- Plain Image Settings --- //
1774 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
1775 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1776 cc3c9807 Andreas Kohlbecker
    '#title' => 'Plain image map settings',
1777
    '#tree' => TRUE,
1778 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
1779 cc3c9807 Andreas Kohlbecker
    '#collapsed' => $open_layers_is_enabled,
1780
    '#description' => 'The settings in this section are still expertimental
1781
      and can only be used with the EDIT map service version 1.1 or above.',
1782 6657531f Andreas Kohlbecker
  );
1783 ba706bf0 Andreas Kohlbecker
  $edit_mapserver_version = get_edit_map_service_version_number();
1784 6657531f Andreas Kohlbecker
  if ($edit_mapserver_version < 1.1) {
1785 cc3c9807 Andreas Kohlbecker
    $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>'
1786
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
1787 6657531f Andreas Kohlbecker
  }
1788
1789 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
1790 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
1791 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background layer',
1792
    '#default_value' => $map_distribution['image_map']['base_layer'],
1793 6657531f Andreas Kohlbecker
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
1794 cc3c9807 Andreas Kohlbecker
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
1795
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
1796 6657531f Andreas Kohlbecker
    )),
1797
  );
1798
1799 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
1800 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
1801 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background color',
1802
    '#default_value' => $map_distribution['image_map']['bg_color'],
1803 6657531f Andreas Kohlbecker
  );
1804
1805 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
1806 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
1807 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background layer style',
1808 6657531f Andreas Kohlbecker
     // Only line color by now.
1809 cc3c9807 Andreas Kohlbecker
    '#default_value' => $map_distribution['image_map']['layer_style'],
1810
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
1811 6657531f Andreas Kohlbecker
  );
1812
1813
1814
  // --- OpenLayers Settings --- //
1815 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
1816 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1817 cc3c9807 Andreas Kohlbecker
    '#title' => 'OpenLayers settings',
1818
    '#tree' => TRUE,
1819 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
1820 cc3c9807 Andreas Kohlbecker
    '#collapsed' => !$open_layers_is_enabled,
1821 6657531f Andreas Kohlbecker
    '#description' => '',
1822
  );
1823
1824 2bbc28c8 Andreas Kohlbecker
1825
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
1826
      '#type' => 'checkbox',
1827
      '#title' => 'Display outside max extent',
1828
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
1829
      '#description' => t('Allows the map to display parts of the layers which are outside
1830
         the max extent if the aspect ratio of the map and of the baselayer
1831
         are not equal.'),
1832
  );
1833
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 cc3c9807 Andreas Kohlbecker
  if (!$open_layers_is_enabled) {
1846
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
1847
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
1848
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
1849 6657531f Andreas Kohlbecker
  }
1850
1851
  $baselayer_options = array(
1852
    /*
1853
   NOTICE: must correspond to the layers defined in
1854
   js/openlayers_,ap.js#getLayersByName()
1855
   */
1856 1d39ec64 w.addink
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
1857
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
1858 6657531f Andreas Kohlbecker
    // all others EPSG:900913
1859
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
1860
    'edit-etopo1' => "ETOPO1 Global Relief Model",
1861
    'mapnik' => 'OpenStreetMap',
1862 2bbc28c8 Andreas Kohlbecker
    'mapquest_open' => "MapQuest",
1863
    'mapquest_sat' => "MapQuest Sattelite",
1864
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
1865 6657531f Andreas Kohlbecker
    'gmap' => 'Google Streets',
1866
    'gsat' => 'Google Satellite',
1867
    'ghyb' => 'Google Hybrid',
1868 cc3c9807 Andreas Kohlbecker
//     'veroad' => 'Virtual Earth Roads',
1869
//     'veaer' => 'Virtual Earth Aerial',
1870
//     'vehyb' => 'Virtual Earth Hybrid',
1871 6657531f Andreas Kohlbecker
    // 'yahoo' => 'Yahoo Street',
1872
    // 'yahoosat' => 'Yahoo Satellite',
1873
    // 'yahoohyb' => 'Yahoo Hybrid',
1874 2bbc28c8 Andreas Kohlbecker
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
1875 6657531f Andreas Kohlbecker
  );
1876
1877 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
1878 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes_preferred',
1879 cc3c9807 Andreas Kohlbecker
    '#title' => 'Base Layers',
1880 6657531f Andreas Kohlbecker
    '#options' => $baselayer_options,
1881 cc3c9807 Andreas Kohlbecker
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
1882
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
1883 6657531f Andreas Kohlbecker
  );
1884
1885 2bbc28c8 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
1886
      '#type' => 'fieldset',
1887
      '#title' => 'Custom WMS base layer',
1888
      '#tree' => TRUE,
1889
      '#collapsible' => FALSE,
1890
      '#collapsed' => FALSE,
1891
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
1892
  );
1893
1894
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
1895
      '#type' => 'textfield',
1896
      '#title' => 'Layer name',
1897
      // Only line color by now.
1898
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
1899
      '#description' => 'A arbitrary name for the layer.',
1900
  );
1901
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
1902
      '#type' => 'textfield',
1903
      '#title' => 'WMS url',
1904
      // Only line color by now.
1905
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
1906
      '#description' => 'Base url for the WMS (e.g.  http://wms.jpl.nasa.gov/wms.cgi)'
1907
  );
1908
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
1909
      '#type' => 'textarea',
1910
      '#title' => 'WMS parameters',
1911
      '#element_validate' => array('form_element_validate_json'),
1912
      // Only line color by now.
1913
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
1914
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON.'
1915
  );
1916
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
1917
      '#type' => 'textfield',
1918
      '#title' => 'Projection',
1919
      // Only line color by now.
1920
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
1921
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
1922
  );
1923
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
1924
      '#type' => 'textfield',
1925
      '#title' => 'Maximum extent',
1926
      // Only line color by now.
1927
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
1928
      '#description' => 'The maximum extent of the map as boundin box in the units of the map.'
1929
  );
1930
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
1931
      '#type' => 'textfield',
1932
      '#title' => 'Units',
1933
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
1934
      '#description' => 'The layer map units.  Defaults to null.  Possible values are ‘degrees’ (or ‘dd’), ‘m’, ‘ft’, ‘km’, ‘mi’, ‘inches’.  Normally taken from the projection.  Only required if both map and layers do not define a projection, or if they define a projection which does not define units.'
1935 6657531f Andreas Kohlbecker
  );
1936
1937 cc3c9807 Andreas Kohlbecker
  /*
1938
   * Map Legend
1939
   */
1940
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
1941 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1942 cc3c9807 Andreas Kohlbecker
    '#title' => 'Map legend',
1943
    '#tree' => TRUE,
1944 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
1945
    '#collapsed' => TRUE,
1946 cc3c9807 Andreas Kohlbecker
    '#description' => 'Configure the maps legend.',
1947 6657531f Andreas Kohlbecker
  );
1948
1949 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
1950 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1951 cc3c9807 Andreas Kohlbecker
    '#title' => 'Display a map legend',
1952
    '#default_value' => $map_distribution['legend']['show'],
1953
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
1954 6657531f Andreas Kohlbecker
  );
1955
1956 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
1957 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
1958 cc3c9807 Andreas Kohlbecker
    '#title' => 'Legend opacity',
1959
    '#default_value' => $map_distribution['legend']['opacity'],
1960
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
1961
                         to 0.0 will be not much visible.',
1962 6657531f Andreas Kohlbecker
  );
1963
1964 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
1965 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
1966 cc3c9807 Andreas Kohlbecker
    '#title' => 'Font size',
1967
    '#default_value' => $map_distribution['legend']['font_size'],
1968
    '#description' => 'Font size in pixels.',
1969 6657531f Andreas Kohlbecker
  );
1970
1971
  $fontStyles = array(
1972
    0 => "plane",
1973
    1 => "italic",
1974
  );
1975 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
1976 6657531f Andreas Kohlbecker
    '#type' => 'select',
1977 cc3c9807 Andreas Kohlbecker
    '#title' => 'Available font styles',
1978
    '#default_value' => $map_distribution['legend']['font_style'],
1979 6657531f Andreas Kohlbecker
    '#options' => $fontStyles,
1980 cc3c9807 Andreas Kohlbecker
    '#description' => 'Select a font style for the map legend.',
1981 6657531f Andreas Kohlbecker
  );
1982
1983 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
1984 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
1985 cc3c9807 Andreas Kohlbecker
    '#title' => 'Icon width',
1986
    '#default_value' => $map_distribution['legend']['icon_width'],
1987
    '#description' => 'Legend icon width in pixels.',
1988 6657531f Andreas Kohlbecker
  );
1989 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
1990 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
1991 cc3c9807 Andreas Kohlbecker
    '#title' => 'Icon height',
1992
    '#default_value' => $map_distribution['legend']['icon_height'],
1993
    '#description' => 'Legend icon height in pixels.',
1994 6657531f Andreas Kohlbecker
  );
1995
1996
  // @WA: D7 form api does not support reset buttons,
1997
  // so to mimic the D5 reset button we add one like this.
1998
  $form['actions']['reset'] = array(
1999
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2000
    '#weight' => 1000,
2001
  );
2002 1d39ec64 w.addink
2003 6657531f Andreas Kohlbecker
  return system_settings_form($form);
2004
}
2005
2006
/**
2007
 * @todo document this function.
2008
 */
2009
function cdm_settings_cache() {
2010
2011
  $form = array();
2012
2013
  $form['cache_settings'] = array(
2014
    '#type' => 'fieldset',
2015
    '#title' => t('Cache Settings'),
2016
    '#collapsible' => FALSE,
2017
    '#collapsed' => FALSE,
2018
    '#description' => t('<p>When caching is enabled all single taxon sites are
2019
      stored in an internal drupal cache doing the portal response of taxa pages
2020
      faster. This is possible because the sites are loaded from the cache and
2021
      are not created from scratch.</p>'),
2022
  );
2023
2024
  $form['cache_settings']['cdm_webservice_cache'] = array(
2025
    '#type' => 'checkbox',
2026
    '#title' => t('<strong>Enable caching</strong>'),
2027
    '#options' => cdm_help_general_cache(),
2028
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2029
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2030
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2031
       application the changes will be not visible till the cache is erased.
2032
       Therefore developers should deactived this feature when they are working
2033
       on the CDM Dataportal Module.</p>'),
2034
  );
2035
2036
  $form['cache_settings']['cdm_run_cache'] = array(
2037
    '#markup' => cdm_view_cache_site(),
2038
  );
2039
2040
  // @WA: D7 form api does not support reset buttons,
2041
  // so to mimic the D5 reset button we add one like this.
2042
  $form['actions']['reset'] = array(
2043
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2044
    '#weight' => 1000,
2045
  );
2046
  return system_settings_form($form);
2047
}
2048
2049
/**
2050
 * Walk and cache all taxon pages.
2051
 */
2052
function cdm_view_cache_site() {
2053
2054
  $out = '';
2055
2056
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2057
2058
  $request_params = array();
2059 7d828d59 Andreas Kohlbecker
  $request_params['class'] = "Taxon";
2060 6657531f Andreas Kohlbecker
2061 7d828d59 Andreas Kohlbecker
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2062
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2063
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2064 6657531f Andreas Kohlbecker
2065
  $out .= t('<p><strong>Cache all taxon pages</strong></p>');
2066
  $out .= '<p>When you launch the cache process the cache is filled and ready to be enabled.<br/>
2067
  Remember that when you load the taxa from the cache last changes on taxa will be not visible till you erase
2068
  the cache and fill it again.</p>';
2069
  $out .= '<p>Before  running the cache bot you have to empty the cache manually.</p>';
2070
2071
  $out .= '<div>' . t('This caching process may take long time and could cause heavy load on your server') . '</div>';
2072
  $out .= '<div id="progress"></div>';
2073
2074
  // Comment @WA: A form within a form is not valid html and not needed here.
2075
  // Also, it would be recommended just to include this part of the form in the
2076
  // rest of the form array in cdm_settings_cache().
2077
  // $out .= '<form id="cache_site">';
2078 0516e3d0 Andreas Kohlbecker
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2079 7d828d59 Andreas Kohlbecker
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2080 6657531f Andreas Kohlbecker
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2081
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2082
  // $out .= '</form>';
2083
  $out .= '</div>';
2084
  /*
2085
  foreach($taxonPager->records as $taxon){
2086
    cdm_dataportal_taxon_view($uuid);
2087
  }
2088
  */
2089
  return $out;
2090
}
2091
2092 7df1be04 Andreas Kohlbecker
2093
function cdm_settings_layout_taxon_submit($form, &$form_state){
2094 9c92cd84 Andreas Kohlbecker
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2095
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2096
    if(is_object($file)){
2097
      $file->status = FILE_STATUS_PERMANENT;
2098
      file_save($file);
2099
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2100
    }
2101 7df1be04 Andreas Kohlbecker
  }
2102 d5403dc4 Andreas Kohlbecker
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2103
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2104
    // we first need to set the variable to persist the changes setting
2105
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
2106
    menu_rebuild();
2107
  }
2108 7df1be04 Andreas Kohlbecker
}
2109
2110 6657531f Andreas Kohlbecker
/**
2111 d1eb0a8c Andreas Kohlbecker
 * Form validation handler for cdm_settings_general
2112 6657531f Andreas Kohlbecker
 *
2113
 * Comment @WA: currently this handler is not used.
2114
 * It seems partly for cdm_settings_general en partly for cdm_settings_cache?
2115
 * Then you can change the name into cdm_settings_general_validate() or
2116
 * cdm_settings_cache_validate().
2117
 * But cdm_api_secref_cache_clear is not doing anything (yet)?
2118
 */
2119 d1eb0a8c Andreas Kohlbecker
function cdm_settings_general_validate($form, &$form_state) {
2120 6657531f Andreas Kohlbecker
2121
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2122
    $form_state['values']['cdm_webservice_url'] .= '/';
2123
  }
2124
2125 d1eb0a8c Andreas Kohlbecker
}
2126
2127
/**
2128
 * Form validation handler for cdm_settings_cache
2129
 */
2130
function cdm_settings_cache_validate() {
2131 6657531f Andreas Kohlbecker
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2132
    cache_clear_all(NULL, 'cache_cdm_ws');
2133
    // Better clear secref_cache since I can not be sure if the cache has not
2134
    // be used during this response.
2135
    cdm_api_secref_cache_clear();
2136
  }
2137 d1eb0a8c Andreas Kohlbecker
2138 6657531f Andreas Kohlbecker
}
2139
2140
/**
2141 ba706bf0 Andreas Kohlbecker
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
2142
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
2143
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
2144
 *  - version: the version, e.g.: v1.1
2145
 *
2146
 * @return array
2147
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
2148 6657531f Andreas Kohlbecker
 */
2149 ba706bf0 Andreas Kohlbecker
function get_edit_map_service_settings() {
2150
2151
  $settings = variable_get('edit_map_server', array(
2152
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
2153
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
2154
      )
2155
  );
2156
  // replace old non tree like settings by default
2157
  // TODO to be removed after release 3.1.5
2158
  if(!is_array($settings)){
2159
    variable_del('edit_map_server');
2160
    return get_edit_map_service_settings();
2161 6657531f Andreas Kohlbecker
  }
2162
2163 ba706bf0 Andreas Kohlbecker
  return $settings;
2164 6657531f Andreas Kohlbecker
}
2165
2166
/**
2167 ba706bf0 Andreas Kohlbecker
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2168
 *
2169
 * @return string
2170
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2171
 */
2172
function get_edit_map_service_full_uri() {
2173
  $settings = get_edit_map_service_settings();
2174
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
2175
}
2176
2177
2178
/**
2179
 * Returns the version number of the currently selected edit mapserver as a float
2180 6657531f Andreas Kohlbecker
 *
2181
 * @return float
2182
 *   The version number of the currently selected edit mapserver as a float.
2183
 *   Returns 0 on error.
2184
 */
2185 ba706bf0 Andreas Kohlbecker
function get_edit_map_service_version_number() {
2186 6657531f Andreas Kohlbecker
2187 ba706bf0 Andreas Kohlbecker
  $pattern = '/v([\d\.]+).*$/';
2188 6657531f Andreas Kohlbecker
2189 ba706bf0 Andreas Kohlbecker
  $settings = get_edit_map_service_settings();
2190
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
2191 6657531f Andreas Kohlbecker
  if (isset($matches[1])) {
2192
    // Convert string to float.
2193
    $version = 1 + $matches[1][0] - 1;
2194
    return $version;
2195
  }
2196
  else {
2197
    // Report error.
2198 ba706bf0 Andreas Kohlbecker
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
2199
        array(
2200
          '!version' => $settings['version'],
2201
          'warning')
2202
        )
2203
      );
2204 6657531f Andreas Kohlbecker
    return 0;
2205
  }
2206
}
2207
2208 30f78c59 Andreas Kohlbecker
/**
2209 ba706bf0 Andreas Kohlbecker
 * Returns the array of selected items in a options array
2210 30f78c59 Andreas Kohlbecker
 *
2211
 * @param array $options
2212
 *   An options array as generated by a form element like checkoxes, select ...,
2213
 */
2214
function get_selection($options) {
2215
  $selection = array();
2216
  foreach ($options as $key=>$val) {
2217
    if (!empty($val)) {
2218
      $selection[] = $val;
2219
    }
2220
  }
2221
  return $selection;
2222
}
2223
2224 bfb2b81a Andreas Kohlbecker
2225 6657531f Andreas Kohlbecker
/**
2226
 * Implements hook_element_info().
2227
 *
2228 14feebe9 Andreas Kohlbecker
 * Allows modules to declare their own Form API element types and specify their default values.
2229
 *
2230
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
2231 6657531f Andreas Kohlbecker
 */
2232
function cdm_dataportal_element_info() {
2233
  $type['checkboxes_preferred'] = array(
2234
    '#input' => TRUE,
2235 14feebe9 Andreas Kohlbecker
    '#process' => array('checkboxes_preferred_expand'),
2236 6657531f Andreas Kohlbecker
    '#after_build' => array('checkboxes_preferred_after_build'),
2237
    '#theme' => array('checkboxes_preferred'),
2238
    // '#theme_wrapper' => array('form_element'),
2239
  );
2240
  return $type;
2241
}
2242
2243
/**
2244 14feebe9 Andreas Kohlbecker
 * #process callback function for the custom form element type 'checkbox_preferred'
2245
 *
2246
 *
2247 6657531f Andreas Kohlbecker
 */
2248 14feebe9 Andreas Kohlbecker
function checkboxes_preferred_expand($element, &$form_state, $form) {
2249
2250
  // First of all create checkboxes for each of the elements
2251 6657531f Andreas Kohlbecker
  $element = form_process_checkboxes($element);
2252
2253 cc3c9807 Andreas Kohlbecker
  // compose the element name
2254
  $parents = array();
2255
  array_deep_copy($element['#parents'], $parents);
2256
  $parents[count($parents) -1 ] .= '_preferred';
2257
  $element_name = $parents[0];
2258
  for ($i=1; $i < count($parents); $i++){
2259
    $element_name .= '[' . $parents[$i] . ']';
2260
  }
2261
2262 6657531f Andreas Kohlbecker
  $children = element_children($element);
2263
2264
  $element['table_start'] = array(
2265
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
2266
    '#weight' => -1,
2267
  );
2268
2269 14feebe9 Andreas Kohlbecker
  // prepare first part each of the table rows which contains the row label
2270 6657531f Andreas Kohlbecker
  $weight = 0;
2271
  foreach ($children as $key) {
2272
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
2273
    $element[$key]['#weight'] = $weight;
2274
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
2275
    $element[$key]['#suffix'] = '</td>';
2276
    unset($element[$key]['#title']);
2277
    $weight += 2;
2278
  }
2279
  $weight = 0;
2280
2281 14feebe9 Andreas Kohlbecker
  // add a radio button to each of the checkboxes, the
2282
  // check boxes have already been created at the beginning
2283
  // of this function
2284 6657531f Andreas Kohlbecker
  if (count($element['#options']) > 0) {
2285
    foreach ($element['#options'] as $key => $choice) {
2286
      if (!isset($element[$key . '_preferred'])) {
2287
        $element[$key . '_preferred'] = array(
2288
          '#type' => 'radio',
2289 cc3c9807 Andreas Kohlbecker
          '#name' => $element_name,
2290 6657531f Andreas Kohlbecker
          '#return_value' => check_plain($key),
2291
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
2292
          '#attributes' => $element['#attributes'],
2293 1d39ec64 w.addink
          '#parents' => $element['#parents'],
2294 6657531f Andreas Kohlbecker
          // '#spawned' => TRUE,
2295
          '#weight' => $weight + 1,
2296 14feebe9 Andreas Kohlbecker
          '#prefix' => '<td>',        // add a prefix to start a new table cell
2297
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
2298 6657531f Andreas Kohlbecker
        );
2299
      }
2300
      $weight += 2;
2301
    }
2302
  }
2303
2304 14feebe9 Andreas Kohlbecker
  // end the table
2305 6657531f Andreas Kohlbecker
  $element['table_end'] = array(
2306
    '#markup' => '</table>',
2307
    '#weight' => $weight++,
2308
  );
2309
2310
  return $element;
2311
}
2312
2313
/**
2314
 * Theme function for the custom form field 'checkboxes_preferred'.
2315
 */
2316
function theme_checkboxes_preferred($variables) {
2317
  $element = $variables['element'];
2318
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
2319
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
2320
  $out .= drupal_render_children($element);
2321
  $out .= '<div class="description">' . $element['#description'] . '</div>';
2322
  $out .= '</div>';
2323
  return $out;
2324
}
2325
2326
/**
2327 14feebe9 Andreas Kohlbecker
 * Callback for checkboxes preferred for widget which will
2328
 * be called after the form or element is built. The call
2329
 * back is configured in the form element by setting it as
2330
 * #after_build parameter.
2331
 *
2332
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
2333
 *
2334 cc3c9807 Andreas Kohlbecker
 * @param $element
2335 14feebe9 Andreas Kohlbecker
 *   Nested array of form elements that comprise the form.
2336
 * @param $form_state
2337
 *   A keyed array containing the current state of the form.
2338 cc3c9807 Andreas Kohlbecker
 *   This includes the current persistent storage data for the form.
2339
 *   Additional information, like the sanitized $_POST data,
2340
 *   is also accumulated here in $form_state['input']
2341 14feebe9 Andreas Kohlbecker
 *
2342
 * @return the modified form array
2343 6657531f Andreas Kohlbecker
 */
2344 cc3c9807 Andreas Kohlbecker
function checkboxes_preferred_after_build($element, &$form_state) {
2345 6657531f Andreas Kohlbecker
2346 cc3c9807 Andreas Kohlbecker
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
2347 6657531f Andreas Kohlbecker
2348
  if ($_POST && count($_POST) > 0) {
2349 cc3c9807 Andreas Kohlbecker
    // TODO use  $form_state['input'] instead of POST !!!
2350 6657531f Andreas Kohlbecker
    // First pass of form processing.
2351 cc3c9807 Andreas Kohlbecker
    $parents = array();
2352
    array_deep_copy($element['#parents'], $parents);
2353
    $parents[count($parents) - 1] .= '_preferred';
2354
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
2355
    $element['#value']['PREFERRED'] = $preferred_layer;
2356
//     $form_state[$parent_id] = $element['#value'];
2357
//     $form_state['values']['baselayers'] = $element['#value'];
2358
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
2359
    $form_state_element_values = $element['#value'];
2360 6657531f Andreas Kohlbecker
  }
2361
  else {
2362
    // Second pass of form processing.
2363 cc3c9807 Andreas Kohlbecker
    $preferred_layer = $element['#value']['PREFERRED'];
2364 6657531f Andreas Kohlbecker
  }
2365
2366
  // Also set the chosen value (not sure if this is good Drupal style ....).
2367 cc3c9807 Andreas Kohlbecker
  foreach ($children = element_children($element) as $key) {
2368
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
2369
      $element[$key]['#value'] = $preferred_layer;
2370 6657531f Andreas Kohlbecker
    }
2371
  }
2372
  // The default layer must always be enabled.
2373 cc3c9807 Andreas Kohlbecker
  $element[$preferred_layer]['#value'] = $preferred_layer;
2374 6657531f Andreas Kohlbecker
2375 cc3c9807 Andreas Kohlbecker
  return $element;
2376 6657531f Andreas Kohlbecker
}
2377 0f5f1c12 Andreas Kohlbecker
2378 3f485c6d Andreas Kohlbecker
function radios_prepare_options_suffix(&$elements){
2379
2380
  $childrenKeys = element_children($elements);
2381
  foreach($childrenKeys as $key){
2382
    if(!is_array($elements[$key]['#theme_wrappers'])){
2383
      $elements[$key]['#theme_wrappers'] = array();
2384
    }
2385
    if(isset($elements['#options_suffixes'][$key])){
2386
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
2387
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
2388
    }
2389
  }
2390
  return $elements;
2391
2392
}
2393
2394
/**
2395
 * TODO
2396
 * @param unknown $variables
2397
 */
2398
function theme_radio_options_suffix($variables) {
2399
  $element = $variables['element'];
2400
  if(isset($element['#options_suffix'])) {
2401
    $element['#children'] .= $element['#options_suffix'];
2402
  }
2403
  return $element['#children'];
2404
}
2405
2406
2407 0f5f1c12 Andreas Kohlbecker
/**
2408
 * Element validate callback for text field and arrays containing json.
2409
 *
2410
 * @param $element
2411
 *   The form element to validate
2412
 * @param $form_state
2413
 *   A keyed array containing the current state of the form.
2414 cc3c9807 Andreas Kohlbecker
 * @param $form
2415
 *   Nested array of form elements that comprise the form.
2416 0f5f1c12 Andreas Kohlbecker
 */
2417
function form_element_validate_json($element, &$form_state, $form) {
2418
   if (!empty($element['#value'])) {
2419
     json_decode($element['#value']);
2420
     if(json_last_error() != JSON_ERROR_NONE){
2421
       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/'));
2422
     }
2423
   }
2424
}
2425
2426
/**
2427
 * Form submission handler for textareas and textfields containing JSON.
2428
 *
2429
 * The contained JSON will be converted into an php array
2430 2bbc28c8 Andreas Kohlbecker
 * or object and will be stored in the variables as such.
2431 0f5f1c12 Andreas Kohlbecker
 *
2432
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2433
 *
2434
 * @param $form
2435
 *   Nested array of form elements that comprise the form.
2436
 * @param $form_state
2437
 *   A keyed array containing the current state of the form.
2438
 *
2439
 */
2440
function submit_json_as_php_array($form, &$form_state) {
2441
  if (is_array($form['#json_elements'])) {
2442
    foreach ($form['#json_elements'] as $element){
2443 80370786 Andreas Kohlbecker
      if (trim($form_state['values'][$element])) {
2444
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
2445
      } else {
2446
        $form_state['values'][$element] = NULL;
2447
      }
2448 0f5f1c12 Andreas Kohlbecker
    }
2449
  }
2450
}