Project

General

Profile

Download (126 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?php
2
/**
3
 * @file
4
 * CDM Dataportal settings.
5
 */
6
7 642b323b Andreas Kohlbecker
  // TODO Genus UUID.
8
9
  define('DEFAULT_TAXONTREE_RANKLIMIT', '1b11c34c-48a8-4efa-98d5-84f7f66ef43a');
10
  define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
11
  define('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
12
13
  define('NO_SORT', -1);
14
  define('SORT_HIERARCHICAL', 9);
15
16
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
17
  define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
18
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
19
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 1);
20
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
21
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
22
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
23
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
24
25
  /* annotationTypeKeys */
26
  $annotationTypeKeys = array_keys(cdm_Vocabulary_as_option(UUID_ANNOTATION_TYPE));
27
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
28
    $annotationTypeKeys = array_flip($annotationTypeKeys);
29
30
    // Technical annotation are off by default.
31
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
32
    $annotationTypeKeys = array_flip($annotationTypeKeys);
33
    // Additional value for the NULL case.
34
    $annotationTypeKeys[] = 'NULL_VALUE';
35
  }
36
  define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
37 6657531f Andreas Kohlbecker
38 642b323b Andreas Kohlbecker
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
39
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
40
    'enabled' => 0,
41
    'key_format' => 'ALPHA'
42
  )));
43 f19f47fa Andreas Kohlbecker
44 642b323b Andreas Kohlbecker
  /* taxonRelationshipTypes */
45
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
46 6657531f Andreas Kohlbecker
47 6280e639 Andreas Kohlbecker
48 1ce9afb7 Patric Plitzner
49 642b323b Andreas Kohlbecker
    /* ---- MAP SETTING CONSTANTS ---- */
50
  /**
51
   * @var array of URIs eg. http://edit.africamuseum.be"
52
   *   An options array
53
   */
54
  define('EDIT_MAPSERVER_URI', serialize(
55
      array(
56
        'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)',
57
        'http://edit.br.fgov.be'=>'Secondary (http://edit.br.fgov.be)',
58
      )
59 ba706bf0 Andreas Kohlbecker
    )
60 642b323b Andreas Kohlbecker
  );
61
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
62
  /**
63
   * @var array of versions eg. "v1.2"
64
   *   An options array
65
   */
66
  define('EDIT_MAPSERVER_VERSION', serialize(
67
      array(
68
        'v1' => 'v1' ,
69
        'v1.1' => 'v1.1',
70
        'v1.2_dev' => 'v1.2_dev',
71
        'v1.2' => 'v1.2',
72
        'v1.3_dev' => 'v1.3_dev',
73
        'v1.4_dev' => 'v1.4_dev'
74
      )
75 f19f47fa Andreas Kohlbecker
    )
76 642b323b Andreas Kohlbecker
  );
77
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
78
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
79 6657531f Andreas Kohlbecker
80 642b323b Andreas Kohlbecker
    // --- Taxon profile settings --- /
81
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
82
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
83
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
84
      array(
85
          'show' => 0,
86
          'maxextend' => 184,
87
          'media_uri_query' => '',
88
          'custom_placeholder_image_on' => 0,
89
          'custom_placeholder_image_fid' => ''
90
      )
91 9c92cd84 Andreas Kohlbecker
    )
92 642b323b Andreas Kohlbecker
  );
93
  define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
94 ba706bf0 Andreas Kohlbecker
95 642b323b Andreas Kohlbecker
  define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
96 c6ee8193 Andreas Kohlbecker
97 6657531f Andreas Kohlbecker
/**
98 b54cbda1 Andreas Kohlbecker
 * Returns the array of implemented taxon page tabs.
99
 * The array has fixed integer keys which must not be changed.
100 6657531f Andreas Kohlbecker
 */
101
function get_taxon_tabs_list() {
102
  return array(
103
    0 => 'General',
104
    1 => 'Synonymy',
105
    2 => 'Images',
106
    3 => 'Specimens',
107
    4 => 'Keys',
108
  );
109
}
110
111 b54cbda1 Andreas Kohlbecker
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
112
  array('general' => '-3', 'synonymy' => '-2', 'images' => '0', 'specimens' => '1', 'keys' => '3')
113
));
114
115 6657531f Andreas Kohlbecker
$taxon_tab_options = get_taxon_tabs_list();
116
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
117
118
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
119
120
/**
121
 * @todo document this function.
122
 */
123
function get_taxon_options_list() {
124
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
125
  foreach ($taxon_tab_options as $key => $value) {
126
    $taxon_tab_options[$key] = t($key);
127
  }
128
  return $taxon_tab_options;
129
130
}
131
132 0f5f1c12 Andreas Kohlbecker
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
133
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
134 f19f47fa Andreas Kohlbecker
  array(
135
      'ZoologicalName' => array(
136 501347df Andreas Kohlbecker
        'namePart' => array('name' => TRUE),
137 f19f47fa Andreas Kohlbecker
        'nameAuthorPart' => array('name' => TRUE),
138
        'referencePart' => array('authors' => TRUE),
139
        'microreferencePart' => array('microreference' => TRUE),
140
        'statusPart' => array('status' => TRUE),
141
        'descriptionPart' => array('description' => TRUE),
142
      ),
143 0f5f1c12 Andreas Kohlbecker
      'BotanicalName'=> array(
144
        'namePart' => array('name' => TRUE),
145
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
146
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
147 51b04faf Andreas Kohlbecker
        'referenceYearPart' => array('reference.year' => TRUE),
148 0f5f1c12 Andreas Kohlbecker
        'statusPart' => array('status' => TRUE),
149
        'descriptionPart' => array('description' => TRUE),
150 f19f47fa Andreas Kohlbecker
      ),
151
     '#DEFAULT' => array(
152
        'namePart' => array(
153
            'name' => TRUE
154 501347df Andreas Kohlbecker
        ),
155
        'nameAuthorPart' => array(
156
            'name' => TRUE,
157
            'authors' => TRUE
158 f19f47fa Andreas Kohlbecker
        ),
159
        'referencePart' => array(
160
            'reference' => TRUE
161
        ),
162
        'microreferencePart' => array(
163
            'microreference' => TRUE,
164
        ),
165
        'statusPart' => array(
166
            'status' => TRUE,
167
        ),
168
        'descriptionPart' => array(
169
            'description' => TRUE,
170
        ),
171
      )
172 0f5f1c12 Andreas Kohlbecker
    )
173
  )
174
);
175 f19f47fa Andreas Kohlbecker
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
176 0f5f1c12 Andreas Kohlbecker
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
177 f19f47fa Andreas Kohlbecker
   array (
178 5972ca1a Andreas Kohlbecker
     'taxon_page_title,polytomousKey'=> array(
179
          'namePart' => array('#uri' => TRUE),
180
        ),
181
      'taxon_page_synonymy,related_taxon'=> array(
182
          'nameAuthorPart' => array('#uri' => TRUE),
183
          'referencePart' => TRUE,
184
          'statusPart' => TRUE,
185
          'descriptionPart' => TRUE,
186
        ),
187 51b04faf Andreas Kohlbecker
       'homonym'=> array(
188
            'nameAuthorPart' => array('#uri' => TRUE),
189
            'referenceYearPart' => TRUE,
190
        ),
191 5972ca1a Andreas Kohlbecker
      'acceptedFor,typedesignations,list_of_taxa' => array(
192
          'nameAuthorPart' => array('#uri' => TRUE),
193
          'referencePart' => TRUE,
194
        ),
195
      '#DEFAULT' => array(
196
          'nameAuthorPart' => array('#uri' => TRUE),
197
          'referencePart' => TRUE,
198 f19f47fa Andreas Kohlbecker
       )
199 0f5f1c12 Andreas Kohlbecker
    )
200
));
201
202 6280e639 Andreas Kohlbecker
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
203
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
204
    // to unset a default enntry set the value to 0
205
    array(
206
      'doTaxa'=>'doTaxa',
207
      'doSynonyms' => 'doSynonyms',
208
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
209
      'doMisappliedNames' => 'doMisappliedNames'
210
    )
211
  )
212
);
213
214 2d0d855a Andreas Kohlbecker
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
215
216 6280e639 Andreas Kohlbecker
/* Gallery variables. */
217
$gallery_settings = array(
218
    "cdm_dataportal_show_taxon_thumbnails" => 1,
219
    "cdm_dataportal_show_synonym_thumbnails" => 0,
220
    "cdm_dataportal_show_thumbnail_captions" => 1,
221
    "cdm_dataportal_media_maxextend" => 120,
222
    "cdm_dataportal_media_cols" => 3,
223
    "cdm_dataportal_media_maxRows" => 1,
224
);
225
226 6657531f Andreas Kohlbecker
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
227
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
228
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
229
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
230
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
231
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
232
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
233
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
234
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
235
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
236
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
237
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
238 30f78c59 Andreas Kohlbecker
/**
239
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
240
 * the snonymy.
241
 *
242
 * @var string
243
 */
244 6657531f Andreas Kohlbecker
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
245 30f78c59 Andreas Kohlbecker
/**
246
 * The drupal variable for the configuration of the information aggregation along
247
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
248
 *    - direct: the uuids of the taxon relationship types to take into account in invers
249
 *      direction.
250
 *    - invers: the uuids of the taxon relationship types to take into account in direct
251
 *      direction.
252
 *
253
 * @var String
254
 */
255
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
256
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
257
    array(
258
        'direct'=>array(),
259
        'invers'=>array()
260
     )
261
   ));
262 6657531f Andreas Kohlbecker
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
263 bfb2b81a Andreas Kohlbecker
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
264 6657531f Andreas Kohlbecker
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
265
266 aa63dfb4 Andreas Kohlbecker
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
267
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
268
      array(
269
      'filter_rules' => array(
270
        'statusOrderPreference' => 0,
271
        'subAreaPreference' => 0,
272
      ),
273
      'hideMarkedAreas' => array()
274
     )
275
));
276
277
278 a950f2f9 Andreas Kohlbecker
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
279
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
280
    array(
281
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
282
        'includeOccurrences' => 0,
283
        'includeTaxonNameDescriptions' => 0
284
     )
285
  ));
286
287 cc3c9807 Andreas Kohlbecker
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
288
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
289
  // needs to be merged with user setting by drupal_array_merge_deep()
290
  'width' => 512, // optimum size for OSM layers is 512
291
  'height' => 512 / 2, // optimum size for OSM layers 256
292
  'bbox' => '', // empty to allow automatic zooming to extend
293
  'show_labels' => FALSE,
294
  'caption' => '',
295
  'distribution_opacity' => '0.5',
296
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
297
  'image_map' => array(
298
    'base_layer' => '', // none, formerly this was cyprusdivs
299
    'bg_color' => '1874CD',
300
    'layer_style' => 'ffffff,606060,,',
301
  ),
302
  'openlayers' => array(
303
    'base_layers' =>  array(
304
      // A layer MUST NOT BE SET in the defaults,
305
      // otherwise it can not be overidden by the user settings:
306
      // 'osgeo_vmap0' => 'osgeo_vmap0',
307
      // it is sufficient to define the preferred layer,
308
      // since it will automatically be enabled:
309
      'PREFERRED' => 'osgeo_vmap0'),
310 2bbc28c8 Andreas Kohlbecker
     'custom_wms_base_layer' => array(
311
            'name' => NULL,
312
            'url' => NULL,
313
            'params' =>  NULL,
314
            'projection' => NULL,
315 e3026d72 Andreas Kohlbecker
            'proj4js_def' => NULL,
316 2bbc28c8 Andreas Kohlbecker
            'max_extent' => NULL,
317
            'units' => NULL
318
     ),
319
    'show_layer_switcher' => TRUE,
320
    'display_outside_max_extent' => FALSE
321 cc3c9807 Andreas Kohlbecker
  ),
322
  'legend' => array(
323
    'show' => TRUE,
324
    'opacity' => '0.5',
325
    'font_size' => 10,
326
    'font_style' => FALSE,
327
    'icon_width' => 35,
328
    'icon_height' => 15
329
  )
330
)));
331
332
/**
333
 * Merges the named array variable with the array of defaults.
334
 *
335 5611d467 Andreas Kohlbecker
 * IMPORTANT: The array keys must be strings. When the keys are integers
336
 * the merging will not take place for these entities. Number keyed entities
337 b54cbda1 Andreas Kohlbecker
 * are just appended to the result array.
338
 *
339 cc3c9807 Andreas Kohlbecker
 * @param string $variable_name
340
 *     The variable name
341
 * @param string | array $default
342
 *     The array containing the default values either as array or serialized as string.
343 5611d467 Andreas Kohlbecker
 *     Unserialization is cared for if necessary
344 cc3c9807 Andreas Kohlbecker
 * @return array
345 5611d467 Andreas Kohlbecker
 *     The merged array as returned by drupal_array_merge_deep()
346 8c962983 Andreas Kohlbecker
 *
347 0f7c9d15 Andreas Kohlbecker
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
348
 * TODO force $default being an array
349 cc3c9807 Andreas Kohlbecker
 */
350
function get_array_variable_merged($variable_name, $default){
351
352
    // unserialize if nessecary
353
    if(!is_array($default)){
354
      $default = unserialize($default);
355
    }
356
    $variable = variable_get($variable_name, array());
357 b54cbda1 Andreas Kohlbecker
    $result = drupal_array_merge_deep($default, $variable);
358
    return $result;
359 cc3c9807 Andreas Kohlbecker
}
360
361 6657531f Andreas Kohlbecker
/**
362
 * @todo document this function.
363
 */
364
function getGallerySettings($gallery_config_form_name) {
365 cc3c9807 Andreas Kohlbecker
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
366 6657531f Andreas Kohlbecker
}
367
368
/**
369
 * Returns the string representation of the default tab.
370
 *
371
 * @param bool $returnTabIndex
372
 *   Defaults to FALSE, if set true this function will return the index number
373
 *   of the default tab. (used to supply default values to form elements).
374
 */
375
function get_default_taxon_tab($returnTabIndex = FALSE) {
376
377
  global $user;
378
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
379
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
380
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
381
  // Get the user value if the used has chosen to overwrite the system settings.
382
  $user_tab_on = variable_get($user_tab_active, FALSE);
383
  if ($user_tab_on) {
384
    $user_value = variable_get($user_tab, 0);
385
    $index_value = $user_value;
386
    // Get the system value.
387
  }
388
  else {
389
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
390
    $index_value = $system_value;
391
  }
392
393
  // Return the index value or the string representation.
394
  if ($returnTabIndex) {
395
    return $index_value;
396
  }
397
  else {
398
    return ($values[$index_value]);
399 22f5e82d Andreas Kohlbecker
  }
400 6657531f Andreas Kohlbecker
}
401
402 22f5e82d Andreas Kohlbecker
403 f3a04cfa Andreas Kohlbecker
  /**
404 8c962983 Andreas Kohlbecker
   * Provides the feature block settings for a specific feature which matches the $feature_uuid parameter.
405 f3a04cfa Andreas Kohlbecker
   *
406 8c962983 Andreas Kohlbecker
   * In case specifically configured settings array, like these which are stored in the drupal variables, is missing
407
   * one or more fields these fields are taken from the default. That is the specific settings are always merges
408
   * with the default.
409 f3a04cfa Andreas Kohlbecker
   *
410
   * Note: These settings only apply to feature blocks which do not have a special rendering
411 abacccbf Andreas Kohlbecker
   * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
412 f3a04cfa Andreas Kohlbecker
   * 'special' element of the settings
413
   *
414
   * @param $feature_uuid
415
   *   The uuid string representation of the feature to return the settings for
416
   *
417
   * @return array
418
   *  an associative array of settings, with the following fields:
419
   *    - as_list: string
420
   *        this setting will be used in compose_cdm_feature_block_elements() as $enclosing_tag
421
   *        possible values are:
422
   *          div: not as list,
423
   *          ul: as bullet list,
424
   *          ol: as numbered list,
425
   *          dl: as definition list
426 08a339ec Andreas Kohlbecker
   *        The tag used for the inner element, thus depends on the value of this field. The
427
   *        inner tag name can be retrieved by the function cdm_feature_block_element_tag_name()
428 f3a04cfa Andreas Kohlbecker
   *    - link_to_reference: boolean,
429
   *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
430
   *    - link_to_name_used_in_source": boolean
431
   *        whether to show name is source information as link which will point to the according name page
432
   *    - sources_as_content (boolean)
433 642b323b Andreas Kohlbecker
   *        TRUE (int: 1):
434 159cd9bb Andreas Kohlbecker
   *          1. If element is of the CDM type TextData and the text is not empty the source references will be
435 44d445c0 Andreas Kohlbecker
   *             appended in brackets like "text (source references)". If the original source has name in source
436
   *             information it will be appended to the citation string,
437
   *             like : "(citation, as name in source; citation, as name in source)"
438
   *          2. if the text of the TextData is empty, the original source citations are the only content
439
   *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
440
   *             prepended to the citation string like: "name in source: citation"
441 642b323b Andreas Kohlbecker
   *        FALSE (int: 0):
442 dcf17487 Andreas Kohlbecker
   *          Original sources are put into the bibliography(=references) pseudo feature block. If the original source
443 159cd9bb Andreas Kohlbecker
   *          citations are the only content, the resulting feature block content would only consist of footnotes.
444
   *          In this case the display of the respective feature block is suppressed.
445 dcf17487 Andreas Kohlbecker
   *          TODO if the bibliography is not enabled the sources will be treated as footnotes like annotations,
446
   *               in future however they will in this case be shown in a separate references section for each
447
   *               feature block.
448 f3a04cfa Andreas Kohlbecker
   *    - sources_as_content_to_bibliography  (boolean)
449
   *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
450 159cd9bb Andreas Kohlbecker
   *        in the bibliography.
451 f3a04cfa Andreas Kohlbecker
   *    - sort_elements
452
   *        whether and how to sort the elements
453 dcf17487 Andreas Kohlbecker
   *        possible values are the constants SORT_ASC, SORT_DESC, NULL,
454 642b323b Andreas Kohlbecker
   *        some feature types (Distribution) also support: SORT_HIERARCHICAL (
455
   *        TODO option to exclude levels, put in special?,
456
   *        TODO make use of this setting in compose_cdm_feature_block_elements())
457 f3a04cfa Andreas Kohlbecker
   *    - element_tag
458
   *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
459 f2e44165 Andreas Kohlbecker
   *        possible values are span | div. the proper inner tag name can be retrieved by the function
460
   *        cdm_feature_block_element_tag_name()
461 f3a04cfa Andreas Kohlbecker
   *    - special: array()
462
   *        an array with further settings, this field can be used for special
463
   *        settings for specialized rendering like for distributions
464
   *  }
465
   *
466
   */
467 642b323b Andreas Kohlbecker
  function get_feature_block_settings($feature_uuid = 'DEFAULT') {
468 f3a04cfa Andreas Kohlbecker
    // the default must conform to the default parameter values of
469
    // compose_cdm_feature_block_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
470 642b323b Andreas Kohlbecker
    // compose_cdm_descriptionElementTextData() : asListElement = NULL
471 f3a04cfa Andreas Kohlbecker
472
    // see #3257 (implement means to define the features to show up in the taxonprofile and in the specimen descriptions)
473
474 642b323b Andreas Kohlbecker
    // ---- DEFAULTS settings
475
476 6776a5bc Andreas Kohlbecker
    // only needed as final option, when the settings are not having a default
477 f3a04cfa Andreas Kohlbecker
    $default = array(
478 6776a5bc Andreas Kohlbecker
      'DEFAULT' => array(
479 6882da59 Andreas Kohlbecker
        'as_list' => 'div',
480 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
481
        'link_to_name_used_in_source' => 1,
482 8c962983 Andreas Kohlbecker
        'sources_as_content' => 0,
483 642b323b Andreas Kohlbecker
        'sources_as_content_to_bibliography' => 0,
484
        'sort_elements' => NO_SORT,
485 6776a5bc Andreas Kohlbecker
        'glue' => '',
486 642b323b Andreas Kohlbecker
        'element_tag' => NULL
487 6776a5bc Andreas Kohlbecker
      )
488
    );
489
490
    // will be used as preset in the settings
491
    $other_themes_default = array(
492 f3a04cfa Andreas Kohlbecker
      'DEFAULT' => array(
493 6882da59 Andreas Kohlbecker
        'as_list' => 'div',
494 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
495
        'link_to_name_used_in_source' => 1,
496
        'sources_as_content' => 0,
497
        'sources_as_content_to_bibliography' => 0,
498
        'sort_elements' => NO_SORT,
499 f3a04cfa Andreas Kohlbecker
        'glue' => '',
500 642b323b Andreas Kohlbecker
        'element_tag' => NULL
501 f3a04cfa Andreas Kohlbecker
      ),
502
      UUID_CITATION => array(
503
        'as_list' => 'div',
504 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
505
        'link_to_name_used_in_source' => 0,
506
        'sources_as_content' => 1,
507
        'sources_as_content_to_bibliography' => 0,
508 dcf17487 Andreas Kohlbecker
        'sort_elements' => SORT_ASC,
509 f3a04cfa Andreas Kohlbecker
        'glue' => '',
510 642b323b Andreas Kohlbecker
        'element_tag' => 'div'
511 dcf17487 Andreas Kohlbecker
      ),
512
      UUID_DISTRIBUTION => array(
513
        'as_list' => 'div', // currently ignored
514 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
515
        'link_to_name_used_in_source' => 0,
516
        'sources_as_content' => 0,
517
        'sources_as_content_to_bibliography' => 0,
518
        'sort_elements' => NO_SORT, // will cause ...
519 dcf17487 Andreas Kohlbecker
        'glue' => '',
520 642b323b Andreas Kohlbecker
        'element_tag' => 'div',
521
        'special' => array()
522 dcf17487 Andreas Kohlbecker
      ),
523 f2e44165 Andreas Kohlbecker
      UUID_COMMON_NAME => array(
524 6a3b101a Andreas Kohlbecker
        'as_list' => 'div',
525 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
526
        'link_to_name_used_in_source' => 1,
527
        'sources_as_content' => 0,
528
        'sources_as_content_to_bibliography' => 0,
529
        'sort_elements' => NO_SORT,
530 f2e44165 Andreas Kohlbecker
        'glue' => '',
531 642b323b Andreas Kohlbecker
        'element_tag' => 'span'
532 f2e44165 Andreas Kohlbecker
      ),
533 f3a04cfa Andreas Kohlbecker
    );
534
535 642b323b Andreas Kohlbecker
    // ---- Special DEFAULTS for existing portals
536
    // TODO:
537
    // this can be removed once the feature block
538
    // settings have been deployed for the first time to these portals
539
540 f3a04cfa Andreas Kohlbecker
    $cichorieae_default = array(
541
      'DEFAULT' => array(
542
        'as_list' => 'div',
543 642b323b Andreas Kohlbecker
        'link_to_reference' => 1,
544
        'link_to_name_used_in_source' => 1,
545
        'sources_as_content' => 1,
546
        'sources_as_content_to_bibliography' => 0,
547
        'sort_elements' => NO_SORT,
548 f3a04cfa Andreas Kohlbecker
        'glue' => '',
549 642b323b Andreas Kohlbecker
        'element_tag' => 'div'
550 f3a04cfa Andreas Kohlbecker
      ),
551
      UUID_CITATION => array(
552
        'as_list' => 'div',
553 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
554
        'link_to_name_used_in_source' => 0,
555
        'sources_as_content' => 1,
556
        'sources_as_content_to_bibliography' => 0,
557 dcf17487 Andreas Kohlbecker
        'sort_elements' => SORT_ASC,
558 f3a04cfa Andreas Kohlbecker
        'glue' => '',
559 642b323b Andreas Kohlbecker
        'element_tag' => 'div'
560 f3a04cfa Andreas Kohlbecker
      ),
561
      UUID_CHROMOSOMES_NUMBERS => array(
562
        'as_list' => 'ul',
563 642b323b Andreas Kohlbecker
        'link_to_reference' => 1,
564
        'link_to_name_used_in_source' => 1,
565
        'sources_as_content' => 1,
566
        'sources_as_content_to_bibliography' => 0,
567
        'sort_elements' => NO_SORT,
568 f3a04cfa Andreas Kohlbecker
        'glue' => '',
569 642b323b Andreas Kohlbecker
        'element_tag' => 'div'
570 f3a04cfa Andreas Kohlbecker
      ),
571
      UUID_CHROMOSOMES => array(
572
        'as_list' => 'ul',
573 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
574
        'link_to_name_used_in_source' => 1,
575
        'sources_as_content' => 1,
576
        'sources_as_content_to_bibliography' => 0,
577
        'sort_elements' => NO_SORT,
578 f3a04cfa Andreas Kohlbecker
        'glue' => '',
579 642b323b Andreas Kohlbecker
        'element_tag' => 'div'
580 f3a04cfa Andreas Kohlbecker
      ),
581 f2e44165 Andreas Kohlbecker
      UUID_COMMON_NAME => array(
582
        'as_list' => 'div',
583 642b323b Andreas Kohlbecker
        'link_to_reference' => 0,
584
        'link_to_name_used_in_source' => 1,
585
        'sources_as_content' => 0,
586
        'sources_as_content_to_bibliography' => 0,
587
        'sort_elements' => NO_SORT,
588 f2e44165 Andreas Kohlbecker
        'glue' => '',
589 642b323b Andreas Kohlbecker
        'element_tag' => 'span'
590 f2e44165 Andreas Kohlbecker
      ),
591 f3a04cfa Andreas Kohlbecker
    );
592
593
    $palmweb_default = array(
594
      'DEFAULT' => array(
595
        'as_list' => 'ul',
596 642b323b Andreas Kohlbecker
        'link_to_reference' => 1,
597
        'link_to_name_used_in_source' => 1,
598
        'sources_as_content' => 1,
599
        'sources_as_content_to_bibliography' => 1,
600
        'sort_elements' => NO_SORT,
601 f3a04cfa Andreas Kohlbecker
        'glue' => '',
602 642b323b Andreas Kohlbecker
        'element_tag' => NULL
603 f3a04cfa Andreas Kohlbecker
      ),
604
      UUID_CITATION => array(
605
        'as_list' => 'ul',
606 642b323b Andreas Kohlbecker
        'link_to_reference' => 1,
607
        'link_to_name_used_in_source' => 1,
608
        'sources_as_content' => 0,
609
        'sources_as_content_to_bibliography' => 1,
610 dcf17487 Andreas Kohlbecker
        'sort_elements' => SORT_ASC,
611 f3a04cfa Andreas Kohlbecker
        'glue' => '',
612 642b323b Andreas Kohlbecker
        'element_tag' => 'div'
613 a009927b Andreas Kohlbecker
      ),
614
      UUID_DISTRIBUTION => array(
615
        'as_list' => 'div', // currently ignored
616 642b323b Andreas Kohlbecker
        'link_to_reference' => 1,
617
        'link_to_name_used_in_source' => 1,
618
        'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
619
        'sources_as_content_to_bibliography' => 1,
620
        'sort_elements' => NO_SORT, // will cause ...
621 a009927b Andreas Kohlbecker
        'glue' => '',
622 642b323b Andreas Kohlbecker
        'element_tag' => 'div',
623
        'special' => array()
624 a009927b Andreas Kohlbecker
      ),
625 f3a04cfa Andreas Kohlbecker
    );
626
627 6776a5bc Andreas Kohlbecker
    $cyprus_default = $cichorieae_default;
628 642b323b Andreas Kohlbecker
    $cyprus_default[UUID_DISTRIBUTION] = array(
629 6776a5bc Andreas Kohlbecker
      'as_list' => 'div', // currently ignored
630 642b323b Andreas Kohlbecker
      'link_to_reference' => 0,
631
      'link_to_name_used_in_source' => 0,
632
      'sources_as_content' => 0,
633
      'sources_as_content_to_bibliography' => 0,
634
      'sort_elements' => NO_SORT, // will cause ...
635 6776a5bc Andreas Kohlbecker
      'glue' => '',
636 642b323b Andreas Kohlbecker
      'element_tag' => 'div',
637
      'special' => array()
638 6776a5bc Andreas Kohlbecker
    );
639
640 f3a04cfa Andreas Kohlbecker
    $default_theme = variable_get('theme_default', NULL);
641
642 642b323b Andreas Kohlbecker
    switch ($default_theme) {
643 f3a04cfa Andreas Kohlbecker
      case 'garland_cichorieae':
644 6776a5bc Andreas Kohlbecker
        $settings_for_theme = $cichorieae_default;
645
        break;
646 f3a04cfa Andreas Kohlbecker
      case 'cyprus':
647
        // cyprus: no longer used in production,
648
        // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
649 6776a5bc Andreas Kohlbecker
        $settings_for_theme = $cyprus_default;
650 f3a04cfa Andreas Kohlbecker
        break;
651
      case 'flore_afrique_centrale':
652
      case 'flora_malesiana':
653
      case 'flore_gabon':
654
        $settings_for_theme = $cichorieae_default;
655
        $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
656
        break;
657
      case 'palmweb_2':
658
        $settings_for_theme = $palmweb_default;
659
        break;
660
      default:
661 642b323b Andreas Kohlbecker
        $settings_for_theme = $other_themes_default;
662 f3a04cfa Andreas Kohlbecker
    }
663 642b323b Andreas Kohlbecker
    // ---- END of DEFAULTS
664 c367b0ab Andreas Kohlbecker
665 642b323b Andreas Kohlbecker
    $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
666
667 57d513cb Andreas Kohlbecker
    $feature_block_setting = null;
668 642b323b Andreas Kohlbecker
669
    if (isset($saved_settings[$feature_uuid])) {
670
      $feature_block_setting = $saved_settings[$feature_uuid];
671
    }
672
    else if (isset($settings_for_theme[$feature_uuid])) {
673
      $feature_block_setting = $settings_for_theme[$feature_uuid];
674 f3a04cfa Andreas Kohlbecker
    }
675 642b323b Andreas Kohlbecker
    else if (isset($settings_for_theme['DEFAULT'])) {
676
      $feature_block_setting = $settings_for_theme['DEFAULT'];
677
    }
678
679 57d513cb Andreas Kohlbecker
    // now merge the default and specific settings
680
    $settings_to_merge = array($default['DEFAULT']);
681
    if(is_array($saved_settings)){
682
      $settings_to_merge[] = $saved_settings['DEFAULT'];
683
    }
684
    if(isset($feature_block_setting)){
685
      $settings_to_merge[] = $feature_block_setting;
686
    }
687
    $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
688 642b323b Andreas Kohlbecker
689
    return $feature_block_setting;
690 1ce9afb7 Patric Plitzner
}
691 22f5e82d Andreas Kohlbecker
  /**
692 5611d467 Andreas Kohlbecker
 * returns the current setting for the original source bibliography
693
 *
694
 * Caches internally
695
 *
696
 * @return array
697
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
698
 *   - 'enabled': 1|0
699
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
700
 */
701 800ff2b0 Andreas Kohlbecker
function get_bibliography_settings($clear_cache = false){
702 5611d467 Andreas Kohlbecker
  static $bibliography_settings = null;
703 800ff2b0 Andreas Kohlbecker
  if(!$bibliography_settings || $clear_cache){
704 f3a04cfa Andreas Kohlbecker
    $bibliography_settings = get_array_variable_merged(
705
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
706
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
707
    );
708 5611d467 Andreas Kohlbecker
  }
709
  return $bibliography_settings;
710
}
711
712 6657531f Andreas Kohlbecker
/**
713
 * @todo Please document this function.
714
 * @see http://drupal.org/node/1354
715
 */
716
function cdm_dataportal_menu_admin(&$items) {
717
  // Display section on admin/config page.
718
  $items['admin/config/cdm_dataportal'] = array(
719
    'title' => 'CDM Dataportal',
720
    'description' => 'Settings for the CDM DataPortal.',
721
    'position' => 'right',
722
    'weight' => 10,
723
    'page callback' => 'system_admin_menu_block_page',
724 e014414c Andreas Kohlbecker
    'access arguments' => array('administer cdm_dataportal'),
725 6657531f Andreas Kohlbecker
    'file' => 'system.admin.inc',
726
    'file path' => drupal_get_path('module', 'system'),
727
  );
728
  $items['admin/config/cdm_dataportal/settings'] = array(
729
    'title' => 'Settings',
730
    'description' => 'Settings for the CDM DataPortal.',
731
    'weight' => 0,
732
    'page callback' => 'drupal_get_form',
733
    'page arguments' => array('cdm_settings_general'),
734
    'access arguments' => array('administer cdm_dataportal'),
735
    'type' => MENU_NORMAL_ITEM,
736
  );
737
  $items['admin/config/cdm_dataportal/settings/general'] = array(
738
    'title' => 'General',
739
    'description' => 'General',
740
    'weight' => 0,
741
    'page callback' => 'drupal_get_form',
742
    'page arguments' => array('cdm_settings_general'),
743
    'access arguments' => array('administer cdm_dataportal'),
744
    'type' => MENU_DEFAULT_LOCAL_TASK,
745
  );
746
747
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
748
    'title' => 'Cache',
749
    'description' => 'Cache',
750
    'access arguments' => array('administer cdm_dataportal'),
751
    'page callback' => 'drupal_get_form',
752
    'page arguments' => array('cdm_settings_cache'),
753
    'weight' => 10,
754
    'type' => MENU_LOCAL_TASK,
755
  );
756
757
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
758
    'title' => 'Geo & Map',
759
    'description' => 'Geo & Map',
760
    'access arguments' => array('administer cdm_dataportal'),
761
    'page callback' => 'drupal_get_form',
762
    'page arguments' => array('cdm_settings_geo'),
763
    'weight' => 1,
764
    'type' => MENU_LOCAL_TASK,
765
  );
766
767
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
768
    'title' => 'Layout',
769
    'description' => 'Configure and adjust the layout of your DataPortal ',
770
    'access arguments' => array('administer cdm_dataportal'),
771
    'page callback' => 'drupal_get_form',
772
    'page arguments' => array('cdm_settings_layout'),
773
    'weight' => 2,
774
    'type' => MENU_LOCAL_TASK,
775
  );
776
777
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
778
    'title' => 'Taxon',
779
    'description' => 'Configure and adjust the layout of your DataPortal ',
780
    'access arguments' => array('administer cdm_dataportal'),
781
    'page callback' => 'drupal_get_form',
782
    'page arguments' => array('cdm_settings_layout_taxon'),
783
    'weight' => 1,
784
    'type' => MENU_LOCAL_TASK,
785
  );
786
  /*
787
  $items[] = array(
788
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
789
  'title' => t('Synonymy'),
790
  'description' => t('Configure and adjust the layout of your DataPortal '),
791
  'access' => user_access('administer cdm_dataportal'),
792
  'callback' => 'drupal_get_form',
793
  'callback arguments' => array('cdm_settings_layout_synonymy'),
794
  'weight' => 1,
795
  'type' => MENU_LOCAL_TASK,
796
  );
797
798
  $items[] = array(
799
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
800
  'title' => t('Specimens'),
801
  'description' => t('Configure and adjust the layout of your DataPortal '),
802
  'access' => user_access('administer cdm_dataportal'),
803
  'callback' => 'drupal_get_form',
804
  'callback arguments' => array('cdm_settings_layout_specimens'),
805
  'weight' => 1,
806
  'type' => MENU_LOCAL_TASK,
807
  );
808
  */
809
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
810
    'title' => 'Search',
811
    'description' => 'Configure and adjust the layout of your DataPortal ',
812
    'access arguments' => array('administer cdm_dataportal'),
813
    'page callback' => 'drupal_get_form',
814
    'page arguments' => array('cdm_settings_layout_search'),
815
    'weight' => 2,
816
    'type' => MENU_LOCAL_TASK,
817
  );
818
819
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
820
    'title' => 'Media',
821
    'description' => 'Configure and adjust the layout of your DataPortal ',
822
    'access arguments' => array('administer cdm_dataportal'),
823
    'page callback' => 'drupal_get_form',
824
    'page arguments' => array('cdm_settings_layout_media'),
825
    'weight' => 3,
826
    'type' => MENU_LOCAL_TASK,
827
  );
828 947c6a8d Andreas Kohlbecker
829 6657531f Andreas Kohlbecker
}
830
831
/**
832
 * @todo document this function.
833
 */
834
function cdm_help_general_cache() {
835
  $form = array();
836
  $form['cache_help'] = array(
837
    '#type' => 'fieldset',
838
    '#title' => t('Help'),
839
    '#collapsible' => TRUE,
840
    '#collapsed' => TRUE,
841
  );
842
  $form['cache_help']['test'] = array('#value' => t('probando'));
843
  return drupal_render($form);
844
  $res = array();
845
  $res['default'] = drupal_render($help);
846
  return $res;
847
}
848
849
/**
850
 * Configures the settings form for the CDM-API module.
851
 *
852
 * @return array
853
 *   Drupal settings form.
854
 */
855
function cdm_settings_general() {
856
857
  $form['cdm_webservice'] = array(
858
    '#type' => 'fieldset',
859
    '#title' => t('CDM Server'),
860
    '#collapsible' => FALSE,
861
    '#collapsed' => FALSE,
862 9438ad3a Andreas Kohlbecker
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
863
        CDM data base to the web via RESTful web services and thus is the source of the data
864
        to be displayed by a CDM DataPotal.'),
865 6657531f Andreas Kohlbecker
  );
866
867
  $form['cdm_webservice']['cdm_webservice_url'] = array(
868
    '#type' => 'textfield',
869
    '#title' => t('CDM web service URL') . ':',
870
    '#description' => t('This is the URL to the CDM-Server exposing your data
871 d1eb0a8c Andreas Kohlbecker
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
872 6657531f Andreas Kohlbecker
    '#default_value' => variable_get('cdm_webservice_url', NULL),
873
  );
874
875
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
876 17c3d760 Andreas Kohlbecker
    '#type' => 'markup',
877 6ab41d7b Andreas Kohlbecker
    '#markup' => '<b>Debug CDM Web Service:</b> The web service debug box has completely been replaced '
878
      . 'by  the ' . l('CDM web service debug block', 'admin/structure/block/manage/cdm_api/cdm_ws_debug/configure')
879 17c3d760 Andreas Kohlbecker
      . '. It is usually only visible for administrative roles like <i>administrator</i> and <i>CDM admin</i>'
880 6657531f Andreas Kohlbecker
  );
881
882
  $form['cdm_webservice']['freetext_index'] = array(
883
    '#type' => 'fieldset',
884
    '#title' => t('Freetext index'),
885
    '#collapsible' => FALSE,
886
    '#collapsed' => FALSE,
887
  );
888
889
  // Check the cdmserver port number and display a waring if it is not port 80
890
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
891
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
892
    $form['cdm_webservice']['freetext_index']['message'] = array(
893
      '#markup' => "<div class=\"description\">"
894
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'."
895
      . " Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server."
896
      . " You may want to contact the maintainer of the according CDM Server in order to solve this problem.", array('!port' => $portNumberMatch[1][0]))
897
      . "</div>",
898
    );
899
  };
900
901
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
902
  $trigger_link_options = array(
903
    'attributes' => array(
904
      'class' => 'index-trigger',
905
    ),
906
  );
907
  $form['cdm_webservice']['freetext_index']['operations'] = array(
908
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
909
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
910
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
911
      ))
912
    . '<div id="index-progress"></div></div>',
913
  );
914
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
915
916
  $form['cdm_webservice']['proxy'] = array(
917
    '#type' => 'fieldset',
918
    '#title' => t('Proxy'),
919
    '#collapsible' => TRUE,
920
    '#collapsed' => TRUE,
921
  );
922
923
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
924
    '#type' => 'textfield',
925
    '#title' => t('Proxy URL') . ':',
926
    '#description' => t('If this proxy url is set the cdm api tries
927
    to connect the web service over the given proxy server.
928
    Otherwise proxy usage is deactivated.'),
929
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
930
  );
931
932
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
933
    '#type' => 'textfield',
934
    '#title' => t('Proxy port') . ':',
935
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
936
  );
937
938
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
939
    '#type' => 'textfield',
940
    '#title' => t('Login') . ':',
941
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
942
  );
943
944
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
945
    '#type' => 'textfield',
946
    '#title' => t('Password') . ':',
947
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
948
  );
949
950
  // TODO: settings are still incomplete, compare with
951
  // trunk/dataportal/inc/config_default.php.inc.
952 9438ad3a Andreas Kohlbecker
  $form['taxon_tree'] = array(
953 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
954
    '#title' => t('Taxon Tree'),
955
    '#collapsible' => FALSE,
956
    '#collapsed' => TRUE,
957
    '#description' => t('<p>When you explore your collection, you can navigate
958
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
959
      able to navigate through your collection the
960
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
961
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
962
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
963
      </a></p>'),
964
  );
965
966 9438ad3a Andreas Kohlbecker
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
967 6657531f Andreas Kohlbecker
    '#type' => 'select',
968
    '#title' => t('Available classifications') . ':',
969
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
970
    '#options' => cdm_get_taxontrees_as_options(),
971
    '#description' => t('Select the default taxa classification for your
972
      <em>taxon tree</em>, the other classifications will be also available but
973
      with a manual user change.'),
974
  );
975
976 9438ad3a Andreas Kohlbecker
  $form['taxon_tree']['taxontree_ranklimit'] = array(
977 6657531f Andreas Kohlbecker
    '#type' => 'select',
978
    '#title' => t('Rank of highest displayed taxon') . ':',
979
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
980
    '#default_value' => variable_get('taxontree_ranklimit', DEFAULT_TAXONTREE_RANKLIMIT),
981
    '#options' => cdm_rankVocabulary_as_option(),
982
    '#description' => t('This is the rank of the highest displayed taxon in the
983
      <em>taxon tree</em>. You can select here which rank should be at the top
984
      level of the tree structure.'),
985
  );
986
987 26fb3778 Andreas Kohlbecker
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
988
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
989
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
990
      '#type' => 'checkboxes',
991
      '#title' => t('Included Classifications') . ':',
992
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
993
      '#options' => cdm_get_taxontrees_as_options(),
994
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
995
  );
996
997 aa63dfb4 Andreas Kohlbecker
  $form['distribution'] = array(
998
      '#type' => 'fieldset',
999
      '#title' => t('Distributions'),
1000
      '#collapsible' => FALSE,
1001
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1002
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1003
          '<p>
1004
          </p>',
1005
  );
1006
1007
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1008
      '#type' => 'fieldset',
1009
      '#title' => 'Distribution filter',
1010
      '#collapsible' => FALSE,
1011
      '#collapsed' => FALSE,
1012
      '#tree' => TRUE,
1013
      '#description' => 'The Distribution filter offers the following options
1014
      <ul>
1015
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1016
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1017
      <li><strong>Marked area filter:</strong>Skip distributions where the area has a Marker with one of the specified MarkerTypes</li>
1018
      </ul>'
1019
  );
1020
1021
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1022
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1023
      '#type' => 'checkboxes',
1024
      '#title' => 'Filter rules',
1025
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1026
      '#options' => array(
1027
          'statusOrderPreference' => 'Status order preference rule',
1028
          'subAreaPreference' => 'Sub area preference rule'
1029
      ),
1030
  );
1031
1032
  $marker_type_options = cdm_terms_as_options( cdm_ws_fetch_all('term', array('class' => 'MarkerType' )) );
1033
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hideMarkedAreas'] = array(
1034
      '#type' => 'checkboxes',
1035
      '#title' => 'Hide marked area filter',
1036
      '#default_value' => $cdm_distribution_filter['hideMarkedAreas'],
1037
      '#options' => $marker_type_options,
1038
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1039
  );
1040
1041 f19f47fa Andreas Kohlbecker
  $form['aggregation'] = array(
1042
      '#type' => 'fieldset',
1043
      '#title' => t('Aggregation of data'),
1044
      '#collapsible' => FALSE,
1045 aa63dfb4 Andreas Kohlbecker
      '#description' => 'This section covers the different aspects of aggregating information.
1046 9438ad3a Andreas Kohlbecker
          <p>
1047 f19f47fa Andreas Kohlbecker
          </p>',
1048 9438ad3a Andreas Kohlbecker
  );
1049
1050 ccde8251 Andreas Kohlbecker
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1051
      '#type' => 'checkboxes',
1052
      '#title' => 'Taxon media filter',
1053
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1054
      '#options' => array(
1055
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1056
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1057
          'includeOccurrences' => 'Media related to specimens and occurrences',
1058
      ),
1059
      '#description' => 'This filter configures which images should be taken into account.',
1060
  );
1061
1062
  $form['aggregation']['notice'] = array(
1063 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
1064 ccde8251 Andreas Kohlbecker
          want to make use of the caching capabilities of the dataportal.',
1065
  );
1066
1067 f19f47fa Andreas Kohlbecker
  $form['aggregation']['media_aggregation'] = array(
1068
      '#type' => 'fieldset',
1069
      '#title' => t('Media aggregation'),
1070
      '#collapsible' => FALSE,
1071 9438ad3a Andreas Kohlbecker
      '#collapsed' => TRUE,
1072 f19f47fa Andreas Kohlbecker
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1073
1074 9438ad3a Andreas Kohlbecker
  );
1075 f19f47fa Andreas Kohlbecker
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1076
      '#type' => 'select',
1077
      '#title' => t('Aggregation of taxon pictures') . ':',
1078
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1079
      '#options' => array(
1080
          0 => "Show only pictures of the current taxon",
1081
          1 => "Include pictures of taxonomic children",
1082
      ),
1083
      '#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."),
1084 9438ad3a Andreas Kohlbecker
  );
1085
1086 f19f47fa Andreas Kohlbecker
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1087 30f78c59 Andreas Kohlbecker
      '#type' => 'fieldset',
1088
      '#attributes' => array('class'=>array('clearfix')),
1089 9438ad3a Andreas Kohlbecker
      '#title' => t('Aggregation via taxon relationsships'),
1090 30f78c59 Andreas Kohlbecker
      '#collapsible' => TRUE,
1091
      '#collapsed' => TRUE,
1092 f19f47fa Andreas Kohlbecker
      '#tree' => TRUE,
1093 30f78c59 Andreas Kohlbecker
      '#description' => t('Information on taxa will be aggregated along the below chosen
1094
          taxon relation ships. This will affect images and occurrences (specimens).
1095
          Taxon relation ships are directed and point form one taxon to another. The taxon
1096
          relationships to be taken into accunt can therefore configured for the direct direction
1097 f19f47fa Andreas Kohlbecker
          and for the inverse.'),
1098
  );
1099
1100 30f78c59 Andreas Kohlbecker
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1101
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1102 f19f47fa Andreas Kohlbecker
1103
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1104
      '#type' => 'checkboxes',
1105
      '#title' => t('Direct'),
1106
      '#options' => $taxonRelationshipTypeOptions,
1107
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1108 30f78c59 Andreas Kohlbecker
  );
1109 f19f47fa Andreas Kohlbecker
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1110
      '#type' => 'checkboxes',
1111
      '#title' => t('Invers'),
1112
      '#options' => $taxonRelationshipTypeOptions,
1113
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1114 30f78c59 Andreas Kohlbecker
  );
1115
1116 5ea8b301 Andreas Kohlbecker
  // ----------------------
1117
  $form['cdm_js_devel_mode'] = array(
1118
      '#type' => 'checkbox',
1119
      '#title' => 'Java-script developer mode',
1120
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1121
      '#description' => 'In production envirionments the java script libraries
1122
      the cdm_dataportal is making use of are compressed and optimized. This
1123
      is good for performance but a caveat if you need to debug java-script. When the
1124
      java-script developer mode is enabled the uncompressed and commented developer
1125
      versions of java-script libraries will be used where possible.
1126
      <br/><strong>Do not use this option in production!</strong>'
1127
  );
1128 2dd59bb5 Andreas Kohlbecker
  // ----------------------
1129
  $form['cdm_debug_mode'] = array(
1130
      '#type' => 'checkbox',
1131
      '#title' => 'CDM page debug mode',
1132
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1133
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1134 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
1135
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1136
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1137 2dd59bb5 Andreas Kohlbecker
      The log is written by the drupal devel module function <code>dd()</code>.
1138 b5deb531 Andreas Kohlbecker
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1139 2dd59bb5 Andreas Kohlbecker
  );
1140 5ea8b301 Andreas Kohlbecker
1141 6657531f Andreas Kohlbecker
  // Comment @WA: D7 form api does not support reset buttons,
1142
  // so to mimic the D5 reset button we add one like this.
1143
  $form['actions']['reset'] = array(
1144
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1145
    '#weight' => 1000,
1146
  );
1147
1148 22eb20d7 Andreas Kohlbecker
  $form['#submit'][] = 'cdm_settings_general_submit';
1149
1150 6657531f Andreas Kohlbecker
  return system_settings_form($form);
1151
}
1152
1153
1154
/**
1155
 * LAYOUT settings
1156 cf839840 Andreas Kohlbecker
 * @return
1157 6657531f Andreas Kohlbecker
 *   todo
1158
 */
1159
function cdm_settings_layout() {
1160
1161
  $form = array();
1162 0f5f1c12 Andreas Kohlbecker
1163
  $form['about'] = array(
1164
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1165 6657531f Andreas Kohlbecker
      layout. If you want to configure the specific sites layout visit the
1166 0f5f1c12 Andreas Kohlbecker
      respective configuration site for taxon, search or media.') . '</p>',
1167 6657531f Andreas Kohlbecker
  );
1168
1169
  // ---- footnotes --- //
1170 0f5f1c12 Andreas Kohlbecker
  $form['footnotes'] = array(
1171 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1172
    '#title' => t('Footnotes'),
1173
    '#collapsible' => FALSE,
1174
    '#collapsed' => FALSE,
1175
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1176
      media or distribution areas may have annotations or footnotes. When the
1177
      footnotes are enabled they will be visible (if they exist).'),
1178
  );
1179
1180 0f5f1c12 Andreas Kohlbecker
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1181 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1182
    '#title' => t('Do not show footnotes'),
1183
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1184
    '#description' => t('Check this if you do not want to show any footnotes'),
1185
  );
1186
1187 0f5f1c12 Andreas Kohlbecker
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1188 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1189
    '#title' => t('Do not show annotations footnotes'),
1190
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1191
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1192
  );
1193
1194 cf839840 Andreas Kohlbecker
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType', SORT_ASC);
1195 6657531f Andreas Kohlbecker
  // Additional option for the NULL case.
1196
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1197 0f5f1c12 Andreas Kohlbecker
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1198 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
1199
    '#title' => t('Annotation types as footnotes'),
1200
    '#description' => t("Only annotations of the selected type will be displayed
1201
       as footnotes. You may want to turn 'technical annotations' off."),
1202
    '#options' => $annotationTypeOptions,
1203
  );
1204
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1205
  if (!empty($annotationsTypesAsFootnotes)) {
1206 0f5f1c12 Andreas Kohlbecker
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1207 6657531f Andreas Kohlbecker
  }
1208
1209 5611d467 Andreas Kohlbecker
  // ---- original source --- //
1210
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1211
      '#type' => 'fieldset',
1212
      '#tree' => TRUE,
1213
      '#title' => t('Source Citations'),
1214
      '#collapsible' => FALSE,
1215
      '#collapsed' => FALSE,
1216
  );
1217 f19f47fa Andreas Kohlbecker
1218 800ff2b0 Andreas Kohlbecker
  $bibliography_settings = get_bibliography_settings(true);
1219 5611d467 Andreas Kohlbecker
1220 800ff2b0 Andreas Kohlbecker
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1221 5611d467 Andreas Kohlbecker
      '#type' => 'checkbox',
1222
      '#title' => t('Original Source in bibliography'),
1223
      '#default_value' => $bibliography_settings['enabled'],
1224
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1225
       annotations in each feature block.'),
1226
  );
1227
1228
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1229
    '#type' => 'select',
1230
    '#title' => t('The format of the key numerals'),
1231
    '#default_value' => $bibliography_settings['key_format'],
1232
    '#options' => array('latin' => 'Latin',
1233
      'ROMAN' => 'Roman (upper case)',
1234
      'roman' => 'Roman (lower case)',
1235
      'ALPHA'=> 'Alphabet (upper case)',
1236
      'alpha' => 'Alphabet (lower case)')
1237
  );
1238 f19f47fa Andreas Kohlbecker
1239
  // --- Advanced Search --- //
1240
  $form['asearch'] = array(
1241 1ce9afb7 Patric Plitzner
      '#type' => 'fieldset',
1242
      '#title' => t('Advanced search'),
1243
      '#collapsible' => FALSE,
1244
      '#collapsed' => FALSE,
1245 f19f47fa Andreas Kohlbecker
  );
1246
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1247 1ce9afb7 Patric Plitzner
      '#type' => 'checkbox',
1248
      '#title' => t('Show advanced search link'),
1249
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1250
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1251 f19f47fa Andreas Kohlbecker
  );
1252
1253
  // ---- Taxon Name Rendering --- //
1254
  $form['taxon_name'] = array(
1255
      '#type' => 'fieldset',
1256
      '#title' => t('Taxon name display'),
1257
      '#collapsible' => TRUE,
1258
      '#collapsed' => TRUE,
1259 0f5f1c12 Andreas Kohlbecker
      '#description' => t('The display of taxon names is configured by two parts.'
1260
          . 'The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.'
1261 f19f47fa Andreas Kohlbecker
          . 'The name parts are defined in the <stong>part definitions</strong>'),
1262 0f5f1c12 Andreas Kohlbecker
  );
1263
1264
  drupal_add_js(
1265
      'jQuery(document).ready( function( ) {
1266
         // pretty print json
1267
         var json_text = jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val();
1268
         var obj = JSON.parse(json_text);
1269
         jQuery(\'#edit-' . CDM_PART_DEFINITIONS . '\').val(JSON.stringify(obj, undefined, 2));
1270
1271
         json_text = jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val();
1272
         obj = JSON.parse(json_text);
1273
         jQuery(\'#edit-' . CDM_NAME_RENDER_TEMPLATES . '\').val(JSON.stringify(obj, undefined, 2));
1274
       });'
1275
      ,array(
1276
          'type' => 'inline',
1277
          'scope' => 'footer'
1278
      )
1279 6657531f Andreas Kohlbecker
  );
1280 f19f47fa Andreas Kohlbecker
1281 78292e72 Andreas Kohlbecker
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1282 0f5f1c12 Andreas Kohlbecker
1283
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1284
      '#type' => 'textarea',
1285
      '#title' => t('Part definitions'),
1286
      '#element_validate' => array('form_element_validate_json'),
1287
      '#default_value' =>  json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions)),
1288
      '#description' => '
1289
          <p>
1290
          (Clearing the text area will reset it to the default)
1291
          </p>
1292
          <p>
1293
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1294
          </p>
1295
          <p>
1296
           A full taxon name plus additional information can consist of the following elements:
1297
          <ul>
1298
             <li>name: the taxon name inclugin rank nbut without author</li>
1299
             <li>authors:  The authors of a reference, also used in taxon names</li>
1300
             <li>reference: the nomenclatural reference,</li>
1301
             <li>microreference:  Volume, page number etc.</li>
1302
             <li>status:  The nomenclatural status of a name</li>
1303
             <li>description: name descriptions like protologues etc ...</li>
1304
          </ul>
1305
          </p>
1306
          <p>
1307
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1308
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1309 51b04faf Andreas Kohlbecker
           The following parts can be formed and are recognized by the system:
1310 0f5f1c12 Andreas Kohlbecker
          <ul>
1311 51b04faf Andreas Kohlbecker
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1312
            <li>authorshipPart: the author (for example: "L.")</li>
1313
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1314 0f5f1c12 Andreas Kohlbecker
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1315
               be combined when a link to the taxon is rendered.</li>
1316 51b04faf Andreas Kohlbecker
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1317
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1318
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1319 0f5f1c12 Andreas Kohlbecker
            <li>statusPart: the nomenclatorical status</li>
1320
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1321
          </ul>
1322
          </p>
1323
          <p>
1324
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1325
           specific parts part definitions:
1326
          <ul>
1327
            <li>BotanicalName</li>
1328
            <li>ZoologicalName</li>
1329
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1330
          </ul>
1331
           An example:
1332
          <pre>
1333
           {
1334
            "ZoologicalName": {
1335
              "namePart": {
1336
                "name": true
1337
              },
1338
              "referencePart": {
1339 b5519d3a Andreas Kohlbecker
                "authors": true
1340 0f5f1c12 Andreas Kohlbecker
              },
1341
              "microreferencePart": {
1342
                "microreference": true
1343
              },
1344
              "statusPart": {
1345
                "status": true
1346
              },
1347
              "descriptionPart": {
1348
                "description": true
1349
              }
1350
            },
1351
            "BotanicalName": {
1352
              "namePart": {
1353
                "name": true,
1354
                "authors": true
1355
              },
1356
              "referencePart": {
1357
                "reference": true,
1358
                "microreference": true
1359
              },
1360
              "statusPart": {
1361
                "status": true
1362
              },
1363
              "descriptionPart": {
1364
                "description": true
1365
              }
1366
            }
1367
          }
1368
           </pre>',
1369
  );
1370
1371 78292e72 Andreas Kohlbecker
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1372 0f5f1c12 Andreas Kohlbecker
1373 f19f47fa Andreas Kohlbecker
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1374
      '#type' => 'textarea',
1375 0f5f1c12 Andreas Kohlbecker
      '#title' => t('Name render templates'),
1376 f19f47fa Andreas Kohlbecker
      '#element_validate' => array('form_element_validate_json'),
1377
      '#default_value' =>  json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates)),
1378 0f5f1c12 Andreas Kohlbecker
      '#description' => '
1379
          <p>
1380
          (Clearing the text area will reset it to the default)
1381
          </p>
1382
          <p>
1383
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1384
          render path. The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1385
          The following render Path keys are curretly recognized:
1386
          <ul>
1387 51b04faf Andreas Kohlbecker
            <li>list_of_taxa</li>
1388
            <li>acceptedFor</li>
1389
            <li>homonym</li>
1390 0f5f1c12 Andreas Kohlbecker
            <li>taxon_page_synonymy</li>
1391
            <li>typedesignations</li>
1392
            <li>taxon_page_title</li>
1393
            <li>polytomousKey</li>
1394
            <li>na: name + authorship</li>
1395
            <li>nar:name + authorship + reference</li>
1396
            <li>#DEFAULT</li>
1397
          </ul>
1398
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1399
          array element should be a comma separated list of render paths, without any whitespace!.
1400
          </p>
1401
          <p>
1402
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1403
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1404
          <p>
1405
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1406
          The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
1407
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1408
          links if the paramters $nameLink or $refenceLink are given to the name render function
1409 f19f47fa Andreas Kohlbecker
          (this is hard coded and cannot be configured here).',
1410 6657531f Andreas Kohlbecker
  );
1411
1412
  // @WA: D7 form api does not support reset buttons,
1413
  // so to mimic the D5 reset button we add one like this.
1414
  $form['actions']['reset'] = array(
1415
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1416
    '#weight' => 1000,
1417
  );
1418 f19f47fa Andreas Kohlbecker
1419 0f5f1c12 Andreas Kohlbecker
  $form['#submit'] = array('submit_json_as_php_array');
1420
  // #json_elements especially defined for submit_json_as_php_array()
1421
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1422 6657531f Andreas Kohlbecker
  return system_settings_form($form);
1423
}
1424
1425
1426
/**
1427
 * @todo Please document this function.
1428
 * @see http://drupal.org/node/1354
1429
 */
1430
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1431
  $form[$form_name] = array(
1432
    '#type' => 'fieldset',
1433
    '#title' => t($form_title),
1434
    '#collapsible' => TRUE,
1435
    '#collapsed' => $collapsed,
1436
    '#tree' => TRUE,
1437
    '#description' => t($form_description),
1438
  );
1439
1440
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1441
  $gallery_settings = variable_get($form_name, $default_values);
1442
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1443
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1444
    /*
1445
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1446
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1447
    '#type' => 'textfield',
1448
    '#title' => t('Search Page Size'),
1449
    '#default_value' => $test,
1450
    '#description' => t('Number of Names to display per page in search results.')
1451
    );
1452
    */
1453
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1454
      '#type' => 'checkbox',
1455
      '#title' => t('Show media thumbnails for accepted taxa'),
1456
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1457
    );
1458
1459
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1460
      '#type' => 'checkbox',
1461
      '#title' => t('Show media thumbnails for synonyms'),
1462
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1463
      '#description' => '',
1464
    );
1465
  }
1466
1467
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1468
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1469
    '#type' => 'checkbox',
1470
    '#title' => t('Show captions under thumbnails'),
1471
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1472
    '#description' => '',
1473
  );
1474
1475
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1476
    '#type' => 'textfield',
1477
    '#title' => t('Thumbnail size') . ':',
1478
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1479
    '#description' => t('Select the size of each individual thumbnail.'),
1480
  );
1481
1482
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1483
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1484
      '#type' => 'textfield',
1485
      '#title' => t('Number of columns') . ':',
1486
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1487
      '#description' => t('Group the thumbnails in columns: select how many
1488
        columns the gallery should display.'),
1489
    );
1490
  }
1491
1492
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1493
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1494
      '#type' => 'textfield',
1495
      '#title' => t('Maximum number of rows') . ':',
1496
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1497
      '#description' => t('You can group the thumbnails in rows, select in how
1498
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1499
        If you want an unlimited number of rows please set to 0.'),
1500
    );
1501
  }
1502
1503
  return $form;
1504
}
1505
1506
/**
1507
 * @todo document this function.
1508
 */
1509
function cdm_settings_layout_taxon() {
1510
  $collapsed = FALSE;
1511
  $form = array();
1512
1513 7df1be04 Andreas Kohlbecker
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1514
1515 d9c55e6c Andreas Kohlbecker
  $form['cdm_dataportal_show_back_to_search_results'] = array(
1516
      '#type' => 'checkbox',
1517
      '#title' => t('Show <em>Back to search results</em> link at the taxon site.'),
1518
      '#default_value' => variable_get('cdm_dataportal_show_back_to_search_results', 1),
1519
      '#description' => t('<p>If checked the link to search results is rendered at
1520
       the top of the taxon site. Clicking on the link the last search performed
1521
       is rendered again.</p>'),
1522
  );
1523
1524 6657531f Andreas Kohlbecker
  // --------- TABBED TAXON ------- //
1525
  $form['taxon_tabs'] = array(
1526
    '#type' => 'fieldset',
1527
    '#title' => t('Taxon tabs'),
1528
    '#collapsible' => TRUE,
1529
    '#collapsed' => FALSE,
1530
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1531
      be splitted in four diferent tabs; General, Synonymy, Images and
1532
      Specimens. If the taxon has no information for any of the tabs/sections
1533
      such tab will be not displayed.'),
1534
  );
1535
1536
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1537
    '#type' => 'checkbox',
1538
    '#title' => t('Tabbed taxon page'),
1539
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1540
    '#description' => t('<p>If selected split the taxon page into individual
1541
      tabs for description, images, synonymy and specimens. If not the taxon
1542
      data is rendered as a long single page without tabs.</p>'),
1543
  );
1544
1545
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1546
    '#type' => 'checkboxes',
1547
    '#title' => t('Tabs visibility options') . ':',
1548
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1549
    '#options' => get_taxon_options_list(),
1550
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1551
  );
1552
1553 b54cbda1 Andreas Kohlbecker
  // WEIGHT
1554
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1555
  $form['taxon_tabs']['cdm_taxonpage_tabs_weight'] = array(
1556
      '#tree' => true
1557
  );
1558
  // Weights range from -delta to +delta, so delta should be at least half
1559
  // of the amount of tabs present.
1560
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1561
  foreach (get_taxon_tabs_list() as $label) {
1562
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1563
    $form['taxon_tabs']['cdm_taxonpage_tabs_weight'][$key] = array(
1564
        '#title' => $label,
1565
        '#type'  => 'weight',
1566
        '#default_value' => $taxontabs_weights[$key],
1567
        '#delta' => $tab_weight_delta
1568
    );
1569
  }
1570
1571 6657531f Andreas Kohlbecker
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1572
    '#type' => 'select',
1573
    '#title' => t('Default tab to display') . ':',
1574
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1575
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1576
    '#description' => t('<p>Select the default tab to display when visiting a
1577
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1578
      <strong>Note:</strong> After performing a search and clicking in any
1579
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1580
      taxon and not the above selected tab.'),
1581
  );
1582
1583
  /* ======  TAXON_PROFILE ====== */
1584
  $form['taxon_profile'] = array(
1585
    '#type' => 'fieldset',
1586
    '#title' => t('Taxon profile (tab)'),
1587 9438ad3a Andreas Kohlbecker
    '#description' => t('<p>This section covers the settings related to the taxon
1588 6657531f Andreas Kohlbecker
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1589
    '#collapsible' => TRUE,
1590 642b323b Andreas Kohlbecker
    '#collapsed' => FALSE,
1591 6657531f Andreas Kohlbecker
  );
1592
1593
  // ---- PROFILE PICTURE ----//
1594 9c92cd84 Andreas Kohlbecker
1595
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1596 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1597 9c92cd84 Andreas Kohlbecker
    '#tree' => TRUE,
1598 9438ad3a Andreas Kohlbecker
    '#title' => t('Taxon profile picture'),
1599 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
1600
    '#collapsed' => FALSE,
1601 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.'),
1602 6657531f Andreas Kohlbecker
  );
1603
1604 9c92cd84 Andreas Kohlbecker
  //FIXME migrate variables:
1605
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1606
  // FIXME
1607 9aff46e4 Andreas Kohlbecker
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1608 9c92cd84 Andreas Kohlbecker
1609
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1610
  /*
1611
   * 'show' => 1,
1612
   * 'maxextend' => 184,
1613 053a92ec Andreas Kohlbecker
   * 'media_uri_query' => ''
1614 9c92cd84 Andreas Kohlbecker
   * 'custom_placeholder_image_on' => 1,
1615
   * 'custom_placeholder_image_fid' => ''
1616
   */
1617
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1618 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
1619
    '#title' => t('Enable profil picture'),
1620
    '#description' => t('Show the profil picture.'),
1621 9c92cd84 Andreas Kohlbecker
    '#default_value' => $taxon_profile_image_settings['show'],
1622 6657531f Andreas Kohlbecker
  );
1623
1624 9c92cd84 Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1625 d9c55e6c Andreas Kohlbecker
      '#type' => 'textfield',
1626
      '#tree' => TRUE,
1627
      '#title' => t('Profil picture maximum extend'),
1628 9c92cd84 Andreas Kohlbecker
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1629 d9c55e6c Andreas Kohlbecker
      '#field_suffix' => 'px',
1630
      '#maxlength' => 4,
1631
      '#size' => 4,
1632
      '#description' => t('The maximum extend in either dimension, width or height, of the profil picture in pixels.')
1633
  );
1634
1635 053a92ec Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1636
      '#type' => 'textfield',
1637
      '#tree' => TRUE,
1638
      '#title' => t('Additional URI query parameter'),
1639
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1640
      '#maxlength' => 1024,
1641
      '#size' => 60,
1642
      '#description' => t('Additional query parameters to be used when requesting for the '
1643
          . 'profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.'
1644 0686f307 Andreas Kohlbecker
          . 'The query parameters will be appended to the uri of the media representation part'
1645 053a92ec Andreas Kohlbecker
          . ' as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1646
  );
1647
1648 9c92cd84 Andreas Kohlbecker
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1649
      '#type' => 'checkbox',
1650
      '#title' => t('Use a custom placeholder image'),
1651 7df1be04 Andreas Kohlbecker
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1652 9c92cd84 Andreas Kohlbecker
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1653 7df1be04 Andreas Kohlbecker
  );
1654
1655 9c92cd84 Andreas Kohlbecker
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1656
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1657
        '#type' => 'managed_file',
1658
        '#title' => t('Custom placeholder image file'),
1659
        '#progress_indicator' => 'bar',
1660
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1661
    //       '#name' => 'custom_placeholder_image',
1662
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1663
    );
1664
1665
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1666
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1667
      $url = file_create_url($profile_image_file->uri);
1668
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1669
                '#type' => 'item',
1670
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1671
      );
1672
    }
1673
  } else {
1674
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1675 642b323b Andreas Kohlbecker
      '#type' => 'hidden',
1676
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1677 9c92cd84 Andreas Kohlbecker
    );
1678
  }
1679
1680 6657531f Andreas Kohlbecker
  $options = cdm_rankVocabulary_as_option();
1681
  array_unshift($options, '-- DISABLED --');
1682
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1683
    '#type' => 'select',
1684 9438ad3a Andreas Kohlbecker
    '#title' => t('Hide profile picture for higher ranks') . ':',
1685 6657531f Andreas Kohlbecker
    '#default_value' => variable_get('image_hide_rank', '0'),
1686
    '#options' => $options,
1687 9438ad3a Andreas Kohlbecker
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1688 6657531f Andreas Kohlbecker
  );
1689
1690
  // -- MEDIA THUMBNAILS -- //
1691
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1692
  $form_title = 'Taxon Profile Images';
1693
  $form_description = '<p>The different section in the taxon  profile can have images associated with them. These images are displayed in a gallery of thumbnails wich can be configuered here:</p>';
1694
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1695
1696 642b323b Andreas Kohlbecker
  // ---- FEATURE TREE BLOCKS ---- //
1697
  $form['taxon_profile']['feature_blocks'] = array(
1698 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
1699 642b323b Andreas Kohlbecker
    '#title' => t('Feature Blocks'),
1700 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
1701
    '#collapsed' => FALSE,
1702
    '#description' => t("This section covers settings related to the taxon's
1703
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1704 642b323b Andreas Kohlbecker
      features such as description, distribution, common names"),
1705 6657531f Andreas Kohlbecker
  );
1706
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
1707 642b323b Andreas Kohlbecker
  $profile_feature_tree = get_profile_feature_tree();
1708
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
1709
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
1710
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
1711 854e1d99 Andreas Kohlbecker
  }
1712 642b323b Andreas Kohlbecker
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
1713 6657531f Andreas Kohlbecker
    '#type' => 'radios',
1714 642b323b Andreas Kohlbecker
    '#title' => t('Taxon profile feature tree') . ':',
1715
    '#default_value' => $profile_feature_tree_uuid,
1716 6657531f Andreas Kohlbecker
    '#options' =>  $featureTrees['options'],
1717 3f485c6d Andreas Kohlbecker
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1718
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1719 642b323b Andreas Kohlbecker
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
1720
      profile page.'
1721 6657531f Andreas Kohlbecker
    ),
1722
  );
1723
1724 642b323b Andreas Kohlbecker
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
1725
  $profile_feature_tree = get_profile_feature_tree();
1726
1727
  if (isset($profile_feature_tree->root->childNodes)) {
1728 6657531f Andreas Kohlbecker
1729 642b323b Andreas Kohlbecker
    $form_feature_block_layout = array(
1730
      '#type' => 'fieldset',
1731
      '#tree' => true,
1732
      '#title' => t('Taxon profile feature block settings'),
1733 6657531f Andreas Kohlbecker
      '#collapsible' => TRUE,
1734
      '#collapsed' => FALSE,
1735 642b323b Andreas Kohlbecker
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
1736
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
1737
      The subforms have the following settings in common:<br />
1738
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
1739
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
1740
      <h6>Link to name used in source:</h6><div>Whether to show name is source information as link which will point to the according name page</div>
1741
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
1742
            <ol>
1743
            <li>If element is of the CDM type TextData and the text is not empty the source references will be
1744
                appended in brackets like "text (source references)". If the original source has name in source
1745
                information it will be appended to the citation string,
1746
                like : "(citation, as name in source; citation, as name in source)"</li>
1747
             <li>if the text of the TextData is empty, the original source citations are the only content
1748
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
1749
                prepended to the citation string like: "name in source: citation"</li>
1750
            </ol>
1751
            <strong>If disabled:</strong><br />
1752
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
1753
             citations are the only content, the resulting feature block content would only consist of footnotes.
1754
             In this case the display of the respective feature block is suppressed.</div>
1755
      </dl>
1756
      <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
1757 0686f307 Andreas Kohlbecker
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
1758
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
1759
        . '</em></div>
1760 642b323b Andreas Kohlbecker
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
1761
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
1762
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
1763
      <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>
1764
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
1765
           cdm_feature_block_element_tag_name()</div>',
1766 6657531f Andreas Kohlbecker
    );
1767
1768 642b323b Andreas Kohlbecker
1769
    $feature_list_layout_settings_disabled = FALSE;
1770 8c962983 Andreas Kohlbecker
1771
    // creating helper object to retrieve the default settings
1772
    $featureNode = new stdClass();
1773
    $featureNode->feature = new stdClass();
1774
    $featureNode->feature->uuid="DEFAULT";
1775
    $featureNode->feature->representation_L10n = "Default";
1776
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
1777
1778 642b323b Andreas Kohlbecker
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
1779 6657531f Andreas Kohlbecker
1780
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
1781
1782 642b323b Andreas Kohlbecker
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
1783
        $subform_id = $featureNode->feature->uuid;
1784
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
1785 6657531f Andreas Kohlbecker
1786 642b323b Andreas Kohlbecker
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
1787
1788
        $form_feature_block_layout[$subform_id] = array(
1789
          '#type' => 'fieldset',
1790 6657531f Andreas Kohlbecker
          '#tree' => TRUE,
1791 642b323b Andreas Kohlbecker
          '#title' => $featureNode->feature->representation_L10n,
1792 6657531f Andreas Kohlbecker
          '#collapsible' => FALSE,
1793
          '#collapsed' => FALSE,
1794
        );
1795 8c962983 Andreas Kohlbecker
        if($featureNode->feature->uuid == "DEFAULT"){
1796
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
1797
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
1798
          references</em> and <em>names in source</em> is only possible in the defaults';
1799
        }
1800 6657531f Andreas Kohlbecker
1801 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['as_list'] = array(
1802
          '#type' => 'select',
1803
          '#title' => 'List type',
1804
          '#default_value' => $feature_block_setting['as_list'],
1805
          '#options' => array(
1806
            'div' => 'not as list',
1807
            'ul' => 'bullet list',
1808
            'ol' => 'numbered list',
1809
            'dl' => 'definition list'
1810
          ),
1811
        );
1812
1813 8c962983 Andreas Kohlbecker
        if($featureNode->feature->uuid == "DEFAULT"){
1814
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
1815
            '#type' => 'checkbox',
1816
            '#title' => t('Link to reference'),
1817
            '#default_value' => $feature_block_setting['link_to_reference'],
1818
          );
1819 642b323b Andreas Kohlbecker
1820 8c962983 Andreas Kohlbecker
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
1821
            '#type' => 'checkbox',
1822
            '#title' => 'Link to name used in source',
1823
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
1824
          );
1825
        }
1826 6657531f Andreas Kohlbecker
1827 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
1828
          '#type' => 'checkbox',
1829
          '#title' => 'Sources as content',
1830
          '#default_value' => $feature_block_setting['sources_as_content'],
1831 6657531f Andreas Kohlbecker
        );
1832
1833 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
1834
          '#type' => 'checkbox',
1835 8c962983 Andreas Kohlbecker
          '#title' => 'Put sources also as content to bibliography',
1836 642b323b Andreas Kohlbecker
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
1837 6657531f Andreas Kohlbecker
        );
1838
1839 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
1840
          '#type' => 'select',
1841
          '#title' => t('Sort elements'),
1842
          '#default_value' => $feature_block_setting['sort_elements'],
1843
          '#options' => array(
1844
            NO_SORT => 'No sorting',
1845
            SORT_ASC => 'Ascending',
1846
            SORT_DESC => 'Descending',
1847
            SORT_HIERARCHICAL => 'Hierachical'
1848
          ),
1849
          '#description' => 'NOT YET USED! only in preparation',
1850 6657531f Andreas Kohlbecker
        );
1851
1852 642b323b Andreas Kohlbecker
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
1853
          '#type' => 'select',
1854
          '#title' => t('Element tag'),
1855
          '#options' => array(
1856
            'span' => 'span',
1857
            'div' => 'div'
1858
          ),
1859
          '#default_value' => $feature_block_setting['element_tag'],
1860
        );
1861 6657531f Andreas Kohlbecker
      }
1862 642b323b Andreas Kohlbecker
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
1863 6657531f Andreas Kohlbecker
    }
1864
  }
1865
1866 642b323b Andreas Kohlbecker
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
1867
  $form['taxon_profile']['structured_description_featuretree'] = array(
1868
    '#type' => 'fieldset',
1869
    '#title' => t('Structured Description Feature Tree'),
1870
    '#collapsible' => TRUE,
1871
    '#collapsed' => FALSE,
1872
  );
1873
  $featureTrees = cdm_get_featureTrees_as_options();
1874
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
1875
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
1876
    $profile_feature_tree_uuid = NULL;
1877
  }
1878
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
1879
    '#type' => 'radios',
1880
    '#title' => t('Natural language representation of structured descriptions') . ':',
1881
    '#default_value' => $profile_feature_tree_uuid,
1882
    '#options' => $featureTrees['options'],
1883
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
1884
    '#options_suffixes' => $featureTrees['treeRepresentations'],
1885
    '#description' => t('Taxon descriptions can be stored in a highly structured
1886
      form. The feature tree selected here will be used to generate textual
1887
      representation in natural language.'
1888
    ),
1889
  );
1890
1891
1892
1893 6657531f Andreas Kohlbecker
  // ---- DISTRIBUTION LAYOUT ---- //
1894
  $form['taxon_profile']['distribution_layout'] = array(
1895
    '#title' => t('Distribution'),
1896
    '#collapsible' => TRUE,
1897
    '#collapsed' => FALSE,
1898
    '#type' => 'fieldset',
1899
    '#description' => t('Select if you want to sort or not the distribution text
1900
      located below the distribution map.'),
1901
  );
1902
1903
  $form['taxon_profile']['distribution_layout']['distribution_sort'] = array(
1904
    '#type' => 'radios',
1905
    '#title' => t('Sort') . ':',
1906
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1907
    '#options' => array(
1908
      'NO_SORT' => t('Standard (No sort)'),
1909
      'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1910
    ),
1911
  );
1912
1913
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
1914
    '#type' => 'checkbox',
1915
    '#title' => t('Show TextData elements on top of the map'),
1916
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
1917
    '#description' => t('Check this if you want to appear all <code>TextData</code>
1918
      elements on top of the map. Otherwise all <code>TextData</code>
1919
      distribution elements will be listed below the other area elements.
1920
      This option is useful if you need to have descriptive texts for each
1921
      distribution map.'),
1922
  );
1923
1924 c6ee8193 Andreas Kohlbecker
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
1925
      '#type' => 'textarea',
1926
      '#title' => t('Custom status colors'),
1927
      '#element_validate' => array('form_element_validate_json'),
1928
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
1929
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
1930
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
1931 eb961cb9 Andreas Kohlbecker
          reference list of the idInVocabulary values of absence and presence terms:
1932 c6ee8193 Andreas Kohlbecker
<pre>
1933 eb961cb9 Andreas Kohlbecker
Presence Term
1934
p	present
1935
pd	present: doubtfully present
1936
n	native
1937
nq	native: presence questionable
1938
nd	native: doubtfully native
1939
c	cultivated
1940
i	introduced
1941
iq	introduced: presence questionable
1942
id	introduced: doubtfully introduced (perhaps cultivated only)
1943
ip	introduced: uncertain degree of naturalisation
1944
ia	introduced: adventitious (casual)
1945
in	introduced: naturalized
1946
ic	introduced: cultivated
1947
e	endemic for the relevant area
1948
na	naturalised
1949
iv	invasive
1950
1951
AbsenceTerm
1952
a	absent
1953
f	reported in error
1954
nf	native: reported in error
1955
if	introduced: reported in error
1956
cf	cultivated: reported in error
1957
ne	native: formerly native
1958
ie	introduced: formerly introduced
1959
1960 c6ee8193 Andreas Kohlbecker
</pre>'),
1961
  );
1962
1963 6657531f Andreas Kohlbecker
1964
  /* ====== SYNONYMY ====== */
1965
  $form['taxon_synonymy'] = array(
1966
    '#type' => 'fieldset',
1967
    '#title' => t('Taxon synonymy (tab)'),
1968
    '#collapsible' => TRUE,
1969
    '#collapsed' => TRUE,
1970
    '#description' => t('This section covers the settings related to the taxon
1971 501347df Andreas Kohlbecker
      <strong>synonymy</strong> tab.'),
1972 6657531f Andreas Kohlbecker
  );
1973
1974
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
1975
    '#type' => 'checkbox',
1976
    '#title' => t('Show accepted taxon on top of the synonymy'),
1977
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
1978
    '#description' => t('If checked, the first homotypic taxon is a repetition
1979
      of the accepted taxon most likely with the full nomenclatural reference
1980
      (depending on the currently chosen theme).'),
1981
  );
1982
1983
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
1984
    '#type' => 'checkbox',
1985
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
1986
      coming from a synonym link.'),
1987
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
1988
    '#description' => t('Check this if after doing a search and clicking on a
1989
      synonym you want to see the "accept of" text for the accepted synonym.'),
1990
  );
1991
1992 24058570 Andreas Kohlbecker
  /* === currently unused ===
1993 6657531f Andreas Kohlbecker
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
1994 5014bf09 Andreas Kohlbecker
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
1995 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
1996
    '#title' => t('Display name relationships') . ':',
1997
    '#default_value' => variable_get('name_relationships_to_show', 0),
1998
    '#options' => $nameRelationshipTypeOptions,
1999
    '#description' => t('Select the name relationships you want to show for the
2000
      accepted taxa.'),
2001
  );
2002 24058570 Andreas Kohlbecker
 */
2003 6657531f Andreas Kohlbecker
2004 5014bf09 Andreas Kohlbecker
  $form['taxon_synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2005 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
2006
    '#title' => t('Show taxon relations ships of accepted taxon'),
2007
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2008
    '#description' => t('If this option is enabled the synonymy will show the
2009
      below selected taxon relationships of accepted taxa.'),
2010
  );
2011
2012
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2013 5014bf09 Andreas Kohlbecker
  $form['taxon_synonymy'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2014 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes',
2015
    '#title' => t('Taxon relationship types') . ':',
2016
    '#description' => t('Only taxon relationships of the selected type will be
2017
      displayed'),
2018
    '#options' => $taxonRelationshipTypeOptions,
2019
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2020
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2021
  );
2022
2023
  // ====== SPECIMENS ====== //
2024
  $form['taxon_specimens'] = array(
2025
    '#type' => 'fieldset',
2026
    '#title' => t('Taxon specimens (tab)'),
2027
    '#collapsible' => TRUE,
2028
    '#collapsed' => TRUE,
2029
    '#description' => t('This section covers the settings related to the taxon
2030
      <strong>specimens</strong> tab.'),
2031
  );
2032
2033 1ce9afb7 Patric Plitzner
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2034
        '#type' => 'checkbox',
2035
        '#title' => t('Show specimen derivates in a compressed table'),
2036
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2037
        '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2038 4ee7a509 Patric Plitzner
        a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2039
    );
2040
    
2041
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2042
        '#type' => 'checkbox',
2043
        '#title' => t('Show "Determined as" in specimen table.'),
2044
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS),
2045
        '#description' => t('Note: only the current determination will be shown.'),
2046 1ce9afb7 Patric Plitzner
    );
2047
2048 854e1d99 Andreas Kohlbecker
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2049 642b323b Andreas Kohlbecker
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2050
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2051
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2052 f19f47fa Andreas Kohlbecker
  }
2053
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2054
      '#type' => 'radios',
2055
      '#title' => t('Specimen description feature tree') . ':',
2056 642b323b Andreas Kohlbecker
      '#default_value' => $profile_feature_tree_uuid,
2057 f19f47fa Andreas Kohlbecker
      '#options' =>  $featureTrees['options'],
2058 3f485c6d Andreas Kohlbecker
      '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2059 f19f47fa Andreas Kohlbecker
      '#options_suffixes' => $featureTrees['treeRepresentations'],
2060
      '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2061
      ),
2062 bfb2b81a Andreas Kohlbecker
  );
2063
2064 6657531f Andreas Kohlbecker
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2065
  $form_title = t('Specimen media');
2066
  $form_description = t('Specimens may have media which is displayed at the
2067
     Specimen tab/section as a gallery. It is possible to configure the
2068
     thumbnails gallery here, however for configuring how a single media should
2069
     be displayed please go to !url.</p>',
2070
     array(
2071
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2072
     ));
2073
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2074
2075
  // --- MEDIA GALLERY ---- //
2076
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2077
  $form_title = 'Media gallery (tab)';
2078
  $form_description = '<p>This section covers the settings related to the taxon <strong>media</strong> tab.
2079
   Taxa may have media (usually images) and they are as thumbnails displayed. It is possible to configure
2080
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2081
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2082
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2083
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2084
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2085
2086
  // Comment @WA: D7 form api does not support reset buttons,
2087
  // so to mimic the D5 reset button we add one like this.
2088
  $form['actions']['reset'] = array(
2089
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2090
    '#weight' => 1000,
2091
  );
2092
  return system_settings_form($form);
2093
}
2094
2095
/**
2096
 * @todo document this function.
2097
 */
2098
function cdm_settings_layout_search() {
2099
2100
  $form = array();
2101
2102 c5ed6357 Andreas Kohlbecker
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2103
2104 6657531f Andreas Kohlbecker
  $form['search_settings'] = array(
2105
    '#type' => 'fieldset',
2106
    '#title' => t('Taxa Search'),
2107 61b6ee11 Andreas Kohlbecker
    '#collapsible' => FALSE,
2108
    '#collapsed' => FALSE,
2109 6657531f Andreas Kohlbecker
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2110
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2111
         where they can write the text to be searched. You can find Drupal block configuration
2112
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2113
  );
2114
2115 f19f47fa Andreas Kohlbecker
  $form['search_settings']['simple_search_ignore_classification'] = array(
2116
      '#type' => 'checkbox',
2117
      '#title' => t('Ignore the chosen classification in simple search'),
2118
      '#default_value' => variable_get('simple_search_ignore_classification', TRUE),
2119 61b6ee11 Andreas Kohlbecker
      '#description' => t('The simple search, which can be executed via the search block,
2120
          will by default search on all classifications. Remove the tick if you want your
2121
          portal to search on the classification selected in the classification browser
2122 f19f47fa Andreas Kohlbecker
          selector.'),
2123 61b6ee11 Andreas Kohlbecker
  );
2124
2125 2d0d855a Andreas Kohlbecker
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2126
    '#type' => 'checkbox',
2127
    '#title' => t('Run simple search with free-text search backend.'),
2128
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, FALSE),
2129
    '#description' => t('The simple search uses by default another search
2130
      backend as the advances search. By checking this option the simple search can be
2131
      configured to also use the free-text search backend.'),
2132
  );
2133
2134 6657531f Andreas Kohlbecker
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2135
    '#type' => 'textfield',
2136
    '#title' => t('Results per page') . ':',
2137
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2138
    '#description' => t('Number of results to display per page.'),
2139
  );
2140
2141 6280e639 Andreas Kohlbecker
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2142
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2143
      '#type' => 'checkboxes',
2144
      '#title' => 'Search mode',
2145
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2146
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2147
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2148
          defaults set here.',
2149
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2150
      '#default_value' => $search_mode_default
2151
      );
2152 6657531f Andreas Kohlbecker
2153
  // --- SEARCH TAXA GALLERY ---- //
2154
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2155
  $collapsed = FALSE;
2156
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2157
  $form_title = 'Taxa Search thumbnails';
2158
  $form_description = 'Search results may show thumbnails. ';
2159
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2160
2161
  // Comment @WA: D7 form api does not support reset buttons,
2162
  // so to mimic the D5 reset button we add one like this.
2163
  $form['actions']['reset'] = array(
2164
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2165
    '#weight' => 1000,
2166
  );
2167
  return system_settings_form($form);
2168
}
2169
2170
/**
2171
 * @todo document this function.
2172
 */
2173
function cdm_settings_layout_media() {
2174
2175
  $form = array();
2176
2177
  $form['media_settings'] = array(
2178
    '#type' => 'fieldset',
2179 a950f2f9 Andreas Kohlbecker
    '#title' => t('Media settings'),
2180
    '#collapsible' => FALSE,
2181 6657531f Andreas Kohlbecker
    '#collapsed' => FALSE,
2182 ccde8251 Andreas Kohlbecker
    '#description' => 'This section covers layout settings for media pages.'
2183
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2184 6657531f Andreas Kohlbecker
  );
2185
2186
  $form['media_settings']['image_gallery_viewer'] = array(
2187
    '#type' => 'select',
2188
    '#title' => t('Image viewer') . ':',
2189
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2190
    '#options' => array(
2191
      'default' => t('Standard image viewer'),
2192
      'fsi' => t('FSI viewer (requires FSI server!)'),
2193
    ),
2194
  );
2195
2196
  // --- MEDIA GALLERY ---- //
2197
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2198
  $form_title = 'Standard viewer';
2199
  $form_description = '<p>Configure the standard image viewer.</p><p><strong>Note:</strong> the image viewer should selected otherwise settings are not taking into account.</p>';
2200
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2201
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2202
2203
  // @WA: D7 form api does not support reset buttons,
2204
  // so to mimic the D5 reset button we add one like this.
2205
  $form['actions']['reset'] = array(
2206
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2207
    '#weight' => 1000,
2208
  );
2209
  return system_settings_form($form);
2210
}
2211
2212
/**
2213
 * GEOSERVICE and Map settings.
2214
 */
2215 1d39ec64 w.addink
function cdm_settings_geo($form, &$form_state) {
2216 6657531f Andreas Kohlbecker
2217 cc3c9807 Andreas Kohlbecker
  $current_geoserver_settings = get_edit_map_service_settings();
2218
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2219 d5661a4c Andreas Kohlbecker
  // The default layer must always be enabled
2220
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2221
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2222 cc3c9807 Andreas Kohlbecker
2223 6657531f Andreas Kohlbecker
  $form = array();
2224
2225 cc3c9807 Andreas Kohlbecker
  $dummy_distribution_query = NULL;
2226
  if($map_distribution['map_type'] != 1){
2227
    // we need to apply a dummy query since the map serice requires for image maps
2228
    // at least as and ad to be defined
2229
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2230
  }
2231 d2fd2a4c Andreas Kohlbecker
  $form['map_preview'] = array(
2232
      '#type' => 'fieldset',
2233
      '#tree' => FALSE,
2234
      '#title' => t('Map preview'),
2235
      '#collapsible' => FALSE,
2236 cc3c9807 Andreas Kohlbecker
      '#description' => 'The preview of the map'
2237 2bbc28c8 Andreas Kohlbecker
       . ($dummy_distribution_query != null ?
2238
           ' may not be accurate in case if image maps, please check the map display in the taxon pages.':
2239 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.')
2240 d2fd2a4c Andreas Kohlbecker
  );
2241 cc3c9807 Andreas Kohlbecker
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL,
2242 d2fd2a4c Andreas Kohlbecker
      array(
2243
          'move' => "this.cdmOpenlayersMap.printInfo",
2244
          '#execute' => "this.cdmOpenlayersMap.printInfo"
2245
      )
2246
  );
2247
2248 cc3c9807 Andreas Kohlbecker
2249 6657531f Andreas Kohlbecker
  /*
2250 d2fd2a4c Andreas Kohlbecker
   * GEO SERVER
2251
   */
2252 ba706bf0 Andreas Kohlbecker
  $form['edit_map_server'] = array(
2253 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2254 ba706bf0 Andreas Kohlbecker
    '#tree' => true,
2255
    '#title' => t('EDIT map service'),
2256 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
2257
    '#collapsed' => TRUE,
2258
    '#description' => t('Configuration and selection of your geo server.
2259
      The Geo Server is responsible for generating the maps.'),
2260
  );
2261
2262 f19f47fa Andreas Kohlbecker
  $form['edit_map_server']['base_uri'] = array(
2263 6657531f Andreas Kohlbecker
    '#type' => 'select',
2264 ba706bf0 Andreas Kohlbecker
    '#title' => t('EDIT map service') . ':',
2265
    '#default_value' => $current_geoserver_settings['base_uri'],
2266
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2267
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2268 6657531f Andreas Kohlbecker
  );
2269 f19f47fa Andreas Kohlbecker
  $form['edit_map_server']['version'] = array(
2270
      '#type' => 'select',
2271
      '#title' => t('Version') . ':',
2272
      '#default_value' => $current_geoserver_settings['version'],
2273
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2274
      '#description' => t('The version of the EDIT map services'),
2275 6657531f Andreas Kohlbecker
  );
2276
2277 cc3c9807 Andreas Kohlbecker
  $localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
2278
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
2279
  $form['gmap_api_key'] = array(
2280
      '#type' => 'textfield',
2281
      '#title' => t('Google maps API key') . ':',
2282
      '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
2283
      '#description' => t('If you want to use the Google Maps Layer, a key is
2284
      needed. If you need a key, visit
2285
      <a href="http://code.google.com/intl/en/apis/maps/signup.html">google maps api key</a>.
2286
      <br/><strong>Note:</strong> The following key: <code>!localhostkey</code>
2287
      is the default key for the localhost (127.0.0.1).',
2288
      array('!localhostkey' => $localhostkey)),
2289
  );
2290
2291
2292 6657531f Andreas Kohlbecker
  /*
2293 d2fd2a4c Andreas Kohlbecker
   * MAP SETTINGS
2294
   */
2295 cc3c9807 Andreas Kohlbecker
2296
  $form[CDM_MAP_DISTRIBUTION] = array(
2297 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2298 cc3c9807 Andreas Kohlbecker
    '#tree' => TRUE,
2299 6657531f Andreas Kohlbecker
    '#title' => t('Maps settings'),
2300
    '#collapsible' => TRUE,
2301
    '#collapsed' => TRUE,
2302
    '#description' => t('General configuration for all map types.'),
2303
  );
2304
2305 cc3c9807 Andreas Kohlbecker
  /*
2306
   * settings for the distribution map are used also for specimens map!!!!
2307
   */
2308
2309
  $form[CDM_MAP_DISTRIBUTION]['width'] = array(
2310 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2311 cc3c9807 Andreas Kohlbecker
    '#title' => 'Width',
2312
    '#default_value' => $map_distribution['width'],
2313
    '#maxlength' => 4,
2314
    '#size' => 4,
2315
    '#description' => 'Width of the map. To allow OSM baselayers to zoom out to the full extend of the world the map width must be
2316 d2fd2a4c Andreas Kohlbecker
      a multiple of 256px since the osm tiles from tile.openstreetmap.org have a size of 256px x 256px and frational zoom
2317
      levels are not possible in this case.',
2318 6657531f Andreas Kohlbecker
  );
2319 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['height'] = array(
2320
      '#type' => 'textfield',
2321
      '#title' => 'Height',
2322
      '#default_value' => $map_distribution['height'],
2323
      '#maxlength' => 4,
2324
      '#size' => 4,
2325
      '#description' => 'Height of the map. Depending on the chosen base layer you may want to choose the height equal
2326
      to the width or half of the width. Any other aspect ratio is also possible if desired.',
2327
  );
2328 6657531f Andreas Kohlbecker
2329 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2330 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2331 cc3c9807 Andreas Kohlbecker
    '#title' => 'Bounding box',
2332
    '#default_value' => $map_distribution['bbox'],
2333 14339c2a Andreas Kohlbecker
    '#description' => t('The bounding box (left, bottom, right, top) defines the area to be initially displayed in maps.
2334 6657531f Andreas Kohlbecker
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2335 2bbc28c8 Andreas Kohlbecker
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2336
      <strong>TIP: </strong>You can use the map preview above to choose a bbox from the map. Maybe you need to change the map type to OpeLayers.
2337 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
2338 2bbc28c8 Andreas Kohlbecker
      below the map from where you can copy the bbox string.</p>'),
2339 6657531f Andreas Kohlbecker
  );
2340
2341 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2342 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
2343 cc3c9807 Andreas Kohlbecker
    '#title' => 'Display area labels',
2344
    '#default_value' => $map_distribution['show_labels'],
2345
    '#description' => t('The map will show name labels of the areas'),
2346 6657531f Andreas Kohlbecker
  );
2347
2348 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2349 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2350 cc3c9807 Andreas Kohlbecker
    '#title' => 'Map caption',
2351
    '#default_value' => $map_distribution['caption'],
2352
    '#description' => t('The caption will be shown below the map.'),
2353 6657531f Andreas Kohlbecker
  );
2354
2355 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2356 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2357 cc3c9807 Andreas Kohlbecker
    '#title' => 'Distribution layer opacity',
2358
    '#default_value' => $map_distribution['distribution_opacity'],
2359 6657531f Andreas Kohlbecker
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions (the countries or regions) will
2360
                           fully visible, while a value near to 0.0 will be not much visible.'),
2361
  );
2362
2363 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2364 6657531f Andreas Kohlbecker
    '#type' => 'radios',
2365 cc3c9807 Andreas Kohlbecker
    '#title' => 'Map types',
2366 6657531f Andreas Kohlbecker
    '#options' => array(
2367 cc3c9807 Andreas Kohlbecker
      1 => "OpenLayers dynamic map viewer",
2368 6657531f Andreas Kohlbecker
      0 => "Plain image",
2369
    ),
2370 cc3c9807 Andreas Kohlbecker
    '#default_value' => $map_distribution['map_type'],
2371
    '#description' => 'Two different map types are available :
2372
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2373
      which allows zooming and panning. If enabled you can configure the default layer
2374
      (background of your maps) below.</li>
2375
      <li><em>Plain image</em>: The map will be static non interactive
2376
      image.</li></ul>',
2377 6657531f Andreas Kohlbecker
  );
2378 cc3c9807 Andreas Kohlbecker
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2379 6657531f Andreas Kohlbecker
2380
2381
  // --- Plain Image Settings --- //
2382 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2383 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2384 cc3c9807 Andreas Kohlbecker
    '#title' => 'Plain image map settings',
2385
    '#tree' => TRUE,
2386 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
2387 cc3c9807 Andreas Kohlbecker
    '#collapsed' => $open_layers_is_enabled,
2388
    '#description' => 'The settings in this section are still expertimental
2389
      and can only be used with the EDIT map service version 1.1 or above.',
2390 6657531f Andreas Kohlbecker
  );
2391 ba706bf0 Andreas Kohlbecker
  $edit_mapserver_version = get_edit_map_service_version_number();
2392 6657531f Andreas Kohlbecker
  if ($edit_mapserver_version < 1.1) {
2393 cc3c9807 Andreas Kohlbecker
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">' . t("The chosen EDIT map service version ($edit_mapserver_version) is too low, it must be at least 1.1") . '</div>'
2394
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2395 6657531f Andreas Kohlbecker
  }
2396
2397 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2398 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2399 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background layer',
2400
    '#default_value' => $map_distribution['image_map']['base_layer'],
2401 6657531f Andreas Kohlbecker
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2402 cc3c9807 Andreas Kohlbecker
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2403
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2404 6657531f Andreas Kohlbecker
    )),
2405
  );
2406
2407 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2408 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2409 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background color',
2410
    '#default_value' => $map_distribution['image_map']['bg_color'],
2411 6657531f Andreas Kohlbecker
  );
2412
2413 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2414 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2415 cc3c9807 Andreas Kohlbecker
    '#title' => 'Background layer style',
2416 6657531f Andreas Kohlbecker
     // Only line color by now.
2417 cc3c9807 Andreas Kohlbecker
    '#default_value' => $map_distribution['image_map']['layer_style'],
2418
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2419 6657531f Andreas Kohlbecker
  );
2420
2421 4bef194f Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2422
      '#type' => 'textfield',
2423
      '#title' => 'Projection',
2424
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2425
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2426
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2427
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2428
  );
2429
2430 6657531f Andreas Kohlbecker
2431
  // --- OpenLayers Settings --- //
2432 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2433 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2434 cc3c9807 Andreas Kohlbecker
    '#title' => 'OpenLayers settings',
2435
    '#tree' => TRUE,
2436 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
2437 cc3c9807 Andreas Kohlbecker
    '#collapsed' => !$open_layers_is_enabled,
2438 6657531f Andreas Kohlbecker
    '#description' => '',
2439
  );
2440
2441 2bbc28c8 Andreas Kohlbecker
2442
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2443
      '#type' => 'checkbox',
2444
      '#title' => 'Display outside max extent',
2445
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2446
      '#description' => t('Allows the map to display parts of the layers which are outside
2447
         the max extent if the aspect ratio of the map and of the baselayer
2448
         are not equal.'),
2449
  );
2450
2451 570f0e73 Andreas Kohlbecker
2452 2bbc28c8 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2453
      '#type' => 'checkbox',
2454
      '#title' => 'Show Layer Switcher',
2455
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2456
      '#description' => 'The Layer Switcher control displays a table of contents
2457
      for the map.  This allows the user interface to switch between
2458
      base layers and to show or hide overlays.  By default the switcher is
2459
      shown minimized on the right edge of the map, the user may expand it
2460
      by clicking on the handle.',
2461
  );
2462
2463 cc3c9807 Andreas Kohlbecker
  if (!$open_layers_is_enabled) {
2464
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2465
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2466
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2467 6657531f Andreas Kohlbecker
  }
2468
2469
  $baselayer_options = array(
2470
    /*
2471
   NOTICE: must correspond to the layers defined in
2472
   js/openlayers_,ap.js#getLayersByName()
2473
   */
2474 1d39ec64 w.addink
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server)", // EPSG:4326: EPSG:900913
2475
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)", // EPSG:4326, EPSG:900913
2476 6657531f Andreas Kohlbecker
    // all others EPSG:900913
2477
    // 'edit-vmap0_world_basic' => 'EDIT Vmap0',
2478
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2479
    'mapnik' => 'OpenStreetMap',
2480 2bbc28c8 Andreas Kohlbecker
    'mapquest_open' => "MapQuest",
2481
    'mapquest_sat' => "MapQuest Sattelite",
2482
//     'osmarender' => 'OpenStreetMap (Tiles@home)',
2483 6657531f Andreas Kohlbecker
    'gmap' => 'Google Streets',
2484
    'gsat' => 'Google Satellite',
2485
    'ghyb' => 'Google Hybrid',
2486 cc3c9807 Andreas Kohlbecker
//     'veroad' => 'Virtual Earth Roads',
2487
//     'veaer' => 'Virtual Earth Aerial',
2488
//     'vehyb' => 'Virtual Earth Hybrid',
2489 6657531f Andreas Kohlbecker
    // 'yahoo' => 'Yahoo Street',
2490
    // 'yahoosat' => 'Yahoo Satellite',
2491
    // 'yahoohyb' => 'Yahoo Hybrid',
2492 2bbc28c8 Andreas Kohlbecker
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
2493 6657531f Andreas Kohlbecker
  );
2494
2495 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
2496 6657531f Andreas Kohlbecker
    '#type' => 'checkboxes_preferred',
2497 cc3c9807 Andreas Kohlbecker
    '#title' => 'Base Layers',
2498 6657531f Andreas Kohlbecker
    '#options' => $baselayer_options,
2499 cc3c9807 Andreas Kohlbecker
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
2500
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
2501 6657531f Andreas Kohlbecker
  );
2502
2503 2bbc28c8 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = array(
2504
      '#type' => 'fieldset',
2505
      '#title' => 'Custom WMS base layer',
2506
      '#tree' => TRUE,
2507
      '#collapsible' => FALSE,
2508
      '#collapsed' => FALSE,
2509
      '#description' => 'Here you an define a custom wms layer as additional base layer.',
2510
  );
2511
2512
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['name'] = array(
2513
      '#type' => 'textfield',
2514
      '#title' => 'Layer name',
2515
      // Only line color by now.
2516
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['name'],
2517
      '#description' => 'A arbitrary name for the layer.',
2518
  );
2519
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['url'] = array(
2520
      '#type' => 'textfield',
2521
      '#title' => 'WMS url',
2522
      // Only line color by now.
2523
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['url'],
2524
      '#description' => 'Base url for the WMS (e.g.  http://wms.jpl.nasa.gov/wms.cgi)'
2525
  );
2526
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['params'] = array(
2527
      '#type' => 'textarea',
2528
      '#title' => 'WMS parameters',
2529
      '#element_validate' => array('form_element_validate_json'),
2530
      // Only line color by now.
2531
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['params'],
2532 570f0e73 Andreas Kohlbecker
      '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values, entered in valid JSON. For example:
2533
<pre> {
2534
  "Layers": "topp:em_tiny_jan2003",
2535
  "Format": "image/png",
2536
  "BGCOLOR": "0xe0faff"
2537
}
2538
</pre>'
2539 2bbc28c8 Andreas Kohlbecker
  );
2540
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['projection'] = array(
2541
      '#type' => 'textfield',
2542
      '#title' => 'Projection',
2543
      // Only line color by now.
2544
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['projection'],
2545
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
2546
  );
2547 e3026d72 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['proj4js_def'] = array(
2548
      '#type' => 'textfield',
2549 14339c2a Andreas Kohlbecker
      '#maxlength' => 256,
2550 e3026d72 Andreas Kohlbecker
      '#title' => 'proj4js definition',
2551
      // Only line color by now.
2552
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['proj4js_def'],
2553
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
2554
            The definitions for
2555
            EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
2556
            EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
2557
            are already predefined and must be added here again.  If your dont know the defintion of your desired projection,
2558
            go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
2559
            choose to display the proj4js definition string.
2560 7f71136d Andreas Kohlbecker
            <h5>Quick Reference on the commion proj4js definition parameters:</h5>
2561
            <pre>
2562
+a         Semimajor radius of the ellipsoid axis
2563
+alpha     ? Used with Oblique Mercator and possibly a few others
2564
+axis      Axis orientation (new in 4.8.0)
2565
+b         Semiminor radius of the ellipsoid axis
2566
+datum     Datum name (see `proj -ld`)
2567
+ellps     Ellipsoid name (see `proj -le`)
2568
+k         Scaling factor (old name)
2569
+k_0       Scaling factor (new name)
2570
+lat_0     Latitude of origin
2571
+lat_1     Latitude of first standard parallel
2572
+lat_2     Latitude of second standard parallel
2573
+lat_ts    Latitude of true scale
2574
+lon_0     Central meridian
2575
+lonc      ? Longitude used with Oblique Mercator and possibly a few others
2576
+lon_wrap  Center longitude to use for wrapping (see below)
2577
+nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
2578
+no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
2579
+over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
2580
+pm        Alternate prime meridian (typically a city name, see below)
2581
+proj      Projection name (see `proj -l`)
2582
+south     Denotes southern hemisphere UTM zone
2583
+to_meter  Multiplier to convert map units to 1.0m
2584
+towgs84   3 or 7 term datum transform parameters (see below)
2585
+units     meters, US survey feet, etc.
2586
+vto_meter vertical conversion to meters.
2587
+vunits    vertical units.
2588
+x_0       False easting
2589
+y_0       False northing
2590
+zone      UTM zone
2591
            </pre>
2592
          For the full reference please refer to <a href="http://trac.osgeo.org/proj/wiki/GenParms">http://trac.osgeo.org/proj/wiki/GenParms</a>.'
2593 e3026d72 Andreas Kohlbecker
  );
2594 2bbc28c8 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['max_extent'] = array(
2595
      '#type' => 'textfield',
2596
      '#title' => 'Maximum extent',
2597
      // Only line color by now.
2598
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['max_extent'],
2599 14339c2a Andreas Kohlbecker
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
2600 2bbc28c8 Andreas Kohlbecker
  );
2601
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer']['units'] = array(
2602
      '#type' => 'textfield',
2603
      '#title' => 'Units',
2604
      '#default_value' => $map_distribution['openlayers']['custom_wms_base_layer']['units'],
2605
      '#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.'
2606 6657531f Andreas Kohlbecker
  );
2607
2608 cc3c9807 Andreas Kohlbecker
  /*
2609
   * Map Legend
2610
   */
2611
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
2612 6657531f Andreas Kohlbecker
    '#type' => 'fieldset',
2613 cc3c9807 Andreas Kohlbecker
    '#title' => 'Map legend',
2614
    '#tree' => TRUE,
2615 6657531f Andreas Kohlbecker
    '#collapsible' => TRUE,
2616
    '#collapsed' => TRUE,
2617 cc3c9807 Andreas Kohlbecker
    '#description' => 'Configure the maps legend.',
2618 6657531f Andreas Kohlbecker
  );
2619
2620 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
2621 6657531f Andreas Kohlbecker
    '#type' => 'checkbox',
2622 cc3c9807 Andreas Kohlbecker
    '#title' => 'Display a map legend',
2623
    '#default_value' => $map_distribution['legend']['show'],
2624
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
2625 6657531f Andreas Kohlbecker
  );
2626
2627 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
2628 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2629 cc3c9807 Andreas Kohlbecker
    '#title' => 'Legend opacity',
2630
    '#default_value' => $map_distribution['legend']['opacity'],
2631
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
2632
                         to 0.0 will be not much visible.',
2633 6657531f Andreas Kohlbecker
  );
2634
2635 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
2636 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2637 cc3c9807 Andreas Kohlbecker
    '#title' => 'Font size',
2638
    '#default_value' => $map_distribution['legend']['font_size'],
2639
    '#description' => 'Font size in pixels.',
2640 6657531f Andreas Kohlbecker
  );
2641
2642
  $fontStyles = array(
2643
    0 => "plane",
2644
    1 => "italic",
2645
  );
2646 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
2647 6657531f Andreas Kohlbecker
    '#type' => 'select',
2648 cc3c9807 Andreas Kohlbecker
    '#title' => 'Available font styles',
2649
    '#default_value' => $map_distribution['legend']['font_style'],
2650 6657531f Andreas Kohlbecker
    '#options' => $fontStyles,
2651 cc3c9807 Andreas Kohlbecker
    '#description' => 'Select a font style for the map legend.',
2652 6657531f Andreas Kohlbecker
  );
2653
2654 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
2655 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2656 cc3c9807 Andreas Kohlbecker
    '#title' => 'Icon width',
2657
    '#default_value' => $map_distribution['legend']['icon_width'],
2658
    '#description' => 'Legend icon width in pixels.',
2659 6657531f Andreas Kohlbecker
  );
2660 cc3c9807 Andreas Kohlbecker
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
2661 6657531f Andreas Kohlbecker
    '#type' => 'textfield',
2662 cc3c9807 Andreas Kohlbecker
    '#title' => 'Icon height',
2663
    '#default_value' => $map_distribution['legend']['icon_height'],
2664
    '#description' => 'Legend icon height in pixels.',
2665 6657531f Andreas Kohlbecker
  );
2666
2667
  // @WA: D7 form api does not support reset buttons,
2668
  // so to mimic the D5 reset button we add one like this.
2669
  $form['actions']['reset'] = array(
2670
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2671
    '#weight' => 1000,
2672
  );
2673 1d39ec64 w.addink
2674 6657531f Andreas Kohlbecker
  return system_settings_form($form);
2675
}
2676
2677
/**
2678
 * @todo document this function.
2679
 */
2680
function cdm_settings_cache() {
2681
2682
  $form = array();
2683
2684
  $form['cache_settings'] = array(
2685
    '#type' => 'fieldset',
2686
    '#title' => t('Cache Settings'),
2687
    '#collapsible' => FALSE,
2688
    '#collapsed' => FALSE,
2689
    '#description' => t('<p>When caching is enabled all single taxon sites are
2690
      stored in an internal drupal cache doing the portal response of taxa pages
2691
      faster. This is possible because the sites are loaded from the cache and
2692
      are not created from scratch.</p>'),
2693
  );
2694
2695
  $form['cache_settings']['cdm_webservice_cache'] = array(
2696
    '#type' => 'checkbox',
2697
    '#title' => t('<strong>Enable caching</strong>'),
2698
    '#options' => cdm_help_general_cache(),
2699
    '#default_value' => variable_get('cdm_webservice_cache', 1),
2700
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
2701
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
2702
       application the changes will be not visible till the cache is erased.
2703
       Therefore developers should deactived this feature when they are working
2704
       on the CDM Dataportal Module.</p>'),
2705
  );
2706
2707
  $form['cache_settings']['cdm_run_cache'] = array(
2708
    '#markup' => cdm_view_cache_site(),
2709
  );
2710
2711
  // @WA: D7 form api does not support reset buttons,
2712
  // so to mimic the D5 reset button we add one like this.
2713
  $form['actions']['reset'] = array(
2714
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2715
    '#weight' => 1000,
2716
  );
2717
  return system_settings_form($form);
2718
}
2719
2720
/**
2721
 * Walk and cache all taxon pages.
2722
 */
2723
function cdm_view_cache_site() {
2724
2725
  $out = '';
2726
2727
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
2728
2729
  $request_params = array();
2730 7d828d59 Andreas Kohlbecker
  $request_params['class'] = "Taxon";
2731 6657531f Andreas Kohlbecker
2732 7d828d59 Andreas Kohlbecker
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
2733
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
2734
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
2735 6657531f Andreas Kohlbecker
2736
  $out .= t('<p><strong>Cache all taxon pages</strong></p>');
2737
  $out .= '<p>When you launch the cache process the cache is filled and ready to be enabled.<br/>
2738
  Remember that when you load the taxa from the cache last changes on taxa will be not visible till you erase
2739
  the cache and fill it again.</p>';
2740
  $out .= '<p>Before  running the cache bot you have to empty the cache manually.</p>';
2741
2742
  $out .= '<div>' . t('This caching process may take long time and could cause heavy load on your server') . '</div>';
2743
  $out .= '<div id="progress"></div>';
2744
2745
  // Comment @WA: A form within a form is not valid html and not needed here.
2746
  // Also, it would be recommended just to include this part of the form in the
2747
  // rest of the form array in cdm_settings_cache().
2748
  // $out .= '<form id="cache_site">';
2749 0516e3d0 Andreas Kohlbecker
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
2750 7d828d59 Andreas Kohlbecker
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
2751 6657531f Andreas Kohlbecker
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
2752
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
2753
  // $out .= '</form>';
2754
  $out .= '</div>';
2755
  /*
2756
  foreach($taxonPager->records as $taxon){
2757
    cdm_dataportal_taxon_view($uuid);
2758
  }
2759
  */
2760
  return $out;
2761
}
2762
2763 7df1be04 Andreas Kohlbecker
2764
function cdm_settings_layout_taxon_submit($form, &$form_state){
2765 9c92cd84 Andreas Kohlbecker
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
2766
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
2767
    if(is_object($file)){
2768
      $file->status = FILE_STATUS_PERMANENT;
2769
      file_save($file);
2770
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
2771
    }
2772 7df1be04 Andreas Kohlbecker
  }
2773 d5403dc4 Andreas Kohlbecker
  // rebuild the menu if the show tabs setting has changed, otherwise the change will not have a consistent effect
2774
  if(variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs']){
2775
    // we first need to set the variable to persist the changes setting
2776
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
2777
    menu_rebuild();
2778
  }
2779 7df1be04 Andreas Kohlbecker
}
2780
2781 c5ed6357 Andreas Kohlbecker
function cdm_settings_layout_search_submit($form, &$form_state){
2782
  // the visibility of media thumbnails also affects the ui of the search results
2783
  // so reset the according session variable
2784
  //    1. in order to give the user immediate
2785
  //       feedback on potential setting changes
2786
  //    2. let refresh the default if it has changed
2787
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2788
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
2789
  }
2790
}
2791
2792 6657531f Andreas Kohlbecker
/**
2793 d1eb0a8c Andreas Kohlbecker
 * Form validation handler for cdm_settings_general
2794 6657531f Andreas Kohlbecker
 *
2795 22eb20d7 Andreas Kohlbecker
 * @param $form
2796
 * @param $form_state
2797 6657531f Andreas Kohlbecker
 */
2798 d1eb0a8c Andreas Kohlbecker
function cdm_settings_general_validate($form, &$form_state) {
2799 6657531f Andreas Kohlbecker
2800
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
2801
    $form_state['values']['cdm_webservice_url'] .= '/';
2802
  }
2803
2804 d1eb0a8c Andreas Kohlbecker
}
2805
2806 22eb20d7 Andreas Kohlbecker
/**
2807
 * Form submit handler for settings general.
2808
 *
2809
 * tasks performed:
2810
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2811
 *
2812
 * @param $form
2813
 * @param $form_state
2814
 */
2815
function cdm_settings_general_submit($form, &$form_state){
2816
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
2817
  unset($_SESSION['cdm']['taxonomictree_uuid']);
2818
}
2819
2820 d1eb0a8c Andreas Kohlbecker
/**
2821
 * Form validation handler for cdm_settings_cache
2822
 */
2823 847bb49e Andreas Kohlbecker
function cdm_settings_cache_validate($form, &$form_state) {
2824 6657531f Andreas Kohlbecker
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
2825
    cache_clear_all(NULL, 'cache_cdm_ws');
2826
    // Better clear secref_cache since I can not be sure if the cache has not
2827
    // be used during this response.
2828
    cdm_api_secref_cache_clear();
2829
  }
2830 d1eb0a8c Andreas Kohlbecker
2831 6657531f Andreas Kohlbecker
}
2832
2833
/**
2834 ba706bf0 Andreas Kohlbecker
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
2835
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
2836
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
2837
 *  - version: the version, e.g.: v1.1
2838
 *
2839
 * @return array
2840
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
2841 6657531f Andreas Kohlbecker
 */
2842 ba706bf0 Andreas Kohlbecker
function get_edit_map_service_settings() {
2843
2844
  $settings = variable_get('edit_map_server', array(
2845
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
2846
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
2847
      )
2848
  );
2849 6657531f Andreas Kohlbecker
2850 ba706bf0 Andreas Kohlbecker
  return $settings;
2851 6657531f Andreas Kohlbecker
}
2852
2853
/**
2854 ba706bf0 Andreas Kohlbecker
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2855
 *
2856
 * @return string
2857
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
2858
 */
2859
function get_edit_map_service_full_uri() {
2860
  $settings = get_edit_map_service_settings();
2861
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
2862
}
2863
2864
2865
/**
2866
 * Returns the version number of the currently selected edit mapserver as a float
2867 6657531f Andreas Kohlbecker
 *
2868
 * @return float
2869
 *   The version number of the currently selected edit mapserver as a float.
2870
 *   Returns 0 on error.
2871
 */
2872 ba706bf0 Andreas Kohlbecker
function get_edit_map_service_version_number() {
2873 6657531f Andreas Kohlbecker
2874 ba706bf0 Andreas Kohlbecker
  $pattern = '/v([\d\.]+).*$/';
2875 6657531f Andreas Kohlbecker
2876 ba706bf0 Andreas Kohlbecker
  $settings = get_edit_map_service_settings();
2877
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
2878 6657531f Andreas Kohlbecker
  if (isset($matches[1])) {
2879
    // Convert string to float.
2880
    $version = 1 + $matches[1][0] - 1;
2881
    return $version;
2882
  }
2883
  else {
2884
    // Report error.
2885 ba706bf0 Andreas Kohlbecker
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
2886
        array(
2887
          '!version' => $settings['version'],
2888
          'warning')
2889
        )
2890
      );
2891 6657531f Andreas Kohlbecker
    return 0;
2892
  }
2893
}
2894
2895 30f78c59 Andreas Kohlbecker
/**
2896 ba706bf0 Andreas Kohlbecker
 * Returns the array of selected items in a options array
2897 30f78c59 Andreas Kohlbecker
 *
2898
 * @param array $options
2899
 *   An options array as generated by a form element like checkoxes, select ...,
2900
 */
2901
function get_selection($options) {
2902
  $selection = array();
2903
  foreach ($options as $key=>$val) {
2904
    if (!empty($val)) {
2905
      $selection[] = $val;
2906
    }
2907
  }
2908
  return $selection;
2909
}
2910
2911 bfb2b81a Andreas Kohlbecker
2912 6657531f Andreas Kohlbecker
/**
2913
 * Implements hook_element_info().
2914
 *
2915 14feebe9 Andreas Kohlbecker
 * Allows modules to declare their own Form API element types and specify their default values.
2916
 *
2917
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
2918 6657531f Andreas Kohlbecker
 */
2919
function cdm_dataportal_element_info() {
2920
  $type['checkboxes_preferred'] = array(
2921
    '#input' => TRUE,
2922 14feebe9 Andreas Kohlbecker
    '#process' => array('checkboxes_preferred_expand'),
2923 6657531f Andreas Kohlbecker
    '#after_build' => array('checkboxes_preferred_after_build'),
2924
    '#theme' => array('checkboxes_preferred'),
2925
    // '#theme_wrapper' => array('form_element'),
2926
  );
2927
  return $type;
2928
}
2929
2930
/**
2931 14feebe9 Andreas Kohlbecker
 * #process callback function for the custom form element type 'checkbox_preferred'
2932
 *
2933
 *
2934 6657531f Andreas Kohlbecker
 */
2935 14feebe9 Andreas Kohlbecker
function checkboxes_preferred_expand($element, &$form_state, $form) {
2936
2937
  // First of all create checkboxes for each of the elements
2938 6657531f Andreas Kohlbecker
  $element = form_process_checkboxes($element);
2939
2940 cc3c9807 Andreas Kohlbecker
  // compose the element name
2941
  $parents = array();
2942
  array_deep_copy($element['#parents'], $parents);
2943
  $parents[count($parents) -1 ] .= '_preferred';
2944
  $element_name = $parents[0];
2945
  for ($i=1; $i < count($parents); $i++){
2946
    $element_name .= '[' . $parents[$i] . ']';
2947
  }
2948
2949 6657531f Andreas Kohlbecker
  $children = element_children($element);
2950
2951
  $element['table_start'] = array(
2952
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
2953
    '#weight' => -1,
2954
  );
2955
2956 14feebe9 Andreas Kohlbecker
  // prepare first part each of the table rows which contains the row label
2957 6657531f Andreas Kohlbecker
  $weight = 0;
2958
  foreach ($children as $key) {
2959
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
2960
    $element[$key]['#weight'] = $weight;
2961
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t($element['#options'][$key]) . '</td><td>';
2962
    $element[$key]['#suffix'] = '</td>';
2963
    unset($element[$key]['#title']);
2964
    $weight += 2;
2965
  }
2966
  $weight = 0;
2967
2968 14feebe9 Andreas Kohlbecker
  // add a radio button to each of the checkboxes, the
2969
  // check boxes have already been created at the beginning
2970
  // of this function
2971 6657531f Andreas Kohlbecker
  if (count($element['#options']) > 0) {
2972
    foreach ($element['#options'] as $key => $choice) {
2973
      if (!isset($element[$key . '_preferred'])) {
2974
        $element[$key . '_preferred'] = array(
2975
          '#type' => 'radio',
2976 cc3c9807 Andreas Kohlbecker
          '#name' => $element_name,
2977 6657531f Andreas Kohlbecker
          '#return_value' => check_plain($key),
2978
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
2979
          '#attributes' => $element['#attributes'],
2980 1d39ec64 w.addink
          '#parents' => $element['#parents'],
2981 6657531f Andreas Kohlbecker
          // '#spawned' => TRUE,
2982
          '#weight' => $weight + 1,
2983 14feebe9 Andreas Kohlbecker
          '#prefix' => '<td>',        // add a prefix to start a new table cell
2984
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
2985 6657531f Andreas Kohlbecker
        );
2986
      }
2987
      $weight += 2;
2988
    }
2989
  }
2990
2991 14feebe9 Andreas Kohlbecker
  // end the table
2992 6657531f Andreas Kohlbecker
  $element['table_end'] = array(
2993
    '#markup' => '</table>',
2994
    '#weight' => $weight++,
2995
  );
2996
2997
  return $element;
2998
}
2999
3000
/**
3001
 * Theme function for the custom form field 'checkboxes_preferred'.
3002
 */
3003
function theme_checkboxes_preferred($variables) {
3004
  $element = $variables['element'];
3005
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3006
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3007
  $out .= drupal_render_children($element);
3008
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3009
  $out .= '</div>';
3010
  return $out;
3011
}
3012
3013
/**
3014 14feebe9 Andreas Kohlbecker
 * Callback for checkboxes preferred for widget which will
3015
 * be called after the form or element is built. The call
3016
 * back is configured in the form element by setting it as
3017
 * #after_build parameter.
3018
 *
3019
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3020
 *
3021 cc3c9807 Andreas Kohlbecker
 * @param $element
3022 14feebe9 Andreas Kohlbecker
 *   Nested array of form elements that comprise the form.
3023
 * @param $form_state
3024
 *   A keyed array containing the current state of the form.
3025 cc3c9807 Andreas Kohlbecker
 *   This includes the current persistent storage data for the form.
3026
 *   Additional information, like the sanitized $_POST data,
3027
 *   is also accumulated here in $form_state['input']
3028 14feebe9 Andreas Kohlbecker
 *
3029
 * @return the modified form array
3030 6657531f Andreas Kohlbecker
 */
3031 cc3c9807 Andreas Kohlbecker
function checkboxes_preferred_after_build($element, &$form_state) {
3032 6657531f Andreas Kohlbecker
3033 cc3c9807 Andreas Kohlbecker
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3034 6657531f Andreas Kohlbecker
3035
  if ($_POST && count($_POST) > 0) {
3036 cc3c9807 Andreas Kohlbecker
    // TODO use  $form_state['input'] instead of POST !!!
3037 6657531f Andreas Kohlbecker
    // First pass of form processing.
3038 cc3c9807 Andreas Kohlbecker
    $parents = array();
3039
    array_deep_copy($element['#parents'], $parents);
3040
    $parents[count($parents) - 1] .= '_preferred';
3041
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3042
    $element['#value']['PREFERRED'] = $preferred_layer;
3043
//     $form_state[$parent_id] = $element['#value'];
3044
//     $form_state['values']['baselayers'] = $element['#value'];
3045
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3046
    $form_state_element_values = $element['#value'];
3047 6657531f Andreas Kohlbecker
  }
3048
  else {
3049
    // Second pass of form processing.
3050 cc3c9807 Andreas Kohlbecker
    $preferred_layer = $element['#value']['PREFERRED'];
3051 6657531f Andreas Kohlbecker
  }
3052
3053
  // Also set the chosen value (not sure if this is good Drupal style ....).
3054 cc3c9807 Andreas Kohlbecker
  foreach ($children = element_children($element) as $key) {
3055
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3056
      $element[$key]['#value'] = $preferred_layer;
3057 6657531f Andreas Kohlbecker
    }
3058
  }
3059
  // The default layer must always be enabled.
3060 cc3c9807 Andreas Kohlbecker
  $element[$preferred_layer]['#value'] = $preferred_layer;
3061 6657531f Andreas Kohlbecker
3062 cc3c9807 Andreas Kohlbecker
  return $element;
3063 6657531f Andreas Kohlbecker
}
3064 0f5f1c12 Andreas Kohlbecker
3065 3f485c6d Andreas Kohlbecker
function radios_prepare_options_suffix(&$elements){
3066
3067
  $childrenKeys = element_children($elements);
3068
  foreach($childrenKeys as $key){
3069
    if(!is_array($elements[$key]['#theme_wrappers'])){
3070
      $elements[$key]['#theme_wrappers'] = array();
3071
    }
3072
    if(isset($elements['#options_suffixes'][$key])){
3073
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3074
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3075
    }
3076
  }
3077
  return $elements;
3078
3079
}
3080
3081
/**
3082
 * TODO
3083
 * @param unknown $variables
3084
 */
3085
function theme_radio_options_suffix($variables) {
3086
  $element = $variables['element'];
3087
  if(isset($element['#options_suffix'])) {
3088
    $element['#children'] .= $element['#options_suffix'];
3089
  }
3090
  return $element['#children'];
3091
}
3092
3093
3094 0f5f1c12 Andreas Kohlbecker
/**
3095
 * Element validate callback for text field and arrays containing json.
3096
 *
3097
 * @param $element
3098
 *   The form element to validate
3099
 * @param $form_state
3100
 *   A keyed array containing the current state of the form.
3101 cc3c9807 Andreas Kohlbecker
 * @param $form
3102
 *   Nested array of form elements that comprise the form.
3103 0f5f1c12 Andreas Kohlbecker
 */
3104
function form_element_validate_json($element, &$form_state, $form) {
3105
   if (!empty($element['#value'])) {
3106
     json_decode($element['#value']);
3107
     if(json_last_error() != JSON_ERROR_NONE){
3108
       form_error($element, t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title'])) . l('JSONLint', 'http://jsonlint.com/'));
3109
     }
3110
   }
3111
}
3112
3113
/**
3114
 * Form submission handler for textareas and textfields containing JSON.
3115
 *
3116
 * The contained JSON will be converted into an php array
3117 2bbc28c8 Andreas Kohlbecker
 * or object and will be stored in the variables as such.
3118 0f5f1c12 Andreas Kohlbecker
 *
3119
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3120
 *
3121
 * @param $form
3122
 *   Nested array of form elements that comprise the form.
3123
 * @param $form_state
3124
 *   A keyed array containing the current state of the form.
3125
 *
3126
 */
3127
function submit_json_as_php_array($form, &$form_state) {
3128
  if (is_array($form['#json_elements'])) {
3129
    foreach ($form['#json_elements'] as $element){
3130 80370786 Andreas Kohlbecker
      if (trim($form_state['values'][$element])) {
3131
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3132
      } else {
3133
        $form_state['values'][$element] = NULL;
3134
      }
3135 0f5f1c12 Andreas Kohlbecker
    }
3136
  }
3137
}