Project

General

Profile

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

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

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

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

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

    
32
define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
33
define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
34
  'enabled' => 1,
35
  'key_format' => 'ALPHA'
36
)));
37

    
38
/* taxonRelationshipTypes */
39
define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
40

    
41

    
42

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

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

    
97
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
98

    
99
/**
100
 * Returns the array of implemented taxon page tabs.
101
 * The array has fixed integer keys which must not be changed.
102
 */
103
function get_taxon_tabs_list() {
104
  return array(
105
    0 => 'General',
106
    1 => 'Synonymy',
107
    2 => 'Images',
108
    3 => 'Specimens',
109
    4 => 'Keys',
110
  );
111
}
112

    
113
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
114
  array('general' => '-3', 'synonymy' => '-2', 'images' => '0', 'specimens' => '1', 'keys' => '3')
115
));
116

    
117
$taxon_tab_options = get_taxon_tabs_list();
118
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
119

    
120
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
121

    
122
/**
123
 * @todo document this function.
124
 */
125
function get_taxon_options_list() {
126
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
127
  foreach ($taxon_tab_options as $key => $value) {
128
    $taxon_tab_options[$key] = t($key);
129
  }
130
  return $taxon_tab_options;
131

    
132
}
133

    
134
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
135
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
136
  array(
137
      'ZoologicalName' => array(
138
        'namePart' => array('name' => TRUE),
139
        'nameAuthorPart' => array('name' => TRUE),
140
        'referencePart' => array('authors' => TRUE),
141
        'microreferencePart' => array('microreference' => TRUE),
142
        'statusPart' => array('status' => TRUE),
143
        'descriptionPart' => array('description' => TRUE),
144
      ),
145
      'BotanicalName'=> array(
146
        'namePart' => array('name' => TRUE),
147
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
148
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
149
        'referenceYearPart' => array('reference.year' => TRUE),
150
        'statusPart' => array('status' => TRUE),
151
        'descriptionPart' => array('description' => TRUE),
152
      ),
153
     '#DEFAULT' => array(
154
        'namePart' => array(
155
            'name' => TRUE
156
        ),
157
        'nameAuthorPart' => array(
158
            'name' => TRUE,
159
            'authors' => TRUE
160
        ),
161
        'referencePart' => array(
162
            'reference' => TRUE
163
        ),
164
        'microreferencePart' => array(
165
            'microreference' => TRUE,
166
        ),
167
        'statusPart' => array(
168
            'status' => TRUE,
169
        ),
170
        'descriptionPart' => array(
171
            'description' => TRUE,
172
        ),
173
      )
174
    )
175
  )
176
);
177
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
178
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
179
   array (
180
     'taxon_page_title,polytomousKey'=> array(
181
          'namePart' => array('#uri' => TRUE),
182
        ),
183
      'taxon_page_synonymy,related_taxon'=> array(
184
          'nameAuthorPart' => array('#uri' => TRUE),
185
          'referencePart' => TRUE,
186
          'statusPart' => TRUE,
187
          'descriptionPart' => TRUE,
188
        ),
189
       'homonym'=> array(
190
            'nameAuthorPart' => array('#uri' => TRUE),
191
            'referenceYearPart' => TRUE,
192
        ),
193
      'acceptedFor,typedesignations,list_of_taxa' => array(
194
          'nameAuthorPart' => array('#uri' => TRUE),
195
          'referencePart' => TRUE,
196
        ),
197
      '#DEFAULT' => array(
198
          'nameAuthorPart' => array('#uri' => TRUE),
199
          'referencePart' => TRUE,
200
       )
201
    )
202
));
203

    
204
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
205
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
206
    // to unset a default enntry set the value to 0
207
    array(
208
      'doTaxa'=>'doTaxa',
209
      'doSynonyms' => 'doSynonyms',
210
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
211
      'doMisappliedNames' => 'doMisappliedNames'
212
    )
213
  )
214
);
215

    
216
/* Gallery variables. */
217
$gallery_settings = array(
218
    "cdm_dataportal_show_taxon_thumbnails" => 1,
219
    "cdm_dataportal_show_synonym_thumbnails" => 0,
220
    "cdm_dataportal_show_thumbnail_captions" => 1,
221
    "cdm_dataportal_media_maxextend" => 120,
222
    "cdm_dataportal_media_cols" => 3,
223
    "cdm_dataportal_media_maxRows" => 1,
224
);
225

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

    
266
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
267
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
268
      array(
269
      'filter_rules' => array(
270
        'statusOrderPreference' => 0,
271
        'subAreaPreference' => 0,
272
      ),
273
      'hideMarkedAreas' => array()
274
     )
275
));
276

    
277

    
278
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
279
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
280
    array(
281
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
282
        'includeOccurrences' => 0,
283
        'includeTaxonNameDescriptions' => 0
284
     )
285
  ));
286

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

    
332
/**
333
 * Merges the named array variable with the array of defaults.
334
 *
335
 * IMPORTANT: The array keys must be strings. When the keys are integers
336
 * the merging will not take place for these entities. Number keyed entities
337
 * are just appended to the result array.
338
 *
339
 * @param string $variable_name
340
 *     The variable name
341
 * @param string | array $default
342
 *     The array containing the default values either as array or serialized as string.
343
 *     Unserialization is cared for if necessary
344
 * @return array
345
 *     The merged array as returned by drupal_array_merge_deep()
346
 */
347
function get_array_variable_merged($variable_name, $default){
348

    
349
    // unserialize if nessecary
350
    if(!is_array($default)){
351
      $default = unserialize($default);
352
    }
353
    $variable = variable_get($variable_name, array());
354
    $result = drupal_array_merge_deep($default, $variable);
355
    return $result;
356
}
357

    
358
/**
359
 * @todo document this function.
360
 */
361
function getGallerySettings($gallery_config_form_name) {
362
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
363
}
364

    
365
/**
366
 * Returns the string representation of the default tab.
367
 *
368
 * @param bool $returnTabIndex
369
 *   Defaults to FALSE, if set true this function will return the index number
370
 *   of the default tab. (used to supply default values to form elements).
371
 */
372
function get_default_taxon_tab($returnTabIndex = FALSE) {
373

    
374
  global $user;
375
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
376
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
377
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
378
  // Get the user value if the used has chosen to overwrite the system settings.
379
  $user_tab_on = variable_get($user_tab_active, FALSE);
380
  if ($user_tab_on) {
381
    $user_value = variable_get($user_tab, 0);
382
    $index_value = $user_value;
383
    // Get the system value.
384
  }
385
  else {
386
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
387
    $index_value = $system_value;
388
  }
389

    
390
  // Return the index value or the string representation.
391
  if ($returnTabIndex) {
392
    return $index_value;
393
  }
394
  else {
395
    return ($values[$index_value]);
396
  }
397

    
398
}
399

    
400
  /**
401
   * preliminary mock implementation
402
   *
403
   *  "$feature uuid": {
404
   *    "as_list": div|ul|ol,                        // div: not as list, ul: as bullet list, ol: as numbered list, will be used in compose_cdm_feature_block_elements() as $enclosing_tag
405
   *    "link_to_reference": boolean,                 // render the reference as link, ignored if the element is NOT a DescriptionElementSource
406
   *    // references_inline:
407
   *    // TRUE:
408
   *    //   1. if element has text (TextData) the source references will be appended in brackets like "text (source references)"
409
   *    //   2. otherwise they are the only content (e.g. use case CITATION) and afre not put into brackets
410
   *    // FALSE:
411
   *    //  they are put into the bibliography(=references) pseudo feature block
412
   *    "references_inline": boolean
413
   *    "sort_elements": SORT_ASC, SORT_DESC, NULL    // whether and how to sort the elements
414
   *    "element_tag": span | div                     // only applies if "as_list" is NULL
415
   *  }
416
   */
417
  function get_feature_block_settings(){
418
    // the default must conform to the default paramter values of
419
    // compose_cdm_feature_block_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
420
    // theme_cdm_descriptionElementTextData() : asListElement = NULL
421

    
422
    // currently only element_tag is used.
423
    $default = array(
424
      'as_list' => 'ul',
425
      'link_to_reference' => FALSE,
426
      'references_inline' => TRUE,
427
      'sort_elements' => FALSE,
428
      'glue' => '',
429
      'element_tag'=> NULL
430
    );
431

    
432
    $cichorieae_default = array(
433
      'as_list' => 'div',
434
      'link_to_reference' => FALSE,
435
      'references_inline' => TRUE,
436
      'sort_elements' => FALSE,
437
      'glue' => '',
438
      'element_tag'=> 'div'
439
    );
440

    
441
    $default_theme = variable_get('theme_default', NULL);
442

    
443
    switch ($default_theme){
444
      case 'garland_cichorieae':
445
      case 'cyprus': // no longer used in production, but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
446
      case 'flore_afrique_centrale':
447
      case 'flora_malesiana':
448
      case 'flore_gabon':
449
        return $cichorieae_default;
450
      default:
451
       return $default;
452
    }
453
  }
454

    
455
/**
456
 * returns the current setting for the original source bibliography
457
 *
458
 * Caches internally
459
 *
460
 * @return array
461
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
462
 *   - 'enabled': 1|0
463
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
464
 */
465
function get_bibliography_settings($clear_cache = false){
466
  static $bibliography_settings = null;
467
  if(!$bibliography_settings || $clear_cache){
468
    $bibliography_settings = get_array_variable_merged(BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE, BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT);
469
  }
470
  return $bibliography_settings;
471
}
472

    
473
/**
474
 * @todo Please document this function.
475
 * @see http://drupal.org/node/1354
476
 */
477
function cdm_dataportal_menu_admin(&$items) {
478
  // Display section on admin/config page.
479
  $items['admin/config/cdm_dataportal'] = array(
480
    'title' => 'CDM Dataportal',
481
    'description' => 'Settings for the CDM DataPortal.',
482
    'position' => 'right',
483
    'weight' => 10,
484
    'page callback' => 'system_admin_menu_block_page',
485
    'access arguments' => array('administer cdm_dataportal'),
486
    'file' => 'system.admin.inc',
487
    'file path' => drupal_get_path('module', 'system'),
488
  );
489
  $items['admin/config/cdm_dataportal/settings'] = array(
490
    'title' => 'Settings',
491
    'description' => 'Settings for the CDM DataPortal.',
492
    'weight' => 0,
493
    'page callback' => 'drupal_get_form',
494
    'page arguments' => array('cdm_settings_general'),
495
    'access arguments' => array('administer cdm_dataportal'),
496
    'type' => MENU_NORMAL_ITEM,
497
  );
498
  $items['admin/config/cdm_dataportal/settings/general'] = array(
499
    'title' => 'General',
500
    'description' => 'General',
501
    'weight' => 0,
502
    'page callback' => 'drupal_get_form',
503
    'page arguments' => array('cdm_settings_general'),
504
    'access arguments' => array('administer cdm_dataportal'),
505
    'type' => MENU_DEFAULT_LOCAL_TASK,
506
  );
507

    
508
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
509
    'title' => 'Cache',
510
    'description' => 'Cache',
511
    'access arguments' => array('administer cdm_dataportal'),
512
    'page callback' => 'drupal_get_form',
513
    'page arguments' => array('cdm_settings_cache'),
514
    'weight' => 10,
515
    'type' => MENU_LOCAL_TASK,
516
  );
517

    
518
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
519
    'title' => 'Geo & Map',
520
    'description' => 'Geo & Map',
521
    'access arguments' => array('administer cdm_dataportal'),
522
    'page callback' => 'drupal_get_form',
523
    'page arguments' => array('cdm_settings_geo'),
524
    'weight' => 1,
525
    'type' => MENU_LOCAL_TASK,
526
  );
527

    
528
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
529
    'title' => 'Layout',
530
    'description' => 'Configure and adjust the layout of your DataPortal ',
531
    'access arguments' => array('administer cdm_dataportal'),
532
    'page callback' => 'drupal_get_form',
533
    'page arguments' => array('cdm_settings_layout'),
534
    'weight' => 2,
535
    'type' => MENU_LOCAL_TASK,
536
  );
537

    
538
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
539
    'title' => 'Taxon',
540
    'description' => 'Configure and adjust the layout of your DataPortal ',
541
    'access arguments' => array('administer cdm_dataportal'),
542
    'page callback' => 'drupal_get_form',
543
    'page arguments' => array('cdm_settings_layout_taxon'),
544
    'weight' => 1,
545
    'type' => MENU_LOCAL_TASK,
546
  );
547
  /*
548
  $items[] = array(
549
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
550
  'title' => t('Synonymy'),
551
  'description' => t('Configure and adjust the layout of your DataPortal '),
552
  'access' => user_access('administer cdm_dataportal'),
553
  'callback' => 'drupal_get_form',
554
  'callback arguments' => array('cdm_settings_layout_synonymy'),
555
  'weight' => 1,
556
  'type' => MENU_LOCAL_TASK,
557
  );
558

    
559
  $items[] = array(
560
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
561
  'title' => t('Specimens'),
562
  'description' => t('Configure and adjust the layout of your DataPortal '),
563
  'access' => user_access('administer cdm_dataportal'),
564
  'callback' => 'drupal_get_form',
565
  'callback arguments' => array('cdm_settings_layout_specimens'),
566
  'weight' => 1,
567
  'type' => MENU_LOCAL_TASK,
568
  );
569
  */
570
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
571
    'title' => 'Search',
572
    'description' => 'Configure and adjust the layout of your DataPortal ',
573
    'access arguments' => array('administer cdm_dataportal'),
574
    'page callback' => 'drupal_get_form',
575
    'page arguments' => array('cdm_settings_layout_search'),
576
    'weight' => 2,
577
    'type' => MENU_LOCAL_TASK,
578
  );
579

    
580
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
581
    'title' => 'Media',
582
    'description' => 'Configure and adjust the layout of your DataPortal ',
583
    'access arguments' => array('administer cdm_dataportal'),
584
    'page callback' => 'drupal_get_form',
585
    'page arguments' => array('cdm_settings_layout_media'),
586
    'weight' => 3,
587
    'type' => MENU_LOCAL_TASK,
588
  );
589

    
590
}
591

    
592
/**
593
 * @todo document this function.
594
 */
595
function cdm_help_general_cache() {
596
  $form = array();
597
  $form['cache_help'] = array(
598
    '#type' => 'fieldset',
599
    '#title' => t('Help'),
600
    '#collapsible' => TRUE,
601
    '#collapsed' => TRUE,
602
  );
603
  $form['cache_help']['test'] = array('#value' => t('probando'));
604
  return drupal_render($form);
605
  $res = array();
606
  $res['default'] = drupal_render($help);
607
  return $res;
608
}
609

    
610
/**
611
 * Configures the settings form for the CDM-API module.
612
 *
613
 * @return array
614
 *   Drupal settings form.
615
 */
616
function cdm_settings_general() {
617

    
618
  $form['cdm_webservice'] = array(
619
    '#type' => 'fieldset',
620
    '#title' => t('CDM Server'),
621
    '#collapsible' => FALSE,
622
    '#collapsed' => FALSE,
623
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
624
        CDM data base to the web via RESTful web services and thus is the source of the data
625
        to be displayed by a CDM DataPotal.'),
626
  );
627

    
628
  $form['cdm_webservice']['cdm_webservice_url'] = array(
629
    '#type' => 'textfield',
630
    '#title' => t('CDM web service URL') . ':',
631
    '#description' => t('This is the URL to the CDM-Server exposing your data
632
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
633
    '#default_value' => variable_get('cdm_webservice_url', NULL),
634
  );
635

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

    
643
  $form['cdm_webservice']['freetext_index'] = array(
644
    '#type' => 'fieldset',
645
    '#title' => t('Freetext index'),
646
    '#collapsible' => FALSE,
647
    '#collapsed' => FALSE,
648
  );
649

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

    
662
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
663
  $trigger_link_options = array(
664
    'attributes' => array(
665
      'class' => 'index-trigger',
666
    ),
667
  );
668
  $form['cdm_webservice']['freetext_index']['operations'] = array(
669
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
670
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
671
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
672
      ))
673
    . '<div id="index-progress"></div></div>',
674
  );
675
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
676

    
677
  $form['cdm_webservice']['proxy'] = array(
678
    '#type' => 'fieldset',
679
    '#title' => t('Proxy'),
680
    '#collapsible' => TRUE,
681
    '#collapsed' => TRUE,
682
  );
683

    
684
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
685
    '#type' => 'textfield',
686
    '#title' => t('Proxy URL') . ':',
687
    '#description' => t('If this proxy url is set the cdm api tries
688
    to connect the web service over the given proxy server.
689
    Otherwise proxy usage is deactivated.'),
690
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
691
  );
692

    
693
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
694
    '#type' => 'textfield',
695
    '#title' => t('Proxy port') . ':',
696
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
697
  );
698

    
699
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
700
    '#type' => 'textfield',
701
    '#title' => t('Login') . ':',
702
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
703
  );
704

    
705
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
706
    '#type' => 'textfield',
707
    '#title' => t('Password') . ':',
708
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
709
  );
710

    
711
  // TODO: settings are still incomplete, compare with
712
  // trunk/dataportal/inc/config_default.php.inc.
713
  $form['taxon_tree'] = array(
714
    '#type' => 'fieldset',
715
    '#title' => t('Taxon Tree'),
716
    '#collapsible' => FALSE,
717
    '#collapsed' => TRUE,
718
    '#description' => t('<p>When you explore your collection, you can navigate
719
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
720
      able to navigate through your collection the
721
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
722
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
723
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
724
      </a></p>'),
725
  );
726

    
727
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
728
    '#type' => 'select',
729
    '#title' => t('Available classifications') . ':',
730
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
731
    '#options' => cdm_get_taxontrees_as_options(),
732
    '#description' => t('Select the default taxa classification for your
733
      <em>taxon tree</em>, the other classifications will be also available but
734
      with a manual user change.'),
735
  );
736

    
737
  $form['taxon_tree']['taxontree_ranklimit'] = array(
738
    '#type' => 'select',
739
    '#title' => t('Rank of highest displayed taxon') . ':',
740
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
741
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
742
    '#options' => cdm_rankVocabulary_as_option(),
743
    '#description' => t('This is the rank of the highest displayed taxon in the
744
      <em>taxon tree</em>. You can select here which rank should be at the top
745
      level of the tree structure.'),
746
  );
747

    
748
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
749
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
750
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
751
      '#type' => 'checkboxes',
752
      '#title' => t('Included Classifications') . ':',
753
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
754
      '#options' => cdm_get_taxontrees_as_options(),
755
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
756
  );
757

    
758
  $form['distribution'] = array(
759
      '#type' => 'fieldset',
760
      '#title' => t('Distributions'),
761
      '#collapsible' => FALSE,
762
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
763
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
764
          '<p>
765
          </p>',
766
  );
767

    
768
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
769
      '#type' => 'fieldset',
770
      '#title' => 'Distribution filter',
771
      '#collapsible' => FALSE,
772
      '#collapsed' => FALSE,
773
      '#tree' => TRUE,
774
      '#description' => 'The Distribution filter offers the following options
775
      <ul>
776
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
777
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
778
      <li><strong>Marked area filter:</strong>Skip distributions where the area has a Marker with one of the specified MarkerTypes</li>
779
      </ul>'
780
  );
781

    
782
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
783
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
784
      '#type' => 'checkboxes',
785
      '#title' => 'Filter rules',
786
      '#default_value' => $cdm_distribution_filter['filter_rules'],
787
      '#options' => array(
788
          'statusOrderPreference' => 'Status order preference rule',
789
          'subAreaPreference' => 'Sub area preference rule'
790
      ),
791
  );
792

    
793
  $marker_type_options = cdm_terms_as_options( cdm_ws_fetch_all('term', array('class' => 'MarkerType' )) );
794
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hideMarkedAreas'] = array(
795
      '#type' => 'checkboxes',
796
      '#title' => 'Hide marked area filter',
797
      '#default_value' => $cdm_distribution_filter['hideMarkedAreas'],
798
      '#options' => $marker_type_options,
799
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
800
  );
801

    
802
  $form['aggregation'] = array(
803
      '#type' => 'fieldset',
804
      '#title' => t('Aggregation of data'),
805
      '#collapsible' => FALSE,
806
      '#description' => 'This section covers the different aspects of aggregating information.
807
          <p>
808
          </p>',
809
  );
810

    
811
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
812
      '#type' => 'checkboxes',
813
      '#title' => 'Taxon media filter',
814
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
815
      '#options' => array(
816
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
817
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
818
          'includeOccurrences' => 'Media related to specimens and occurrences',
819
      ),
820
      '#description' => 'This filter configures which images should be taken into account.',
821
  );
822

    
823
  $form['aggregation']['notice'] = array(
824
      '#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
825
          want to make use of the caching capabilities of the dataportal.',
826
  );
827

    
828
  $form['aggregation']['media_aggregation'] = array(
829
      '#type' => 'fieldset',
830
      '#title' => t('Media aggregation'),
831
      '#collapsible' => FALSE,
832
      '#collapsed' => TRUE,
833
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
834

    
835
  );
836
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
837
      '#type' => 'select',
838
      '#title' => t('Aggregation of taxon pictures') . ':',
839
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
840
      '#options' => array(
841
          0 => "Show only pictures of the current taxon",
842
          1 => "Include pictures of taxonomic children",
843
      ),
844
      '#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."),
845
  );
846

    
847
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
848
      '#type' => 'fieldset',
849
      '#attributes' => array('class'=>array('clearfix')),
850
      '#title' => t('Aggregation via taxon relationsships'),
851
      '#collapsible' => TRUE,
852
      '#collapsed' => TRUE,
853
      '#tree' => TRUE,
854
      '#description' => t('Information on taxa will be aggregated along the below chosen
855
          taxon relation ships. This will affect images and occurrences (specimens).
856
          Taxon relation ships are directed and point form one taxon to another. The taxon
857
          relationships to be taken into accunt can therefore configured for the direct direction
858
          and for the inverse.'),
859
  );
860

    
861
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
862
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
863

    
864
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
865
      '#type' => 'checkboxes',
866
      '#title' => t('Direct'),
867
      '#options' => $taxonRelationshipTypeOptions,
868
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
869
  );
870
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
871
      '#type' => 'checkboxes',
872
      '#title' => t('Invers'),
873
      '#options' => $taxonRelationshipTypeOptions,
874
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
875
  );
876

    
877
  // ----------------------
878
  $form['cdm_js_devel_mode'] = array(
879
      '#type' => 'checkbox',
880
      '#title' => 'Java-script developer mode',
881
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
882
      '#description' => 'In production envirionments the java script libraries
883
      the cdm_dataportal is making use of are compressed and optimized. This
884
      is good for performance but a caveat if you need to debug java-script. When the
885
      java-script developer mode is enabled the uncompressed and commented developer
886
      versions of java-script libraries will be used where possible.
887
      <br/><strong>Do not use this option in production!</strong>'
888
  );
889
  // ----------------------
890
  $form['cdm_debug_mode'] = array(
891
      '#type' => 'checkbox',
892
      '#title' => 'CDM page debug mode',
893
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
894
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
895
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
896
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
897
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
898
      The log is written by the drupal devel module function <code>dd()</code>.
899
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
900
  );
901

    
902
  // Comment @WA: D7 form api does not support reset buttons,
903
  // so to mimic the D5 reset button we add one like this.
904
  $form['actions']['reset'] = array(
905
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
906
    '#weight' => 1000,
907
  );
908

    
909
  $form['#submit'][] = 'cdm_settings_general_submit';
910

    
911
  return system_settings_form($form);
912
}
913

    
914

    
915
/**
916
 * LAYOUT settings
917
 * @return
918
 *   todo
919
 */
920
function cdm_settings_layout() {
921

    
922
  $form = array();
923

    
924
  $form['about'] = array(
925
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
926
      layout. If you want to configure the specific sites layout visit the
927
      respective configuration site for taxon, search or media.') . '</p>',
928
  );
929

    
930
  // ---- footnotes --- //
931
  $form['footnotes'] = array(
932
    '#type' => 'fieldset',
933
    '#title' => t('Footnotes'),
934
    '#collapsible' => FALSE,
935
    '#collapsed' => FALSE,
936
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
937
      media or distribution areas may have annotations or footnotes. When the
938
      footnotes are enabled they will be visible (if they exist).'),
939
  );
940

    
941
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
942
    '#type' => 'checkbox',
943
    '#title' => t('Do not show footnotes'),
944
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
945
    '#description' => t('Check this if you do not want to show any footnotes'),
946
  );
947

    
948
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
949
    '#type' => 'checkbox',
950
    '#title' => t('Do not show annotations footnotes'),
951
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
952
    '#description' => t('Check this if you do not want to show annotation footnotes'),
953
  );
954

    
955
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType', SORT_ASC);
956
  // Additional option for the NULL case.
957
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
958
  $form['footnotes']['annotations_types_as_footnotes'] = array(
959
    '#type' => 'checkboxes',
960
    '#title' => t('Annotation types as footnotes'),
961
    '#description' => t("Only annotations of the selected type will be displayed
962
       as footnotes. You may want to turn 'technical annotations' off."),
963
    '#options' => $annotationTypeOptions,
964
  );
965
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
966
  if (!empty($annotationsTypesAsFootnotes)) {
967
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
968
  }
969

    
970
  // ---- original source --- //
971
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
972
      '#type' => 'fieldset',
973
      '#tree' => TRUE,
974
      '#title' => t('Source Citations'),
975
      '#collapsible' => FALSE,
976
      '#collapsed' => FALSE,
977
  );
978

    
979
  $bibliography_settings = get_bibliography_settings(true);
980

    
981
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
982
      '#type' => 'checkbox',
983
      '#title' => t('Original Source in bibliography'),
984
      '#default_value' => $bibliography_settings['enabled'],
985
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
986
       annotations in each feature block.'),
987
  );
988

    
989
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
990
    '#type' => 'select',
991
    '#title' => t('The format of the key numerals'),
992
    '#default_value' => $bibliography_settings['key_format'],
993
    '#options' => array('latin' => 'Latin',
994
      'ROMAN' => 'Roman (upper case)',
995
      'roman' => 'Roman (lower case)',
996
      'ALPHA'=> 'Alphabet (upper case)',
997
      'alpha' => 'Alphabet (lower case)')
998
  );
999

    
1000
  // --- Advanced Search --- //
1001
  $form['asearch'] = array(
1002
    '#type' => 'fieldset',
1003
    '#title' => t('Advanced search'),
1004
    '#collapsible' => FALSE,
1005
    '#collapsed' => FALSE,
1006
  );
1007

    
1008
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1009
    '#type' => 'checkbox',
1010
    '#title' => t('Show advanced search link'),
1011
    '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1012
    '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1013
  );
1014

    
1015
  // ---- Taxon Name Rendering --- //
1016
  $form['taxon_name'] = array(
1017
      '#type' => 'fieldset',
1018
      '#title' => t('Taxon name display'),
1019
      '#collapsible' => TRUE,
1020
      '#collapsed' => TRUE,
1021
      '#description' => t('The display of taxon names is configured by two parts.'
1022
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
1023
          . 'The name parts are defined in the <stong>part definitions</strong>'),
1024
  );
1025

    
1026
  drupal_add_js(
1027
      'jQuery(document).ready( function( ) {
1028
         // pretty print json
1029
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
1030
         var obj = JSON.parse(json_text);
1031
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
1032

    
1033
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
1034
         obj = JSON.parse(json_text);
1035
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
1036
       });'
1037
      ,array(
1038
          'type' => 'inline',
1039
          'scope' => 'footer'
1040
      )
1041
  );
1042

    
1043
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1044

    
1045
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1046
      '#type' => 'textarea',
1047
      '#title' => t('Part definitions'),
1048
      '#element_validate' => array('form_element_validate_json'),
1049
      '#default_value' =>  json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions)),
1050
      '#description' => '
1051
          <p>
1052
          (Clearing the text area will reset it to the default)
1053
          </p>
1054
          <p>
1055
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1056
          </p>
1057
          <p>
1058
           A full taxon name plus additional information can consist of the following elements:
1059
          <ul>
1060
             <li>name: the taxon name inclugin rank nbut without author</li>
1061
             <li>authors:  The authors of a reference, also used in taxon names</li>
1062
             <li>reference: the nomenclatural reference,</li>
1063
             <li>microreference:  Volume, page number etc.</li>
1064
             <li>status:  The nomenclatural status of a name</li>
1065
             <li>description: name descriptions like protologues etc ...</li>
1066
          </ul>
1067
          </p>
1068
          <p>
1069
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1070
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1071
           The following parts can be formed and are recognized by the system:
1072
          <ul>
1073
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1074
            <li>authorshipPart: the author (for example: "L.")</li>
1075
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1076
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1077
               be combined when a link to the taxon is rendered.</li>
1078
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1079
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1080
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1081
            <li>statusPart: the nomenclatorical status</li>
1082
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1083
          </ul>
1084
          </p>
1085
          <p>
1086
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1087
           specific parts part definitions:
1088
          <ul>
1089
            <li>BotanicalName</li>
1090
            <li>ZoologicalName</li>
1091
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1092
          </ul>
1093
           An example:
1094
          <pre>
1095
           {
1096
            "ZoologicalName": {
1097
              "namePart": {
1098
                "name": true
1099
              },
1100
              "referencePart": {
1101
                "authors": true
1102
              },
1103
              "microreferencePart": {
1104
                "microreference": true
1105
              },
1106
              "statusPart": {
1107
                "status": true
1108
              },
1109
              "descriptionPart": {
1110
                "description": true
1111
              }
1112
            },
1113
            "BotanicalName": {
1114
              "namePart": {
1115
                "name": true,
1116
                "authors": true
1117
              },
1118
              "referencePart": {
1119
                "reference": true,
1120
                "microreference": true
1121
              },
1122
              "statusPart": {
1123
                "status": true
1124
              },
1125
              "descriptionPart": {
1126
                "description": true
1127
              }
1128
            }
1129
          }
1130
           </pre>',
1131
  );
1132

    
1133
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1134

    
1135
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1136
      '#type' => 'textarea',
1137
      '#title' => t('Name render templates'),
1138
      '#element_validate' => array('form_element_validate_json'),
1139
      '#default_value' =>  json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates)),
1140
      '#description' => '
1141
          <p>
1142
          (Clearing the text area will reset it to the default)
1143
          </p>
1144
          <p>
1145
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1146
          render path. The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1147
          The following render Path keys are curretly recognized:
1148
          <ul>
1149
            <li>list_of_taxa</li>
1150
            <li>acceptedFor</li>
1151
            <li>homonym</li>
1152
            <li>taxon_page_synonymy</li>
1153
            <li>typedesignations</li>
1154
            <li>taxon_page_title</li>
1155
            <li>polytomousKey</li>
1156
            <li>na: name + authorship</li>
1157
            <li>nar:name + authorship + reference</li>
1158
            <li>#DEFAULT</li>
1159
          </ul>
1160
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1161
          array element should be a comma separated list of render paths, without any whitespace!.
1162
          </p>
1163
          <p>
1164
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1165
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1166
          <p>
1167
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1168
          The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
1169
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1170
          links if the paramters $nameLink or $refenceLink are given to the name render function
1171
          (this is hard coded and cannot be configured here).',
1172
  );
1173

    
1174
  // @WA: D7 form api does not support reset buttons,
1175
  // so to mimic the D5 reset button we add one like this.
1176
  $form['actions']['reset'] = array(
1177
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1178
    '#weight' => 1000,
1179
  );
1180

    
1181
  $form['#submit'] = array('submit_json_as_php_array');
1182
  // #json_elements especially defined for submit_json_as_php_array()
1183
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1184
  return system_settings_form($form);
1185
}
1186

    
1187

    
1188
/**
1189
 * @todo Please document this function.
1190
 * @see http://drupal.org/node/1354
1191
 */
1192
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1193
  $form[$form_name] = array(
1194
    '#type' => 'fieldset',
1195
    '#title' => t($form_title),
1196
    '#collapsible' => TRUE,
1197
    '#collapsed' => $collapsed,
1198
    '#tree' => TRUE,
1199
    '#description' => t($form_description),
1200
  );
1201

    
1202
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1203
  $gallery_settings = variable_get($form_name, $default_values);
1204
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1205
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1206
    /*
1207
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1208
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1209
    '#type' => 'textfield',
1210
    '#title' => t('Search Page Size'),
1211
    '#default_value' => $test,
1212
    '#description' => t('Number of Names to display per page in search results.')
1213
    );
1214
    */
1215
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1216
      '#type' => 'checkbox',
1217
      '#title' => t('Show media thumbnails for accepted taxa'),
1218
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1219
    );
1220

    
1221
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1222
      '#type' => 'checkbox',
1223
      '#title' => t('Show media thumbnails for synonyms'),
1224
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1225
      '#description' => '',
1226
    );
1227
  }
1228

    
1229
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1230
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1231
    '#type' => 'checkbox',
1232
    '#title' => t('Show captions under thumbnails'),
1233
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1234
    '#description' => '',
1235
  );
1236

    
1237
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1238
    '#type' => 'textfield',
1239
    '#title' => t('Thumbnail size') . ':',
1240
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1241
    '#description' => t('Select the size of each individual thumbnail.'),
1242
  );
1243

    
1244
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1245
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1246
      '#type' => 'textfield',
1247
      '#title' => t('Number of columns') . ':',
1248
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1249
      '#description' => t('Group the thumbnails in columns: select how many
1250
        columns the gallery should display.'),
1251
    );
1252
  }
1253

    
1254
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1255
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1256
      '#type' => 'textfield',
1257
      '#title' => t('Maximum number of rows') . ':',
1258
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1259
      '#description' => t('You can group the thumbnails in rows, select in how
1260
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1261
        If you want an unlimited number of rows please set to 0.'),
1262
    );
1263
  }
1264

    
1265
  return $form;
1266
}
1267

    
1268
/**
1269
 * @todo document this function.
1270
 */
1271
function cdm_settings_layout_taxon() {
1272
  $collapsed = FALSE;
1273
  $form = array();
1274

    
1275
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1276

    
1277
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1278
      '#type' => 'checkbox',
1279
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1280
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1281
      '#description' => t('<p>If checked the link to search results is rendered at
1282
       the top of the taxon site. Clicking on the link the last search performed
1283
       is rendered again.</p>'),
1284
  );
1285

    
1286
  // --------- TABBED TAXON ------- //
1287
  $form['taxon_tabs'] = array(
1288
    '#type' => 'fieldset',
1289
    '#title' => t('Taxon tabs'),
1290
    '#collapsible' => TRUE,
1291
    '#collapsed' => FALSE,
1292
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1293
      be splitted in four diferent tabs; General, Synonymy, Images and
1294
      Specimens. If the taxon has no information for any of the tabs/sections
1295
      such tab will be not displayed.'),
1296
  );
1297

    
1298
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1299
    '#type' => 'checkbox',
1300
    '#title' => t('Tabbed taxon page'),
1301
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1302
    '#description' => t('<p>If selected split the taxon page into individual
1303
      tabs for description, images, synonymy and specimens. If not the taxon
1304
      data is rendered as a long single page without tabs.</p>'),
1305
  );
1306

    
1307
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1308
    '#type' => 'checkboxes',
1309
    '#title' => t('Tabs visibility options') . ':',
1310
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1311
    '#options' => get_taxon_options_list(),
1312
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1313
  );
1314

    
1315
  // WEIGHT
1316
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1317
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1318
      '#tree' => true
1319
  );
1320
  // Weights range from -delta to +delta, so delta should be at least half
1321
  // of the amount of tabs present.
1322
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1323
  foreach (get_taxon_tabs_list() as $label) {
1324
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1325
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1326
        '#title' => $label,
1327
        '#type'  => 'weight',
1328
        '#default_value' => $taxontabs_weights[$key],
1329
        '#delta' => $tab_weight_delta
1330
    );
1331
  }
1332

    
1333
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1334
    '#type' => 'select',
1335
    '#title' => t('Default tab to display') . ':',
1336
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1337
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1338
    '#description' => t('<p>Select the default tab to display when visiting a
1339
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1340
      <strong>Note:</strong> After performing a search and clicking in any
1341
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1342
      taxon and not the above selected tab.'),
1343
  );
1344

    
1345
  /* ======  TAXON_PROFILE ====== */
1346
  $form['taxon_profile'] = array(
1347
    '#type' => 'fieldset',
1348
    '#title' => t('Taxon profile (tab)'),
1349
    '#description' => t('<p>This section covers the settings related to the taxon
1350
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1351
    '#collapsible' => TRUE,
1352
    '#collapsed' => TRUE,
1353
  );
1354

    
1355
  // ---- PROFILE PICTURE ----//
1356

    
1357
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1358
    '#type' => 'fieldset',
1359
    '#tree' => TRUE,
1360
    '#title' => t('Taxon profile picture'),
1361
    '#collapsible' => TRUE,
1362
    '#collapsed' => FALSE,
1363
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1364
  );
1365

    
1366
  //FIXME migrate variables:
1367
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1368
  // FIXME
1369
  //  eanable file modul in profile and in update
1370

    
1371
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1372
  /*
1373
   * 'show' => 1,
1374
   * 'maxextend' => 184,
1375
   * 'media_uri_query' => ''
1376
   * 'custom_placeholder_image_on' => 1,
1377
   * 'custom_placeholder_image_fid' => ''
1378
   */
1379
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1380
    '#type' => 'checkbox',
1381
    '#title' => t('Enable profil picture'),
1382
    '#description' => t('Show the profil picture.'),
1383
    '#default_value' => $taxon_profile_image_settings['show'],
1384
  );
1385

    
1386
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1387
      '#type' => 'textfield',
1388
      '#tree' => TRUE,
1389
      '#title' => t('Profil picture maximum extend'),
1390
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1391
      '#field_suffix' => 'px',
1392
      '#maxlength' => 4,
1393
      '#size' => 4,
1394
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1395
  );
1396

    
1397
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1398
      '#type' => 'textfield',
1399
      '#tree' => TRUE,
1400
      '#title' => t('Additional URI query parameter'),
1401
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1402
      '#maxlength' => 1024,
1403
      '#size' => 60,
1404
      '#description' => t('Additional query parameters to be used when requesting for the '
1405
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1406
          . 'The query parameters will be appendend to the uri of the media representation part'
1407
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1408
  );
1409

    
1410
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1411
      '#type' => 'checkbox',
1412
      '#title' => t('Use a custom placeholder image'),
1413
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1414
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1415
  );
1416

    
1417
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1418
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1419
        '#type' => 'managed_file',
1420
        '#title' => t('Custom placeholder image file'),
1421
        '#progress_indicator' => 'bar',
1422
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1423
    //       '#name' => 'custom_placeholder_image',
1424
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1425
    );
1426

    
1427
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1428
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1429
      $url = file_create_url($profile_image_file->uri);
1430
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1431
                '#type' => 'item',
1432
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1433
      );
1434
    }
1435
  } else {
1436
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1437
        '#type' => 'hidden',
1438
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1439
    );
1440
  }
1441

    
1442

    
1443

    
1444
  $options = cdm_rankVocabulary_as_option();
1445
  array_unshift($options, '-- DISABLED --');
1446
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1447
    '#type' => 'select',
1448
    '#title' => t('Hide profile picture for higher ranks') . ':',
1449
    '#default_value' => variable_get('image_hide_rank', '0'),
1450
    '#options' => $options,
1451
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1452
  );
1453

    
1454
  // -- MEDIA THUMBNAILS -- //
1455
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1456
  $form_title = 'Taxon Profile Images';
1457
  $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>';
1458
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1459

    
1460
  // ---- FEATURE TREE ---- //
1461
  $form['taxon_profile']['feature_trees'] = array(
1462
    '#type' => 'fieldset',
1463
    '#title' => t('Features'),
1464
    '#collapsible' => TRUE,
1465
    '#collapsed' => FALSE,
1466
    '#description' => t("This section covers settings related to the taxon's
1467
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1468
      features such as description, distribution, common names, etc. that Drupal
1469
      will render at the taxon profile page."),
1470
  );
1471
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1472
  $saved_uuid = variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1473
  if(!isset($featureTrees['options'][$saved_uuid])) {
1474
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1475
  }
1476
  $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
1477
    '#type' => 'radios',
1478
    '#title' => t('Taxon profile sections') . ':',
1479
    '#default_value' => $saved_uuid,
1480
    '#options' =>  $featureTrees['options'],
1481
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1482
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1483
    '#description' => t('Select the Feature Tree to be displayed at the taxon
1484
      profile. Click "Show Details" to see the Feature Tree elements.'
1485
    ),
1486
  );
1487
  $featureTrees = cdm_get_featureTrees_as_options();
1488
  $saved_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1489
  if(!isset($featureTrees['options'][$saved_uuid])) {
1490
    $saved_uuid = NULL;
1491
  }
1492
  $form['taxon_profile']['feature_trees'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
1493
    '#type' => 'radios',
1494
    '#title' => t('Natural language representation of structured descriptions') . ':',
1495
    '#default_value' => $saved_uuid,
1496
    '#options' => $featureTrees['options'],
1497
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1498
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1499
    '#description' => t('Taxon descriptions can be stored in a highly structured
1500
      form. The feature tree selected here will be used to generate textual
1501
      representation in natural language.'
1502
    ),
1503
  );
1504

    
1505
  // ---- LAYOUT PER FEATURE ---- //
1506
  $feature_tree = get_profile_featureTree();
1507
  if (isset($feature_tree->root->childNodes)) {
1508

    
1509
    $form_feature_list_layout = array(
1510
      '#title' => t('Taxon profile layout'),
1511
      '#collapsible' => TRUE,
1512
      '#collapsed' => FALSE,
1513
      '#type' => 'fieldset',
1514
      '#description' => t('Will be available in a future release.'),
1515
    );
1516

    
1517
    $feature_list_layout_settings_disabled = TRUE;
1518
    foreach ($feature_tree->root->childNodes as $featureNode) {
1519

    
1520
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1521
        // Must not exceed 45 characters !!!
1522
        $subform_id = LAYOUT_SETTING_PREFIX . $featureNode->feature->uuid;
1523

    
1524
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1525
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
1526

    
1527
        $form_feature_list_layout[$subform_id] = array(
1528
          '#tree' => TRUE,
1529
          '#title' => 'test' . $featureNode->feature->representation_L10n,
1530
          '#collapsible' => FALSE,
1531
          '#collapsed' => FALSE,
1532
          '#type' => 'fieldset',
1533
          '#description' => t(''),
1534
        );
1535

    
1536
        $form_feature_list_layout[$subform_id]['enabled'] = array(
1537
          '#type' => 'checkbox',
1538
          '#title' => t('Enable'),
1539
          '#default_value' => $settings['enabled'],
1540
          '#description' => t('Enable user defined layout for this feature'),
1541
        );
1542

    
1543
        $form_feature_list_layout[$subform_id]['enclosingTag'] = array(
1544
          '#type' => 'textfield',
1545
          '#title' => t('Enclosing tag'),
1546
          '#disabled' => !$settings['enabled'],
1547
          '#default_value' => $settings['enclosingTag'],
1548
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['enclosingTag'] . "</code>'",
1549
        );
1550

    
1551
        $form_feature_list_layout[$subform_id]['entryEnclosingTag'] = array(
1552
          '#type' => 'textfield',
1553
          '#title' => t('Entry enclosing tag'),
1554
          '#disabled' => !$settings['enabled'],
1555
          '#default_value' => $settings['entryEnclosingTag'],
1556
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['entryEnclosingTag'] . "</code>'",
1557
        );
1558

    
1559
        $form_feature_list_layout[$subform_id]['glue'] = array(
1560
          '#type' => 'textfield',
1561
          '#title' => t('Glue'),
1562
          '#disabled' => !$settings['enabled'],
1563
          '#default_value' => $settings['glue'],
1564
          '#description' => t('Default is: ') . "'<code>" . $systemDefaults['glue'] . "</code>'",
1565
        );
1566

    
1567
      }
1568

    
1569
      $form['taxon_profile']['feature_list_layout'] = $form_feature_list_layout;
1570
    }
1571
  }
1572

    
1573
  // ---- DISTRIBUTION LAYOUT ---- //
1574
  $form['taxon_profile']['distribution_layout'] = array(
1575
    '#title' => t('Distribution'),
1576
    '#collapsible' => TRUE,
1577
    '#collapsed' => FALSE,
1578
    '#type' => 'fieldset',
1579
    '#description' => t('Select if you want to sort or not the distribution text
1580
      located below the distribution map.'),
1581
  );
1582

    
1583
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1584
    '#type' => 'radios',
1585
    '#title' => t('Sort') . ':',
1586
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1587
    '#options' => array(
1588
      'NO_SORT' => t('Standard (No sort)'),
1589
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1590
    ),
1591
  );
1592

    
1593
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1594
    '#type' => 'checkbox',
1595
    '#title' => t('Show TextData elements on top of the map'),
1596
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1597
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1598
      elements on top of the map. Otherwise all <code>TextData</code>
1599
      distribution elements will be listed below the other area elements.
1600
      This option is useful if you need to have descriptive texts for each
1601
      distribution map.'),
1602
  );
1603

    
1604
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
1605
      '#type' => 'textarea',
1606
      '#title' => t('Custom status colors'),
1607
      '#element_validate' => array('form_element_validate_json'),
1608
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
1609
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
1610
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
1611
          reference list of the idInVocabulary values of absence and presence terms:
1612
<pre>
1613
Presence Term
1614
p	present
1615
pd	present: doubtfully present
1616
n	native
1617
nq	native: presence questionable
1618
nd	native: doubtfully native
1619
c	cultivated
1620
i	introduced
1621
iq	introduced: presence questionable
1622
id	introduced: doubtfully introduced (perhaps cultivated only)
1623
ip	introduced: uncertain degree of naturalisation
1624
ia	introduced: adventitious (casual)
1625
in	introduced: naturalized
1626
ic	introduced: cultivated
1627
e	endemic for the relevant area
1628
na	naturalised
1629
iv	invasive
1630

    
1631
AbsenceTerm
1632
a	absent
1633
f	reported in error
1634
nf	native: reported in error
1635
if	introduced: reported in error
1636
cf	cultivated: reported in error
1637
ne	native: formerly native
1638
ie	introduced: formerly introduced
1639

    
1640
</pre>'),
1641
  );
1642

    
1643

    
1644
  /* ====== SYNONYMY ====== */
1645
  $form['taxon_synonymy'] = array(
1646
    '#type' => 'fieldset',
1647
    '#title' => t('Taxon synonymy (tab)'),
1648
    '#collapsible' => TRUE,
1649
    '#collapsed' => TRUE,
1650
    '#description' => t('This section covers the settings related to the taxon
1651
      <strong>synonymy</strong> tab.'),
1652
  );
1653

    
1654
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1655
    '#type' => 'checkbox',
1656
    '#title' => t('Show accepted taxon on top of the synonymy'),
1657
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1658
    '#description' => t('If checked, the first homotypic taxon is a repetition
1659
      of the accepted taxon most likely with the full nomenclatural reference
1660
      (depending on the currently chosen theme).'),
1661
  );
1662

    
1663
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1664
    '#type' => 'checkbox',
1665
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1666
      coming from a synonym link.'),
1667
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1668
    '#description' => t('Check this if after doing a search and clicking on a
1669
      synonym you want to see the "accept of" text for the accepted synonym.'),
1670
  );
1671

    
1672
  /* === currently unused ===
1673
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1674
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1675
    '#type' => 'checkboxes',
1676
    '#title' => t('Display name relationships') . ':',
1677
    '#default_value' => variable_get('name_relationships_to_show', 0),
1678
    '#options' => $nameRelationshipTypeOptions,
1679
    '#description' => t('Select the name relationships you want to show for the
1680
      accepted taxa.'),
1681
  );
1682
 */
1683

    
1684
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
1685
    '#type' => 'checkbox',
1686
    '#title' => t('Show taxon relations ships of accepted taxon'),
1687
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1688
    '#description' => t('If this option is enabled the synonymy will show the
1689
      below selected taxon relationships of accepted taxa.'),
1690
  );
1691

    
1692
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1693
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
1694
    '#type' => 'checkboxes',
1695
    '#title' => t('Taxon relationship types') . ':',
1696
    '#description' => t('Only taxon relationships of the selected type will be
1697
      displayed'),
1698
    '#options' => $taxonRelationshipTypeOptions,
1699
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
1700
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
1701
  );
1702

    
1703
  // ====== SPECIMENS ====== //
1704
  $form['taxon_specimens'] = array(
1705
    '#type' => 'fieldset',
1706
    '#title' => t('Taxon specimens (tab)'),
1707
    '#collapsible' => TRUE,
1708
    '#collapsed' => TRUE,
1709
    '#description' => t('This section covers the settings related to the taxon
1710
      <strong>specimens</strong> tab.'),
1711
  );
1712

    
1713
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1714
  $saved_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1715
  if(!isset($featureTrees['options'][$saved_uuid])) {
1716
    $saved_uuid = UUID_DEFAULT_FEATURETREE;
1717
  }
1718
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
1719
      '#type' => 'radios',
1720
      '#title' => t('Specimen description feature tree') . ':',
1721
      '#default_value' => $saved_uuid,
1722
      '#options' =>  $featureTrees['options'],
1723
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1724
      '#options_suffixes' => $featureTrees['treeRepresentations'],
1725
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
1726
      ),
1727
  );
1728

    
1729
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
1730
  $form_title = t('Specimen media');
1731
  $form_description = t('Specimens may have media which is displayed at the
1732
     Specimen tab/section as a gallery. It is possible to configure the
1733
     thumbnails gallery here, however for configuring how a single media should
1734
     be displayed please go to !url.</p>',
1735
     array(
1736
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
1737
     ));
1738
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1739

    
1740
  // --- MEDIA GALLERY ---- //
1741
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
1742
  $form_title = 'Media gallery (tab)';
1743
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
1744
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
1745
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
1746
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
1747
   <p><strong>Note:</strong> These settings are only taken into account when the standard
1748
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
1749
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
1750

    
1751
  // Comment @WA: D7 form api does not support reset buttons,
1752
  // so to mimic the D5 reset button we add one like this.
1753
  $form['actions']['reset'] = array(
1754
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1755
    '#weight' => 1000,
1756
  );
1757
  return system_settings_form($form);
1758
}
1759

    
1760
/**
1761
 * @todo document this function.
1762
 */
1763
function cdm_settings_layout_search() {
1764

    
1765
  $form = array();
1766

    
1767
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
1768

    
1769
  $form['search_settings'] = array(
1770
    '#type' => 'fieldset',
1771
    '#title' => t('Taxa Search'),
1772
    '#collapsible' => FALSE,
1773
    '#collapsed' => FALSE,
1774
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
1775
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
1776
         where they can write the text to be searched. You can find Drupal block configuration
1777
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
1778
  );
1779

    
1780
  $form['search_settings']['simple_search_ignore_classification'] = array(
1781
      '#type' => 'checkbox',
1782
      '#title' => t('Ignore the chosen classification in simple search'),
1783
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
1784
      '#description' => t('The simple search, which can be executed via the search block,
1785
          will by default search on all classifications. Remove the tick if you want your
1786
          portal to search on the classification selected in the classification browser
1787
          selector.'),
1788
  );
1789

    
1790
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
1791
    '#type' => 'textfield',
1792
    '#title' => t('Results per page') . ':',
1793
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
1794
    '#description' => t('Number of results to display per page.'),
1795
  );
1796

    
1797
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
1798
  $form['search_settings']['cdm_search_taxa_mode'] = array(
1799
      '#type' => 'checkboxes',
1800
      '#title' => 'Search mode',
1801
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
1802
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
1803
          for the advance search form and the behaviour of the simple search form which always will behave according to the
1804
          defaults set here.',
1805
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
1806
      '#default_value' => $search_mode_default
1807
      );
1808

    
1809
  // --- SEARCH TAXA GALLERY ---- //
1810
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1811
  $collapsed = FALSE;
1812
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
1813
  $form_title = 'Taxa Search thumbnails';
1814
  $form_description = 'Search results may show thumbnails. ';
1815
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1816

    
1817
  // Comment @WA: D7 form api does not support reset buttons,
1818
  // so to mimic the D5 reset button we add one like this.
1819
  $form['actions']['reset'] = array(
1820
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1821
    '#weight' => 1000,
1822
  );
1823
  return system_settings_form($form);
1824
}
1825

    
1826
/**
1827
 * @todo document this function.
1828
 */
1829
function cdm_settings_layout_media() {
1830

    
1831
  $form = array();
1832

    
1833
  $form['media_settings'] = array(
1834
    '#type' => 'fieldset',
1835
    '#title' => t('Media settings'),
1836
    '#collapsible' => FALSE,
1837
    '#collapsed' => FALSE,
1838
    '#description' => 'This section covers layout settings for media pages.'
1839
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
1840
  );
1841

    
1842
  $form['media_settings']['image_gallery_viewer'] = array(
1843
    '#type' => 'select',
1844
    '#title' => t('Image viewer') . ':',
1845
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
1846
    '#options' => array(
1847
      'default' => t('Standard image viewer'),
1848
      'fsi' => t('FSI viewer (requires FSI server!)'),
1849
    ),
1850
  );
1851

    
1852
  // --- MEDIA GALLERY ---- //
1853
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
1854
  $form_title = 'Standard viewer';
1855
  $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>';
1856
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
1857
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
1858

    
1859
  // @WA: D7 form api does not support reset buttons,
1860
  // so to mimic the D5 reset button we add one like this.
1861
  $form['actions']['reset'] = array(
1862
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1863
    '#weight' => 1000,
1864
  );
1865
  return system_settings_form($form);
1866
}
1867

    
1868
/**
1869
 * GEOSERVICE and Map settings.
1870
 */
1871
function cdm_settings_geo($form, &$form_state) {
1872

    
1873
  $current_geoserver_settings = get_edit_map_service_settings();
1874
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
1875
  // The default layer must always be enabled
1876
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
1877
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
1878

    
1879
  $form = array();
1880

    
1881
  $dummy_distribution_query = NULL;
1882
  if($map_distribution['map_type'] != 1){
1883
    // we need to apply a dummy query since the map serice requires for image maps
1884
    // at least as and ad to be defined
1885
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
1886
  }
1887
  $form['map_preview'] = array(
1888
      '#type' => 'fieldset',
1889
      '#tree' => FALSE,
1890
      '#title' => t('Map preview'),
1891
      '#collapsible' => FALSE,
1892
      '#description' => 'The preview of the map'
1893
       . ($dummy_distribution_query != null ?
1894
           ' may not be accurate in case if image maps, please check the map display in the taxon pages.':
1895
           '.<br/>Hold down Strg and drag with your mouse to select a bbox to zoom to. <br/>The bbox of the visible area of the map is always displayed below the map.')
1896
  );
1897
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL,
1898
      array(
1899
          'move' => "this.cdmOpenlayersMap.printInfo",
1900
          '#execute' => "this.cdmOpenlayersMap.printInfo"
1901
      )
1902
  );
1903

    
1904

    
1905
  /*
1906
   * GEO SERVER
1907
   */
1908
  $form['edit_map_server'] = array(
1909
    '#type' => 'fieldset',
1910
    '#tree' => true,
1911
    '#title' => t('EDIT map service'),
1912
    '#collapsible' => TRUE,
1913
    '#collapsed' => TRUE,
1914
    '#description' => t('Configuration and selection of your geo server.
1915
      The Geo Server is responsible for generating the maps.'),
1916
  );
1917

    
1918
  $form['edit_map_server']['base_uri'] = array(
1919
    '#type' => 'select',
1920
    '#title' => t('EDIT map service') . ':',
1921
    '#default_value' => $current_geoserver_settings['base_uri'],
1922
    '#options' => unserialize(EDIT_MAPSERVER_URI),
1923
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
1924
  );
1925
  $form['edit_map_server']['version'] = array(
1926
      '#type' => 'select',
1927
      '#title' => t('Version') . ':',
1928
      '#default_value' => $current_geoserver_settings['version'],
1929
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
1930
      '#description' => t('The version of the EDIT map services'),
1931
  );
1932

    
1933
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1934
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1935
  $form['gmap_api_key'] = array(
1936
      '#type' => 'textfield',
1937
      '#title' => t('Google maps API key') . ':',
1938
      '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1939
      '#description' => t('If you want to use the Google Maps Layer, a key is
1940
      needed. If you need a key, visit
1941
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
1942
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
1943
      is the default key for the localhost (127.0.0.1).',
1944
      array('!localhostkey' => $localhostkey)),
1945
  );
1946

    
1947

    
1948
  /*
1949
   * MAP SETTINGS
1950
   */
1951

    
1952
  $form[CDM_MAP_DISTRIBUTION] = array(
1953
    '#type' => 'fieldset',
1954
    '#tree' => TRUE,
1955
    '#title' => t('Maps settings'),
1956
    '#collapsible' => TRUE,
1957
    '#collapsed' => TRUE,
1958
    '#description' => t('General configuration for all map types.'),
1959
  );
1960

    
1961
  /*
1962
   * settings for the distribution map are used also for specimens map!!!!
1963
   */
1964

    
1965
  $form[CDM_MAP_DISTRIBUTION]['width'] = array(
1966
    '#type' => 'textfield',
1967
    '#title' => 'Width',
1968
    '#default_value' => $map_distribution['width'],
1969
    '#maxlength' => 4,
1970
    '#size' => 4,
1971
    '#description' => 'Width of the map. To allow OSM baselayers to zoom out to the full extend of the world the map width must be
1972
      a multiple of 256px since the osm tiles from tile.openstreetmap.org have a size of 256px x 256px and frational zoom
1973
      levels are not possible in this case.',
1974
  );
1975
  $form[CDM_MAP_DISTRIBUTION]['height'] = array(
1976
      '#type' => 'textfield',
1977
      '#title' => 'Height',
1978
      '#default_value' => $map_distribution['height'],
1979
      '#maxlength' => 4,
1980
      '#size' => 4,
1981
      '#description' => 'Height of the map. Depending on the chosen base layer you may want to choose the height equal
1982
      to the width or half of the width. Any other aspect ratio is also possible if desired.',
1983
  );
1984

    
1985
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
1986
    '#type' => 'textfield',
1987
    '#title' => 'Bounding box',
1988
    '#default_value' => $map_distribution['bbox'],
1989
    '#description' => t('The bounding box (left, bottom, right, top) defines the area to be initially displayed in maps.
1990
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
1991
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
1992
      <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.
1993
      Hold down Strg and drag with your mouse to select a bbox to zoom to. The bbox of the visible area of the map is always displayed
1994
      below the map from where you can copy the bbox string.</p>'),
1995
  );
1996

    
1997
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
1998
    '#type' => 'checkbox',
1999
    '#title' => 'Display area labels',
2000
    '#default_value' => $map_distribution['show_labels'],
2001
    '#description' => t('The map will show name labels of the areas'),
2002
  );
2003

    
2004
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2005
    '#type' => 'textfield',
2006
    '#title' => 'Map caption',
2007
    '#default_value' => $map_distribution['caption'],
2008
    '#description' => t('The caption will be shown below the map.'),
2009
  );
2010

    
2011
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2012
    '#type' => 'textfield',
2013
    '#title' => 'Distribution layer opacity',
2014
    '#default_value' => $map_distribution['distribution_opacity'],
2015
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
2016
                           fully visible, while a value near to 0.0 will be not much visible.'),
2017
  );
2018

    
2019
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2020
    '#type' => 'radios',
2021
    '#title' => 'Map types',
2022
    '#options' => array(
2023
      1 => "OpenLayers dynamic map viewer",
2024
      0 => "Plain image",
2025
    ),
2026
    '#default_value' => $map_distribution['map_type'],
2027
    '#description' => 'Two different map types are available :
2028
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2029
      which allows zooming and panning. If enabled you can configure the default layer
2030
      (background of your maps) below.</li>
2031
      <li><em>Plain image</em>: The map will be static non interactive
2032
      image.</li></ul>',
2033
  );
2034
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2035

    
2036

    
2037
  // --- Plain Image Settings --- //
2038
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2039
    '#type' => 'fieldset',
2040
    '#title' => 'Plain image map settings',
2041
    '#tree' => TRUE,
2042
    '#collapsible' => TRUE,
2043
    '#collapsed' => $open_layers_is_enabled,
2044
    '#description' => 'The settings in this section are still expertimental
2045
      and can only be used with the EDIT map service version 1.1 or above.',
2046
  );
2047
  $edit_mapserver_version = get_edit_map_service_version_number();
2048
  if ($edit_mapserver_version < 1.1) {
2049
    $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>'
2050
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2051
  }
2052

    
2053
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2054
    '#type' => 'textfield',
2055
    '#title' => 'Background layer',
2056
    '#default_value' => $map_distribution['image_map']['base_layer'],
2057
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2058
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2059
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2060
    )),
2061
  );
2062

    
2063
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2064
    '#type' => 'textfield',
2065
    '#title' => 'Background color',
2066
    '#default_value' => $map_distribution['image_map']['bg_color'],
2067
  );
2068

    
2069
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2070
    '#type' => 'textfield',
2071
    '#title' => 'Background layer style',
2072
     // Only line color by now.
2073
    '#default_value' => $map_distribution['image_map']['layer_style'],
2074
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2075
  );
2076

    
2077
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2078
      '#type' => 'textfield',
2079
      '#title' => 'Projection',
2080
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2081
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2082
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2083
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2084
  );
2085

    
2086

    
2087
  // --- OpenLayers Settings --- //
2088
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2089
    '#type' => 'fieldset',
2090
    '#title' => 'OpenLayers settings',
2091
    '#tree' => TRUE,
2092
    '#collapsible' => TRUE,
2093
    '#collapsed' => !$open_layers_is_enabled,
2094
    '#description' => '',
2095
  );
2096

    
2097

    
2098
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2099
      '#type' => 'checkbox',
2100
      '#title' => 'Display outside max extent',
2101
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2102
      '#description' => t('Allows the map to display parts of the layers which are outside
2103
         the max extent if the aspect ratio of the map and of the baselayer
2104
         are not equal.'),
2105
  );
2106

    
2107

    
2108
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2109
      '#type' => 'checkbox',
2110
      '#title' => 'Show Layer Switcher',
2111
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2112
      '#description' => 'The Layer Switcher control displays a table of contents
2113
      for the map.  This allows the user interface to switch between
2114
      base layers and to show or hide overlays.  By default the switcher is
2115
      shown minimized on the right edge of the map, the user may expand it
2116
      by clicking on the handle.',
2117
  );
2118

    
2119
  if (!$open_layers_is_enabled) {
2120
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2121
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2122
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2123
  }
2124

    
2125
  $baselayer_options = array(
2126
    /*
2127
   NOTICE: must correspond to the layers defined in
2128
   js/openlayers_,ap.js#getLayersByName()
2129
   */
2130
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
2131
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
2132
    // all others EPSG:900913
2133
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
2134
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2135
    'mapnik' => 'OpenStreetMap',
2136
    'mapquest_open' => "MapQuest",
2137
    'mapquest_sat' => "MapQuest Sattelite",
2138
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2139
    'gmap' => 'Google Streets',
2140
    'gsat' => 'Google Satellite',
2141
    'ghyb' => 'Google Hybrid',
2142
//     'veroad' => 'Virtual Earth Roads',
2143
//     'veaer' => 'Virtual Earth Aerial',
2144
//     'vehyb' => 'Virtual Earth Hybrid',
2145
    // 'yahoo' => 'Yahoo Street',
2146
    // 'yahoosat' => 'Yahoo Satellite',
2147
    // 'yahoohyb' => 'Yahoo Hybrid',
2148
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2149
  );
2150

    
2151
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2152
    '#type' => 'checkboxes_preferred',
2153
    '#title' => 'Base Layers',
2154
    '#options' => $baselayer_options,
2155
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2156
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2157
  );
2158

    
2159
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2160
      '#type' => 'fieldset',
2161
      '#title' => 'Custom WMS base layer',
2162
      '#tree' => TRUE,
2163
      '#collapsible' => FALSE,
2164
      '#collapsed' => FALSE,
2165
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2166
  );
2167

    
2168
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2169
      '#type' => 'textfield',
2170
      '#title' => 'Layer name',
2171
      // Only line color by now.
2172
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2173
      '#description' => 'A arbitrary name for the layer.',
2174
  );
2175
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2176
      '#type' => 'textfield',
2177
      '#title' => 'WMS url',
2178
      // Only line color by now.
2179
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2180
      '#description' => 'Base url for the WMS (e.g.  http://wms.jpl.nasa.gov/wms.cgi)'
2181
  );
2182
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2183
      '#type' => 'textarea',
2184
      '#title' => 'WMS parameters',
2185
      '#element_validate' => array('form_element_validate_json'),
2186
      // Only line color by now.
2187
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2188
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2189
<pre> {
2190
  "Layers": "topp:em_tiny_jan2003",
2191
  "Format": "image/png",
2192
  "BGCOLOR": "0xe0faff"
2193
}
2194
</pre>'
2195
  );
2196
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2197
      '#type' => 'textfield',
2198
      '#title' => 'Projection',
2199
      // Only line color by now.
2200
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2201
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2202
  );
2203
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2204
      '#type' => 'textfield',
2205
      '#maxlength' => 256,
2206
      '#title' => 'proj4js definition',
2207
      // Only line color by now.
2208
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2209
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2210
            The definitions for
2211
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2212
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2213
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2214
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2215
            choose to display the proj4js definition string.
2216
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2217
            <pre>
2218
+a         Semimajor radius of the ellipsoid axis
2219
+alpha     ? Used with Oblique Mercator and possibly a few others
2220
+axis      Axis orientation (new in 4.8.0)
2221
+b         Semiminor radius of the ellipsoid axis
2222
+datum     Datum name (see `proj -ld`)
2223
+ellps     Ellipsoid name (see `proj -le`)
2224
+k         Scaling factor (old name)
2225
+k_0       Scaling factor (new name)
2226
+lat_0     Latitude of origin
2227
+lat_1     Latitude of first standard parallel
2228
+lat_2     Latitude of second standard parallel
2229
+lat_ts    Latitude of true scale
2230
+lon_0     Central meridian
2231
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
2232
+lon_wrap  Center longitude to use for wrapping (see below)
2233
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
2234
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
2235
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
2236
+pm        Alternate prime meridian (typically a city name, see below)
2237
+proj      Projection name (see `proj -l`)
2238
+south     Denotes southern hemisphere UTM zone
2239
+to_meter  Multiplier to convert map units to 1.0m
2240
+towgs84   3 or 7 term datum transform parameters (see below)
2241
+units     meters, US survey feet, etc.
2242
+vto_meter vertical conversion to meters.
2243
+vunits    vertical units.
2244
+x_0       False easting
2245
+y_0       False northing
2246
+zone      UTM zone
2247
            </pre>
2248
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
2249
  );
2250
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
2251
      '#type' => 'textfield',
2252
      '#title' => 'Maximum extent',
2253
      // Only line color by now.
2254
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
2255
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
2256
  );
2257
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
2258
      '#type' => 'textfield',
2259
      '#title' => 'Units',
2260
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
2261
      '#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.'
2262
  );
2263

    
2264
  /*
2265
   * Map Legend
2266
   */
2267
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2268
    '#type' => 'fieldset',
2269
    '#title' => 'Map legend',
2270
    '#tree' => TRUE,
2271
    '#collapsible' => TRUE,
2272
    '#collapsed' => TRUE,
2273
    '#description' => 'Configure the maps legend.',
2274
  );
2275

    
2276
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2277
    '#type' => 'checkbox',
2278
    '#title' => 'Display a map legend',
2279
    '#default_value' => $map_distribution['legend']['show'],
2280
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2281
  );
2282

    
2283
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2284
    '#type' => 'textfield',
2285
    '#title' => 'Legend opacity',
2286
    '#default_value' => $map_distribution['legend']['opacity'],
2287
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2288
                         to 0.0 will be not much visible.',
2289
  );
2290

    
2291
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2292
    '#type' => 'textfield',
2293
    '#title' => 'Font size',
2294
    '#default_value' => $map_distribution['legend']['font_size'],
2295
    '#description' => 'Font size in pixels.',
2296
  );
2297

    
2298
  $fontStyles = array(
2299
    0 => "plane",
2300
    1 => "italic",
2301
  );
2302
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2303
    '#type' => 'select',
2304
    '#title' => 'Available font styles',
2305
    '#default_value' => $map_distribution['legend']['font_style'],
2306
    '#options' => $fontStyles,
2307
    '#description' => 'Select a font style for the map legend.',
2308
  );
2309

    
2310
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2311
    '#type' => 'textfield',
2312
    '#title' => 'Icon width',
2313
    '#default_value' => $map_distribution['legend']['icon_width'],
2314
    '#description' => 'Legend icon width in pixels.',
2315
  );
2316
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2317
    '#type' => 'textfield',
2318
    '#title' => 'Icon height',
2319
    '#default_value' => $map_distribution['legend']['icon_height'],
2320
    '#description' => 'Legend icon height in pixels.',
2321
  );
2322

    
2323
  // @WA: D7 form api does not support reset buttons,
2324
  // so to mimic the D5 reset button we add one like this.
2325
  $form['actions']['reset'] = array(
2326
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2327
    '#weight' => 1000,
2328
  );
2329

    
2330
  return system_settings_form($form);
2331
}
2332

    
2333
/**
2334
 * @todo document this function.
2335
 */
2336
function cdm_settings_cache() {
2337

    
2338
  $form = array();
2339

    
2340
  $form['cache_settings'] = array(
2341
    '#type' => 'fieldset',
2342
    '#title' => t('Cache Settings'),
2343
    '#collapsible' => FALSE,
2344
    '#collapsed' => FALSE,
2345
    '#description' => t('<p>When caching is enabled all single taxon sites are
2346
      stored in an internal drupal cache doing the portal response of taxa pages
2347
      faster. This is possible because the sites are loaded from the cache and
2348
      are not created from scratch.</p>'),
2349
  );
2350

    
2351
  $form['cache_settings']['cdm_webservice_cache'] = array(
2352
    '#type' => 'checkbox',
2353
    '#title' => t('<strong>Enable caching</strong>'),
2354
    '#options' => cdm_help_general_cache(),
2355
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2356
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2357
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2358
       application the changes will be not visible till the cache is erased.
2359
       Therefore developers should deactived this feature when they are working
2360
       on the CDM Dataportal Module.</p>'),
2361
  );
2362

    
2363
  $form['cache_settings']['cdm_run_cache'] = array(
2364
    '#markup' => cdm_view_cache_site(),
2365
  );
2366

    
2367
  // @WA: D7 form api does not support reset buttons,
2368
  // so to mimic the D5 reset button we add one like this.
2369
  $form['actions']['reset'] = array(
2370
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2371
    '#weight' => 1000,
2372
  );
2373
  return system_settings_form($form);
2374
}
2375

    
2376
/**
2377
 * Walk and cache all taxon pages.
2378
 */
2379
function cdm_view_cache_site() {
2380

    
2381
  $out = '';
2382

    
2383
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2384

    
2385
  $request_params = array();
2386
  $request_params['class'] = "Taxon";
2387

    
2388
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2389
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2390
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2391

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

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

    
2401
  // Comment @WA: A form within a form is not valid html and not needed here.
2402
  // Also, it would be recommended just to include this part of the form in the
2403
  // rest of the form array in cdm_settings_cache().
2404
  // $out .= '<form id="cache_site">';
2405
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2406
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2407
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2408
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2409
  // $out .= '</form>';
2410
  $out .= '</div>';
2411
  /*
2412
  foreach($taxonPager->records as $taxon){
2413
    cdm_dataportal_taxon_view($uuid);
2414
  }
2415
  */
2416
  return $out;
2417
}
2418

    
2419

    
2420
function cdm_settings_layout_taxon_submit($form, &$form_state){
2421
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2422
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2423
    if(is_object($file)){
2424
      $file->status = FILE_STATUS_PERMANENT;
2425
      file_save($file);
2426
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2427
    }
2428
  }
2429
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2430
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2431
    // we first need to set the variable to persist the changes setting
2432
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
2433
    menu_rebuild();
2434
  }
2435
}
2436

    
2437
function cdm_settings_layout_search_submit($form, &$form_state){
2438
  // the visibility of media thumbnails also affects the ui of the search results
2439
  // so reset the according session variable
2440
  //    1. in order to give the user immediate
2441
  //       feedback on potential setting changes
2442
  //    2. let refresh the default if it has changed
2443
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2444
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
2445
  }
2446
}
2447

    
2448
/**
2449
 * Form validation handler for cdm_settings_general
2450
 *
2451
 * @param $form
2452
 * @param $form_state
2453
 */
2454
function cdm_settings_general_validate($form, &$form_state) {
2455

    
2456
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2457
    $form_state['values']['cdm_webservice_url'] .= '/';
2458
  }
2459

    
2460
}
2461

    
2462
/**
2463
 * Form submit handler for settings general.
2464
 *
2465
 * tasks performed:
2466
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2467
 *
2468
 * @param $form
2469
 * @param $form_state
2470
 */
2471
function cdm_settings_general_submit($form, &$form_state){
2472
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2473
  unset($_SESSION['cdm']['taxonomictree_uuid']);
2474
}
2475

    
2476
/**
2477
 * Form validation handler for cdm_settings_cache
2478
 */
2479
function cdm_settings_cache_validate($form, &$form_state) {
2480
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2481
    cache_clear_all(NULL, 'cache_cdm_ws');
2482
    // Better clear secref_cache since I can not be sure if the cache has not
2483
    // be used during this response.
2484
    cdm_api_secref_cache_clear();
2485
  }
2486

    
2487
}
2488

    
2489
/**
2490
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
2491
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
2492
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
2493
 *  - version: the version, e.g.: v1.1
2494
 *
2495
 * @return array
2496
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
2497
 */
2498
function get_edit_map_service_settings() {
2499

    
2500
  $settings = variable_get('edit_map_server', array(
2501
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
2502
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
2503
      )
2504
  );
2505

    
2506
  return $settings;
2507
}
2508

    
2509
/**
2510
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2511
 *
2512
 * @return string
2513
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2514
 */
2515
function get_edit_map_service_full_uri() {
2516
  $settings = get_edit_map_service_settings();
2517
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
2518
}
2519

    
2520

    
2521
/**
2522
 * Returns the version number of the currently selected edit mapserver as a float
2523
 *
2524
 * @return float
2525
 *   The version number of the currently selected edit mapserver as a float.
2526
 *   Returns 0 on error.
2527
 */
2528
function get_edit_map_service_version_number() {
2529

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

    
2532
  $settings = get_edit_map_service_settings();
2533
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
2534
  if (isset($matches[1])) {
2535
    // Convert string to float.
2536
    $version = 1 + $matches[1][0] - 1;
2537
    return $version;
2538
  }
2539
  else {
2540
    // Report error.
2541
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
2542
        array(
2543
          '!version' => $settings['version'],
2544
          'warning')
2545
        )
2546
      );
2547
    return 0;
2548
  }
2549
}
2550

    
2551
/**
2552
 * Returns the array of selected items in a options array
2553
 *
2554
 * @param array $options
2555
 *   An options array as generated by a form element like checkoxes, select ...,
2556
 */
2557
function get_selection($options) {
2558
  $selection = array();
2559
  foreach ($options as $key=>$val) {
2560
    if (!empty($val)) {
2561
      $selection[] = $val;
2562
    }
2563
  }
2564
  return $selection;
2565
}
2566

    
2567

    
2568
/**
2569
 * Implements hook_element_info().
2570
 *
2571
 * Allows modules to declare their own Form API element types and specify their default values.
2572
 *
2573
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
2574
 */
2575
function cdm_dataportal_element_info() {
2576
  $type['checkboxes_preferred'] = array(
2577
    '#input' => TRUE,
2578
    '#process' => array('checkboxes_preferred_expand'),
2579
    '#after_build' => array('checkboxes_preferred_after_build'),
2580
    '#theme' => array('checkboxes_preferred'),
2581
    // '#theme_wrapper' => array('form_element'),
2582
  );
2583
  return $type;
2584
}
2585

    
2586
/**
2587
 * #process callback function for the custom form element type 'checkbox_preferred'
2588
 *
2589
 *
2590
 */
2591
function checkboxes_preferred_expand($element, &$form_state, $form) {
2592

    
2593
  // First of all create checkboxes for each of the elements
2594
  $element = form_process_checkboxes($element);
2595

    
2596
  // compose the element name
2597
  $parents = array();
2598
  array_deep_copy($element['#parents'], $parents);
2599
  $parents[count($parents) -1 ] .= '_preferred';
2600
  $element_name = $parents[0];
2601
  for ($i=1; $i < count($parents); $i++){
2602
    $element_name .= '[' . $parents[$i] . ']';
2603
  }
2604

    
2605
  $children = element_children($element);
2606

    
2607
  $element['table_start'] = array(
2608
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
2609
    '#weight' => -1,
2610
  );
2611

    
2612
  // prepare first part each of the table rows which contains the row label
2613
  $weight = 0;
2614
  foreach ($children as $key) {
2615
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
2616
    $element[$key]['#weight'] = $weight;
2617
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
2618
    $element[$key]['#suffix'] = '</td>';
2619
    unset($element[$key]['#title']);
2620
    $weight += 2;
2621
  }
2622
  $weight = 0;
2623

    
2624
  // add a radio button to each of the checkboxes, the
2625
  // check boxes have already been created at the beginning
2626
  // of this function
2627
  if (count($element['#options']) > 0) {
2628
    foreach ($element['#options'] as $key => $choice) {
2629
      if (!isset($element[$key . '_preferred'])) {
2630
        $element[$key . '_preferred'] = array(
2631
          '#type' => 'radio',
2632
          '#name' => $element_name,
2633
          '#return_value' => check_plain($key),
2634
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
2635
          '#attributes' => $element['#attributes'],
2636
          '#parents' => $element['#parents'],
2637
          // '#spawned' => TRUE,
2638
          '#weight' => $weight + 1,
2639
          '#prefix' => '<td>',        // add a prefix to start a new table cell
2640
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
2641
        );
2642
      }
2643
      $weight += 2;
2644
    }
2645
  }
2646

    
2647
  // end the table
2648
  $element['table_end'] = array(
2649
    '#markup' => '</table>',
2650
    '#weight' => $weight++,
2651
  );
2652

    
2653
  return $element;
2654
}
2655

    
2656
/**
2657
 * Theme function for the custom form field 'checkboxes_preferred'.
2658
 */
2659
function theme_checkboxes_preferred($variables) {
2660
  $element = $variables['element'];
2661
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
2662
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
2663
  $out .= drupal_render_children($element);
2664
  $out .= '<div class="description">' . $element['#description'] . '</div>';
2665
  $out .= '</div>';
2666
  return $out;
2667
}
2668

    
2669
/**
2670
 * Callback for checkboxes preferred for widget which will
2671
 * be called after the form or element is built. The call
2672
 * back is configured in the form element by setting it as
2673
 * #after_build parameter.
2674
 *
2675
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
2676
 *
2677
 * @param $element
2678
 *   Nested array of form elements that comprise the form.
2679
 * @param $form_state
2680
 *   A keyed array containing the current state of the form.
2681
 *   This includes the current persistent storage data for the form.
2682
 *   Additional information, like the sanitized $_POST data,
2683
 *   is also accumulated here in $form_state['input']
2684
 *
2685
 * @return the modified form array
2686
 */
2687
function checkboxes_preferred_after_build($element, &$form_state) {
2688

    
2689
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
2690

    
2691
  if ($_POST && count($_POST) > 0) {
2692
    // TODO use  $form_state['input'] instead of POST !!!
2693
    // First pass of form processing.
2694
    $parents = array();
2695
    array_deep_copy($element['#parents'], $parents);
2696
    $parents[count($parents) - 1] .= '_preferred';
2697
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
2698
    $element['#value']['PREFERRED'] = $preferred_layer;
2699
//     $form_state[$parent_id] = $element['#value'];
2700
//     $form_state['values']['baselayers'] = $element['#value'];
2701
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
2702
    $form_state_element_values = $element['#value'];
2703
  }
2704
  else {
2705
    // Second pass of form processing.
2706
    $preferred_layer = $element['#value']['PREFERRED'];
2707
  }
2708

    
2709
  // Also set the chosen value (not sure if this is good Drupal style ....).
2710
  foreach ($children = element_children($element) as $key) {
2711
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
2712
      $element[$key]['#value'] = $preferred_layer;
2713
    }
2714
  }
2715
  // The default layer must always be enabled.
2716
  $element[$preferred_layer]['#value'] = $preferred_layer;
2717

    
2718
  return $element;
2719
}
2720

    
2721
function radios_prepare_options_suffix(&$elements){
2722

    
2723
  $childrenKeys = element_children($elements);
2724
  foreach($childrenKeys as $key){
2725
    if(!is_array($elements[$key]['#theme_wrappers'])){
2726
      $elements[$key]['#theme_wrappers'] = array();
2727
    }
2728
    if(isset($elements['#options_suffixes'][$key])){
2729
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
2730
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
2731
    }
2732
  }
2733
  return $elements;
2734

    
2735
}
2736

    
2737
/**
2738
 * TODO
2739
 * @param unknown $variables
2740
 */
2741
function theme_radio_options_suffix($variables) {
2742
  $element = $variables['element'];
2743
  if(isset($element['#options_suffix'])) {
2744
    $element['#children'] .= $element['#options_suffix'];
2745
  }
2746
  return $element['#children'];
2747
}
2748

    
2749

    
2750
/**
2751
 * Element validate callback for text field and arrays containing json.
2752
 *
2753
 * @param $element
2754
 *   The form element to validate
2755
 * @param $form_state
2756
 *   A keyed array containing the current state of the form.
2757
 * @param $form
2758
 *   Nested array of form elements that comprise the form.
2759
 */
2760
function form_element_validate_json($element, &$form_state, $form) {
2761
   if (!empty($element['#value'])) {
2762
     json_decode($element['#value']);
2763
     if(json_last_error() != JSON_ERROR_NONE){
2764
       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/'));
2765
     }
2766
   }
2767
}
2768

    
2769
/**
2770
 * Form submission handler for textareas and textfields containing JSON.
2771
 *
2772
 * The contained JSON will be converted into an php array
2773
 * or object and will be stored in the variables as such.
2774
 *
2775
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
2776
 *
2777
 * @param $form
2778
 *   Nested array of form elements that comprise the form.
2779
 * @param $form_state
2780
 *   A keyed array containing the current state of the form.
2781
 *
2782
 */
2783
function submit_json_as_php_array($form, &$form_state) {
2784
  if (is_array($form['#json_elements'])) {
2785
    foreach ($form['#json_elements'] as $element){
2786
      if (trim($form_state['values'][$element])) {
2787
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
2788
      } else {
2789
        $form_state['values'][$element] = NULL;
2790
      }
2791
    }
2792
  }
2793
}
(14-14/14)