Beispiel #1
0
 /**
  * Returns a control that allows the setting of the centre of a dive, plus optional
  * start and end points if a drift dive.
  * @param $auth
  * @param $args
  * @param $tabalias
  * @param $options
  * - drift_start_attr_id
  * - drift_end_attr_id
  * @param $path
  * @return string
  */
 public static function drift_dive_position_entry($auth, $args, $tabalias, $options, $path, $attributes)
 {
     if (empty($options['drift_start_attr_id']) || empty($options['drift_end_attr_id'])) {
         return 'The seasearch.drift_dive_position_entry control requires @drift_start_attr_id ' . 'and @drift_start_attr_id options to be supplied.';
     }
     $centreTokens = self::getCentreTokens();
     foreach ($attributes as $attribute) {
         if (preg_match("/^smpAttr:{$options['drift_start_attr_id']}(:\\d+)?\$/", $attribute['fieldname'])) {
             $driftStartDefault = $attribute['default'];
         }
         if (preg_match("/^smpAttr:{$options['drift_end_attr_id']}(:\\d+)?\$/", $attribute['fieldname'])) {
             $driftEndDefault = $attribute['default'];
         }
     }
     $regexToExtractPartsOfLatLong = '/(?P<latdeg>\\d+):(?P<latmin>\\d+(\\.\\d+)?)N, (?P<longdeg>\\d+):(?P<longmin>\\d+(\\.\\d+)?)(?P<longdir>[EW])/';
     preg_match($regexToExtractPartsOfLatLong, $driftStartDefault, $driftStartTokens);
     preg_match($regexToExtractPartsOfLatLong, $driftEndDefault, $driftEndTokens);
     // fill in defaults to make code cleaner later
     $driftStartTokens = array_merge(array('latdeg' => '', 'latmin' => '', 'longdeg' => '', 'longmin' => '', 'longdir' => ''), $driftStartTokens);
     $driftEndTokens = array_merge(array('latdeg' => '', 'latmin' => '', 'longdeg' => '', 'longmin' => '', 'longdir' => ''), $driftEndTokens);
     // Add a GPS datum or grid system selection control
     $r = '<label class="auto">Position format and datum ' . data_entry_helper::sref_system_select(array('fieldname' => 'sample:entered_sref_system', 'systems' => array('4326' => 'Latitude and longitiude (degrees and decimal minutes WGS84)', '4277' => 'Latitude and longitiude (degrees and decimal minutes OSGB36)', 'OSGB' => 'Ordnance Survey British National Grid'))) . '</label>';
     $r .= '<div><div id="input-ll-container"><p>' . lang::get('Position (degrees and decimal minutes)') . '</p>';
     $r .= '<table id="position-data"><thead><th colspan="2"></th><th colspan="2">' . lang::get('Latitude') . '</th><th colspan="2">' . lang::get('Longitude') . '</th><th>' . lang::get('W or E') . '</th><tr></tr></thead>';
     $r .= '<tbody><tr id="input-centre"><td>' . lang::get('Centre of site') . '</td>';
     $r .= "<td><input type=\"radio\" title=\"" . lang::get('Select this option then click on the map to set the dive centre') . "\" name=\"which-point\" value=\"centre\" checked=\"checked\"/></td>";
     $r .= "<td><input id=\"input-lat-deg\" class=\"input-lat input-deg {required: true,pattern:/^[0-9]*\$/}\" type=\"text\" value=\"{$centreTokens['latdeg']}\"/>&deg;</td>";
     $r .= "<td class=\"td-pad\"><input id=\"input-lat-min\" class=\"input-lat input-min {required: true,pattern:/^[0-9]+(.[\\d]+)?\$/}\" type=\"text\" value=\"{$centreTokens['latmin']}\"/>N</td>";
     $r .= "<td><input id=\"input-long-deg\" class=\"input-long input-deg {required: true,pattern:/^[0-9]*\$/}\" type=\"text\" value=\"{$centreTokens['longdeg']}\"/>&deg;</td>";
     $r .= "<td><input id=\"input-long-min\" class=\"input-long input-min {required: true,pattern:/^[0-9]+(.[\\d]+)?\$/}\" type=\"text\" value=\"{$centreTokens['longmin']}\"/></td>";
     $r .= '<td>' . data_entry_helper::select(array('lookupValues' => array('E' => 'E', 'W' => 'W'), 'blankText' => lang::get('choose'), 'fieldname' => 'e-w', 'default' => $centreTokens['longdir'])) . '</td>';
     $r .= '</tr>';
     $r .= '<tr><td colspan="6">' . lang::get('For drift dives') . '</td></tr>';
     $r .= '<tr id="input-drift-from"><td>' . lang::get('From') . '</td>';
     $r .= "<td><input type=\"radio\" title=\"" . lang::get('Select this option then click on the map to set the dive start') . "\" name=\"which-point\" value=\"from\" /></td>";
     $r .= "<td><input id=\"input-lat-deg-from\" class=\"input-lat input-deg {pattern:/^[0-9]*\$/}\" type=\"text\" value=\"{$driftStartTokens['latdeg']}\"/>&deg;</td>";
     $r .= "<td class=\"td-pad\"><input id=\"input-lat-min-from\" class=\"input-lat input-min {pattern:/^[0-9]+(.[\\d]+)?\$/}\" type=\"text\" value=\"{$driftStartTokens['latmin']}\"/>N</td>";
     $r .= "<td><input id=\"input-long-deg-from\" class=\"input-long input-deg {pattern:/^[0-9]*\$/}\" type=\"text\" value=\"{$driftStartTokens['longdeg']}\"/>&deg;</td>";
     $r .= "<td><input id=\"input-long-min-from\" class=\"input-long input-min {pattern:/^[0-9]+(.[\\d]+)?\$/}\" type=\"text\" value=\"{$driftStartTokens['longmin']}\"/></td>";
     $r .= '<td>' . data_entry_helper::select(array('lookupValues' => array('E' => 'E', 'W' => 'W'), 'blankText' => lang::get('choose'), 'fieldname' => 'e-w-from', 'default' => $driftStartTokens['longdir'])) . '</td>';
     $r .= '</tr>';
     $r .= '<tr id="input-drift-to"><td>' . lang::get('To') . '</td>';
     $r .= "<td><input type=\"radio\" title=\"" . lang::get('Select this option then click on the map to set the dive end') . "\" name=\"which-point\" value=\"to\" />";
     $r .= "<td><input id=\"input-lat-deg-to\" class=\"input-lat input-deg {pattern:/^[0-9]*\$/}\" type=\"text\" value=\"{$driftEndTokens['latdeg']}\"/>&deg;</td>";
     $r .= "<td class=\"td-pad\"><input id=\"input-lat-min-to\" class=\"input-lat input-min {pattern:/^[0-9]+(.[\\d]+)?\$/}\" type=\"text\" value=\"{$driftEndTokens['latmin']}\"/>N</td>";
     $r .= "<td><input id=\"input-long-deg-to\" class=\"input-long input-deg {pattern:/^[0-9]*\$/}\" type=\"text\" value=\"{$driftEndTokens['longdeg']}\"/>&deg;</td>";
     $r .= "<td><input id=\"input-long-min-to\" class=\"input-long input-min {pattern:/^[0-9]+(.[\\d]+)?\$/}\" type=\"text\" value=\"{$driftEndTokens['longmin']}\"/></td>";
     $r .= '<td>' . data_entry_helper::select(array('lookupValues' => array('E' => 'E', 'W' => 'W'), 'blankText' => lang::get('choose'), 'fieldname' => 'e-w-to', 'default' => $driftEndTokens['longdir'])) . '</td>';
     $r .= '</tr>';
     $r .= '</tbody></table></div>';
     $r .= '<label id="input-os-grid-container">OS Grid Reference<input id="input-os-grid" type="text"/></label>';
     $default = empty(data_entry_helper::$entity_to_load['sample:entered_sref']) ? '' : data_entry_helper::$entity_to_load['sample:entered_sref'];
     $r .= "<input type=\"hidden\" name=\"sample:entered_sref\" id=\"imp-sref\" value=\"{$default}\" />";
     // Pass the drift start and end  attribute IDs to JS so the values can be synced to the visible controls
     data_entry_helper::$javascript .= "indiciaData.driftStartAttrFieldname='smpAttr:{$options['drift_start_attr_id']}';\n";
     $r .= "<input type=\"hidden\" name=\"smpAttr:{$options['drift_start_attr_id']}\" id=\"smpAttr:{$options['drift_start_attr_id']}\" value=\"{$driftStartDefault}\"/>";
     data_entry_helper::$javascript .= "indiciaData.driftEndAttrFieldname='smpAttr:{$options['drift_end_attr_id']}';\n";
     $r .= "<input type=\"hidden\" name=\"smpAttr:{$options['drift_end_attr_id']}\" name=\"smpAttr:{$options['drift_end_attr_id']}\"  value=\"{$driftEndDefault}\"/>";
     $r .= '</div>';
     return $r;
 }
 protected static function get_section_details_tab($auth, $args, $settings)
 {
     $r = '<div id="section-details" class="ui-helper-clearfix">';
     $r .= '<form method="post" id="section-form" action="' . self::$ajaxFormUrl . '">';
     $r .= '<fieldset><legend>' . lang::get('Section Details') . '</legend>';
     // Output a selector for the current section.
     $r .= self::section_selector($settings, 'section-select') . "<br/>";
     if ($settings['canEditBody']) {
         $r .= "<input type=\"hidden\" name=\"location:id\" value=\"\" id=\"section-location-id\" />\n";
         $r .= '<input type="hidden" name="website_id" value="' . $args['website_id'] . "\" />\n";
     }
     // for the SRef, we want to be able to edit the sref, but just display the system. Do not want the Geometry.
     $r .= '<label for="imp-sref">Section Grid Ref.:</label><input type="text" value="" class="required" name="location:centroid_sref" id="section-location-sref"><span class="deh-required">*</span>';
     // for the system we need to translate the system: easiest way is to have a disabled select plus a hidden field.
     $systems = array();
     $list = explode(',', str_replace(' ', '', $args['spatial_systems']));
     foreach ($list as $system) {
         $systems[$system] = lang::get($system);
     }
     $options = array('fieldname' => '', 'systems' => $systems, 'disabled' => ' disabled="disabled"', 'id' => 'section-location-system-select');
     // Output the hidden system control
     $r .= '<input type="hidden" id="section-location-system" name="location:centroid_sref_system" value="" />';
     $r .= data_entry_helper::sref_system_select($options);
     // force a blank centroid, so that the Warehouse will recalculate it from the boundary
     //$r .= "<input type=\"hidden\" name=\"location:centroid_geom\" value=\"\" />\n";
     $r .= get_attribute_html($settings['section_attributes'], $args, array('extraParams' => $auth['read'], 'disabled' => $settings['canEditBody'] ? '' : ' disabled="disabled" '));
     if ($settings['canEditBody']) {
         $r .= '<input type="submit" value="' . lang::get('Save') . '" class="form-button right" id="submit-section" />';
     }
     $r .= '</fieldset></form>';
     $r .= '</div>';
     return $r;
 }
 private static function get_site_trees_tab($auth, $args, $settings)
 {
     global $indicia_templates;
     $r = '<div id="site-trees" class="ui-helper-clearfix">';
     $r .= '<form method="post" id="tree-form" action="' . self::$ajaxFormUrl . '">';
     $help = '<p>' . lang::get('To add a tree, click on the "Add Tree" button. You can then use the map\'s Location Tool to select the approximate location of your tree on the map. A new tree will then appear on the map.') . '</p>' . '<p>' . lang::get('To select a tree from the existing list of trees at this site you can either:') . '</p>' . '<ol><li>' . lang::get('Click on the button for the tree you wish to view, or') . '</li>' . '<li>' . lang::get('Use the map\'s Query Tool to click on the tree you wish to view on the map.') . '</li></ol>' . '<p>' . lang::get('To remove a tree, first select the tree you wish to remove, then click on the "Remove Tree" button. It will remove the current tree you are viewing completely.') . '</p>';
     $r .= '<div class="ui-state-highlight page-notice ui-corner-all">' . $help . '</div>';
     $r .= self::tree_selector($settings);
     $r .= '<input type="button" value="' . lang::get('Remove Tree') . '" class="remove-tree form-button right" title="' . lang::get('Completely remove the highlighted tree. The total number of tree will be reduced by one. The form will be reloaded after the tree is deleted.') . '">';
     $r .= '<input type="button" value="' . lang::get('Add Tree') . '" class="insert-tree form-button right" title="' . lang::get('This inserts an extra tree.') . '">';
     $r .= '<div id="cols" class="ui-helper-clearfix"><div class="left" style="width: ' . (98 - (isset($args['percent_width']) ? $args['percent_width'] : 50)) . '%">';
     $r .= '<fieldset><legend>' . lang::get('Tree Details') . '</legend>';
     $r .= '<input type="hidden" name="location:id" value="" id="tree-location-id" />';
     $r .= '<input type="hidden" name="locations_website:website_id" value="' . $args['website_id'] . '" id="locations-website-website-id" />';
     $r .= '<input type="hidden" name="location:parent_id" value="' . $settings['locationId'] . '" />';
     $r .= '<input type="hidden" name="location:location_type_id" value="' . $settings['TreeLocationType'][0]['id'] . '" />';
     $r .= '<input type="hidden" name="website_id" value="' . $args['website_id'] . "\" />\n";
     $r .= data_entry_helper::text_input(array('fieldname' => 'location:name', 'label' => lang::get('Tree ID'), 'class' => 'control-width-4 required'));
     $systems = array();
     $list = explode(',', str_replace(' ', '', $args['spatial_systems']));
     foreach ($list as $system) {
         $systems[$system] = lang::get($system);
     }
     $srefOptions = array('id' => 'imp-sref-tree', 'fieldname' => 'location:centroid_sref', 'geomid' => 'imp-geom-tree', 'geomFieldname' => 'location:centroid_geom', 'label' => 'Grid Ref', 'labelClass' => 'auto', 'class' => 'required', 'helpText' => lang::get('You can also click on the map to set the grid reference. If directly entering the coordinates from a GPS device, set the format to "Lat/Long" first. To enter an OS Grid square, choose the "OSGB" or "OSIE" formats.'));
     data_entry_helper::$javascript .= "\n\$('#imp-sref-tree').attr('title',\n    '" . lang::get("When directly entering coordinates as a GPS Lat/Long reading, there should be no spaces between the numbers and the letter. " . "The degrees, minutes and seconds must all be separated by a colon (:). The direction letter can be placed at the start or the end of the number (e.g. N56.532 or 56.532N). " . "The figures may be entered as decimal degrees (e.g. 56.532), degrees and decimal minutes (e.g. 56:31.92), or degrees, minutes and decimal seconds (e.g. 56:31:55.2). " . "You can mix the formats of the Latitude and Longitude, provided they each follow the previous guidelines and a space separates them (e.g. N56.532 2:30W).") . "  " . lang::get("When directly entering an OS map reference, there should be no spaces between any of the characters. " . "An OSGB reference should comprise of 2 letters followed by an even number of digits (e.g. NT274628). " . "An OSIE reference should comprise of of 1 letter followed by an even number of digits (e.g. J081880).") . "');\n";
     // Output the sref control
     $r .= data_entry_helper::sref_textbox($srefOptions);
     $srefOptions = array('id' => 'imp-sref-system-tree', 'fieldname' => 'location:centroid_sref_system', 'class' => 'required', 'systems' => $systems);
     // Output the system control
     if (count($systems) < 2) {
         // Hidden field for the system
         $keys = array_keys($options['systems']);
         $r .= "<input type=\"hidden\" id=\"imp-sref-system-tree\" name=\"" . $options['fieldname'] . "\" value=\"" . $keys[0] . "\" />\n";
         // TODO    	self::include_sref_handler_js($options['systems']);
     } else {
         $r .= data_entry_helper::sref_system_select($srefOptions);
     }
     $r .= '<input type="hidden" name="survey_id" value="' . $args['survey_id'] . '" />';
     $r .= '<input type="hidden" name="sample:survey_id" value="' . $args['survey_id'] . '" />';
     $r .= '<input type="hidden" name="sample:id" value="" />';
     // this sample will reference the location id.
     if (isset(data_entry_helper::$entity_to_load['sample:date']) && preg_match('/^(\\d{4})/', data_entry_helper::$entity_to_load['sample:date'])) {
         // Date has 4 digit year first (ISO style) - convert date to expected output format
         // @todo The date format should be a global configurable option. It should also be applied to reloading of custom date attributes.
         $d = new DateTime(data_entry_helper::$entity_to_load['sample:date']);
         data_entry_helper::$entity_to_load['sample:date'] = $d->format('d/m/Y');
     }
     $r .= data_entry_helper::date_picker(array('label' => lang::get('Date Tree Selected'), 'fieldname' => 'sample:date', 'class' => 'control-width-2 required'));
     $r .= '<input type="hidden" id="sample:sample_method_id" value="' . $settings['treeSampleMethod']['id'] . '" name="sample:sample_method_id">';
     $r .= '<input type="hidden" id="sample:location_name" value="" name="sample:location_name">';
     $r .= '<input type="hidden" name="occurrence:id" value="" id="occurrence:id" />';
     $r .= '<input type="hidden" name="occurrence:record_status" value="C" id="occurrence:record_status" />';
     $extraParams = $auth['read'];
     $extraParams['taxon_list_id'] = $args['taxon_list_id'];
     $options = array('speciesNameFilterMode' => $args['speciesNameFilterMode']);
     $ctrl = $args['species_ctrl'];
     $species_ctrl_opts = array_merge(array('fieldname' => 'occurrence:taxa_taxon_list_id', 'label' => lang::get('Tree Species'), 'columns' => 1, 'parentField' => 'parent_id', 'blankText' => lang::get('Please select'), 'cacheLookup' => false), $options);
     if (isset($species_ctrl_opts['extraParams'])) {
         $species_ctrl_opts['extraParams'] = array_merge($extraParams, $species_ctrl_opts['extraParams']);
     } else {
         $species_ctrl_opts['extraParams'] = $extraParams;
     }
     if (!empty($args['taxon_filter'])) {
         $species_ctrl_opts['taxonFilterField'] = $args['taxon_filter_field'];
         // applies to autocompletes
         $species_ctrl_opts['taxonFilter'] = helper_base::explode_lines($args['taxon_filter']);
         // applies to autocompletes
     }
     // obtain table to query and hence fields to use
     $db = data_entry_helper::get_species_lookup_db_definition(false);
     // get local vars for the array
     extract($db);
     if ($ctrl !== 'species_autocomplete') {
         // The species autocomplete has built in support for the species name filter.
         // For other controls we need to apply the species name filter to the params used for population
         if (!empty($species_ctrl_opts['taxonFilter']) || $options['speciesNameFilterMode']) {
             $species_ctrl_opts['extraParams'] = array_merge($species_ctrl_opts['extraParams'], data_entry_helper::get_species_names_filter($species_ctrl_opts));
         }
         // for controls which don't know how to do the lookup, we need to tell them
         $species_ctrl_opts = array_merge(array('table' => $tblTaxon, 'captionField' => $colTaxon, 'valueField' => $colId), $species_ctrl_opts);
     }
     // if using something other than an autocomplete, then set the caption template to include the appropriate names. Autocompletes
     // use a JS function instead.
     if ($ctrl !== 'autocomplete' && isset($args['species_include_both_names']) && $args['species_include_both_names']) {
         if ($args['speciesNameFilterMode'] === 'all') {
             $indicia_templates['species_caption'] = "{{$colTaxon}}";
         } elseif ($args['speciesNameFilterMode'] === 'language') {
             $indicia_templates['species_caption'] = "{{$colTaxon}} - {{$colPreferred}}";
         } else {
             $indicia_templates['species_caption'] = "{{$colTaxon}} - {{$colCommon}}";
         }
         $species_ctrl_opts['captionTemplate'] = 'species_caption';
     }
     if ($ctrl == 'tree_browser') {
         // change the node template to include images
         $indicia_templates['tree_browser_node'] = '<div>' . '<img src="' . data_entry_helper::$base_url . '/upload/thumb-{image_path}" alt="Image of {caption}" width="80" /></div>' . '<span>{caption}</span>';
     }
     // Dynamically generate the species selection control required.
     $r .= call_user_func(array('data_entry_helper', $ctrl), $species_ctrl_opts);
     $ctrlOptions = array('extraParams' => $auth['read']);
     $attrSpecificOptions = array();
     $options = helper_base::explode_lines_key_value_pairs($args['attrOptions']);
     self::parseForAttrSpecificOptions($options, $ctrlOptions, $attrSpecificOptions);
     $r .= get_attribute_html($settings['tree_attributes'], $args, $ctrlOptions, '', $attrSpecificOptions);
     $r .= '</fieldset>';
     $r .= "</div>" . '<div class="right" style="width: ' . (isset($args['percent_width']) ? $args['percent_width'] : 50) . '%">';
     $olOptions = iform_map_get_ol_options($args);
     $options = iform_map_get_map_options($args, $auth['read']);
     $options['divId'] = 'trees-map';
     $options['toolbarDiv'] = 'top';
     $options['tabDiv'] = 'site-trees';
     $options['gridRefHint'] = true;
     $options['latLongFormat'] = 'DMS';
     // TODO drive from args or user.
     if (array_key_exists('standard_controls_trees', $args) && $args['standard_controls_trees']) {
         $standard_controls_trees = str_replace("\r\n", "\n", $args['standard_controls_trees']);
         $options['standardControls'] = explode("\n", $standard_controls_trees);
         // If drawing controls are enabled, then allow polygon recording.
         if (in_array('drawPolygon', $options['standardControls']) || in_array('drawLine', $options['standardControls'])) {
             $options['allowPolygonRecording'] = true;
         }
     }
     // also let the user click on a feature to select it. The highlighter just makes it easier to select one.
     // these controls are not present in read-only mode: all you can do is look at the map.
     $options['switchOffSrefRetrigger'] = true;
     $options['clickForSpatialRef'] = true;
     // override the opacity so the parent square does not appear filled in.
     $options['fillOpacity'] = 0;
     // override the map height and buffer size, which are specific to this map.
     $options['height'] = $args['tree_map_height'];
     $options['maxZoomBuffer'] = $args['tree_map_buffer'];
     $options['srefId'] = 'imp-sref-tree';
     $options['geomId'] = 'imp-geom-tree';
     $options['srefSystemId'] = 'imp-sref-system-tree';
     $help = '<p>' . lang::get('Add your trees using the appropriate tools in the top right of the map') . ':</p>' . '<ol><li>' . lang::get('Navigation Tool.') . '</li>' . '<li>' . lang::get('Query Tool. This tool allows you to click on a tree on the map to view its tree details.') . '</li>' . '<li>' . lang::get('Location Tool. This tool allows you to select the approximate location of a new tree on your site map. You can also reposition existing trees by first clicking on the tree and then clicking on its new location on the map.') . '</li></ol>';
     $r .= '<div class="ui-state-highlight page-notice ui-corner-all">' . $help . '</div>';
     $r .= map_helper::map_panel($options, $olOptions);
     $r .= data_entry_helper::file_box(array('table' => 'location_medium', 'readAuth' => $auth['read'], 'caption' => lang::get('Photos of Tree'), 'readAuth' => $auth['read']));
     $r .= "</div>";
     // right
     $r .= '<div class="follow_on_block" style="clear:both;">';
     $r .= get_attribute_html($settings['tree_attributes'], $args, $ctrlOptions, 'Lower Block', $attrSpecificOptions);
     data_entry_helper::$javascript .= "\n\$('#fieldset-optional-external-sc').prepend(\"" . lang::get('If you choose to record this tree for one of the citizen science projects below, please submit the tree ID used for that scheme.') . "\");\n";
     $r .= data_entry_helper::textarea(array('id' => 'location-comment', 'fieldname' => 'location:comment', 'label' => lang::get("Additional information"), 'labelClass' => 'autowidth')) . "<br />";
     $r .= '<input type="submit" value="' . lang::get('Save') . '" class="form-button right" id="submit-tree" />';
     $r .= '</div></form></div>';
     data_entry_helper::$onload_javascript .= "\$('#current-tree').change(selectTree);\n";
     return $r;
 }