Project

General

Profile

Download (157 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?php
2
/**
3
 * @file
4
 * CDM Dataportal settings.
5
 */
6
7 b2b9e057 Andreas Kohlbecker
8 642b323b Andreas Kohlbecker
  // TODO Genus UUID.
9
10 aaa81689 Andreas Kohlbecker
  define('TAXONTREE_RANKLIMIT', 'cdm_taxontree_ranklimit');
11
  define('TAXONTREE_RANKLIMIT_DEFAULT', 0);
12 642b323b Andreas Kohlbecker
  define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
13
  define('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
14
15 80d21b78 Andreas Kohlbecker
  define('CDM_SUB_TREE_FILTER_UUID', 'cdm_sub_tree_filter_uuid');
16
17 642b323b Andreas Kohlbecker
  define('NO_SORT', -1);
18
  define('SORT_HIERARCHICAL', 9);
19
20
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
21 1d69a96c Andreas Kohlbecker
22
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
23
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
24
25 642b323b Andreas Kohlbecker
  define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
26
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
27 2e82a602 Patrick Plitzner
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE', 50);
28 9e72b600 Patrick Plitzner
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 0);
29 642b323b Andreas Kohlbecker
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
30 1cda248c Andreas Kohlbecker
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE', 'cdm_synonymy_accepted_taxon_sec_separate');
31
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL', 'cdm_synonymy_accepted_taxon_sec_separate_label');
32
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT', 'Source');
33 642b323b Andreas Kohlbecker
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
34
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
35
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
36 276f39f6 Katja Luther
  define('CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE', 0);
37 642b323b Andreas Kohlbecker
38 6eaec849 Katja Luther
  define('CDM_WS_PORTAL_BLAST', 'http://127.0.0.1:9001/api/sequence');
39
  define('CDM_BLAST', 0);
40 977bba78 Andreas Kohlbecker
  define('CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK', 'cdm_registration_presistent_identifier_as_link');
41
42 642b323b Andreas Kohlbecker
  /* annotationTypeKeys */
43 7ca5ef1e Andreas Kohlbecker
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
44 642b323b Andreas Kohlbecker
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
45
    $annotationTypeKeys = array_flip($annotationTypeKeys);
46
47
    // Technical annotation are off by default.
48
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
49
    $annotationTypeKeys = array_flip($annotationTypeKeys);
50
    // Additional value for the NULL case.
51
    $annotationTypeKeys[] = 'NULL_VALUE';
52
  }
53 7370f4f7 Andreas Kohlbecker
54
  define('ANNOTATION_TYPES_VISIBLE', 'annotations_types_as_footnotes');
55 642b323b Andreas Kohlbecker
  define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
56 6657531f Andreas Kohlbecker
57 642b323b Andreas Kohlbecker
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
58
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
59
    'enabled' => 0,
60
    'key_format' => 'ALPHA'
61
  )));
62 f19f47fa Andreas Kohlbecker
63 642b323b Andreas Kohlbecker
  /* taxonRelationshipTypes */
64 f95ba88b Andreas Kohlbecker
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(
65
    array(
66 eafb60f0 Andreas Kohlbecker
      UUID_MISAPPLIED_NAME_FOR => UUID_MISAPPLIED_NAME_FOR,
67
      UUID_PROPARTE_MISAPPLIEDNAME_FOR => UUID_PROPARTE_MISAPPLIEDNAME_FOR,
68
      UUID_PARTIAL_MISAPPLIEDNAME_FOR => UUID_PARTIAL_MISAPPLIEDNAME_FOR,
69
      UUID_PROPARTE_SYNONYM_FOR => UUID_PROPARTE_SYNONYM_FOR,
70
      UUID_PARTIAL_SYNONYM_FOR => UUID_PARTIAL_SYNONYM_FOR,
71
      UUID_INVALID_DESIGNATION_FOR => UUID_INVALID_DESIGNATION_FOR
72 f95ba88b Andreas Kohlbecker
    )
73
  ));
74 6657531f Andreas Kohlbecker
75 6280e639 Andreas Kohlbecker
76 b92bf608 Andreas Kohlbecker
  /* ---- MAP SETTING CONSTANTS ---- */
77 642b323b Andreas Kohlbecker
  /**
78
   * @var array of URIs eg. http://edit.africamuseum.be"
79
   *   An options array
80
   */
81
  define('EDIT_MAPSERVER_URI', serialize(
82
      array(
83 a84e1925 Andreas Kohlbecker
        'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)'
84 642b323b Andreas Kohlbecker
      )
85 ba706bf0 Andreas Kohlbecker
    )
86 642b323b Andreas Kohlbecker
  );
87
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
88
  /**
89
   * @var array of versions eg. "v1.2"
90
   *   An options array
91
   */
92
  define('EDIT_MAPSERVER_VERSION', serialize(
93
      array(
94 fb9c2a03 Andreas Kohlbecker
//        'v1' => 'v1' ,           // no longer recommended
95
//        'v1.1' => 'v1.1',        // no longer recommended
96
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
97 642b323b Andreas Kohlbecker
        'v1.2' => 'v1.2',
98 fb9c2a03 Andreas Kohlbecker
        'v1.3_dev' => 'v1.3_dev (not recommended)',
99
        'v1.4_dev' => 'v1.4_dev (experimental features)'
100 642b323b Andreas Kohlbecker
      )
101 f19f47fa Andreas Kohlbecker
    )
102 642b323b Andreas Kohlbecker
  );
103
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
104
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
105 6657531f Andreas Kohlbecker
106 642b323b Andreas Kohlbecker
    // --- Taxon profile settings --- /
107
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
108
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
109
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
110
      array(
111
          'show' => 0,
112
          'maxextend' => 184,
113
          'media_uri_query' => '',
114 ca47ea76 Andreas Kohlbecker
          'custom_placeholder_enabled' => 1,
115 642b323b Andreas Kohlbecker
          'custom_placeholder_image_on' => 0,
116
          'custom_placeholder_image_fid' => ''
117
      )
118 9c92cd84 Andreas Kohlbecker
    )
119 642b323b Andreas Kohlbecker
  );
120 ba706bf0 Andreas Kohlbecker
121 846c0606 Andreas Kohlbecker
122
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
123
124
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
125
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
126
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
127
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
128
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
129
130
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
131
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
132
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
133
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
134 c6ee8193 Andreas Kohlbecker
135 22383f95 Andreas Kohlbecker
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
136
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
137
138 6657531f Andreas Kohlbecker
/**
139 b54cbda1 Andreas Kohlbecker
 * Returns the array of implemented taxon page tabs.
140
 * The array has fixed integer keys which must not be changed.
141 6657531f Andreas Kohlbecker
 */
142
function get_taxon_tabs_list() {
143 22383f95 Andreas Kohlbecker
  $opts = array(
144 6657531f Andreas Kohlbecker
    0 => 'General',
145
    1 => 'Synonymy',
146
    2 => 'Images',
147
    3 => 'Specimens',
148
    4 => 'Keys',
149 7663cd0b Andreas Kohlbecker
    5 => 'Experts',
150 6657531f Andreas Kohlbecker
  );
151 22383f95 Andreas Kohlbecker
  if(variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) !== 1){
152
    // skip the Synonymy if it is shown in  the general tab
153
    unset($opts[1]);
154
  }
155
  return $opts;
156 6657531f Andreas Kohlbecker
}
157
158 4feeabc7 Andreas Kohlbecker
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
159 b54cbda1 Andreas Kohlbecker
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
160 d9763fd3 Andreas Kohlbecker
  array(
161
    'general' => '-3',
162
    'synonymy' => '-2',
163
    'images' => '0',
164
    'specimens' => '1',
165
    'keys' => '3',
166
    'experts' => '5',
167
    )
168 b54cbda1 Andreas Kohlbecker
));
169
170 4feeabc7 Andreas Kohlbecker
171
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
172
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
173
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
174
  array(
175
    'general' => null,
176
    'synonymy' => null,
177
    'images' => null,
178
    'specimens' => null,
179
    'keys' => null,
180
    'experts' => null,
181
  )
182
));
183
184 6657531f Andreas Kohlbecker
$taxon_tab_options = get_taxon_tabs_list();
185
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
186
187
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
188
189
/**
190
 * @todo document this function.
191
 */
192
function get_taxon_options_list() {
193
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
194
  foreach ($taxon_tab_options as $key => $value) {
195 7cc085da Andreas Kohlbecker
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
196 6657531f Andreas Kohlbecker
  }
197
  return $taxon_tab_options;
198
199
}
200
201 0f5f1c12 Andreas Kohlbecker
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
202
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
203 102f8c26 Andreas Kohlbecker
    array(
204 f19f47fa Andreas Kohlbecker
      'ZoologicalName' => array(
205 501347df Andreas Kohlbecker
        'namePart' => array('name' => TRUE),
206 f19f47fa Andreas Kohlbecker
        'nameAuthorPart' => array('name' => TRUE),
207
        'referencePart' => array('authors' => TRUE),
208
        'microreferencePart' => array('microreference' => TRUE),
209 e24d373b Andreas Kohlbecker
        'secReferencePart' => array('secReference' => TRUE,),
210 f19f47fa Andreas Kohlbecker
        'statusPart' => array('status' => TRUE),
211
        'descriptionPart' => array('description' => TRUE),
212
      ),
213 0f5f1c12 Andreas Kohlbecker
      'BotanicalName'=> array(
214
        'namePart' => array('name' => TRUE),
215
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
216
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
217 43998144 Andreas Kohlbecker
        'secReferencePart' => array('secReference' => TRUE,),
218 51b04faf Andreas Kohlbecker
        'referenceYearPart' => array('reference.year' => TRUE),
219 0f5f1c12 Andreas Kohlbecker
        'statusPart' => array('status' => TRUE),
220
        'descriptionPart' => array('description' => TRUE),
221 f19f47fa Andreas Kohlbecker
      ),
222
     '#DEFAULT' => array(
223
        'namePart' => array(
224
            'name' => TRUE
225 501347df Andreas Kohlbecker
        ),
226
        'nameAuthorPart' => array(
227
            'name' => TRUE,
228
            'authors' => TRUE
229 f19f47fa Andreas Kohlbecker
        ),
230 43998144 Andreas Kohlbecker
       'referencePart' => array(
231
         'reference' => TRUE
232 f19f47fa Andreas Kohlbecker
        ),
233 43998144 Andreas Kohlbecker
       'secReferencePart' => array(
234
         'secReference' => TRUE,
235
       ),
236
       'microreferencePart' => array(
237
          'microreference' => TRUE,
238 f19f47fa Andreas Kohlbecker
        ),
239 43998144 Andreas Kohlbecker
       'statusPart' => array(
240
          'status' => TRUE,
241 f19f47fa Andreas Kohlbecker
        ),
242 43998144 Andreas Kohlbecker
       'descriptionPart' => array(
243
          'description' => TRUE,
244 f19f47fa Andreas Kohlbecker
        ),
245
      )
246 0f5f1c12 Andreas Kohlbecker
    )
247
  )
248
);
249 102f8c26 Andreas Kohlbecker
define('CDM_PART_DEFINITIONS_DEFAULT_PRE_380', serialize(
250 1a01f6dd Andreas Kohlbecker
    array(
251
      'ZoologicalName' => array(
252
        'namePart' => array('name' => TRUE),
253
        'nameAuthorPart' => array('name' => TRUE),
254
        'referencePart' => array('authors' => TRUE),
255
        'microreferencePart' => array('microreference' => TRUE),
256
        'statusPart' => array('status' => TRUE),
257
        'descriptionPart' => array('description' => TRUE),
258
      ),
259
      'BotanicalName'=> array(
260
        'namePart' => array('name' => TRUE),
261
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
262
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
263
        'referenceYearPart' => array('reference.year' => TRUE),
264
        'statusPart' => array('status' => TRUE),
265
        'descriptionPart' => array('description' => TRUE),
266
      ),
267
      '#DEFAULT' => array(
268
        'namePart' => array(
269
          'name' => TRUE
270
        ),
271
        'nameAuthorPart' => array(
272
          'name' => TRUE,
273
          'authors' => TRUE
274
        ),
275
        'referencePart' => array(
276
          'reference' => TRUE
277
        ),
278
        'microreferencePart' => array(
279
          'microreference' => TRUE,
280
        ),
281
        'statusPart' => array(
282
          'status' => TRUE,
283
        ),
284
        'descriptionPart' => array(
285
          'description' => TRUE,
286
        ),
287
      )
288
    )
289
  )
290
  );
291
292 f19f47fa Andreas Kohlbecker
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
293 0f5f1c12 Andreas Kohlbecker
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
294 e24d373b Andreas Kohlbecker
  array (
295
    'taxon_page_title,polytomousKey'=> array(
296 1a01f6dd Andreas Kohlbecker
        'namePart' => array('#uri' => TRUE),
297
      ),
298 e24d373b Andreas Kohlbecker
    'not_in_current_classification' => array(
299
     'nameAuthorPart' => TRUE,
300
     'referencePart' => TRUE,
301
     'statusPart' => TRUE,
302
     'secReferencePart' => TRUE,
303
    ),
304
    'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy'=> array(
305
      'nameAuthorPart' => array('#uri' => TRUE),
306
      'referencePart' => TRUE,
307
      'descriptionPart' => TRUE,
308 c266a8fe Andreas Kohlbecker
      'statusPart' => TRUE,
309 e24d373b Andreas Kohlbecker
    ),
310 df6226aa Andreas Kohlbecker
    'related_taxon.other_taxon_relationship.taxon_relationships.taxon_page_synonymy'=> array(
311 e24d373b Andreas Kohlbecker
      'nameAuthorPart' => array('#uri' => TRUE),
312
      'referencePart' => TRUE,
313 c266a8fe Andreas Kohlbecker
      'descriptionPart' => TRUE,
314 e24d373b Andreas Kohlbecker
      'statusPart' => TRUE,
315
      'secReferencePart' => TRUE,
316
    ),
317 df6226aa Andreas Kohlbecker
    'related_taxon.misapplied_name_for.taxon_relationships.taxon_page_synonymy' => array(
318
      'nameAuthorPart' => array('#uri' => TRUE),
319
      'referencePart' => TRUE,
320 c266a8fe Andreas Kohlbecker
      'descriptionPart' => TRUE,
321 df6226aa Andreas Kohlbecker
      'statusPart' => TRUE,
322
      /* no sec ref in this case, misapplied names are
323
       * de-duplicated and the sec ref is shown as footnote */
324
    ),
325 e24d373b Andreas Kohlbecker
    'homonym'=> array(
326 1a01f6dd Andreas Kohlbecker
        'nameAuthorPart' => array('#uri' => TRUE),
327
        'referenceYearPart' => TRUE,
328 c97cae85 Andreas Kohlbecker
        'statusPart' => TRUE,
329 e24d373b Andreas Kohlbecker
    ),
330
    'acceptedFor,typedesignations,list_of_taxa' => array(
331 1a01f6dd Andreas Kohlbecker
        'nameAuthorPart' => array('#uri' => TRUE),
332
        'referencePart' => TRUE,
333
      ),
334 e24d373b Andreas Kohlbecker
    '#DEFAULT' => array(
335 1a01f6dd Andreas Kohlbecker
        'nameAuthorPart' => array('#uri' => TRUE),
336
        'referencePart' => TRUE,
337 e24d373b Andreas Kohlbecker
     )
338
  )
339
));
340
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
341
  array (
342
    'taxon_page_title,polytomousKey'=> array(
343
      'namePart' => array('#uri' => TRUE),
344
    ),
345
    'taxon_page_synonymy,related_taxon'=> array(
346
      'nameAuthorPart' => array('#uri' => TRUE),
347
      'referencePart' => TRUE,
348
      'statusPart' => TRUE,
349
      'descriptionPart' => TRUE,
350
    ),
351
    'homonym'=> array(
352
      'nameAuthorPart' => array('#uri' => TRUE),
353
      'referenceYearPart' => TRUE,
354
    ),
355
    'acceptedFor,typedesignations,list_of_taxa' => array(
356
      'nameAuthorPart' => array('#uri' => TRUE),
357
      'referencePart' => TRUE,
358
    ),
359
    '#DEFAULT' => array(
360
      'nameAuthorPart' => array('#uri' => TRUE),
361
      'referencePart' => TRUE,
362 1a01f6dd Andreas Kohlbecker
    )
363 e24d373b Andreas Kohlbecker
  )
364
));
365 0f5f1c12 Andreas Kohlbecker
366 6280e639 Andreas Kohlbecker
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
367
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
368
    // to unset a default enntry set the value to 0
369
    array(
370
      'doTaxa'=>'doTaxa',
371
      'doSynonyms' => 'doSynonyms',
372
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
373
      'doMisappliedNames' => 'doMisappliedNames'
374
    )
375
  )
376
);
377
378 072122ee Andreas Kohlbecker
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
379
380 2d0d855a Andreas Kohlbecker
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
381 90a6166e Andreas Kohlbecker
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
382 023c4a03 Patrick Plitzner
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
383 2d0d855a Andreas Kohlbecker
384 6280e639 Andreas Kohlbecker
/* Gallery variables. */
385
$gallery_settings = array(
386
    "cdm_dataportal_show_taxon_thumbnails" => 1,
387
    "cdm_dataportal_show_synonym_thumbnails" => 0,
388
    "cdm_dataportal_show_thumbnail_captions" => 1,
389
    "cdm_dataportal_media_maxextend" => 120,
390
    "cdm_dataportal_media_cols" => 3,
391
    "cdm_dataportal_media_maxRows" => 1,
392
);
393
394 6657531f Andreas Kohlbecker
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
395
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
396
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
397 204e8173 Andreas Kohlbecker
define('CDM_DATAPORTAL_TYPE_SPECIMEN_GALLERY_NAME', 'type_specimen_gallery');
398 6657531f Andreas Kohlbecker
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
399
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
400
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
401
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
402
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
403
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
404
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
405
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
406 6421984d Andreas Kohlbecker
407 63d5030d Andreas Kohlbecker
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
408
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
409
  'media_representation_details_enabled' => 0
410
)));
411
412 30f78c59 Andreas Kohlbecker
/**
413
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
414
 * the snonymy.
415
 *
416
 * @var string
417
 */
418 6657531f Andreas Kohlbecker
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
419 6421984d Andreas Kohlbecker
420
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
421
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
422
    array(
423 e4ccc0a0 Andreas Kohlbecker
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
424
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
425
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
426 6421984d Andreas Kohlbecker
    )
427
  )
428
);
429
430 30f78c59 Andreas Kohlbecker
/**
431
 * The drupal variable for the configuration of the information aggregation along
432
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
433
 *    - direct: the uuids of the taxon relationship types to take into account in invers
434
 *      direction.
435
 *    - invers: the uuids of the taxon relationship types to take into account in direct
436
 *      direction.
437
 *
438
 * @var String
439
 */
440
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
441
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
442
    array(
443
        'direct'=>array(),
444
        'invers'=>array()
445
     )
446
   ));
447 6657531f Andreas Kohlbecker
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
448 bfb2b81a Andreas Kohlbecker
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
449 6657531f Andreas Kohlbecker
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
450
451 aa63dfb4 Andreas Kohlbecker
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
452
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
453
      array(
454
      'filter_rules' => array(
455
        'statusOrderPreference' => 0,
456
        'subAreaPreference' => 0,
457
      ),
458 6fbf1bd3 Andreas Kohlbecker
      'hiddenAreaMarkerType' => array()
459 aa63dfb4 Andreas Kohlbecker
     )
460
));
461
462 38dd933d Andreas Kohlbecker
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
463
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
464
  "level_0" => array(
465
    'label_suffix' => ':',
466 3de12c0d Andreas Kohlbecker
    'status_glue' => '',
467 38dd933d Andreas Kohlbecker
    'item_glue' => ' ',
468
    'item_group_prefix' => '',
469
    'item_group_postfix' => ''
470
  ),
471
  "level_1" => array(
472 3de12c0d Andreas Kohlbecker
    'label_suffix' => '',
473
    'status_glue' => '‒ ', // '&#8210; '
474 38dd933d Andreas Kohlbecker
    'item_glue' => '; ',
475
    'item_group_prefix' => ', ',
476
    'item_group_postfix' => ''
477
  ),
478
  "level_2" => array(
479 3de12c0d Andreas Kohlbecker
    'label_suffix' => '',
480
    'status_glue' => '‒ ', // '&#8210; '
481 38dd933d Andreas Kohlbecker
    'item_glue' => ', ',
482
    'item_group_prefix' => ' (',
483
    'item_group_postfix' => ')'
484
  )
485
)));
486 aa63dfb4 Andreas Kohlbecker
487 378bc1ce Andreas Kohlbecker
/**
488
 * Constant for the drupal variable key distribution_map_visibility
489
 *
490
 * possible values:
491
 *  - never
492
 *  - automatic
493
 *  - always
494
 */
495
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
496
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
497
498
/**
499
 * Constant for the drupal variable key specimen_map_visibility
500
 *
501
 * possible values:
502
 *  - never
503
 *  - automatic
504
 *  - always
505
 */
506
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
507
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
508
509 a950f2f9 Andreas Kohlbecker
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
510
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
511
    array(
512
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
513
        'includeOccurrences' => 0,
514
        'includeTaxonNameDescriptions' => 0
515
     )
516
  ));
517
518 cc3c9807 Andreas Kohlbecker
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
519
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
520
  // needs to be merged with user setting by drupal_array_merge_deep()
521 b4503332 Andreas Kohlbecker
  // 'width' => 512, // optimum size for OSM layers is 512
522
  // 'height' => 512 / 2, // optimum size for OSM layers 256
523
  'aspect_ratio' => 2,
524 cc3c9807 Andreas Kohlbecker
  'bbox' => '', // empty to allow automatic zooming to extend
525 46de7f4c Andreas Kohlbecker
  'maxZoom' => 15, // corresponds to the default in cdm_openlayers_map.defaults
526 cc3c9807 Andreas Kohlbecker
  'show_labels' => FALSE,
527
  'caption' => '',
528
  'distribution_opacity' => '0.5',
529
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
530
  'image_map' => array(
531
    'base_layer' => '', // none, formerly this was cyprusdivs
532
    'bg_color' => '1874CD',
533
    'layer_style' => 'ffffff,606060,,',
534
  ),
535
  'openlayers' => array(
536
    'base_layers' =>  array(
537
      // A layer MUST NOT BE SET in the defaults,
538
      // otherwise it can not be overidden by the user settings:
539 5cef0b6d Andreas Kohlbecker
      // 'mapproxy_vmap0' => 'mapproxy_vmap0',
540 cc3c9807 Andreas Kohlbecker
      // it is sufficient to define the preferred layer,
541
      // since it will automatically be enabled:
542 5cef0b6d Andreas Kohlbecker
      'PREFERRED' => 'mapproxy_vmap0'),
543 fb9c2a03 Andreas Kohlbecker
    'custom_wms_base_layer' => array(
544
      'name' => NULL,
545
      'url' => NULL,
546
      'params' =>  NULL,
547
      'projection' => NULL,
548
      'proj4js_def' => NULL,
549
      'max_extent' => NULL,
550 2dc774be Andreas Kohlbecker
      'units' => NULL,
551
      'untiled' => FALSE
552
    ),
553
    'wms_overlay_layer' => array(
554
      'name' => NULL,
555
      'url' => NULL,
556
      'params' =>  NULL,
557
      'untiled' => FALSE
558 fb9c2a03 Andreas Kohlbecker
    ),
559 2bbc28c8 Andreas Kohlbecker
    'show_layer_switcher' => TRUE,
560 2b83cc8b Andreas Kohlbecker
    'display_outside_max_extent' => FALSE,
561
    'google_maps_api_key' => NULL,
562 cc3c9807 Andreas Kohlbecker
  ),
563
  'legend' => array(
564
    'show' => TRUE,
565
    'opacity' => '0.5',
566
    'font_size' => 10,
567
    'font_style' => FALSE,
568
    'icon_width' => 35,
569
    'icon_height' => 15
570
  )
571
)));
572
573
/**
574
 * Merges the named array variable with the array of defaults.
575
 *
576 5611d467 Andreas Kohlbecker
 * IMPORTANT: The array keys must be strings. When the keys are integers
577
 * the merging will not take place for these entities. Number keyed entities
578 b54cbda1 Andreas Kohlbecker
 * are just appended to the result array.
579
 *
580 cc3c9807 Andreas Kohlbecker
 * @param string $variable_name
581
 *     The variable name
582
 * @param string | array $default
583
 *     The array containing the default values either as array or serialized as string.
584 5611d467 Andreas Kohlbecker
 *     Unserialization is cared for if necessary
585 cc3c9807 Andreas Kohlbecker
 * @return array
586 5611d467 Andreas Kohlbecker
 *     The merged array as returned by drupal_array_merge_deep()
587 8c962983 Andreas Kohlbecker
 *
588 0f7c9d15 Andreas Kohlbecker
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
589
 * TODO force $default being an array
590 cc3c9807 Andreas Kohlbecker
 */
591
function get_array_variable_merged($variable_name, $default){
592
593
    // unserialize if nessecary
594
    if(!is_array($default)){
595
      $default = unserialize($default);
596
    }
597
    $variable = variable_get($variable_name, array());
598 b54cbda1 Andreas Kohlbecker
    $result = drupal_array_merge_deep($default, $variable);
599
    return $result;
600 cc3c9807 Andreas Kohlbecker
}
601
602 6657531f Andreas Kohlbecker
/**
603
 * @todo document this function.
604
 */
605
function getGallerySettings($gallery_config_form_name) {
606 cc3c9807 Andreas Kohlbecker
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
607 6657531f Andreas Kohlbecker
}
608
609
/**
610
 * Returns the string representation of the default tab.
611
 *
612
 * @param bool $returnTabIndex
613
 *   Defaults to FALSE, if set true this function will return the index number
614
 *   of the default tab. (used to supply default values to form elements).
615
 */
616
function get_default_taxon_tab($returnTabIndex = FALSE) {
617
618
  global $user;
619
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
620
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
621
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
622
  // Get the user value if the used has chosen to overwrite the system settings.
623
  $user_tab_on = variable_get($user_tab_active, FALSE);
624
  if ($user_tab_on) {
625
    $user_value = variable_get($user_tab, 0);
626
    $index_value = $user_value;
627
    // Get the system value.
628
  }
629
  else {
630
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
631
    $index_value = $system_value;
632
  }
633
634
  // Return the index value or the string representation.
635
  if ($returnTabIndex) {
636
    return $index_value;
637
  }
638
  else {
639
    return ($values[$index_value]);
640 22f5e82d Andreas Kohlbecker
  }
641 6657531f Andreas Kohlbecker
}
642
643 4407c9a7 Andreas Kohlbecker
/**
644
 * Provides the feature block settings for a specific feature which matches the $feature_uuid parameter.
645
 *
646
 * In case specifically configured settings array, like these which are stored in the drupal variables, is missing
647
 * one or more fields these fields are taken from the default. That is the specific settings are always merges
648
 * with the default.
649
 *
650
 * Note: These settings only apply to feature blocks which do not have a special rendering
651
 * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
652
 * 'special' element of the settings
653
 *
654
 * @param $feature_uuid
655
 *   The uuid string representation of the feature to return the settings for
656
 *
657
 * @return array
658
 *  an associative array of settings, with the following fields:
659
 *    - as_list: string
660
 *        this setting will be used in compose_feature_block_wrap_elements() as $enclosing_tag
661
 *        possible values are:
662
 *          div: not as list,
663
 *          ul: as bullet list,
664
 *          ol: as numbered list,
665
 *          dl: as definition list
666
 *        The tag used for the inner element, thus depends on the value of this field. The
667
 *        inner tag name can be retrieved by the function cdm_feature_block_element_tag_name()
668
 *    - link_to_reference: boolean,
669
 *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
670
 *    - link_to_name_used_in_source": boolean
671
 *        whether to show name in source information as link which will point to the according name page
672
 *    - sources_as_content (boolean)
673
 *        TRUE (int: 1):
674
 *          1. If element is of the CDM type TextData and the text is not empty the source references will be
675
 *             appended in brackets like "text (source references)". If the original source has name in source
676
 *             information it will be appended to the citation string,
677
 *             like : "(citation, as name in source; citation, as name in source)"
678
 *          2. if the text of the TextData is empty, the original source citations are the only content
679
 *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
680
 *             prepended to the citation string like: "name in source: citation"
681
 *        FALSE (int: 0):
682
 *          Original sources are put into the bibliography(=references) pseudo feature block. If the original source
683
 *          citations are the only content, the resulting feature block content would only consist of footnotes.
684
 *          In this case the display of the respective feature block is suppressed.
685
 *          TODO if the bibliography is not enabled the sources will be treated as footnotes like annotations,
686
 *               in future however they will in this case be shown in a separate references section for each
687
 *               feature block.
688
 *    - sources_as_content_to_bibliography  (boolean)
689
 *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
690
 *        in the bibliography.
691
 *    - sort_elements
692
 *        whether and how to sort the elements
693
 *        possible values are the constants SORT_ASC, SORT_DESC, NULL,
694
 *        some feature types (Distribution) also support: SORT_HIERARCHICAL (
695
 *        TODO option to exclude levels, put in special?,
696
 *        TODO make use of this setting in compose_feature_block_wrap_elements())
697
 *    - element_tag
698
 *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
699
 *        possible values are span | div. the proper inner tag name can be retrieved by the function
700
 *        cdm_feature_block_element_tag_name()
701
 *    - special: array()
702
 *        an array with further settings, this field can be used for special
703
 *        settings for specialized rendering like for distributions
704
 *  }
705
 *
706
 */
707
function get_feature_block_settings($feature_uuid = 'DEFAULT') {
708
  // the default must conform to the default parameter values of
709
  // compose_feature_block_wrap_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
710
  // compose_description_element_text_data() : asListElement = NULL
711 22f5e82d Andreas Kohlbecker
712 4407c9a7 Andreas Kohlbecker
  // see #3257 (implement means to define the features to show up in the taxonprofile and in the specimen descriptions)
713
714
  // ---- DEFAULTS settings
715
716
  // only needed as final option, when the settings are not having a default
717
  $default = array(
718
    'DEFAULT' => array(
719
      'as_list' => 'div',
720
      'link_to_reference' => 0,
721
      'link_to_name_used_in_source' => 1,
722
      'sources_as_content' => 0,
723
      'sources_as_content_to_bibliography' => 0,
724
      'sort_elements' => NO_SORT,
725
      'glue' => '',
726
      'element_tag' => NULL
727
    ),
728
    // settings for pseudo feature bibliography
729
    // only hard coded here
730
    'BIBLIOGRAPHY' => array(
731
      'as_list' => 'div',
732
      'link_to_reference' => 0,
733
      'link_to_name_used_in_source' => 1,
734
      'sources_as_content' => 0,
735
      'sources_as_content_to_bibliography' => 0,
736
      'sort_elements' => NO_SORT,
737
      'glue' => '',
738
      'element_tag' => NULL
739
    )
740
  );
741 f3a04cfa Andreas Kohlbecker
742 4407c9a7 Andreas Kohlbecker
  // will be used as preset in the settings
743
  $other_themes_default = array(
744
    'DEFAULT' => array(
745
      'as_list' => 'div',
746
      'link_to_reference' => 0,
747
      'link_to_name_used_in_source' => 1,
748
      'sources_as_content' => 0,
749
      'sources_as_content_to_bibliography' => 0,
750
      'sort_elements' => NO_SORT,
751
      'glue' => '',
752
      'element_tag' => NULL
753
    ),
754
    UUID_CITATION => array(
755
      'as_list' => 'div',
756
      'link_to_reference' => 0,
757
      'link_to_name_used_in_source' => 0,
758
      'sources_as_content' => 1,
759
      'sources_as_content_to_bibliography' => 0,
760
      'sort_elements' => SORT_ASC,
761
      'glue' => '',
762
      'element_tag' => 'div'
763
    ),
764
    UUID_DISTRIBUTION => array(
765 6776a5bc Andreas Kohlbecker
      'as_list' => 'div', // currently ignored
766 642b323b Andreas Kohlbecker
      'link_to_reference' => 0,
767
      'link_to_name_used_in_source' => 0,
768
      'sources_as_content' => 0,
769
      'sources_as_content_to_bibliography' => 0,
770
      'sort_elements' => NO_SORT, // will cause ...
771 4407c9a7 Andreas Kohlbecker
      'glue' => '',
772 642b323b Andreas Kohlbecker
      'element_tag' => 'div',
773
      'special' => array()
774 4407c9a7 Andreas Kohlbecker
    ),
775
    UUID_COMMON_NAME => array(
776
      'as_list' => 'div',
777
      'link_to_reference' => 0,
778
      'link_to_name_used_in_source' => 1,
779
      'sources_as_content' => 0,
780
      'sources_as_content_to_bibliography' => 0,
781
      'sort_elements' => NO_SORT,
782
      'glue' => '',
783
      'element_tag' => 'span'
784
    ),
785
  );
786 1b756c5f Andreas Kohlbecker
787 4407c9a7 Andreas Kohlbecker
  // ---- Special DEFAULTS for existing portals
788
  // TODO:
789
  // this can be removed once the feature block
790
  // settings have been deployed for the first time to these portals
791
792
  $cichorieae_default = array(
793
    'DEFAULT' => array(
794
      'as_list' => 'div',
795
      'link_to_reference' => 1,
796
      'link_to_name_used_in_source' => 1,
797
      'sources_as_content' => 1,
798
      'sources_as_content_to_bibliography' => 0,
799
      'sort_elements' => NO_SORT,
800
      'glue' => '',
801
      'element_tag' => 'div'
802
    ),
803
    UUID_CITATION => array(
804
      'as_list' => 'div',
805
      'link_to_reference' => 0,
806
      'link_to_name_used_in_source' => 0,
807
      'sources_as_content' => 1,
808
      'sources_as_content_to_bibliography' => 0,
809
      'sort_elements' => SORT_ASC,
810
      'glue' => '',
811
      'element_tag' => 'div'
812
    ),
813
    UUID_CHROMOSOMES_NUMBERS => array(
814
      'as_list' => 'ul',
815
      'link_to_reference' => 1,
816
      'link_to_name_used_in_source' => 1,
817
      'sources_as_content' => 1,
818
      'sources_as_content_to_bibliography' => 0,
819
      'sort_elements' => NO_SORT,
820
      'glue' => '',
821
      'element_tag' => 'div'
822
    ),
823
    UUID_CHROMOSOMES => array(
824
      'as_list' => 'ul',
825
      'link_to_reference' => 0,
826
      'link_to_name_used_in_source' => 1,
827
      'sources_as_content' => 1,
828
      'sources_as_content_to_bibliography' => 0,
829
      'sort_elements' => NO_SORT,
830
      'glue' => '',
831
      'element_tag' => 'div'
832
    ),
833
    UUID_COMMON_NAME => array(
834
      'as_list' => 'div',
835
      'link_to_reference' => 0,
836
      'link_to_name_used_in_source' => 1,
837
      'sources_as_content' => 0,
838
      'sources_as_content_to_bibliography' => 0,
839
      'sort_elements' => NO_SORT,
840
      'glue' => '',
841
      'element_tag' => 'span'
842
    ),
843
  );
844 c367b0ab Andreas Kohlbecker
845 4407c9a7 Andreas Kohlbecker
  $palmweb_default = array(
846
    'DEFAULT' => array(
847
      'as_list' => 'ul',
848
      'link_to_reference' => 1,
849
      'link_to_name_used_in_source' => 1,
850
      'sources_as_content' => 1,
851
      'sources_as_content_to_bibliography' => 1,
852
      'sort_elements' => NO_SORT,
853
      'glue' => '',
854
      'element_tag' => NULL
855
    ),
856
    UUID_CITATION => array(
857
      'as_list' => 'ul',
858
      'link_to_reference' => 1,
859
      'link_to_name_used_in_source' => 1,
860
      'sources_as_content' => 0,
861
      'sources_as_content_to_bibliography' => 1,
862
      'sort_elements' => SORT_ASC,
863
      'glue' => '',
864
      'element_tag' => 'div'
865
    ),
866
    UUID_DISTRIBUTION => array(
867
      'as_list' => 'div', // currently ignored
868
      'link_to_reference' => 1,
869
      'link_to_name_used_in_source' => 1,
870
      'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
871
      'sources_as_content_to_bibliography' => 1,
872
      'sort_elements' => NO_SORT, // will cause ...
873
      'glue' => ', ',
874
      'element_tag' => 'span',
875
      'special' => array()
876
    ),
877
  );
878 642b323b Andreas Kohlbecker
879 4407c9a7 Andreas Kohlbecker
  $cyprus_default = $cichorieae_default;
880
  $cyprus_default[UUID_DISTRIBUTION] = array(
881
    'as_list' => 'div', // currently ignored
882
    'link_to_reference' => 0,
883
    'link_to_name_used_in_source' => 0,
884
    'sources_as_content' => 0,
885
    'sources_as_content_to_bibliography' => 0,
886
    'sort_elements' => NO_SORT, // will cause ...
887
    'glue' => ' ',
888
    'element_tag' => 'div',
889
    'special' => array()
890
  );
891 642b323b Andreas Kohlbecker
892 4407c9a7 Andreas Kohlbecker
  $default_theme = variable_get('theme_default', NULL);
893
894
  switch ($default_theme) {
895
    case 'garland_cichorieae':
896
      $settings_for_theme = $cichorieae_default;
897
      break;
898
    case 'cyprus':
899
      // cyprus: no longer used in production,
900
      // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
901
      $settings_for_theme = $cyprus_default;
902
      break;
903
    case 'flore_afrique_centrale':
904
    case 'flora_malesiana':
905
    case 'flore_gabon':
906
      $settings_for_theme = $cichorieae_default;
907
      $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
908
      break;
909
    case 'palmweb_2':
910
      $settings_for_theme = $palmweb_default;
911
      break;
912
    default:
913
      $settings_for_theme = $other_themes_default;
914
  }
915
  // add pseudo feature settings
916
  $settings_for_theme['BIBLIOGRAPHY'] = $default['BIBLIOGRAPHY'];
917 642b323b Andreas Kohlbecker
918 4407c9a7 Andreas Kohlbecker
  // ---- END of DEFAULTS
919
920
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
921
922
  $feature_block_setting = null;
923
924
  if (isset($saved_settings[$feature_uuid])) {
925
    $feature_block_setting = $saved_settings[$feature_uuid];
926
  }
927
  else if (isset($settings_for_theme[$feature_uuid])) {
928
    $feature_block_setting = $settings_for_theme[$feature_uuid];
929
  }
930
  else if (isset($settings_for_theme['DEFAULT'])) {
931
    $feature_block_setting = $settings_for_theme['DEFAULT'];
932
  }
933
934
  // now merge the default and specific settings
935
  $settings_to_merge = array($default['DEFAULT']);
936
  if(is_array($saved_settings)){
937
    $settings_to_merge[] = $saved_settings['DEFAULT'];
938
  }
939
  if(isset($feature_block_setting)){
940
    $settings_to_merge[] = $feature_block_setting;
941
  }
942
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
943 642b323b Andreas Kohlbecker
944 4407c9a7 Andreas Kohlbecker
  return $feature_block_setting;
945 1ce9afb7 Patric Plitzner
}
946 1b756c5f Andreas Kohlbecker
947
/**
948 5611d467 Andreas Kohlbecker
 * returns the current setting for the original source bibliography
949
 *
950
 * Caches internally
951
 *
952
 * @return array
953
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
954
 *   - 'enabled': 1|0
955
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
956
 */
957 800ff2b0 Andreas Kohlbecker
function get_bibliography_settings($clear_cache = false){
958 5611d467 Andreas Kohlbecker
  static $bibliography_settings = null;
959 800ff2b0 Andreas Kohlbecker
  if(!$bibliography_settings || $clear_cache){
960 f3a04cfa Andreas Kohlbecker
    $bibliography_settings = get_array_variable_merged(
961
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
962
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
963
    );
964 5611d467 Andreas Kohlbecker
  }
965
  return $bibliography_settings;
966
}
967
968 6657531f Andreas Kohlbecker
/**
969
 * @todo Please document this function.
970
 * @see http://drupal.org/node/1354
971
 */
972
function cdm_dataportal_menu_admin(&$items) {
973
  // Display section on admin/config page.
974
  $items['admin/config/cdm_dataportal'] = array(
975
    'title' => 'CDM Dataportal',
976
    'description' => 'Settings for the CDM DataPortal.',
977
    'position' => 'right',
978
    'weight' => 10,
979
    'page callback' => 'system_admin_menu_block_page',
980 e014414c Andreas Kohlbecker
    'access arguments' => array('administer cdm_dataportal'),
981 6657531f Andreas Kohlbecker
    'file' => 'system.admin.inc',
982
    'file path' => drupal_get_path('module', 'system'),
983
  );
984
  $items['admin/config/cdm_dataportal/settings'] = array(
985
    'title' => 'Settings',
986
    'description' => 'Settings for the CDM DataPortal.',
987
    'weight' => 0,
988
    'page callback' => 'drupal_get_form',
989
    'page arguments' => array('cdm_settings_general'),
990
    'access arguments' => array('administer cdm_dataportal'),
991
    'type' => MENU_NORMAL_ITEM,
992
  );
993
  $items['admin/config/cdm_dataportal/settings/general'] = array(
994
    'title' => 'General',
995
    'description' => 'General',
996
    'weight' => 0,
997
    'page callback' => 'drupal_get_form',
998
    'page arguments' => array('cdm_settings_general'),
999
    'access arguments' => array('administer cdm_dataportal'),
1000
    'type' => MENU_DEFAULT_LOCAL_TASK,
1001
  );
1002
1003
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
1004
    'title' => 'Cache',
1005
    'description' => 'Cache',
1006
    'access arguments' => array('administer cdm_dataportal'),
1007
    'page callback' => 'drupal_get_form',
1008
    'page arguments' => array('cdm_settings_cache'),
1009
    'weight' => 10,
1010
    'type' => MENU_LOCAL_TASK,
1011
  );
1012
1013
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
1014
    'title' => 'Geo & Map',
1015
    'description' => 'Geo & Map',
1016
    'access arguments' => array('administer cdm_dataportal'),
1017
    'page callback' => 'drupal_get_form',
1018
    'page arguments' => array('cdm_settings_geo'),
1019
    'weight' => 1,
1020
    'type' => MENU_LOCAL_TASK,
1021
  );
1022
1023
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
1024
    'title' => 'Layout',
1025
    'description' => 'Configure and adjust the layout of your DataPortal ',
1026
    'access arguments' => array('administer cdm_dataportal'),
1027
    'page callback' => 'drupal_get_form',
1028
    'page arguments' => array('cdm_settings_layout'),
1029
    'weight' => 2,
1030
    'type' => MENU_LOCAL_TASK,
1031
  );
1032
1033
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
1034
    'title' => 'Taxon',
1035
    'description' => 'Configure and adjust the layout of your DataPortal ',
1036
    'access arguments' => array('administer cdm_dataportal'),
1037
    'page callback' => 'drupal_get_form',
1038
    'page arguments' => array('cdm_settings_layout_taxon'),
1039
    'weight' => 1,
1040
    'type' => MENU_LOCAL_TASK,
1041
  );
1042
  /*
1043
  $items[] = array(
1044
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
1045
  'title' => t('Synonymy'),
1046
  'description' => t('Configure and adjust the layout of your DataPortal '),
1047
  'access' => user_access('administer cdm_dataportal'),
1048
  'callback' => 'drupal_get_form',
1049
  'callback arguments' => array('cdm_settings_layout_synonymy'),
1050
  'weight' => 1,
1051
  'type' => MENU_LOCAL_TASK,
1052
  );
1053
1054
  $items[] = array(
1055
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
1056
  'title' => t('Specimens'),
1057
  'description' => t('Configure and adjust the layout of your DataPortal '),
1058
  'access' => user_access('administer cdm_dataportal'),
1059
  'callback' => 'drupal_get_form',
1060
  'callback arguments' => array('cdm_settings_layout_specimens'),
1061
  'weight' => 1,
1062
  'type' => MENU_LOCAL_TASK,
1063
  );
1064
  */
1065
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1066
    'title' => 'Search',
1067
    'description' => 'Configure and adjust the layout of your DataPortal ',
1068
    'access arguments' => array('administer cdm_dataportal'),
1069
    'page callback' => 'drupal_get_form',
1070
    'page arguments' => array('cdm_settings_layout_search'),
1071
    'weight' => 2,
1072
    'type' => MENU_LOCAL_TASK,
1073
  );
1074
1075
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1076
    'title' => 'Media',
1077
    'description' => 'Configure and adjust the layout of your DataPortal ',
1078
    'access arguments' => array('administer cdm_dataportal'),
1079
    'page callback' => 'drupal_get_form',
1080
    'page arguments' => array('cdm_settings_layout_media'),
1081
    'weight' => 3,
1082
    'type' => MENU_LOCAL_TASK,
1083
  );
1084 947c6a8d Andreas Kohlbecker
1085 6657531f Andreas Kohlbecker
}
1086
1087
/**
1088
 * @todo document this function.
1089
 */
1090
function cdm_help_general_cache() {
1091
  $form = array();
1092
  $form['cache_help'] = array(
1093
    '#type' => 'fieldset',
1094
    '#title' => t('Help'),
1095
    '#collapsible' => TRUE,
1096
    '#collapsed' => TRUE,
1097
  );
1098
  $form['cache_help']['test'] = array('#value' => t('probando'));
1099
  return drupal_render($form);
1100
  $res = array();
1101
  $res['default'] = drupal_render($help);
1102
  return $res;
1103
}
1104
1105
/**
1106
 * Configures the settings form for the CDM-API module.
1107
 *
1108
 * @return array
1109
 *   Drupal settings form.
1110
 */
1111
function cdm_settings_general() {
1112
1113
  $form['cdm_webservice'] = array(
1114
    '#type' => 'fieldset',
1115
    '#title' => t('CDM Server'),
1116
    '#collapsible' => FALSE,
1117
    '#collapsed' => FALSE,
1118 9438ad3a Andreas Kohlbecker
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1119
        CDM data base to the web via RESTful web services and thus is the source of the data
1120
        to be displayed by a CDM DataPotal.'),
1121 6657531f Andreas Kohlbecker
  );
1122
1123
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1124
    '#type' => 'textfield',
1125
    '#title' => t('CDM web service URL') . ':',
1126
    '#description' => t('This is the URL to the CDM-Server exposing your data
1127 d1eb0a8c Andreas Kohlbecker
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1128 6657531f Andreas Kohlbecker
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1129
  );
1130
1131
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1132 17c3d760 Andreas Kohlbecker
    '#type' => 'markup',
1133 d1e3ac25 Andreas Kohlbecker
    '#markup' => '<b>Debug CDM Web Service:</b> Debugging web services is possible via the ' . l('CDM web service debug block', 'admin/structure/block/manage/cdm_api/cdm_ws_debug/configure')
1134
      . ' visible only for administrators',
1135 6657531f Andreas Kohlbecker
  );
1136
1137
  $form['cdm_webservice']['freetext_index'] = array(
1138
    '#type' => 'fieldset',
1139
    '#title' => t('Freetext index'),
1140
    '#collapsible' => FALSE,
1141
    '#collapsed' => FALSE,
1142
  );
1143
1144
  // Check the cdmserver port number and display a waring if it is not port 80
1145
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1146
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1147
    $form['cdm_webservice']['freetext_index']['message'] = array(
1148
      '#markup' => "<div class=\"description\">"
1149 7cc085da Andreas Kohlbecker
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1150
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1151
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1152
          array('!port' => $portNumberMatch[1][0])
1153
        )
1154 6657531f Andreas Kohlbecker
      . "</div>",
1155
    );
1156
  };
1157
1158
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1159
  $trigger_link_options = array(
1160
    'attributes' => array(
1161 c9b3fcf5 Andreas Kohlbecker
      'class' => 'index-trigger'
1162 6657531f Andreas Kohlbecker
    ),
1163
  );
1164
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1165
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1166
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1167
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1168
      ))
1169
    . '<div id="index-progress"></div></div>',
1170
  );
1171 c9b3fcf5 Andreas Kohlbecker
1172
  $form['cdm_webservice']['freetext_index']['cdm_login'] = array(
1173
    // this must not be stored, it is only used by the _add_js_cdm_ws_progressbar
1174
    '#type' => 'textfield',
1175
    '#title' => t('Login'),
1176
    '#description' => t('Your cdm user credentials in the following form: <code>user:password</code>')
1177
  );
1178
  drupal_add_js('
1179
        jQuery(document).ready(function() {
1180
             jQuery("#edit-cdm-login").change(function (e) {
1181
                var login = jQuery(e.target).val();
1182
                jQuery("#edit-freetext-index .index-trigger").each(function(index){
1183
                   var url = jQuery(this).attr("href");
1184
                   url = url.replace(/:\/\/[^@]+@|:\/\//, "://" + login + "@");
1185
                   jQuery(this).attr("href", url);
1186
                });
1187
            });
1188
        });
1189
      ',
1190
    array(
1191
      'type' => 'inline',
1192
      'scope' => 'footer'
1193
    )
1194
  );
1195 6657531f Andreas Kohlbecker
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1196
1197
  $form['cdm_webservice']['proxy'] = array(
1198
    '#type' => 'fieldset',
1199
    '#title' => t('Proxy'),
1200
    '#collapsible' => TRUE,
1201
    '#collapsed' => TRUE,
1202
  );
1203
1204
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1205
    '#type' => 'textfield',
1206
    '#title' => t('Proxy URL') . ':',
1207
    '#description' => t('If this proxy url is set the cdm api tries
1208
    to connect the web service over the given proxy server.
1209
    Otherwise proxy usage is deactivated.'),
1210
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1211
  );
1212
1213
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1214
    '#type' => 'textfield',
1215
    '#title' => t('Proxy port') . ':',
1216
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1217
  );
1218
1219
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1220
    '#type' => 'textfield',
1221
    '#title' => t('Login') . ':',
1222
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1223
  );
1224
1225
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1226
    '#type' => 'textfield',
1227
    '#title' => t('Password') . ':',
1228
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1229
  );
1230
1231 80d21b78 Andreas Kohlbecker
  $form['sub_tree_filter'] = array(
1232
    '#type' => 'fieldset',
1233
    '#title' => t('Subtree filter'),
1234
    '#collapsible' => FALSE,
1235
    '#collapsed' => TRUE,
1236
    '#description' => t('The Data Portal can be restricted to the taxa which belong to a specific classification subtree. Other taxa will not be shown or accessible otherwise.'),
1237
  );
1238
1239
  $sub_tree_filter_uuid_value = variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE);
1240
  $taxon_node_info = '';
1241
  if($sub_tree_filter_uuid_value){
1242
    $taxon_node_dto = cdm_ws_get(CDM_WS_TAXONNODE, array($sub_tree_filter_uuid_value));
1243
    if($taxon_node_dto){
1244
      $taxon_node_info = " Current taxon node: <strong>" . cdm_tagged_text_to_markup($taxon_node_dto->taggedTitle) . " [" . $taxon_node_dto->treeIndex . "]</strong>";
1245
    }
1246
  }
1247
  $form['sub_tree_filter'][CDM_SUB_TREE_FILTER_UUID] = array(
1248
    '#type' => 'textfield',
1249
    '#title' => t('Taxon Node UUID') . ':',
1250
    '#default_value' => variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE),
1251
    '#description' => "The uuid of the TaxonNode entity to be used as filter." . $taxon_node_info
1252
  );
1253
1254 6657531f Andreas Kohlbecker
  // TODO: settings are still incomplete, compare with
1255
  // trunk/dataportal/inc/config_default.php.inc.
1256 9438ad3a Andreas Kohlbecker
  $form['taxon_tree'] = array(
1257 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1258
    '#title' => t('Taxon Tree'),
1259
    '#collapsible' => FALSE,
1260
    '#collapsed' => TRUE,
1261
    '#description' => t('<p>When you explore your collection, you can navigate
1262
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1263
      able to navigate through your collection the
1264
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1265
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1266
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1267
      </a></p>'),
1268
  );
1269
1270 9438ad3a Andreas Kohlbecker
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1271 6657531f Andreas Kohlbecker
    '#type' => 'select',
1272 fe1b1203 Andreas Kohlbecker
    '#title' => t('Default classification') . ':',
1273 6657531f Andreas Kohlbecker
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1274
    '#options' => cdm_get_taxontrees_as_options(),
1275 fe1b1203 Andreas Kohlbecker
    '#description' => t('The default taxa classification to be used in the whole portal. 
1276
      This affects most obviously the classification browser and the search in case is is restricted 
1277
      to a specific classification. See also <i>Included Classifications</i> below.'),
1278 6657531f Andreas Kohlbecker
  );
1279
1280 aaa81689 Andreas Kohlbecker
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1281 6657531f Andreas Kohlbecker
    '#type' => 'select',
1282
    '#title' => t('Rank of highest displayed taxon') . ':',
1283
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1284 aaa81689 Andreas Kohlbecker
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1285 2d3d6556 Andreas Kohlbecker
    '#options' => cdm_vocabulary_as_option(UUID_RANK, null, true),
1286 6657531f Andreas Kohlbecker
    '#description' => t('This is the rank of the highest displayed taxon in the
1287
      <em>taxon tree</em>. You can select here which rank should be at the top
1288
      level of the tree structure.'),
1289
  );
1290
1291 26fb3778 Andreas Kohlbecker
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1292
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1293
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1294
      '#type' => 'checkboxes',
1295
      '#title' => t('Included Classifications') . ':',
1296
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1297
      '#options' => cdm_get_taxontrees_as_options(),
1298 fe1b1203 Andreas Kohlbecker
      '#description' => t('Only the checked classifications will be available in the classification chooser.'),
1299 26fb3778 Andreas Kohlbecker
  );
1300
1301 aa63dfb4 Andreas Kohlbecker
  $form['distribution'] = array(
1302
      '#type' => 'fieldset',
1303
      '#title' => t('Distributions'),
1304
      '#collapsible' => FALSE,
1305
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1306
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1307 562a6ac4 Andreas Kohlbecker
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1308
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1309
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1310 aa63dfb4 Andreas Kohlbecker
          '<p>
1311
          </p>',
1312
  );
1313
1314
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1315
      '#type' => 'fieldset',
1316
      '#title' => 'Distribution filter',
1317
      '#collapsible' => FALSE,
1318
      '#collapsed' => FALSE,
1319
      '#tree' => TRUE,
1320
      '#description' => 'The Distribution filter offers the following options
1321
      <ul>
1322 0eef1621 Andreas Kohlbecker
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1323
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1324
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1325
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1326
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1327
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1328
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1329
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1330
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1331
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1332 aa63dfb4 Andreas Kohlbecker
      </ul>'
1333
  );
1334
1335
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1336
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1337
      '#type' => 'checkboxes',
1338
      '#title' => 'Filter rules',
1339
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1340
      '#options' => array(
1341
          'statusOrderPreference' => 'Status order preference rule',
1342
          'subAreaPreference' => 'Sub area preference rule'
1343
      ),
1344
  );
1345
1346 7ca5ef1e Andreas Kohlbecker
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1347 6fbf1bd3 Andreas Kohlbecker
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1348 aa63dfb4 Andreas Kohlbecker
      '#type' => 'checkboxes',
1349
      '#title' => 'Hide marked area filter',
1350 6fbf1bd3 Andreas Kohlbecker
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1351 aa63dfb4 Andreas Kohlbecker
      '#options' => $marker_type_options,
1352
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1353
  );
1354
1355 f19f47fa Andreas Kohlbecker
  $form['aggregation'] = array(
1356
      '#type' => 'fieldset',
1357
      '#title' => t('Aggregation of data'),
1358
      '#collapsible' => FALSE,
1359 aa63dfb4 Andreas Kohlbecker
      '#description' => 'This section covers the different aspects of aggregating information.
1360 9438ad3a Andreas Kohlbecker
          <p>
1361 f19f47fa Andreas Kohlbecker
          </p>',
1362 9438ad3a Andreas Kohlbecker
  );
1363
1364 ccde8251 Andreas Kohlbecker
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1365
      '#type' => 'checkboxes',
1366
      '#title' => 'Taxon media filter',
1367
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1368
      '#options' => array(
1369
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1370
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1371
          'includeOccurrences' => 'Media related to specimens and occurrences',
1372
      ),
1373
      '#description' => 'This filter configures which images should be taken into account.',
1374
  );
1375
1376
  $form['aggregation']['notice'] = array(
1377 3a874294 Andreas Kohlbecker
      '#markup' => '<strong>NOTICE:</strong> The below aggregation settings can slow down the data portal, so you may want to sensibly apply these setting and you may also
1378 ccde8251 Andreas Kohlbecker
          want to make use of the caching capabilities of the dataportal.',
1379
  );
1380
1381 f19f47fa Andreas Kohlbecker
  $form['aggregation']['media_aggregation'] = array(
1382
      '#type' => 'fieldset',
1383
      '#title' => t('Media aggregation'),
1384
      '#collapsible' => FALSE,
1385 9438ad3a Andreas Kohlbecker
      '#collapsed' => TRUE,
1386 f19f47fa Andreas Kohlbecker
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1387
1388 9438ad3a Andreas Kohlbecker
  );
1389 f19f47fa Andreas Kohlbecker
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1390
      '#type' => 'select',
1391
      '#title' => t('Aggregation of taxon pictures') . ':',
1392
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1393
      '#options' => array(
1394
          0 => "Show only pictures of the current taxon",
1395
          1 => "Include pictures of taxonomic children",
1396
      ),
1397
      '#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."),
1398 9438ad3a Andreas Kohlbecker
  );
1399
1400 f19f47fa Andreas Kohlbecker
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1401 30f78c59 Andreas Kohlbecker
      '#type' => 'fieldset',
1402 38dd933d Andreas Kohlbecker
      '#attributes' => array('class' => array('clearfix')),
1403 9438ad3a Andreas Kohlbecker
      '#title' => t('Aggregation via taxon relationsships'),
1404 30f78c59 Andreas Kohlbecker
      '#collapsible' => TRUE,
1405
      '#collapsed' => TRUE,
1406 f19f47fa Andreas Kohlbecker
      '#tree' => TRUE,
1407 30f78c59 Andreas Kohlbecker
      '#description' => t('Information on taxa will be aggregated along the below chosen
1408
          taxon relation ships. This will affect images and occurrences (specimens).
1409
          Taxon relation ships are directed and point form one taxon to another. The taxon
1410
          relationships to be taken into accunt can therefore configured for the direct direction
1411 f19f47fa Andreas Kohlbecker
          and for the inverse.'),
1412
  );
1413
1414 7ca5ef1e Andreas Kohlbecker
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1415 30f78c59 Andreas Kohlbecker
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1416 f19f47fa Andreas Kohlbecker
1417
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1418
      '#type' => 'checkboxes',
1419
      '#title' => t('Direct'),
1420
      '#options' => $taxonRelationshipTypeOptions,
1421
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1422 30f78c59 Andreas Kohlbecker
  );
1423 f19f47fa Andreas Kohlbecker
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1424
      '#type' => 'checkboxes',
1425
      '#title' => t('Invers'),
1426
      '#options' => $taxonRelationshipTypeOptions,
1427
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1428 30f78c59 Andreas Kohlbecker
  );
1429
1430 06c2b3e2 Andreas Kohlbecker
  $form['drupal_integration'] = array(
1431
    '#type' => 'fieldset',
1432 38dd933d Andreas Kohlbecker
    '#attributes' => array('class'=> array('clearfix')),
1433 06c2b3e2 Andreas Kohlbecker
    '#title' => t('Drupal integration'),
1434
    '#collapsible' => FALSE,
1435
    '#collapsed' => FALSE,
1436
    '#tree' => FALSE
1437
  );
1438
1439
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1440
    '#type' => 'checkbox',
1441
    '#title' => 'Create drupal nodes',
1442
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1443 944d793a Andreas Kohlbecker
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1444 06c2b3e2 Andreas Kohlbecker
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1445
    cdm pages it is required that drupal nodes are created and stored in the database.'
1446
  );
1447
1448
1449
1450
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1451
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1452
    <div class="description">Using this button, you will lose all content associated with the cdm drupal nodes which is stored in the drupal data base.</div>',
1453
  );
1454
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1455
    '#type' => 'submit',
1456
    '#value' => t('Drop all cdm nodes'),
1457
    '#submit' => array('drop_all_cdm_nodes_submit')
1458
  );
1459
1460
  $form['drupal_integration']['drop_all_cdm_nodes_warning_post'] = array(
1461
    '#markup' => '<div class="description">All Drupal nodes created for cdm content can be deleted at once using this button.</div>',
1462
  );
1463
1464
    // ----------------------
1465 5ea8b301 Andreas Kohlbecker
  $form['cdm_js_devel_mode'] = array(
1466
      '#type' => 'checkbox',
1467
      '#title' => 'Java-script developer mode',
1468
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1469
      '#description' => 'In production envirionments the java script libraries
1470
      the cdm_dataportal is making use of are compressed and optimized. This
1471
      is good for performance but a caveat if you need to debug java-script. When the
1472
      java-script developer mode is enabled the uncompressed and commented developer
1473
      versions of java-script libraries will be used where possible.
1474
      <br/><strong>Do not use this option in production!</strong>'
1475
  );
1476 2dd59bb5 Andreas Kohlbecker
  // ----------------------
1477
  $form['cdm_debug_mode'] = array(
1478
      '#type' => 'checkbox',
1479
      '#title' => 'CDM page debug mode',
1480
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1481
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1482 b5deb531 Andreas Kohlbecker
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1483
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1484
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1485 2dd59bb5 Andreas Kohlbecker
      The log is written by the drupal devel module function <code>dd()</code>.
1486 b5deb531 Andreas Kohlbecker
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1487 2dd59bb5 Andreas Kohlbecker
  );
1488 5ea8b301 Andreas Kohlbecker
1489 6657531f Andreas Kohlbecker
  // Comment @WA: D7 form api does not support reset buttons,
1490
  // so to mimic the D5 reset button we add one like this.
1491
  $form['actions']['reset'] = array(
1492
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1493
    '#weight' => 1000,
1494
  );
1495
1496 22eb20d7 Andreas Kohlbecker
  $form['#submit'][] = 'cdm_settings_general_submit';
1497
1498 6657531f Andreas Kohlbecker
  return system_settings_form($form);
1499
}
1500
1501 06c2b3e2 Andreas Kohlbecker
/**
1502
 * Submit callback; drops all cdm nodes.
1503
 *
1504
 * @ingroup forms
1505
 */
1506
function drop_all_cdm_nodes_submit($form, &$form_state) {
1507
  cdm_delete_all_cdm_nodes();
1508
  drupal_set_message(t('All cdm nodes dropped.'));
1509
}
1510
1511 6657531f Andreas Kohlbecker
1512
/**
1513
 * LAYOUT settings
1514 cf839840 Andreas Kohlbecker
 * @return
1515 6657531f Andreas Kohlbecker
 *   todo
1516
 */
1517
function cdm_settings_layout() {
1518
1519
  $form = array();
1520 0f5f1c12 Andreas Kohlbecker
1521
  $form['about'] = array(
1522
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1523 6657531f Andreas Kohlbecker
      layout. If you want to configure the specific sites layout visit the
1524 0f5f1c12 Andreas Kohlbecker
      respective configuration site for taxon, search or media.') . '</p>',
1525 6657531f Andreas Kohlbecker
  );
1526
1527
  // ---- footnotes --- //
1528 0f5f1c12 Andreas Kohlbecker
  $form['footnotes'] = array(
1529 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1530
    '#title' => t('Footnotes'),
1531
    '#collapsible' => FALSE,
1532
    '#collapsed' => FALSE,
1533
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1534
      media or distribution areas may have annotations or footnotes. When the
1535
      footnotes are enabled they will be visible (if they exist).'),
1536
  );
1537
1538 0f5f1c12 Andreas Kohlbecker
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1539 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1540
    '#title' => t('Do not show footnotes'),
1541
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1542
    '#description' => t('Check this if you do not want to show any footnotes'),
1543
  );
1544
1545 0f5f1c12 Andreas Kohlbecker
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1546 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1547 10055120 Andreas Kohlbecker
    '#title' => t('Do not show annotation footnotes'),
1548 6657531f Andreas Kohlbecker
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1549
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1550
  );
1551
1552 7370f4f7 Andreas Kohlbecker
  $form['annotations'] = array(
1553
    '#type' => 'fieldset',
1554
    '#title' => t('Annotations'),
1555
    '#collapsible' => FALSE,
1556
    '#collapsed' => FALSE,
1557
    '#description' => t('This sections allows configuring global settings regarding annotations and thus will affect annotations dispayed as footnote and others.'),
1558
  );
1559
1560 7ca5ef1e Andreas Kohlbecker
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1561 6657531f Andreas Kohlbecker
  // Additional option for the NULL case.
1562
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1563 7370f4f7 Andreas Kohlbecker
  $annotationsTypesAsFootnotes = variable_get(ANNOTATION_TYPES_VISIBLE, unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1564
  $form['annotations'][ANNOTATION_TYPES_VISIBLE] = array(
1565 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
1566 7370f4f7 Andreas Kohlbecker
    '#title' => t('Visbility of annotation types'),
1567
    '#description' => t("Only annotations of the selected type will be displayed. You may want to turn 'technical annotations' off."),
1568 6657531f Andreas Kohlbecker
    '#options' => $annotationTypeOptions,
1569 7370f4f7 Andreas Kohlbecker
    '#default_value' => $annotationsTypesAsFootnotes
1570 6657531f Andreas Kohlbecker
  );
1571 7370f4f7 Andreas Kohlbecker
1572 6657531f Andreas Kohlbecker
1573 5611d467 Andreas Kohlbecker
  // ---- original source --- //
1574
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1575
      '#type' => 'fieldset',
1576
      '#tree' => TRUE,
1577
      '#title' => t('Source Citations'),
1578
      '#collapsible' => FALSE,
1579
      '#collapsed' => FALSE,
1580
  );
1581 f19f47fa Andreas Kohlbecker
1582 800ff2b0 Andreas Kohlbecker
  $bibliography_settings = get_bibliography_settings(true);
1583 5611d467 Andreas Kohlbecker
1584 800ff2b0 Andreas Kohlbecker
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1585 5611d467 Andreas Kohlbecker
      '#type' => 'checkbox',
1586
      '#title' => t('Original Source in bibliography'),
1587
      '#default_value' => $bibliography_settings['enabled'],
1588
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1589 31f0f2b8 Andreas Kohlbecker
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1590
       into the bibliography also depends on the settings in the ' .
1591
        l("Taxon profile feature block settings", "settings/layout/taxon") .
1592
        '. For more information please refer to the description on the settings "<em>Sources as content</em>" & "<em>Sources as content to bibliography</em>" in that settings page.'),
1593 5611d467 Andreas Kohlbecker
  );
1594
1595
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1596
    '#type' => 'select',
1597
    '#title' => t('The format of the key numerals'),
1598
    '#default_value' => $bibliography_settings['key_format'],
1599
    '#options' => array('latin' => 'Latin',
1600
      'ROMAN' => 'Roman (upper case)',
1601
      'roman' => 'Roman (lower case)',
1602
      'ALPHA'=> 'Alphabet (upper case)',
1603
      'alpha' => 'Alphabet (lower case)')
1604
  );
1605 f19f47fa Andreas Kohlbecker
1606
  // --- Advanced Search --- //
1607
  $form['asearch'] = array(
1608 1ce9afb7 Patric Plitzner
      '#type' => 'fieldset',
1609
      '#title' => t('Advanced search'),
1610
      '#collapsible' => FALSE,
1611
      '#collapsed' => FALSE,
1612 f19f47fa Andreas Kohlbecker
  );
1613
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1614 1ce9afb7 Patric Plitzner
      '#type' => 'checkbox',
1615
      '#title' => t('Show advanced search link'),
1616
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1617
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1618 f19f47fa Andreas Kohlbecker
  );
1619
1620 977bba78 Andreas Kohlbecker
  // --- Registrations --- //
1621
  $form['registrations'] = array(
1622
    '#type' => 'fieldset',
1623
    '#title' => t('Registrations'),
1624
    '#collapsible' => FALSE,
1625
    '#collapsed' => FALSE,
1626
  );
1627
  $form['registrations']['cdm_registration_presistent_identifier_as_link'] = array(
1628
    '#type' => 'checkbox',
1629
    '#title' => t('Use the persistent http identifier as link'),
1630
    '#default_value' => variable_get('cdm_registration_presistent_identifier_as_link', 0),
1631
    '#description' => t('Switch the portal from using the drupal path <code>registration/{url encoded persistent http identifier}</code> to using the persistent http identifier directly as link.'),
1632
  );
1633
1634 f19f47fa Andreas Kohlbecker
  // ---- Taxon Name Rendering --- //
1635
  $form['taxon_name'] = array(
1636
      '#type' => 'fieldset',
1637
      '#title' => t('Taxon name display'),
1638
      '#collapsible' => TRUE,
1639
      '#collapsed' => TRUE,
1640 7cc085da Andreas Kohlbecker
      '#description' => t('The display of taxon names is configured by two parts.
1641
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1642
          The name parts are defined in the <stong>part definitions</strong>'),
1643 0f5f1c12 Andreas Kohlbecker
  );
1644
1645 78292e72 Andreas Kohlbecker
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1646 b2b9e057 Andreas Kohlbecker
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1647
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1648
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1649 1a01f6dd Andreas Kohlbecker
1650 b2b9e057 Andreas Kohlbecker
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1651 2eaa13b4 Andreas Kohlbecker
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1652 b2b9e057 Andreas Kohlbecker
    $which_version_message = '(These are the old default part definition from before EDIT platform release 3.8.0, you may want to reset these by clearing the text area and and submitting the form.)';
1653
  } else if($is_custom_part_definition){
1654 102f8c26 Andreas Kohlbecker
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1655 2eaa13b4 Andreas Kohlbecker
  } else  {
1656 1a01f6dd Andreas Kohlbecker
    $which_version_message = '(These are the default part definition.)';
1657
  }
1658
1659 b2b9e057 Andreas Kohlbecker
  $diff_viewer_markup = '';
1660
  if($is_custom_part_definition){
1661
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1662
  }
1663
1664
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1665
    . $which_version_message
1666
    . '</div>'
1667
    . $diff_viewer_markup;
1668
1669 0f5f1c12 Andreas Kohlbecker
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1670
      '#type' => 'textarea',
1671
      '#title' => t('Part definitions'),
1672
      '#element_validate' => array('form_element_validate_json'),
1673 43998144 Andreas Kohlbecker
      '#default_value' =>  $current_part_definition_json,
1674 0f5f1c12 Andreas Kohlbecker
      '#description' => '
1675 1a01f6dd Andreas Kohlbecker
          <p>' . $which_version_message . '</p>
1676 0f5f1c12 Andreas Kohlbecker
          <p>
1677
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1678
          </p>
1679
          <p>
1680
           A full taxon name plus additional information can consist of the following elements:
1681
          <ul>
1682
             <li>name: the taxon name inclugin rank nbut without author</li>
1683
             <li>authors:  The authors of a reference, also used in taxon names</li>
1684
             <li>reference: the nomenclatural reference,</li>
1685
             <li>microreference:  Volume, page number etc.</li>
1686
             <li>status:  The nomenclatural status of a name</li>
1687
             <li>description: name descriptions like protologues etc ...</li>
1688
          </ul>
1689
          </p>
1690
          <p>
1691
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1692
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1693 51b04faf Andreas Kohlbecker
           The following parts can be formed and are recognized by the system:
1694 0f5f1c12 Andreas Kohlbecker
          <ul>
1695 51b04faf Andreas Kohlbecker
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1696
            <li>authorshipPart: the author (for example: "L.")</li>
1697
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1698 0f5f1c12 Andreas Kohlbecker
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1699
               be combined when a link to the taxon is rendered.</li>
1700 51b04faf Andreas Kohlbecker
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1701
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1702
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1703 0f5f1c12 Andreas Kohlbecker
            <li>statusPart: the nomenclatorical status</li>
1704
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1705
          </ul>
1706
          </p>
1707
          <p>
1708
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1709
           specific parts part definitions:
1710
          <ul>
1711
            <li>BotanicalName</li>
1712
            <li>ZoologicalName</li>
1713
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1714
          </ul>
1715
           An example:
1716
          <pre>
1717
           {
1718
            "ZoologicalName": {
1719
              "namePart": {
1720
                "name": true
1721
              },
1722
              "referencePart": {
1723 b5519d3a Andreas Kohlbecker
                "authors": true
1724 0f5f1c12 Andreas Kohlbecker
              },
1725
              "microreferencePart": {
1726
                "microreference": true
1727
              },
1728
              "statusPart": {
1729
                "status": true
1730
              },
1731
              "descriptionPart": {
1732
                "description": true
1733
              }
1734
            },
1735
            "BotanicalName": {
1736
              "namePart": {
1737
                "name": true,
1738
                "authors": true
1739
              },
1740
              "referencePart": {
1741
                "reference": true,
1742
                "microreference": true
1743
              },
1744 43998144 Andreas Kohlbecker
              "secReferencePart": {
1745
                "secReference": true
1746
              },
1747 0f5f1c12 Andreas Kohlbecker
              "statusPart": {
1748
                "status": true
1749
              },
1750
              "descriptionPart": {
1751
                "description": true
1752
              }
1753
            }
1754
          }
1755
           </pre>',
1756
  );
1757
1758 78292e72 Andreas Kohlbecker
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1759 b2b9e057 Andreas Kohlbecker
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1760
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1761
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1762
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1763 1a01f6dd Andreas Kohlbecker
1764 2eaa13b4 Andreas Kohlbecker
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1765 b2b9e057 Andreas Kohlbecker
    $which_version_message = '(These are the old default render templates from before EDIT platform release 3.8.0, you may want to reset these by clearing the text area and and submitting the form.)';
1766
  } else if($is_custom_render_template){
1767
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1768 1a01f6dd Andreas Kohlbecker
  } else {
1769
    $which_version_message = '(These are the default render templates.)';
1770
  }
1771
1772 b2b9e057 Andreas Kohlbecker
  $diff_viewer_markup = '';
1773
  if($is_custom_render_template){
1774
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1775
  }
1776
1777
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1778
    . $which_version_message
1779
    . '</div>'
1780
    . $diff_viewer_markup;
1781
1782 f19f47fa Andreas Kohlbecker
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1783
      '#type' => 'textarea',
1784 0f5f1c12 Andreas Kohlbecker
      '#title' => t('Name render templates'),
1785 f19f47fa Andreas Kohlbecker
      '#element_validate' => array('form_element_validate_json'),
1786 1a01f6dd Andreas Kohlbecker
      '#default_value' =>  $current_render_templates_json,
1787 0f5f1c12 Andreas Kohlbecker
      '#description' => '
1788 1a01f6dd Andreas Kohlbecker
          <p>' . $which_version_message . '</p>
1789 0f5f1c12 Andreas Kohlbecker
          <p>
1790
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1791 f695daf4 Andreas Kohlbecker
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1792
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1793
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1794
          The following render Path keys are currently recognized:
1795 0f5f1c12 Andreas Kohlbecker
          <ul>
1796 51b04faf Andreas Kohlbecker
            <li>list_of_taxa</li>
1797
            <li>acceptedFor</li>
1798
            <li>homonym</li>
1799 0f5f1c12 Andreas Kohlbecker
            <li>taxon_page_synonymy</li>
1800
            <li>typedesignations</li>
1801
            <li>taxon_page_title</li>
1802
            <li>polytomousKey</li>
1803
            <li>na: name + authorship</li>
1804
            <li>nar:name + authorship + reference</li>
1805
            <li>#DEFAULT</li>
1806
          </ul>
1807
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1808
          array element should be a comma separated list of render paths, without any whitespace!.
1809
          </p>
1810
          <p>
1811
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1812
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1813
          <p>
1814
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1815 43998144 Andreas Kohlbecker
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1816
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1817 0f5f1c12 Andreas Kohlbecker
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1818
          links if the paramters $nameLink or $refenceLink are given to the name render function
1819 f19f47fa Andreas Kohlbecker
          (this is hard coded and cannot be configured here).',
1820 6657531f Andreas Kohlbecker
  );
1821
1822
  // @WA: D7 form api does not support reset buttons,
1823
  // so to mimic the D5 reset button we add one like this.
1824
  $form['actions']['reset'] = array(
1825
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1826
    '#weight' => 1000,
1827
  );
1828 f19f47fa Andreas Kohlbecker
1829 0f5f1c12 Andreas Kohlbecker
  $form['#submit'] = array('submit_json_as_php_array');
1830
  // #json_elements especially defined for submit_json_as_php_array()
1831
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1832 6657531f Andreas Kohlbecker
  return system_settings_form($form);
1833
}
1834
1835
1836 045fb441 Andreas Kohlbecker
/**
1837
 * @param $form_name
1838
 * @param $form_title
1839
 * @param $collapsed
1840
 * @param string $form_description
1841
 *   The description for the fieldset of the gallery setting.
1842
 * @return mixed
1843 6657531f Andreas Kohlbecker
 */
1844
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1845
  $form[$form_name] = array(
1846
    '#type' => 'fieldset',
1847 7cc085da Andreas Kohlbecker
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1848 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
1849
    '#collapsed' => $collapsed,
1850
    '#tree' => TRUE,
1851 045fb441 Andreas Kohlbecker
    '#description' => $form_description,
1852 6657531f Andreas Kohlbecker
  );
1853
1854
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1855
  $gallery_settings = variable_get($form_name, $default_values);
1856
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1857
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1858
    /*
1859
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1860
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1861
    '#type' => 'textfield',
1862
    '#title' => t('Search Page Size'),
1863
    '#default_value' => $test,
1864
    '#description' => t('Number of Names to display per page in search results.')
1865
    );
1866
    */
1867
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1868
      '#type' => 'checkbox',
1869
      '#title' => t('Show media thumbnails for accepted taxa'),
1870
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1871
    );
1872
1873
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1874
      '#type' => 'checkbox',
1875
      '#title' => t('Show media thumbnails for synonyms'),
1876
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1877
      '#description' => '',
1878
    );
1879
  }
1880
1881
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1882
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1883
    '#type' => 'checkbox',
1884
    '#title' => t('Show captions under thumbnails'),
1885
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1886
    '#description' => '',
1887
  );
1888
1889
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1890
    '#type' => 'textfield',
1891 5358baff Andreas Kohlbecker
    '#title' => t('Thumbnail size (max of width or height)') . ':',
1892 6657531f Andreas Kohlbecker
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1893 5358baff Andreas Kohlbecker
    '#description' => t('The maximum extend in either dimension, width or height, in pixels for the thumbnail images in the gallery.'),
1894 6657531f Andreas Kohlbecker
  );
1895
1896 63d5030d Andreas Kohlbecker
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1897
    '#type' => 'textfield',
1898
    '#title' => t('Number of columns') . ':',
1899
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1900
    '#description' => t('Group the thumbnails in columns: select how many
1901
      columns the gallery should display.'),
1902
  );
1903 6657531f Andreas Kohlbecker
1904
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1905
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1906
      '#type' => 'textfield',
1907
      '#title' => t('Maximum number of rows') . ':',
1908
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1909
      '#description' => t('You can group the thumbnails in rows, select in how
1910
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1911
        If you want an unlimited number of rows please set to 0.'),
1912
    );
1913
  }
1914
1915
  return $form;
1916
}
1917
1918
/**
1919
 * @todo document this function.
1920
 */
1921
function cdm_settings_layout_taxon() {
1922
  $collapsed = FALSE;
1923
  $form = array();
1924
1925 7df1be04 Andreas Kohlbecker
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1926
1927 6657531f Andreas Kohlbecker
  // --------- TABBED TAXON ------- //
1928
  $form['taxon_tabs'] = array(
1929
    '#type' => 'fieldset',
1930
    '#title' => t('Taxon tabs'),
1931
    '#collapsible' => TRUE,
1932 6421984d Andreas Kohlbecker
    '#collapsed' => TRUE,
1933 423f5e58 Andreas Kohlbecker
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
1934 6657531f Andreas Kohlbecker
  );
1935
1936
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1937
    '#type' => 'checkbox',
1938
    '#title' => t('Tabbed taxon page'),
1939
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1940 423f5e58 Andreas Kohlbecker
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1941 22383f95 Andreas Kohlbecker
  );
1942
1943
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
1944
    '#type' => 'checkbox',
1945
    '#title' => t('Synonymy as tab'),
1946
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
1947
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
1948
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
1949 6657531f Andreas Kohlbecker
  );
1950
1951
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1952
    '#type' => 'checkboxes',
1953 423f5e58 Andreas Kohlbecker
    '#title' => t('Section/Tab visibility') . ':',
1954 6657531f Andreas Kohlbecker
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1955 423f5e58 Andreas Kohlbecker
    '#options' => get_taxon_options_list()
1956 6657531f Andreas Kohlbecker
  );
1957
1958 b54cbda1 Andreas Kohlbecker
  // WEIGHT
1959 4feeabc7 Andreas Kohlbecker
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1960
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1961 423f5e58 Andreas Kohlbecker
    '#title'  => 'Section/Tab order',
1962 2a61a296 Andreas Kohlbecker
    '#type' => 'fieldset',
1963
    '#collapsible' => false,
1964 4feeabc7 Andreas Kohlbecker
    '#tree' => true,
1965 423f5e58 Andreas Kohlbecker
    '#description' => 'The weight value defines the order of the section/tab.'
1966 b54cbda1 Andreas Kohlbecker
  );
1967
  // Weights range from -delta to +delta, so delta should be at least half
1968
  // of the amount of tabs present.
1969
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1970
  foreach (get_taxon_tabs_list() as $label) {
1971
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1972 4feeabc7 Andreas Kohlbecker
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1973 b54cbda1 Andreas Kohlbecker
        '#title' => $label,
1974
        '#type'  => 'weight',
1975 4feeabc7 Andreas Kohlbecker
        '#default_value' => $taxon_tabs_weights[$key],
1976 b54cbda1 Andreas Kohlbecker
        '#delta' => $tab_weight_delta
1977
    );
1978
  }
1979
1980 4feeabc7 Andreas Kohlbecker
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1981
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1982 423f5e58 Andreas Kohlbecker
    '#title'  => 'Section/Tab label override',
1983 2a61a296 Andreas Kohlbecker
    '#type' => 'fieldset',
1984
    '#collapsible' => false,
1985 4feeabc7 Andreas Kohlbecker
    '#tree' => true,
1986 423f5e58 Andreas Kohlbecker
    '#description' => 'Setting a label for a section/tab will override the default label. 
1987 93115722 Andreas Kohlbecker
      Please enter the label text in the default language of the portal.'
1988 4feeabc7 Andreas Kohlbecker
  );
1989
  foreach (get_taxon_tabs_list() as $label) {
1990
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1991
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1992
      '#title' => $label,
1993
      '#type'  => 'textfield',
1994
      '#default_value' => $taxon_tabs_labels[$key]
1995
    );
1996
  }
1997
1998 6657531f Andreas Kohlbecker
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1999
    '#type' => 'select',
2000
    '#title' => t('Default tab to display') . ':',
2001
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
2002
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
2003
    '#description' => t('<p>Select the default tab to display when visiting a
2004
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
2005
      <strong>Note:</strong> After performing a search and clicking in any
2006
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
2007
      taxon and not the above selected tab.'),
2008
  );
2009
2010
  /* ======  TAXON_PROFILE ====== */
2011
  $form['taxon_profile'] = array(
2012
    '#type' => 'fieldset',
2013
    '#title' => t('Taxon profile (tab)'),
2014 9438ad3a Andreas Kohlbecker
    '#description' => t('<p>This section covers the settings related to the taxon
2015 6657531f Andreas Kohlbecker
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
2016
    '#collapsible' => TRUE,
2017 6421984d Andreas Kohlbecker
    '#collapsed' => TRUE,
2018 6657531f Andreas Kohlbecker
  );
2019
2020
  // ---- PROFILE PICTURE ----//
2021 9c92cd84 Andreas Kohlbecker
2022
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
2023 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2024 9c92cd84 Andreas Kohlbecker
    '#tree' => TRUE,
2025 9438ad3a Andreas Kohlbecker
    '#title' => t('Taxon profile picture'),
2026 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
2027
    '#collapsed' => FALSE,
2028 9438ad3a Andreas Kohlbecker
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
2029 6657531f Andreas Kohlbecker
  );
2030
2031 9c92cd84 Andreas Kohlbecker
  //FIXME migrate variables:
2032
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
2033
  // FIXME
2034 9aff46e4 Andreas Kohlbecker
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
2035 9c92cd84 Andreas Kohlbecker
2036
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
2037 9506fd1f Andreas Kohlbecker
2038 9c92cd84 Andreas Kohlbecker
  /*
2039
   * 'show' => 1,
2040
   * 'maxextend' => 184,
2041 053a92ec Andreas Kohlbecker
   * 'media_uri_query' => ''
2042 9c92cd84 Andreas Kohlbecker
   * 'custom_placeholder_image_on' => 1,
2043
   * 'custom_placeholder_image_fid' => ''
2044
   */
2045
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
2046 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
2047 6421984d Andreas Kohlbecker
    '#title' => t('Enable profile picture'),
2048
    '#description' => t('Show the profile picture.'),
2049 9c92cd84 Andreas Kohlbecker
    '#default_value' => $taxon_profile_image_settings['show'],
2050 6657531f Andreas Kohlbecker
  );
2051
2052 9c92cd84 Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
2053 d9c55e6c Andreas Kohlbecker
      '#type' => 'textfield',
2054
      '#tree' => TRUE,
2055 6421984d Andreas Kohlbecker
      '#title' => t('Profile picture maximum extend'),
2056 9c92cd84 Andreas Kohlbecker
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
2057 d9c55e6c Andreas Kohlbecker
      '#field_suffix' => 'px',
2058
      '#maxlength' => 4,
2059
      '#size' => 4,
2060 7cc085da Andreas Kohlbecker
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
2061 d9c55e6c Andreas Kohlbecker
  );
2062
2063 053a92ec Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
2064
      '#type' => 'textfield',
2065
      '#tree' => TRUE,
2066
      '#title' => t('Additional URI query parameter'),
2067
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
2068
      '#maxlength' => 1024,
2069
      '#size' => 60,
2070 7cc085da Andreas Kohlbecker
      '#description' => t('Additional query parameters to be used when requesting for the  
2071
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
2072
            The query parameters will be appended to the uri of the media representation part
2073
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
2074 053a92ec Andreas Kohlbecker
  );
2075
2076 ca47ea76 Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2077
    '#type' => 'checkbox',
2078
    '#title' => t('Show the placeholder image'),
2079 792a9d48 Andreas Kohlbecker
    '#description' => t("A placeholder image will be shown if no taxon profile picture is available."),
2080 ca47ea76 Andreas Kohlbecker
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2081
  );
2082
2083 9c92cd84 Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2084
      '#type' => 'checkbox',
2085
      '#title' => t('Use a custom placeholder image'),
2086 7df1be04 Andreas Kohlbecker
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2087 9c92cd84 Andreas Kohlbecker
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2088 7df1be04 Andreas Kohlbecker
  );
2089
2090 9c92cd84 Andreas Kohlbecker
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2091
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2092
        '#type' => 'managed_file',
2093
        '#title' => t('Custom placeholder image file'),
2094
        '#progress_indicator' => 'bar',
2095
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2096
    //       '#name' => 'custom_placeholder_image',
2097
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2098
    );
2099
2100
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2101
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2102
      $url = file_create_url($profile_image_file->uri);
2103
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2104
                '#type' => 'item',
2105
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2106
      );
2107
    }
2108
  } else {
2109
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2110 642b323b Andreas Kohlbecker
      '#type' => 'hidden',
2111
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2112 9c92cd84 Andreas Kohlbecker
    );
2113
  }
2114
2115 2d3d6556 Andreas Kohlbecker
  $options = cdm_vocabulary_as_option(UUID_RANK, null, true);
2116 6657531f Andreas Kohlbecker
  array_unshift($options, '-- DISABLED --');
2117
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2118
    '#type' => 'select',
2119 9438ad3a Andreas Kohlbecker
    '#title' => t('Hide profile picture for higher ranks') . ':',
2120 6657531f Andreas Kohlbecker
    '#default_value' => variable_get('image_hide_rank', '0'),
2121
    '#options' => $options,
2122 9438ad3a Andreas Kohlbecker
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2123 6657531f Andreas Kohlbecker
  );
2124
2125
  // -- MEDIA THUMBNAILS -- //
2126
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2127
  $form_title = 'Taxon Profile Images';
2128 5358baff Andreas Kohlbecker
  $form_description = '<p>The different sections 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>';
2129 6657531f Andreas Kohlbecker
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2130
2131 642b323b Andreas Kohlbecker
  // ---- FEATURE TREE BLOCKS ---- //
2132
  $form['taxon_profile']['feature_blocks'] = array(
2133 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2134 642b323b Andreas Kohlbecker
    '#title' => t('Feature Blocks'),
2135 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
2136
    '#collapsed' => FALSE,
2137
    '#description' => t("This section covers settings related to the taxon's
2138
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2139 642b323b Andreas Kohlbecker
      features such as description, distribution, common names"),
2140 6657531f Andreas Kohlbecker
  );
2141
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2142 642b323b Andreas Kohlbecker
  $profile_feature_tree = get_profile_feature_tree();
2143
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2144
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2145
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2146 854e1d99 Andreas Kohlbecker
  }
2147 642b323b Andreas Kohlbecker
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2148 6657531f Andreas Kohlbecker
    '#type' => 'radios',
2149 642b323b Andreas Kohlbecker
    '#title' => t('Taxon profile feature tree') . ':',
2150
    '#default_value' => $profile_feature_tree_uuid,
2151 6657531f Andreas Kohlbecker
    '#options' =>  $featureTrees['options'],
2152 3f485c6d Andreas Kohlbecker
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2153
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2154 642b323b Andreas Kohlbecker
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
2155
      profile page.'
2156 6657531f Andreas Kohlbecker
    ),
2157
  );
2158
2159 642b323b Andreas Kohlbecker
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2160
  $profile_feature_tree = get_profile_feature_tree();
2161
2162
  if (isset($profile_feature_tree->root->childNodes)) {
2163 6657531f Andreas Kohlbecker
2164 642b323b Andreas Kohlbecker
    $form_feature_block_layout = array(
2165
      '#type' => 'fieldset',
2166
      '#tree' => true,
2167
      '#title' => t('Taxon profile feature block settings'),
2168 6657531f Andreas Kohlbecker
      '#collapsible' => TRUE,
2169
      '#collapsed' => FALSE,
2170 642b323b Andreas Kohlbecker
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2171
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
2172
      The subforms have the following settings in common:<br />
2173
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2174
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2175 a2196313 Andreas Kohlbecker
      <h6>Link to name used in source:</h6><div>Whether to show name in source information as link which will point to the according name page</div>
2176 642b323b Andreas Kohlbecker
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2177
            <ol>
2178 a2196313 Andreas Kohlbecker
            <li>If the element is a CDM TextData instance and if the text is not empty the source references will be
2179 642b323b Andreas Kohlbecker
                appended in brackets like "text (source references)". If the original source has name in source
2180
                information it will be appended to the citation string,
2181 a2196313 Andreas Kohlbecker
                like : "(citation-A, as name-in-source-A; citation-B, as name-in-source-B)"</li>
2182 642b323b Andreas Kohlbecker
             <li>if the text of the TextData is empty, the original source citations are the only content
2183
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2184
                prepended to the citation string like: "name in source: citation"</li>
2185
            </ol>
2186
            <strong>If disabled:</strong><br />
2187
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2188
             citations are the only content, the resulting feature block content would only consist of footnotes.
2189
             In this case the display of the respective feature block is suppressed.</div>
2190
      </dl>
2191
      <h6>Sources as content to bibliography:</h6><div>Only valid if <em>Sources as content</em> is enabled, will cause the sources to be also shown
2192 0686f307 Andreas Kohlbecker
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2193
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2194
        . '</em></div>
2195 642b323b Andreas Kohlbecker
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2196
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2197
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2198
      <h6>Element tag:</h6><div>The tag to be used for creating the elements, only applies if "List type" is set to <em>No list</em>
2199
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2200 b9e9f59b Andreas Kohlbecker
           cdm_feature_block_element_tag_name()</div>
2201
       <h6>Element glue:</h6><div>This string is used to concatenate individual items together. The glue is ignored when the items are displayed 
2202
           as list.<b>NOTE:</b>The glue is not yet fully implemented for all features and thus may not work as expected, see '
2203
           . l('#6831', 'https://dev.e-taxonomy.eu/redmine/issues/6831') . '</div>',
2204 6657531f Andreas Kohlbecker
    );
2205
2206 642b323b Andreas Kohlbecker
2207
    $feature_list_layout_settings_disabled = FALSE;
2208 8c962983 Andreas Kohlbecker
2209
    // creating helper object to retrieve the default settings
2210
    $featureNode = new stdClass();
2211 b011743c Andreas Kohlbecker
    $featureNode->term = new stdClass();
2212
    $featureNode->term->uuid="DEFAULT";
2213
    $featureNode->term->representation_L10n = "Default";
2214 8c962983 Andreas Kohlbecker
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2215
2216 642b323b Andreas Kohlbecker
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2217 6657531f Andreas Kohlbecker
2218 b011743c Andreas Kohlbecker
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2219 6657531f Andreas Kohlbecker
2220 642b323b Andreas Kohlbecker
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2221 b011743c Andreas Kohlbecker
        $subform_id = $featureNode->term->uuid;
2222
        $feature_block_setting = get_feature_block_settings($featureNode->term->uuid);
2223 6657531f Andreas Kohlbecker
2224 642b323b Andreas Kohlbecker
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2225
2226
        $form_feature_block_layout[$subform_id] = array(
2227
          '#type' => 'fieldset',
2228 6657531f Andreas Kohlbecker
          '#tree' => TRUE,
2229 b011743c Andreas Kohlbecker
          '#title' => $featureNode->term->representation_L10n,
2230 6657531f Andreas Kohlbecker
          '#collapsible' => FALSE,
2231
          '#collapsed' => FALSE,
2232
        );
2233 b011743c Andreas Kohlbecker
        if($featureNode->term->uuid == "DEFAULT"){
2234 8c962983 Andreas Kohlbecker
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2235
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2236
          references</em> and <em>names in source</em> is only possible in the defaults';
2237
        }
2238 6657531f Andreas Kohlbecker
2239 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2240
          '#type' => 'select',
2241
          '#title' => 'List type',
2242
          '#default_value' => $feature_block_setting['as_list'],
2243
          '#options' => array(
2244
            'div' => 'not as list',
2245
            'ul' => 'bullet list',
2246
            'ol' => 'numbered list',
2247
            'dl' => 'definition list'
2248
          ),
2249
        );
2250
2251 b011743c Andreas Kohlbecker
        if($featureNode->term->uuid == "DEFAULT"){
2252 8c962983 Andreas Kohlbecker
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2253
            '#type' => 'checkbox',
2254
            '#title' => t('Link to reference'),
2255
            '#default_value' => $feature_block_setting['link_to_reference'],
2256
          );
2257 642b323b Andreas Kohlbecker
2258 8c962983 Andreas Kohlbecker
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2259
            '#type' => 'checkbox',
2260
            '#title' => 'Link to name used in source',
2261
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2262
          );
2263
        }
2264 6657531f Andreas Kohlbecker
2265 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2266
          '#type' => 'checkbox',
2267
          '#title' => 'Sources as content',
2268
          '#default_value' => $feature_block_setting['sources_as_content'],
2269 6657531f Andreas Kohlbecker
        );
2270
2271 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2272
          '#type' => 'checkbox',
2273 8c962983 Andreas Kohlbecker
          '#title' => 'Put sources also as content to bibliography',
2274 642b323b Andreas Kohlbecker
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2275 6657531f Andreas Kohlbecker
        );
2276
2277 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2278
          '#type' => 'select',
2279
          '#title' => t('Sort elements'),
2280
          '#default_value' => $feature_block_setting['sort_elements'],
2281
          '#options' => array(
2282
            NO_SORT => 'No sorting',
2283
            SORT_ASC => 'Ascending',
2284
            SORT_DESC => 'Descending',
2285 3eccfdb9 Andreas Kohlbecker
            SORT_HIERARCHICAL => 'Hierarchical'
2286 642b323b Andreas Kohlbecker
          ),
2287 3eccfdb9 Andreas Kohlbecker
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2288
          <dl>
2289
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2290
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2291
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2292
          <dr><dt>Hierarchical</dt><dd>Use the order of items and their hierarchy. This is not possible for all feature and item types.</dd></dr>
2293
          </dl>',
2294 6657531f Andreas Kohlbecker
        );
2295
2296 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2297
          '#type' => 'select',
2298
          '#title' => t('Element tag'),
2299
          '#options' => array(
2300
            'span' => 'span',
2301 29f63b48 Andreas Kohlbecker
            'div' => 'div',
2302
            'p' => 'p'
2303 642b323b Andreas Kohlbecker
          ),
2304
          '#default_value' => $feature_block_setting['element_tag'],
2305
        );
2306 b9e9f59b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['glue'] = array(
2307
          '#type' => 'textfield',
2308
          '#title' => t('Element glue'),
2309
          '#default_value' => $feature_block_setting['glue'],
2310
          '#size' => 10
2311
      );
2312
2313 6657531f Andreas Kohlbecker
      }
2314 642b323b Andreas Kohlbecker
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2315 6657531f Andreas Kohlbecker
    }
2316
  }
2317
2318 642b323b Andreas Kohlbecker
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2319
  $form['taxon_profile']['structured_description_featuretree'] = array(
2320
    '#type' => 'fieldset',
2321
    '#title' => t('Structured Description Feature Tree'),
2322
    '#collapsible' => TRUE,
2323
    '#collapsed' => FALSE,
2324
  );
2325
  $featureTrees = cdm_get_featureTrees_as_options();
2326
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2327
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2328
    $profile_feature_tree_uuid = NULL;
2329
  }
2330
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2331
    '#type' => 'radios',
2332
    '#title' => t('Natural language representation of structured descriptions') . ':',
2333
    '#default_value' => $profile_feature_tree_uuid,
2334
    '#options' => $featureTrees['options'],
2335
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2336
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2337
    '#description' => t('Taxon descriptions can be stored in a highly structured
2338
      form. The feature tree selected here will be used to generate textual
2339
      representation in natural language.'
2340
    ),
2341
  );
2342
2343
2344
2345 6657531f Andreas Kohlbecker
  // ---- DISTRIBUTION LAYOUT ---- //
2346
  $form['taxon_profile']['distribution_layout'] = array(
2347
    '#title' => t('Distribution'),
2348
    '#collapsible' => TRUE,
2349
    '#collapsed' => FALSE,
2350
    '#type' => 'fieldset',
2351 378bc1ce Andreas Kohlbecker
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2352
        Map settings regarding the geometry, layers, etc are found in the '
2353 562a6ac4 Andreas Kohlbecker
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2354
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2355
      . l(
2356
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2357
        array('fragment' => 'edit-feature-block-settings')
2358
      )
2359
      . ' More general settings regrading the filtering of Distributions are found at '
2360
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2361
      . '. (These settings here will be merged in future releases into the feature block settings)',
2362
2363 6657531f Andreas Kohlbecker
  );
2364
2365 378bc1ce Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2366
2367 bda17f32 Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2368
    '#type' => 'checkbox',
2369
    '#title' => t('Condensed distribution'),
2370
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2371
    '#description' => 'This option enables the display of a very compact representation
2372
    of the distribution which includes also information on the status.',
2373
  );
2374
2375 846c0606 Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2376
    '#type' => 'select',
2377
    '#title' => t('Condensed distribution recipe'),
2378
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2379
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2380
    '#description' => 'Recipe for creating the condensed distribution.',
2381
  );
2382
2383 6858b474 Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2384
    '#type' => 'textfield',
2385
    '#title' => t('Condensed distribution info path'),
2386
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2387
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2388
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2389
  );
2390
2391 bda17f32 Andreas Kohlbecker
2392 f5bc56a0 Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2393 6657531f Andreas Kohlbecker
    '#type' => 'radios',
2394 c359043a Andreas Kohlbecker
    '#title' => t('Display mode') . ':',
2395 97ac3d38 Andreas Kohlbecker
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2396 6657531f Andreas Kohlbecker
    '#options' => array(
2397 f5bc56a0 Andreas Kohlbecker
      'FLAT_ALPHA' => t('Flat list'),
2398
      'TREE' => t('Hierarchically ordered'),
2399 6657531f Andreas Kohlbecker
    ),
2400 0eef1621 Andreas Kohlbecker
    '#description' => 'Taxon distribution information is displayed with
2401 f5bc56a0 Andreas Kohlbecker
    focus on the area of the distribution. The list of areas can either be shown
2402 0eef1621 Andreas Kohlbecker
    as flat list ordered alphabetically or in the hierarchical of the parent
2403
    area and subarea relationship. Fall back areas areas with no Distribution data
2404
    are hidden from the area hierarchy so that their sub areas will move one level up.
2405
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2406 40420110 Andreas Kohlbecker
    ' for details on the <em>Marked area filter</em>.',
2407 6657531f Andreas Kohlbecker
  );
2408
2409 38dd933d Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2410
    '#type' => 'fieldset',
2411
    '#tree' => true,
2412
    '#title' => t('Distribution hierarchy style')
2413
  );
2414
2415
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2416
  foreach(array_keys($hierarchy_styles) as $level) {
2417
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2418
      '#type' => 'fieldset',
2419
      '#tree' => true,
2420 7cc085da Andreas Kohlbecker
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2421 38dd933d Andreas Kohlbecker
      '#attributes' => array('class' => array('fieldset-float'))
2422
    );
2423
    foreach ($hierarchy_styles[$level] as $key => $value) {
2424
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2425
        '#type' => 'textfield',
2426 7cc085da Andreas Kohlbecker
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2427 38dd933d Andreas Kohlbecker
        '#default_value' => $hierarchy_styles[$level][$key],
2428
        '#maxlength' => 4,
2429
        '#size' => 4
2430
      );
2431
    }
2432
  }
2433
2434 b3b63fc8 Andreas Kohlbecker
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2435 f5bc56a0 Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2436
    '#type' => 'checkboxes',
2437
    '#title' => 'Omit area levels',
2438
    '#options' => $level_options,
2439
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2440 284fb36d Andreas Kohlbecker
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2441
    Areas which belong to the selected area levels will be hidden in the portal.',
2442 f5bc56a0 Andreas Kohlbecker
  );
2443
2444 6657531f Andreas Kohlbecker
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2445
    '#type' => 'checkbox',
2446
    '#title' => t('Show TextData elements on top of the map'),
2447
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2448
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2449
      elements on top of the map. Otherwise all <code>TextData</code>
2450
      distribution elements will be listed below the other area elements.
2451
      This option is useful if you need to have descriptive texts for each
2452
      distribution map.'),
2453
  );
2454
2455 c6ee8193 Andreas Kohlbecker
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2456
      '#type' => 'textarea',
2457
      '#title' => t('Custom status colors'),
2458
      '#element_validate' => array('form_element_validate_json'),
2459
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2460
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2461
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2462 eb961cb9 Andreas Kohlbecker
          reference list of the idInVocabulary values of absence and presence terms:
2463 c6ee8193 Andreas Kohlbecker
<pre>
2464 eb961cb9 Andreas Kohlbecker
Presence Term
2465
p	present
2466
pd	present: doubtfully present
2467
n	native
2468
nq	native: presence questionable
2469
nd	native: doubtfully native
2470
c	cultivated
2471
i	introduced
2472
iq	introduced: presence questionable
2473
id	introduced: doubtfully introduced (perhaps cultivated only)
2474
ip	introduced: uncertain degree of naturalisation
2475
ia	introduced: adventitious (casual)
2476
in	introduced: naturalized
2477
ic	introduced: cultivated
2478
e	endemic for the relevant area
2479
na	naturalised
2480
iv	invasive
2481
2482
AbsenceTerm
2483
a	absent
2484
f	reported in error
2485
nf	native: reported in error
2486
if	introduced: reported in error
2487
cf	cultivated: reported in error
2488
ne	native: formerly native
2489
ie	introduced: formerly introduced
2490
2491 c6ee8193 Andreas Kohlbecker
</pre>'),
2492
  );
2493
2494 6657531f Andreas Kohlbecker
2495
  /* ====== SYNONYMY ====== */
2496
  $form['taxon_synonymy'] = array(
2497
    '#type' => 'fieldset',
2498
    '#title' => t('Taxon synonymy (tab)'),
2499
    '#collapsible' => TRUE,
2500
    '#collapsed' => TRUE,
2501
    '#description' => t('This section covers the settings related to the taxon
2502 501347df Andreas Kohlbecker
      <strong>synonymy</strong> tab.'),
2503 6657531f Andreas Kohlbecker
  );
2504
2505
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2506
    '#type' => 'checkbox',
2507 1cda248c Andreas Kohlbecker
    '#title' => t('Accepted taxon on top of the synonymy'),
2508 6657531f Andreas Kohlbecker
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2509
    '#description' => t('If checked, the first homotypic taxon is a repetition
2510 1cda248c Andreas Kohlbecker
      of the accepted taxon most likely with the full nomenclatural reference, 
2511
      depending on the ' . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout') . '.'),
2512 6657531f Andreas Kohlbecker
  );
2513
2514 1cda248c Andreas Kohlbecker
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE] = array(
2515
    '#type' => 'checkbox',
2516
    '#title' => t('Secundum referenence as separate line above the accepted taxon.'),
2517
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE, 0),
2518
    '#description' => t('You may want to remove the <code>"secReferencePart": true,</code> entry from <code>"accepted_taxon.taxon_page_synonymy"{</code> the in the '
2519
      . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout')
2520
      . ' (Only applicable when the "Show accepted taxon on top of the synonymy" option above is enabled.)'),
2521
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE)
2522
  );
2523
2524
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL] = array(
2525
    '#type' => 'textfield',
2526
    '#description' => 'Label for the secundum referenence.',
2527
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT),
2528
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', 0)
2529
    );
2530
2531 6657531f Andreas Kohlbecker
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2532
    '#type' => 'checkbox',
2533
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2534
      coming from a synonym link.'),
2535
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2536
    '#description' => t('Check this if after doing a search and clicking on a
2537
      synonym you want to see the "accept of" text for the accepted synonym.'),
2538
  );
2539
2540 24058570 Andreas Kohlbecker
  /* === currently unused ===
2541 7ca5ef1e Andreas Kohlbecker
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2542 5014bf09 Andreas Kohlbecker
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2543 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
2544
    '#title' => t('Display name relationships') . ':',
2545
    '#default_value' => variable_get('name_relationships_to_show', 0),
2546
    '#options' => $nameRelationshipTypeOptions,
2547
    '#description' => t('Select the name relationships you want to show for the
2548
      accepted taxa.'),
2549
  );
2550 24058570 Andreas Kohlbecker
 */
2551 6657531f Andreas Kohlbecker
2552 6421984d Andreas Kohlbecker
  $form['taxon_synonymy']['taxon_relations'] = array(
2553
    '#type' => 'fieldset',
2554
    '#title' => t('Taxon relationships'),
2555
    '#collapsible' => FALSE,
2556
    '#collapsed' => FALSE
2557
  );
2558
2559
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2560 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
2561
    '#title' => t('Show taxon relations ships of accepted taxon'),
2562
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2563
    '#description' => t('If this option is enabled the synonymy will show the
2564
      below selected taxon relationships of accepted taxa.'),
2565
  );
2566
2567 eafb60f0 Andreas Kohlbecker
  $taxon_relationship_type_options = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2568
  $taxon_relationship_type_defaults = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
2569 6421984d Andreas Kohlbecker
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2570 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
2571
    '#title' => t('Taxon relationship types') . ':',
2572
    '#description' => t('Only taxon relationships of the selected type will be
2573
      displayed'),
2574 eafb60f0 Andreas Kohlbecker
    '#options' => $taxon_relationship_type_options,
2575
    '#default_value' => $taxon_relationship_type_defaults,
2576 6657531f Andreas Kohlbecker
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2577
  );
2578
2579 6421984d Andreas Kohlbecker
  $form['taxon_synonymy']['name_relations'] = array(
2580
    '#type' => 'fieldset',
2581
    '#title' => t('Name relationships'),
2582
    '#collapsible' => FALSE,
2583
    '#collapsed' => FALSE
2584
  );
2585
2586 eafb60f0 Andreas Kohlbecker
  $name_relationship_type_options = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2587 6421984d Andreas Kohlbecker
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2588
    '#type' => 'checkboxes',
2589
    '#title' => t('Name relationship types') . ':',
2590
    '#description' => t('Only name relationships of the selected type will be
2591
      displayed'),
2592 eafb60f0 Andreas Kohlbecker
    '#options' => $name_relationship_type_options,
2593 6421984d Andreas Kohlbecker
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2594
  );
2595
2596 6657531f Andreas Kohlbecker
  // ====== SPECIMENS ====== //
2597
  $form['taxon_specimens'] = array(
2598
    '#type' => 'fieldset',
2599
    '#title' => t('Taxon specimens (tab)'),
2600
    '#collapsible' => TRUE,
2601
    '#collapsed' => TRUE,
2602
    '#description' => t('This section covers the settings related to the taxon
2603
      <strong>specimens</strong> tab.'),
2604
  );
2605
2606 378bc1ce Andreas Kohlbecker
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2607
2608
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2609
    '#type' => 'checkbox',
2610
    '#title' => t('Show specimen derivatives in a compressed table'),
2611
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2612
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2613
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2614
  );
2615
2616 09f028e2 Andreas Kohlbecker
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2617
      '#type' => 'textfield',
2618
      '#title' => t('Number of records per page') . ':',
2619
      '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2620 378bc1ce Andreas Kohlbecker
  );
2621 1ce9afb7 Patric Plitzner
2622 276f39f6 Katja Luther
    $form['taxon_specimens']['cdm_dataportal_specimen_derivate_tree'] = array(
2623
        '#type' => 'checkbox',
2624
        '#title' => t('Show specimen derivatives in a tree view'),
2625
        '#default_value' => variable_get('cdm_dataportal_specimen_derivate_tree', CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE),
2626
        '#description' => t('If checked, the specimen will be listed in a tree view.'),
2627
    );
2628
2629
2630
    $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2631 642b323b Andreas Kohlbecker
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2632
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2633
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2634 f19f47fa Andreas Kohlbecker
  }
2635
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2636 378bc1ce Andreas Kohlbecker
    '#type' => 'radios',
2637
    '#title' => t('Specimen description feature tree') . ':',
2638
    '#default_value' => $profile_feature_tree_uuid,
2639
    '#options' =>  $featureTrees['options'],
2640
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2641
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2642
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2643
    ),
2644 bfb2b81a Andreas Kohlbecker
  );
2645
2646 6657531f Andreas Kohlbecker
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2647
  $form_title = t('Specimen media');
2648
  $form_description = t('Specimens may have media which is displayed at the
2649
     Specimen tab/section as a gallery. It is possible to configure the
2650
     thumbnails gallery here, however for configuring how a single media should
2651
     be displayed please go to !url.</p>',
2652
     array(
2653
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2654
     ));
2655
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2656
2657
  // --- MEDIA GALLERY ---- //
2658
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2659
  $form_title = 'Media gallery (tab)';
2660 43034365 Patrick Plitzner
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2661
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2662 6657531f Andreas Kohlbecker
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2663
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2664
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2665
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2666
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2667
2668
  // Comment @WA: D7 form api does not support reset buttons,
2669
  // so to mimic the D5 reset button we add one like this.
2670
  $form['actions']['reset'] = array(
2671
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2672
    '#weight' => 1000,
2673
  );
2674
  return system_settings_form($form);
2675
}
2676
2677 378bc1ce Andreas Kohlbecker
/**
2678
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2679
 *
2680
 * @param $map_id
2681
 * @param $form
2682
 * @return mixed
2683
 */
2684
function _cdm_map_visibility_setting($map_id)
2685
{
2686
  return array(
2687
    '#type' => 'select',
2688
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2689
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2690
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2691
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2692
        The map also can forced to show up <b>always</b> or <b>never</b>."
2693
  );
2694
}
2695
2696 6657531f Andreas Kohlbecker
/**
2697
 * @todo document this function.
2698
 */
2699
function cdm_settings_layout_search() {
2700
2701
  $form = array();
2702
2703 c5ed6357 Andreas Kohlbecker
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2704
2705 6657531f Andreas Kohlbecker
  $form['search_settings'] = array(
2706
    '#type' => 'fieldset',
2707
    '#title' => t('Taxa Search'),
2708 61b6ee11 Andreas Kohlbecker
    '#collapsible' => FALSE,
2709
    '#collapsed' => FALSE,
2710 6657531f Andreas Kohlbecker
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2711
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2712
         where they can write the text to be searched. You can find Drupal block configuration
2713
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2714
  );
2715
2716 90a6166e Andreas Kohlbecker
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2717 f19f47fa Andreas Kohlbecker
      '#type' => 'checkbox',
2718
      '#title' => t('Ignore the chosen classification in simple search'),
2719 90a6166e Andreas Kohlbecker
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2720 61b6ee11 Andreas Kohlbecker
      '#description' => t('The simple search, which can be executed via the search block,
2721 90a6166e Andreas Kohlbecker
          will by default search on the classification selected in the classification browser
2722
          selector. Set the tick if you want your portal to search on all classifications.'),
2723 61b6ee11 Andreas Kohlbecker
  );
2724
2725 2d0d855a Andreas Kohlbecker
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2726
    '#type' => 'checkbox',
2727
    '#title' => t('Run simple search with free-text search backend.'),
2728 90a6166e Andreas Kohlbecker
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2729 2d0d855a Andreas Kohlbecker
    '#description' => t('The simple search uses by default another search
2730
      backend as the advances search. By checking this option the simple search can be
2731
      configured to also use the free-text search backend.'),
2732
  );
2733
2734 023c4a03 Patrick Plitzner
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2735
    '#type' => 'checkbox',
2736
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2737
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2738
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2739
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2740
  );
2741
2742 6657531f Andreas Kohlbecker
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2743
    '#type' => 'textfield',
2744
    '#title' => t('Results per page') . ':',
2745
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2746
    '#description' => t('Number of results to display per page.'),
2747
  );
2748 276f39f6 Katja Luther
2749 1d69a96c Andreas Kohlbecker
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2750
    '#type' => 'checkbox',
2751 c278f2a0 Andreas Kohlbecker
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2752 1d69a96c Andreas Kohlbecker
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2753
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2754
  );
2755
2756 6280e639 Andreas Kohlbecker
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2757
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2758
      '#type' => 'checkboxes',
2759
      '#title' => 'Search mode',
2760
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2761
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2762
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2763
          defaults set here.',
2764
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2765
      '#default_value' => $search_mode_default
2766
      );
2767 6657531f Andreas Kohlbecker
2768 072122ee Andreas Kohlbecker
  $form['search_settings'][CDM_SEARCH_AREA_FILTER_PRESET] = array(
2769 f4cc620d Andreas Kohlbecker
    '#type' => 'textarea',
2770 072122ee Andreas Kohlbecker
    '#title' => t('area_filter_preset') . ':',
2771
    '#default_value' => variable_get(CDM_SEARCH_AREA_FILTER_PRESET, ''), // '05b0dd06-30f8-477d-bf4c-30d9def56320' =>  Caucasia (Ab + Ar + Gg + Rf(CS)) (Cc)
2772
2773
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2774
  );
2775
2776 6eaec849 Katja Luther
    $form['blast_search_settings'] = array(
2777
        '#type' => 'fieldset',
2778
        '#title' => t('Blast Search'),
2779
        '#collapsible' => TRUE,
2780
        '#collapsed' => TRUE,
2781
        '#description' => t('<p>To perform blast searchs
2782
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2783
         where they can write the text to be searched. You can find Drupal block configuration
2784
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p>
2785
         <p>To perform a blast search a blast database for the cdm instance is needed.</p> '),
2786
    );
2787
2788
    $form['blast_search_settings'][CDM_BLAST] = array(
2789
        '#type' => 'checkbox',
2790
        '#title' => t('Activate Blast search') . ':',
2791
        '#default_value' => variable_get(CDM_BLAST, 0), // '05b0dd06-30f8-477d-bf4c-30d9def56320' =>  Caucasia (Ab + Ar + Gg + Rf(CS)) (Cc)
2792
2793
        '#description' => t('Activate the blast search for this portal, this works only with an existing blast database!'),
2794
    );
2795
    $form['blast_search_settings'][CDM_WS_PORTAL_BLAST] = array(
2796
        '#type' => 'textfield',
2797
        '#title' => t('Webservice URL for blast search') . ':',
2798
        '#default_value' => variable_get(CDM_WS_PORTAL_BLAST, 'http://127.0.0.1:9001/api/sequence'), // '05b0dd06-30f8-477d-bf4c-30d9def56320' =>  Caucasia (Ab + Ar + Gg + Rf(CS)) (Cc)
2799
2800
        '#description' => t('Enter the webservice URL for blast search'),
2801
    );
2802
2803 6657531f Andreas Kohlbecker
  // --- SEARCH TAXA GALLERY ---- //
2804
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2805
  $collapsed = FALSE;
2806
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2807
  $form_title = 'Taxa Search thumbnails';
2808
  $form_description = 'Search results may show thumbnails. ';
2809
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2810
2811
  // Comment @WA: D7 form api does not support reset buttons,
2812
  // so to mimic the D5 reset button we add one like this.
2813
  $form['actions']['reset'] = array(
2814
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2815
    '#weight' => 1000,
2816
  );
2817
  return system_settings_form($form);
2818
}
2819
2820
/**
2821
 * @todo document this function.
2822
 */
2823
function cdm_settings_layout_media() {
2824
2825
  $form = array();
2826
2827
  $form['media_settings'] = array(
2828
    '#type' => 'fieldset',
2829 a950f2f9 Andreas Kohlbecker
    '#title' => t('Media settings'),
2830
    '#collapsible' => FALSE,
2831 6657531f Andreas Kohlbecker
    '#collapsed' => FALSE,
2832 ccde8251 Andreas Kohlbecker
    '#description' => 'This section covers layout settings for media pages.'
2833
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2834 6657531f Andreas Kohlbecker
  );
2835
2836
  $form['media_settings']['image_gallery_viewer'] = array(
2837
    '#type' => 'select',
2838
    '#title' => t('Image viewer') . ':',
2839
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2840
    '#options' => array(
2841
      'default' => t('Standard image viewer'),
2842
      'fsi' => t('FSI viewer (requires FSI server!)'),
2843
    ),
2844
  );
2845
2846 63d5030d Andreas Kohlbecker
  // --- STANDARD_IMAGE_VIEWER ---- //
2847
  if(variable_get('image_gallery_viewer', 'default') == 'default') {
2848
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2849
      '#type' => 'fieldset',
2850
      '#tree' => true,
2851
      '#title' => t('Standard image viewer settings'),
2852
      '#collapsible' => FALSE,
2853
      '#collapsed' => FALSE,
2854
      );
2855
2856
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2857
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2858
      '#type' => 'checkbox',
2859
      '#title' => 'Show media representations',
2860
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2861
2862
    );
2863
  }
2864
2865 6657531f Andreas Kohlbecker
2866
  // @WA: D7 form api does not support reset buttons,
2867
  // so to mimic the D5 reset button we add one like this.
2868
  $form['actions']['reset'] = array(
2869
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2870
    '#weight' => 1000,
2871
  );
2872
  return system_settings_form($form);
2873
}
2874
2875
/**
2876
 * GEOSERVICE and Map settings.
2877
 */
2878 1d39ec64 w.addink
function cdm_settings_geo($form, &$form_state) {
2879 6657531f Andreas Kohlbecker
2880 cc3c9807 Andreas Kohlbecker
  $current_geoserver_settings = get_edit_map_service_settings();
2881
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2882 ff965d76 Andreas Kohlbecker
2883 cc3c9807 Andreas Kohlbecker
2884 6657531f Andreas Kohlbecker
  $form = array();
2885
2886 cc3c9807 Andreas Kohlbecker
  $dummy_distribution_query = NULL;
2887
  if($map_distribution['map_type'] != 1){
2888 ff965d76 Andreas Kohlbecker
    // we need to apply a dummy query since the map service requires for image maps
2889 cc3c9807 Andreas Kohlbecker
    // at least as and ad to be defined
2890
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2891
  }
2892 087bb473 Andreas Kohlbecker
2893 d2fd2a4c Andreas Kohlbecker
  $form['map_preview'] = array(
2894
      '#type' => 'fieldset',
2895
      '#tree' => FALSE,
2896
      '#title' => t('Map preview'),
2897
      '#collapsible' => FALSE,
2898 cc3c9807 Andreas Kohlbecker
      '#description' => 'The preview of the map'
2899 2bbc28c8 Andreas Kohlbecker
       . ($dummy_distribution_query != null ?
2900 ff965d76 Andreas Kohlbecker
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2901 d5661a4c Andreas Kohlbecker
           '.<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.')
2902 d2fd2a4c Andreas Kohlbecker
  );
2903 4c21ffdb Andreas Kohlbecker
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2904 653e9c6b Andreas Kohlbecker
    'move' => "this.cdmOpenlayersMap.printInfo",
2905
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2906
  ), true // resizable
2907 d2fd2a4c Andreas Kohlbecker
  );
2908 087bb473 Andreas Kohlbecker
2909 6f718d1b Andreas Kohlbecker
  /*
2910
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2911
  );
2912
  */
2913 cc3c9807 Andreas Kohlbecker
2914 6657531f Andreas Kohlbecker
  /*
2915 d2fd2a4c Andreas Kohlbecker
   * GEO SERVER
2916
   */
2917 ba706bf0 Andreas Kohlbecker
  $form['edit_map_server'] = array(
2918 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2919 ba706bf0 Andreas Kohlbecker
    '#tree' => true,
2920
    '#title' => t('EDIT map service'),
2921 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
2922
    '#collapsed' => TRUE,
2923
    '#description' => t('Configuration and selection of your geo server.
2924
      The Geo Server is responsible for generating the maps.'),
2925
  );
2926
2927 f19f47fa Andreas Kohlbecker
  $form['edit_map_server']['base_uri'] = array(
2928 6657531f Andreas Kohlbecker
    '#type' => 'select',
2929 ba706bf0 Andreas Kohlbecker
    '#title' => t('EDIT map service') . ':',
2930
    '#default_value' => $current_geoserver_settings['base_uri'],
2931
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2932
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2933 6657531f Andreas Kohlbecker
  );
2934 f19f47fa Andreas Kohlbecker
  $form['edit_map_server']['version'] = array(
2935
      '#type' => 'select',
2936
      '#title' => t('Version') . ':',
2937
      '#default_value' => $current_geoserver_settings['version'],
2938
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2939
      '#description' => t('The version of the EDIT map services'),
2940 6657531f Andreas Kohlbecker
  );
2941
2942
  /*
2943 d2fd2a4c Andreas Kohlbecker
   * MAP SETTINGS
2944
   */
2945 cc3c9807 Andreas Kohlbecker
2946
  $form[CDM_MAP_DISTRIBUTION] = array(
2947 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2948 cc3c9807 Andreas Kohlbecker
    '#tree' => TRUE,
2949 6657531f Andreas Kohlbecker
    '#title' => t('Maps settings'),
2950
    '#collapsible' => TRUE,
2951
    '#collapsed' => TRUE,
2952
    '#description' => t('General configuration for all map types.'),
2953
  );
2954
2955 6f718d1b Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2956
    '#type' => 'radios',
2957
    '#title' => 'Map types',
2958
    '#options' => array(
2959
      1 => "OpenLayers dynamic map viewer",
2960
      0 => "Plain image",
2961
    ),
2962
    '#default_value' => $map_distribution['map_type'],
2963
    '#description' => 'Two different map types are available :
2964
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2965
      which allows zooming and panning. If enabled you can configure the default layer
2966
      (background of your maps) below.</li>
2967
      <li><em>Plain image</em>: The map will be static non interactive
2968
      image.</li></ul>',
2969
  );
2970
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2971
2972 cc3c9807 Andreas Kohlbecker
  /*
2973
   * settings for the distribution map are used also for specimens map!!!!
2974
   */
2975
2976 b4503332 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2977 cc3c9807 Andreas Kohlbecker
      '#type' => 'textfield',
2978 b4503332 Andreas Kohlbecker
      '#title' => 'Aspect ratio',
2979
      '#default_value' => $map_distribution['aspect_ratio'],
2980 cc3c9807 Andreas Kohlbecker
      '#maxlength' => 4,
2981
      '#size' => 4,
2982 ff965d76 Andreas Kohlbecker
      '#element_validate' => array('element_validate_number'),
2983 b4503332 Andreas Kohlbecker
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2984
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2985
      width by the height:</br>
2986
      <pre>aspect ratio = w / h</pre>
2987
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2988
      for a square map use <strong>1</strong>.',
2989 cc3c9807 Andreas Kohlbecker
  );
2990 6657531f Andreas Kohlbecker
2991 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2992 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2993 cc3c9807 Andreas Kohlbecker
    '#title' => 'Bounding box',
2994
    '#default_value' => $map_distribution['bbox'],
2995 b4503332 Andreas Kohlbecker
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2996 6657531f Andreas Kohlbecker
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2997 2bbc28c8 Andreas Kohlbecker
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2998 087bb473 Andreas Kohlbecker
      <strong>TIP:</strong> You can use the map preview above to choose the <span class="map-extent-bbox"><strong>map extent bbox</strong> in <strong class="degree-value"">degree</strong></span> from the map.
2999 b4503332 Andreas Kohlbecker
      (Maybe you need to change the map base layer to OpeLayers.)
3000 d5661a4c Andreas Kohlbecker
      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
3001 2bbc28c8 Andreas Kohlbecker
      below the map from where you can copy the bbox string.</p>'),
3002 6657531f Andreas Kohlbecker
  );
3003
3004 46de7f4c Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
3005
    '#type' => 'select',
3006
    '#title' => 'Max zoom level',
3007
    '#default_value' => $map_distribution['maxZoom'],
3008
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
3009
  );
3010
3011 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
3012 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
3013 cc3c9807 Andreas Kohlbecker
    '#title' => 'Display area labels',
3014
    '#default_value' => $map_distribution['show_labels'],
3015
    '#description' => t('The map will show name labels of the areas'),
3016 6657531f Andreas Kohlbecker
  );
3017
3018 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
3019 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
3020 cc3c9807 Andreas Kohlbecker
    '#title' => 'Map caption',
3021
    '#default_value' => $map_distribution['caption'],
3022
    '#description' => t('The caption will be shown below the map.'),
3023 6657531f Andreas Kohlbecker
  );
3024
3025 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
3026 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
3027 cc3c9807 Andreas Kohlbecker
    '#title' => 'Distribution layer opacity',
3028
    '#default_value' => $map_distribution['distribution_opacity'],
3029 b4503332 Andreas Kohlbecker
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
3030
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
3031 6657531f Andreas Kohlbecker
  );
3032
3033
  // --- Plain Image Settings --- //
3034 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
3035 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
3036 cc3c9807 Andreas Kohlbecker
    '#title' => 'Plain image map settings',
3037
    '#tree' => TRUE,
3038 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
3039 cc3c9807 Andreas Kohlbecker
    '#collapsed' => $open_layers_is_enabled,
3040
    '#description' => 'The settings in this section are still expertimental
3041
      and can only be used with the EDIT map service version 1.1 or above.',
3042 6657531f Andreas Kohlbecker
  );
3043 ba706bf0 Andreas Kohlbecker
  $edit_mapserver_version = get_edit_map_service_version_number();
3044 6657531f Andreas Kohlbecker
  if ($edit_mapserver_version < 1.1) {
3045 7cc085da Andreas Kohlbecker
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
3046
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
3047
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
3048 cc3c9807 Andreas Kohlbecker
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
3049 6657531f Andreas Kohlbecker
  }
3050
3051 b4503332 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
3052
    '#type' => 'textfield',
3053
    '#title' => 'Width',
3054
    '#default_value' => $map_distribution['image_map']['width'],
3055
    '#maxlength' => 4,
3056
    '#size' => 4,
3057 50791e51 Andreas Kohlbecker
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
3058 b4503332 Andreas Kohlbecker
  );
3059
3060 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
3061 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
3062 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background layer',
3063
    '#default_value' => $map_distribution['image_map']['base_layer'],
3064 6657531f Andreas Kohlbecker
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
3065 cc3c9807 Andreas Kohlbecker
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
3066
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
3067 6657531f Andreas Kohlbecker
    )),
3068
  );
3069
3070 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3071 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
3072 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background color',
3073
    '#default_value' => $map_distribution['image_map']['bg_color'],
3074 6657531f Andreas Kohlbecker
  );
3075
3076 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3077 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
3078 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background layer style',
3079 6657531f Andreas Kohlbecker
     // Only line color by now.
3080 cc3c9807 Andreas Kohlbecker
    '#default_value' => $map_distribution['image_map']['layer_style'],
3081
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3082 6657531f Andreas Kohlbecker
  );
3083
3084 4bef194f Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3085
      '#type' => 'textfield',
3086
      '#title' => 'Projection',
3087
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3088
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3089
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3090
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3091
  );
3092
3093 6657531f Andreas Kohlbecker
3094
  // --- OpenLayers Settings --- //
3095 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3096 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
3097 cc3c9807 Andreas Kohlbecker
    '#title' => 'OpenLayers settings',
3098
    '#tree' => TRUE,
3099 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
3100 cc3c9807 Andreas Kohlbecker
    '#collapsed' => !$open_layers_is_enabled,
3101 6657531f Andreas Kohlbecker
    '#description' => '',
3102
  );
3103
3104 2bbc28c8 Andreas Kohlbecker
3105
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3106
      '#type' => 'checkbox',
3107
      '#title' => 'Display outside max extent',
3108
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3109
      '#description' => t('Allows the map to display parts of the layers which are outside
3110
         the max extent if the aspect ratio of the map and of the baselayer
3111
         are not equal.'),
3112
  );
3113
3114 570f0e73 Andreas Kohlbecker
3115 2bbc28c8 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3116
      '#type' => 'checkbox',
3117
      '#title' => 'Show Layer Switcher',
3118
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3119
      '#description' => 'The Layer Switcher control displays a table of contents
3120
      for the map.  This allows the user interface to switch between
3121
      base layers and to show or hide overlays.  By default the switcher is
3122
      shown minimized on the right edge of the map, the user may expand it
3123
      by clicking on the handle.',
3124
  );
3125
3126 cc3c9807 Andreas Kohlbecker
  if (!$open_layers_is_enabled) {
3127
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3128
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3129
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3130 6657531f Andreas Kohlbecker
  }
3131
3132 ff965d76 Andreas Kohlbecker
  // The default layer must always be enabled
3133
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3134
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3135
3136 6657531f Andreas Kohlbecker
  $baselayer_options = array(
3137
    /*
3138
   NOTICE: must correspond to the layers defined in
3139
   js/openlayers_,ap.js#getLayersByName()
3140
   */
3141 1f3c62f9 Andreas Kohlbecker
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3142
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3143
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3144
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3145 6657531f Andreas Kohlbecker
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3146 1f3c62f9 Andreas Kohlbecker
    // all others EPSG:900913
3147 4213b101 Andreas Kohlbecker
    'mapnik' => 'OpenStreetMap (mapnik)',
3148
    'stamen_terrain' => 'Stamen Terrain',
3149
    'open_topomap' => 'OpenTopoMap',
3150
    // map quest is no longer free. it is required to sign up for a test plan.
3151
    // 'mapquest_open' => "MapQuest",
3152
    // 'mapquest_sat' => "MapQuest Sattelite",
3153 2b83cc8b Andreas Kohlbecker
    'groadmap' => 'Google Roadmap',
3154
    'gsatellite' => 'Google Satellite',
3155 f619ffbf Andreas Kohlbecker
    'ghybrid' => 'Google Hybrid',
3156 2b83cc8b Andreas Kohlbecker
    'gterrain' => 'Google Terrain',
3157 cc3c9807 Andreas Kohlbecker
//     'veroad' => 'Virtual Earth Roads',
3158
//     'veaer' => 'Virtual Earth Aerial',
3159
//     'vehyb' => 'Virtual Earth Hybrid',
3160 6657531f Andreas Kohlbecker
    // 'yahoo' => 'Yahoo Street',
3161
    // 'yahoosat' => 'Yahoo Satellite',
3162
    // 'yahoohyb' => 'Yahoo Hybrid',
3163 2bbc28c8 Andreas Kohlbecker
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3164 6657531f Andreas Kohlbecker
  );
3165
3166 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3167 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes_preferred',
3168 cc3c9807 Andreas Kohlbecker
    '#title' => 'Base Layers',
3169 6657531f Andreas Kohlbecker
    '#options' => $baselayer_options,
3170 cc3c9807 Andreas Kohlbecker
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3171
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3172 6657531f Andreas Kohlbecker
  );
3173
3174 2b83cc8b Andreas Kohlbecker
  $google_maps_api_key = null;
3175
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3176
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3177
  }
3178
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3179
    '#type' => 'textfield',
3180
    '#title' => 'Google Maps API Key',
3181
    '#default_value' => $google_maps_api_key,
3182
    '#description' => 'In order to use any of the Google map layers you need to provide 
3183
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3184
  );
3185
3186 cb961f9d Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3187
    $map_distribution['openlayers']['custom_wms_base_layer'],
3188
    'Custom WMS base layer',
3189
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3190
    true // add projection settings
3191
    );
3192 2bbc28c8 Andreas Kohlbecker
3193 cb961f9d Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3194
    $map_distribution['openlayers']['wms_overlay_layer'],
3195
    'WMS overlay layer',
3196
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3197
                You can actually combine multiple layers for this overlay. 
3198
                For details please refer to the wms query parameter <code>Layers</code> .'
3199 2bbc28c8 Andreas Kohlbecker
  );
3200 cb961f9d Andreas Kohlbecker
3201
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3202
    '#type' => 'checkbox',
3203
    '#title' => 'Enable overlay layer',
3204
    '#weight' => -100,
3205
    '#default_value' => $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3206 6657531f Andreas Kohlbecker
  );
3207
3208 cc3c9807 Andreas Kohlbecker
  /*
3209
   * Map Legend
3210
   */
3211
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3212 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
3213 cc3c9807 Andreas Kohlbecker
    '#title' => 'Map legend',
3214
    '#tree' => TRUE,
3215 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
3216
    '#collapsed' => TRUE,
3217 cc3c9807 Andreas Kohlbecker
    '#description' => 'Configure the maps legend.',
3218 6657531f Andreas Kohlbecker
  );
3219
3220 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3221 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
3222 cc3c9807 Andreas Kohlbecker
    '#title' => 'Display a map legend',
3223
    '#default_value' => $map_distribution['legend']['show'],
3224
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3225 6657531f Andreas Kohlbecker
  );
3226
3227 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3228 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
3229 cc3c9807 Andreas Kohlbecker
    '#title' => 'Legend opacity',
3230
    '#default_value' => $map_distribution['legend']['opacity'],
3231
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3232
                         to 0.0 will be not much visible.',
3233 6657531f Andreas Kohlbecker
  );
3234
3235 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3236 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
3237 cc3c9807 Andreas Kohlbecker
    '#title' => 'Font size',
3238
    '#default_value' => $map_distribution['legend']['font_size'],
3239
    '#description' => 'Font size in pixels.',
3240 6657531f Andreas Kohlbecker
  );
3241
3242
  $fontStyles = array(
3243
    0 => "plane",
3244
    1 => "italic",
3245
  );
3246 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3247 6657531f Andreas Kohlbecker
    '#type' => 'select',
3248 cc3c9807 Andreas Kohlbecker
    '#title' => 'Available font styles',
3249
    '#default_value' => $map_distribution['legend']['font_style'],
3250 6657531f Andreas Kohlbecker
    '#options' => $fontStyles,
3251 cc3c9807 Andreas Kohlbecker
    '#description' => 'Select a font style for the map legend.',
3252 6657531f Andreas Kohlbecker
  );
3253
3254 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3255 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
3256 cc3c9807 Andreas Kohlbecker
    '#title' => 'Icon width',
3257
    '#default_value' => $map_distribution['legend']['icon_width'],
3258
    '#description' => 'Legend icon width in pixels.',
3259 6657531f Andreas Kohlbecker
  );
3260 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3261 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
3262 cc3c9807 Andreas Kohlbecker
    '#title' => 'Icon height',
3263
    '#default_value' => $map_distribution['legend']['icon_height'],
3264
    '#description' => 'Legend icon height in pixels.',
3265 6657531f Andreas Kohlbecker
  );
3266
3267
  // @WA: D7 form api does not support reset buttons,
3268
  // so to mimic the D5 reset button we add one like this.
3269
  $form['actions']['reset'] = array(
3270
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3271
    '#weight' => 1000,
3272
  );
3273 1d39ec64 w.addink
3274 6657531f Andreas Kohlbecker
  return system_settings_form($form);
3275
}
3276
3277 cb961f9d Andreas Kohlbecker
/**
3278
 * @param $default_settings
3279
 * @param $title
3280
 * @param $description
3281
 * @param bool $add_projection_settings
3282
 * @return array
3283
 */
3284
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3285
{
3286
  $form_elements = array(
3287
    '#type' => 'fieldset',
3288
    '#title' => $title,
3289
    '#tree' => TRUE,
3290
    '#collapsible' => FALSE,
3291
    '#collapsed' => FALSE,
3292
    '#description' => $description,
3293
  );
3294
3295
  $form_elements['name'] = array(
3296
    '#type' => 'textfield',
3297
    '#title' => 'Layer name',
3298
    '#default_value' => $default_settings['name'],
3299
    '#description' => 'A arbitrary name for the layer.',
3300
  );
3301
  $form_elements['url'] = array(
3302
    '#type' => 'textfield',
3303
    '#title' => 'WMS url',
3304
    '#default_value' => $default_settings['url'],
3305
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3306
  );
3307 2dc774be Andreas Kohlbecker
  $form_elements['untiled'] = array(
3308
    '#type' => 'checkbox',
3309
    '#title' => 'Untiled',
3310
    '#default_value' => $default_settings['untiled'],
3311
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3312
  );
3313 cb961f9d Andreas Kohlbecker
  $form_elements['params'] = array(
3314
    '#type' => 'textarea',
3315
    '#title' => 'WMS parameters',
3316
    '#element_validate' => array('form_element_validate_json'),
3317
    '#default_value' => $default_settings['params'],
3318
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3319
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3320
      . '), entered in valid JSON. For example:
3321
<pre> {
3322
  "Layers": "topp:em_tiny_jan2003",
3323
  "Format": "image/png",
3324
  "BGCOLOR": "0xe0faff"
3325
}
3326
</pre>
3327
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3328
  );
3329
3330
  if($add_projection_settings){
3331
3332
    $form_elements['projection'] = array(
3333
      '#type' => 'textfield',
3334
      '#title' => 'Projection',
3335
      '#default_value' => $default_settings['projection'],
3336
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
3337
    );
3338
    $form_elements['proj4js_def'] = array(
3339
      '#type' => 'textfield',
3340
      '#maxlength' => 256,
3341
      '#title' => 'proj4js definition',
3342
      '#default_value' => $default_settings['proj4js_def'],
3343
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
3344
              The definitions for
3345
              EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
3346
              EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
3347
              are already predefined and must NOT be added here again.  If your dont know the defintion of your desired projection,
3348
              go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
3349
              choose to display the proj4js definition string.
3350
              <h5>Quick Reference on the common proj4js definition parameters:</h5>
3351
              <pre>
3352
  +a         Semimajor radius of the ellipsoid axis
3353
  +alpha     ? Used with Oblique Mercator and possibly a few others
3354
  +axis      Axis orientation (new in 4.8.0)
3355
  +b         Semiminor radius of the ellipsoid axis
3356
  +datum     Datum name (see `proj -ld`)
3357
  +ellps     Ellipsoid name (see `proj -le`)
3358
  +k         Scaling factor (old name)
3359
  +k_0       Scaling factor (new name)
3360
  +lat_0     Latitude of origin
3361
  +lat_1     Latitude of first standard parallel
3362
  +lat_2     Latitude of second standard parallel
3363
  +lat_ts    Latitude of true scale
3364
  +lon_0     Central meridian
3365
  +lonc      ? Longitude used with Oblique Mercator and possibly a few others
3366
  +lon_wrap  Center longitude to use for wrapping (see below)
3367
  +nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
3368
  +no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
3369
  +over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
3370
  +pm        Alternate prime meridian (typically a city name, see below)
3371
  +proj      Projection name (see `proj -l`)
3372
  +south     Denotes southern hemisphere UTM zone
3373
  +to_meter  Multiplier to convert map units to 1.0m
3374
  +towgs84   3 or 7 term datum transform parameters (see below)
3375
  +units     meters, US survey feet, etc.
3376
  +vto_meter vertical conversion to meters.
3377
  +vunits    vertical units.
3378
  +x_0       False easting
3379
  +y_0       False northing
3380
  +zone      UTM zone
3381
              </pre>
3382
            For the full reference please refer to <a href="http://proj4.org/parameters.html">http://proj4.org/parameters.html</a>.'
3383
    );
3384
    $form_elements['max_extent'] = array(
3385
      '#type' => 'textfield',
3386
      '#title' => 'Maximum extent',
3387
      '#default_value' => $default_settings['max_extent'],
3388
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
3389
    );
3390
    $form_elements['units'] = array(
3391
      '#type' => 'textfield',
3392
      '#title' => 'Units',
3393
      '#default_value' => $default_settings['units'],
3394
      '#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.'
3395
    );
3396
3397
  }
3398
  return $form_elements;
3399
}
3400
3401 ff965d76 Andreas Kohlbecker
3402 6657531f Andreas Kohlbecker
/**
3403
 * @todo document this function.
3404
 */
3405
function cdm_settings_cache() {
3406
3407
  $form = array();
3408
3409
  $form['cache_settings'] = array(
3410
    '#type' => 'fieldset',
3411
    '#title' => t('Cache Settings'),
3412
    '#collapsible' => FALSE,
3413
    '#collapsed' => FALSE,
3414
    '#description' => t('<p>When caching is enabled all single taxon sites are
3415
      stored in an internal drupal cache doing the portal response of taxa pages
3416
      faster. This is possible because the sites are loaded from the cache and
3417
      are not created from scratch.</p>'),
3418
  );
3419
3420
  $form['cache_settings']['cdm_webservice_cache'] = array(
3421
    '#type' => 'checkbox',
3422
    '#title' => t('<strong>Enable caching</strong>'),
3423
    '#options' => cdm_help_general_cache(),
3424
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3425
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3426
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3427
       application the changes will be not visible till the cache is erased.
3428
       Therefore developers should deactived this feature when they are working
3429
       on the CDM Dataportal Module.</p>'),
3430
  );
3431
3432
  $form['cache_settings']['cdm_run_cache'] = array(
3433
    '#markup' => cdm_view_cache_site(),
3434
  );
3435
3436
  // @WA: D7 form api does not support reset buttons,
3437
  // so to mimic the D5 reset button we add one like this.
3438
  $form['actions']['reset'] = array(
3439
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3440
    '#weight' => 1000,
3441
  );
3442
  return system_settings_form($form);
3443
}
3444
3445
/**
3446
 * Walk and cache all taxon pages.
3447
 */
3448
function cdm_view_cache_site() {
3449
3450
  $out = '';
3451
3452
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3453
3454
  $request_params = array();
3455 7d828d59 Andreas Kohlbecker
  $request_params['class'] = "Taxon";
3456 6657531f Andreas Kohlbecker
3457 7d828d59 Andreas Kohlbecker
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3458
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3459
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3460 6657531f Andreas Kohlbecker
3461
  $out .= t('<p><strong>Cache all taxon pages</strong></p>');
3462
  $out .= '<p>When you launch the cache process the cache is filled and ready to be enabled.<br/>
3463
  Remember that when you load the taxa from the cache last changes on taxa will be not visible till you erase
3464
  the cache and fill it again.</p>';
3465
  $out .= '<p>Before  running the cache bot you have to empty the cache manually.</p>';
3466
3467
  $out .= '<div>' . t('This caching process may take long time and could cause heavy load on your server') . '</div>';
3468
  $out .= '<div id="progress"></div>';
3469
3470
  // Comment @WA: A form within a form is not valid html and not needed here.
3471
  // Also, it would be recommended just to include this part of the form in the
3472
  // rest of the form array in cdm_settings_cache().
3473
  // $out .= '<form id="cache_site">';
3474 0516e3d0 Andreas Kohlbecker
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3475 7d828d59 Andreas Kohlbecker
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3476 6657531f Andreas Kohlbecker
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3477
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3478
  // $out .= '</form>';
3479
  $out .= '</div>';
3480
  /*
3481
  foreach($taxonPager->records as $taxon){
3482
    cdm_dataportal_taxon_view($uuid);
3483
  }
3484
  */
3485
  return $out;
3486
}
3487
3488 7df1be04 Andreas Kohlbecker
3489
function cdm_settings_layout_taxon_submit($form, &$form_state){
3490 9c92cd84 Andreas Kohlbecker
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3491
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3492
    if(is_object($file)){
3493
      $file->status = FILE_STATUS_PERMANENT;
3494
      file_save($file);
3495
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3496
    }
3497 7df1be04 Andreas Kohlbecker
  }
3498 93115722 Andreas Kohlbecker
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3499
  $tab_lables_modified = serialize(get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT)) != serialize($form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3500
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3501
  if($tab_lables_modified || $tabs_enabled_modified){
3502 d5403dc4 Andreas Kohlbecker
    // we first need to set the variable to persist the changes setting
3503
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3504 93115722 Andreas Kohlbecker
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3505 d5403dc4 Andreas Kohlbecker
    menu_rebuild();
3506
  }
3507 7df1be04 Andreas Kohlbecker
}
3508
3509 c5ed6357 Andreas Kohlbecker
function cdm_settings_layout_search_submit($form, &$form_state){
3510
  // the visibility of media thumbnails also affects the ui of the search results
3511
  // so reset the according session variable
3512
  //    1. in order to give the user immediate
3513
  //       feedback on potential setting changes
3514
  //    2. let refresh the default if it has changed
3515
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3516
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3517
  }
3518
}
3519
3520 6657531f Andreas Kohlbecker
/**
3521 d1eb0a8c Andreas Kohlbecker
 * Form validation handler for cdm_settings_general
3522 6657531f Andreas Kohlbecker
 *
3523 22eb20d7 Andreas Kohlbecker
 * @param $form
3524
 * @param $form_state
3525 6657531f Andreas Kohlbecker
 */
3526 d1eb0a8c Andreas Kohlbecker
function cdm_settings_general_validate($form, &$form_state) {
3527 6657531f Andreas Kohlbecker
3528
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3529
    $form_state['values']['cdm_webservice_url'] .= '/';
3530
  }
3531
3532 d1eb0a8c Andreas Kohlbecker
}
3533
3534 22eb20d7 Andreas Kohlbecker
/**
3535
 * Form submit handler for settings general.
3536
 *
3537
 * tasks performed:
3538
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3539
 *
3540
 * @param $form
3541
 * @param $form_state
3542
 */
3543
function cdm_settings_general_submit($form, &$form_state){
3544
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3545
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3546 c9b3fcf5 Andreas Kohlbecker
  unset($_SESSION['cdm_login']);
3547 22eb20d7 Andreas Kohlbecker
}
3548
3549 d1eb0a8c Andreas Kohlbecker
/**
3550
 * Form validation handler for cdm_settings_cache
3551
 */
3552 847bb49e Andreas Kohlbecker
function cdm_settings_cache_validate($form, &$form_state) {
3553 6657531f Andreas Kohlbecker
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3554
    cache_clear_all(NULL, 'cache_cdm_ws');
3555
    // Better clear secref_cache since I can not be sure if the cache has not
3556
    // be used during this response.
3557
    cdm_api_secref_cache_clear();
3558
  }
3559 d1eb0a8c Andreas Kohlbecker
3560 6657531f Andreas Kohlbecker
}
3561
3562
/**
3563 ba706bf0 Andreas Kohlbecker
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3564
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3565
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3566
 *  - version: the version, e.g.: v1.1
3567
 *
3568
 * @return array
3569
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3570 6657531f Andreas Kohlbecker
 */
3571 ba706bf0 Andreas Kohlbecker
function get_edit_map_service_settings() {
3572
3573
  $settings = variable_get('edit_map_server', array(
3574
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3575
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3576
      )
3577
  );
3578 6657531f Andreas Kohlbecker
3579 ba706bf0 Andreas Kohlbecker
  return $settings;
3580 6657531f Andreas Kohlbecker
}
3581
3582
/**
3583 ba706bf0 Andreas Kohlbecker
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3584
 *
3585
 * @return string
3586
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3587
 */
3588
function get_edit_map_service_full_uri() {
3589
  $settings = get_edit_map_service_settings();
3590
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3591
}
3592
3593
3594
/**
3595
 * Returns the version number of the currently selected edit mapserver as a float
3596 6657531f Andreas Kohlbecker
 *
3597
 * @return float
3598
 *   The version number of the currently selected edit mapserver as a float.
3599
 *   Returns 0 on error.
3600
 */
3601 ba706bf0 Andreas Kohlbecker
function get_edit_map_service_version_number() {
3602 6657531f Andreas Kohlbecker
3603 ba706bf0 Andreas Kohlbecker
  $pattern = '/v([\d\.]+).*$/';
3604 6657531f Andreas Kohlbecker
3605 ba706bf0 Andreas Kohlbecker
  $settings = get_edit_map_service_settings();
3606
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3607 6657531f Andreas Kohlbecker
  if (isset($matches[1])) {
3608
    // Convert string to float.
3609
    $version = 1 + $matches[1][0] - 1;
3610
    return $version;
3611
  }
3612
  else {
3613
    // Report error.
3614 ba706bf0 Andreas Kohlbecker
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3615
        array(
3616
          '!version' => $settings['version'],
3617
          'warning')
3618
        )
3619
      );
3620 6657531f Andreas Kohlbecker
    return 0;
3621
  }
3622
}
3623
3624 30f78c59 Andreas Kohlbecker
/**
3625 ba706bf0 Andreas Kohlbecker
 * Returns the array of selected items in a options array
3626 30f78c59 Andreas Kohlbecker
 *
3627
 * @param array $options
3628
 *   An options array as generated by a form element like checkoxes, select ...,
3629
 */
3630
function get_selection($options) {
3631
  $selection = array();
3632
  foreach ($options as $key=>$val) {
3633
    if (!empty($val)) {
3634
      $selection[] = $val;
3635
    }
3636
  }
3637
  return $selection;
3638
}
3639
3640 bfb2b81a Andreas Kohlbecker
3641 6657531f Andreas Kohlbecker
/**
3642
 * Implements hook_element_info().
3643
 *
3644 14feebe9 Andreas Kohlbecker
 * Allows modules to declare their own Form API element types and specify their default values.
3645
 *
3646
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3647 6657531f Andreas Kohlbecker
 */
3648
function cdm_dataportal_element_info() {
3649
  $type['checkboxes_preferred'] = array(
3650
    '#input' => TRUE,
3651 14feebe9 Andreas Kohlbecker
    '#process' => array('checkboxes_preferred_expand'),
3652 6657531f Andreas Kohlbecker
    '#after_build' => array('checkboxes_preferred_after_build'),
3653
    '#theme' => array('checkboxes_preferred'),
3654
    // '#theme_wrapper' => array('form_element'),
3655
  );
3656
  return $type;
3657
}
3658
3659
/**
3660 14feebe9 Andreas Kohlbecker
 * #process callback function for the custom form element type 'checkbox_preferred'
3661
 *
3662
 *
3663 6657531f Andreas Kohlbecker
 */
3664 14feebe9 Andreas Kohlbecker
function checkboxes_preferred_expand($element, &$form_state, $form) {
3665
3666
  // First of all create checkboxes for each of the elements
3667 6657531f Andreas Kohlbecker
  $element = form_process_checkboxes($element);
3668
3669 cc3c9807 Andreas Kohlbecker
  // compose the element name
3670
  $parents = array();
3671
  array_deep_copy($element['#parents'], $parents);
3672
  $parents[count($parents) -1 ] .= '_preferred';
3673
  $element_name = $parents[0];
3674
  for ($i=1; $i < count($parents); $i++){
3675
    $element_name .= '[' . $parents[$i] . ']';
3676
  }
3677
3678 6657531f Andreas Kohlbecker
  $children = element_children($element);
3679
3680
  $element['table_start'] = array(
3681
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3682
    '#weight' => -1,
3683
  );
3684
3685 14feebe9 Andreas Kohlbecker
  // prepare first part each of the table rows which contains the row label
3686 6657531f Andreas Kohlbecker
  $weight = 0;
3687
  foreach ($children as $key) {
3688
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3689
    $element[$key]['#weight'] = $weight;
3690 7cc085da Andreas Kohlbecker
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3691 6657531f Andreas Kohlbecker
    $element[$key]['#suffix'] = '</td>';
3692
    unset($element[$key]['#title']);
3693
    $weight += 2;
3694
  }
3695
  $weight = 0;
3696
3697 14feebe9 Andreas Kohlbecker
  // add a radio button to each of the checkboxes, the
3698
  // check boxes have already been created at the beginning
3699
  // of this function
3700 6657531f Andreas Kohlbecker
  if (count($element['#options']) > 0) {
3701
    foreach ($element['#options'] as $key => $choice) {
3702
      if (!isset($element[$key . '_preferred'])) {
3703
        $element[$key . '_preferred'] = array(
3704
          '#type' => 'radio',
3705 cc3c9807 Andreas Kohlbecker
          '#name' => $element_name,
3706 6657531f Andreas Kohlbecker
          '#return_value' => check_plain($key),
3707
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3708
          '#attributes' => $element['#attributes'],
3709 1d39ec64 w.addink
          '#parents' => $element['#parents'],
3710 6657531f Andreas Kohlbecker
          // '#spawned' => TRUE,
3711
          '#weight' => $weight + 1,
3712 14feebe9 Andreas Kohlbecker
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3713
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3714 6657531f Andreas Kohlbecker
        );
3715
      }
3716
      $weight += 2;
3717
    }
3718
  }
3719
3720 14feebe9 Andreas Kohlbecker
  // end the table
3721 6657531f Andreas Kohlbecker
  $element['table_end'] = array(
3722
    '#markup' => '</table>',
3723
    '#weight' => $weight++,
3724
  );
3725
3726
  return $element;
3727
}
3728
3729
/**
3730
 * Theme function for the custom form field 'checkboxes_preferred'.
3731
 */
3732
function theme_checkboxes_preferred($variables) {
3733
  $element = $variables['element'];
3734
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3735
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3736
  $out .= drupal_render_children($element);
3737
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3738
  $out .= '</div>';
3739
  return $out;
3740
}
3741
3742
/**
3743 14feebe9 Andreas Kohlbecker
 * Callback for checkboxes preferred for widget which will
3744
 * be called after the form or element is built. The call
3745
 * back is configured in the form element by setting it as
3746
 * #after_build parameter.
3747
 *
3748
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3749
 *
3750 cc3c9807 Andreas Kohlbecker
 * @param $element
3751 14feebe9 Andreas Kohlbecker
 *   Nested array of form elements that comprise the form.
3752
 * @param $form_state
3753
 *   A keyed array containing the current state of the form.
3754 cc3c9807 Andreas Kohlbecker
 *   This includes the current persistent storage data for the form.
3755
 *   Additional information, like the sanitized $_POST data,
3756
 *   is also accumulated here in $form_state['input']
3757 14feebe9 Andreas Kohlbecker
 *
3758
 * @return the modified form array
3759 6657531f Andreas Kohlbecker
 */
3760 cc3c9807 Andreas Kohlbecker
function checkboxes_preferred_after_build($element, &$form_state) {
3761 6657531f Andreas Kohlbecker
3762 cc3c9807 Andreas Kohlbecker
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3763 6657531f Andreas Kohlbecker
3764
  if ($_POST && count($_POST) > 0) {
3765 cc3c9807 Andreas Kohlbecker
    // TODO use  $form_state['input'] instead of POST !!!
3766 6657531f Andreas Kohlbecker
    // First pass of form processing.
3767 cc3c9807 Andreas Kohlbecker
    $parents = array();
3768
    array_deep_copy($element['#parents'], $parents);
3769
    $parents[count($parents) - 1] .= '_preferred';
3770
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3771
    $element['#value']['PREFERRED'] = $preferred_layer;
3772
//     $form_state[$parent_id] = $element['#value'];
3773
//     $form_state['values']['baselayers'] = $element['#value'];
3774
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3775
    $form_state_element_values = $element['#value'];
3776 6657531f Andreas Kohlbecker
  }
3777
  else {
3778
    // Second pass of form processing.
3779 cc3c9807 Andreas Kohlbecker
    $preferred_layer = $element['#value']['PREFERRED'];
3780 6657531f Andreas Kohlbecker
  }
3781
3782
  // Also set the chosen value (not sure if this is good Drupal style ....).
3783 cc3c9807 Andreas Kohlbecker
  foreach ($children = element_children($element) as $key) {
3784
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3785
      $element[$key]['#value'] = $preferred_layer;
3786 6657531f Andreas Kohlbecker
    }
3787
  }
3788
  // The default layer must always be enabled.
3789 cc3c9807 Andreas Kohlbecker
  $element[$preferred_layer]['#value'] = $preferred_layer;
3790 6657531f Andreas Kohlbecker
3791 cc3c9807 Andreas Kohlbecker
  return $element;
3792 6657531f Andreas Kohlbecker
}
3793 0f5f1c12 Andreas Kohlbecker
3794 3f485c6d Andreas Kohlbecker
function radios_prepare_options_suffix(&$elements){
3795
3796
  $childrenKeys = element_children($elements);
3797
  foreach($childrenKeys as $key){
3798
    if(!is_array($elements[$key]['#theme_wrappers'])){
3799
      $elements[$key]['#theme_wrappers'] = array();
3800
    }
3801
    if(isset($elements['#options_suffixes'][$key])){
3802
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3803
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3804
    }
3805
  }
3806
  return $elements;
3807
3808
}
3809
3810
/**
3811
 * TODO
3812
 * @param unknown $variables
3813
 */
3814
function theme_radio_options_suffix($variables) {
3815
  $element = $variables['element'];
3816
  if(isset($element['#options_suffix'])) {
3817
    $element['#children'] .= $element['#options_suffix'];
3818
  }
3819
  return $element['#children'];
3820
}
3821
3822
3823 0f5f1c12 Andreas Kohlbecker
/**
3824
 * Element validate callback for text field and arrays containing json.
3825
 *
3826
 * @param $element
3827
 *   The form element to validate
3828
 * @param $form_state
3829
 *   A keyed array containing the current state of the form.
3830 cc3c9807 Andreas Kohlbecker
 * @param $form
3831
 *   Nested array of form elements that comprise the form.
3832 0f5f1c12 Andreas Kohlbecker
 */
3833
function form_element_validate_json($element, &$form_state, $form) {
3834
   if (!empty($element['#value'])) {
3835
     json_decode($element['#value']);
3836
     if(json_last_error() != JSON_ERROR_NONE){
3837 7cc085da Andreas Kohlbecker
       form_error($element,
3838
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3839
         . l('JSONLint', 'http://jsonlint.com/')
3840
       );
3841 0f5f1c12 Andreas Kohlbecker
     }
3842
   }
3843
}
3844
3845
/**
3846
 * Form submission handler for textareas and textfields containing JSON.
3847
 *
3848
 * The contained JSON will be converted into an php array
3849 2bbc28c8 Andreas Kohlbecker
 * or object and will be stored in the variables as such.
3850 0f5f1c12 Andreas Kohlbecker
 *
3851
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3852
 *
3853
 * @param $form
3854
 *   Nested array of form elements that comprise the form.
3855
 * @param $form_state
3856
 *   A keyed array containing the current state of the form.
3857
 *
3858
 */
3859
function submit_json_as_php_array($form, &$form_state) {
3860
  if (is_array($form['#json_elements'])) {
3861
    foreach ($form['#json_elements'] as $element){
3862 80370786 Andreas Kohlbecker
      if (trim($form_state['values'][$element])) {
3863
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3864
      } else {
3865
        $form_state['values'][$element] = NULL;
3866
      }
3867 0f5f1c12 Andreas Kohlbecker
    }
3868
  }
3869
}