protected static function get_control_customJS($auth, $args, $tabalias, $options) { global $indicia_templates; data_entry_helper::$javascript .= "\nif(\$.browser.msie && \$.browser.version < 9)\n \$('input[type=radio],[type=checkbox]').live('click', function(){\n this.blur();\n this.focus();\n});\n"; self::$check_or_radio_group_template = $indicia_templates['check_or_radio_group']; self::$check_or_radio_group_item_template = $indicia_templates['check_or_radio_group_item']; $indicia_templates['check_or_radio_group'] = '<div class="radio_group_container"><span {class}>{items}</span></div>'; $indicia_templates['check_or_radio_group_item'] = '<nobr><div class="radio_group_item"><input type="{type}" name="{fieldname}" id="{itemId}" value="{value}"{class}{checked} {disabled}/><label for="{itemId}">{caption}</label></div></nobr> {sep}'; if (isset($options['resizeRadioGroupSelector'])) { $selectors = explode(',', $options['resizeRadioGroupSelector']); foreach ($selectors as $selector) { data_entry_helper::$javascript .= "resize_radio_groups('" . $selector . "');\n"; } } data_entry_helper::$javascript .= "\nindiciaData.resizeSpeciesRadioGroup = " . (isset($options['resizeRadioGroupSelector']) && (in_array('*', $selectors) || in_array('species', $selectors)) ? 'true' : 'false') . ";\n"; if (lang::get('validation_required') != 'validation_required') { data_entry_helper::$late_javascript .= "\n\$.validator.messages.required = \"" . lang::get('validation_required') . "\";"; } if (lang::get('validation_max') != 'validation_max') { data_entry_helper::$late_javascript .= "\n\$.validator.messages.max = \$.validator.format(\"" . lang::get('validation_max') . "\");"; } if (lang::get('validation_min') != 'validation_min') { data_entry_helper::$late_javascript .= "\n\$.validator.messages.min = \$.validator.format(\"" . lang::get('validation_min') . "\");"; } if (lang::get('validation_number') != 'validation_number') { data_entry_helper::$late_javascript .= "\n\$.validator.messages.number = \$.validator.format(\"" . lang::get('validation_number') . "\");"; } if (lang::get('validation_digits') != 'validation_digits') { data_entry_helper::$late_javascript .= "\n\$.validator.messages.digits = \$.validator.format(\"" . lang::get('validation_digits') . "\");"; } if (lang::get('validation_integer') != 'validation_integer') { data_entry_helper::$late_javascript .= "\n\$.validator.messages.integer = \$.validator.format(\"" . lang::get('validation_integer') . "\");"; } // possible clash with link_species_popups, so latter disabled. iform_mnhnl_addCancelButton($args['interface']); $attrOpts = array('valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']); if (isset($args['sample_method_id']) && $args['sample_method_id'] != "") { $attrOpts['sample_method_id'] = $args['sample_method_id']; } $attributes = data_entry_helper::getAttributes($attrOpts); foreach ($attributes as $attribute) { data_entry_helper::$javascript .= "\$('#smpAttr\\\\:" . $attribute['attributeId'] . "').addClass('smpAttr-" . str_replace(' ', '', ucWords($attribute['untranslatedCaption'])) . "');\n"; } $restrictText = array(); if (isset($options["attrRestrictions"]) && $options["attrRestrictions"] != "") { $restrictionRules = explode(';', $options["attrRestrictions"]); foreach ($restrictionRules as $restrictionRule) { $parts = explode(':', $restrictionRule); $valList = array(); for ($i = 2; $i < count($parts); $i++) { $values = explode(',', trim($parts[$i])); $valString = "{value : " . $values[0] . ", list: [\""; unset($values[0]); $valList[] = $valString . implode("\",\"", $values) . "\"]}"; } $restrictText[] = "{parent : " . $parts[0] . ", child : " . $parts[1] . ",\n values: [" . implode(",\n ", $valList) . "]}"; } } data_entry_helper::$javascript .= "\nrelationships = [" . implode(",\n", $restrictText) . "\n];"; if (isset($options["attrRestrictionsProcessOrder"]) && $options["attrRestrictionsProcessOrder"] != "") { $attrOrder = explode(':', $options["attrRestrictionsProcessOrder"]); if (!isset($options["attrRestrictionsDuplicateAttrList"])) { $options["attrRestrictionsDuplicateAttrList"] = $options["attrRestrictionsProcessOrder"]; } $duplicateAttrList = explode(':', $options["attrRestrictionsDuplicateAttrList"]); data_entry_helper::$javascript .= "\nattrRestrictionsProcessOrder = [" . implode(',', $attrOrder) . "];\nattrRestrictionsDuplicates = " . (isset($options["attrRestrictionsEnforceDuplicates"]) ? 'true' : 'false') . ";\nattrRestrictionsDuplicateAttrList = [" . implode(',', $duplicateAttrList) . "];\n// set up pre-existing ones: trigger first which will bubble through\njQuery('.mnhnl-species-grid').find('[name\$=occAttr\\:" . $attrOrder[0] . "],[name*=occAttr\\:" . $attrOrder[0] . "\\:]').each(function(){\n set_up_relationships(" . $attrOrder[1] . ", \$(this), false, " . (isset($options["attrRestrictionsEnforceDuplicates"]) ? 'true' : 'false') . ");\n});\n// Set up what happens when existing fields are changed\n"; // need to check all but last for ($i = 0; $i < count($attrOrder) - 1; $i++) { data_entry_helper::$javascript .= "\njQuery('.mnhnl-species-grid').find('[name\$=occAttr\\:" . $attrOrder[$i] . "],[name*=occAttr\\:" . $attrOrder[$i] . "\\:]').change(function(){\n set_up_relationships(" . $attrOrder[$i + 1] . ", \$(this), true, " . (isset($options["attrRestrictionsEnforceDuplicates"]) ? 'true' : 'false') . ");\n});\n"; } data_entry_helper::$javascript .= "// last is special - only updates similar on other rows.\njQuery('.mnhnl-species-grid').find('[name\$=occAttr\\:" . $attrOrder[count($attrOrder) - 1] . "],[name*=occAttr\\:" . $attrOrder[count($attrOrder) - 1] . "\\:]').change(function(){\n set_up_last_relationship(this, " . $attrOrder[count($attrOrder) - 1] . ", " . $attrOrder[count($attrOrder) - 2] . ", true);\n});\n"; // for duplicate checks had to trigger on all duplicate based fields. Don't include the precision field, which is on the sample field. $selector = isset($options['includeSubSample']) ? '.imp-srefX,.imp-srefY' : ''; foreach ($duplicateAttrList as $attr) { if (!in_array($attr, $attrOrder)) { $selector .= ($selector == "" ? "" : ",") . "[name\$=occAttr\\:" . $attr . "],[name*=occAttr\\:" . $attr . "\\:]"; } } if ($selector != "" && isset($options["attrRestrictionsEnforceDuplicates"])) { data_entry_helper::$javascript .= "\nattrRestrictionsDuplicateSelector = \"" . $selector . "\";\njQuery('.mnhnl-species-grid').find('" . $selector . "').change(function(){\n set_up_last_relationship(this, " . $attrOrder[count($attrOrder) - 1] . ", " . $attrOrder[count($attrOrder) - 2] . ", true);\n});\n"; } } if (!empty($args['attributeValidation'])) { $rules = array(); $argRules = explode(';', $args['attributeValidation']); foreach ($argRules as $rule) { $rules[] = explode(',', $rule); } foreach ($rules as $rule) { // But only do if a parameter given as rule:param - eg min:-40 for ($i = 1; $i < count($rule); $i++) { if (strpos($rule[$i], ':') !== false) { $details = explode(':', $rule[$i]); data_entry_helper::$late_javascript .= "\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').attr('" . $details[0] . "'," . $details[1] . ");"; } else { if ($rule[$i] == 'no_observation') { data_entry_helper::$late_javascript .= "\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').filter(':checkbox').rules('add', {no_observation: true});\nhook_species_grid_changed=function() {\n if(jQuery('.scPresence').filter('[value=true]').length==0)\n jQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').removeAttr('disabled');\n else\n jQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').filter(':checkbox').attr('disabled','disabled').removeAttr('checked');\n};\nhook_species_grid_changed();\n\$.validator.addMethod('no_observation', function(arg1, arg2){\n var numRows = jQuery('.scPresence').filter('[value=true]').length;\n var isChecked = jQuery('[name='+jQuery(arg2).attr('name')+']').not(':hidden').filter('[checked]').length>0;\n if(isChecked) return(numRows==0)\n else if(numRows>0) return true;\n // Not checked, no rows: ensure no obs can be filled in, and flag failure.\n jQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').removeAttr('disabled');\n // this is being used against a boolean checkbox, which has a hidden zero field before. Have to tag on to later field explicitly.\n return false;\n},\n \"" . lang::get('validation_no_observation') . "\");\n"; } else { if ($rule[$i] == 'end_time') { // we are assuming this is on the main supersample. $attrOpts = array('valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']); if (isset($args['sample_method_id']) && $args['sample_method_id'] != "") { $attrOpts['sample_method_id'] = $args['sample_method_id']; } $sampleAttrs = data_entry_helper::getAttributes($attrOpts, true); // fetch start time. $found = false; foreach ($sampleAttrs as $id => $attr) { if ($attr["untranslatedCaption"] == "Start time") { $found = $id; break; } } if ($found === false) { continue; } data_entry_helper::$late_javascript .= "\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').rules('add', {end_time: true});\n\$.validator.addMethod('end_time', function(value, element){\n var startTime = jQuery('[name=smpAttr\\:" . $found . "],[name^=smpAttr\\:" . $found . "\\:]') \n if(value=='' || startTime.val() == '') return true; \n return (value >= startTime.val()); \n},\n \"" . lang::get('validation_end_time') . "\");\n"; } else { if ($rule[$i] == 'N=2') { // We change the way this is handled: no longer a validation rule as this is only applied when the next step is pressed // we want immediate, restrict number checkable. Still are assuming this is on the main supersample. // allow a maximum of 2 entries in a multiple value checkbox set. $func = "check_N2_" . str_replace(':', '_', $rule[0]); $selector = str_replace(':', '\\:', $rule[0]); data_entry_helper::$late_javascript .= $func . " = function(){\n var controls = jQuery('[name=" . $selector . "\\[\\]],[name=" . $selector . "],[name^=" . $selector . "\\:]').filter('[type=checkbox]'); \n var checkedControls = controls.filter(':checked'); \n if(checkedControls.length >= 2)\n controls.not(':checked').attr('disabled',true);\n else\n controls.removeAttr('disabled');\n};\njQuery('[name=" . $selector . "\\[\\]],[name=" . $selector . "],[name^=" . $selector . "\\:]').click(" . $func . ");\n" . $func . "();\n"; } else { if ($rule[$i] == 'N=3') { // we want immediate, restrict number checkable.. // allow a maximum of 3 entries in a multiple value checkbox set. name will be the same. $func = "check_N3_" . str_replace(':', '_', $rule[0]); $selector = str_replace(':', '\\:', $rule[0]); data_entry_helper::$late_javascript .= $func . "_sub = function(elem){\n var controls = jQuery('[name='+elem.name+']'); \n var checkedControls = controls.filter(':checked');\n if(checkedControls.length >= 3)\n controls.not(':checked').attr('disabled',true);\n else\n controls.removeAttr('disabled');\n};\n" . $func . " = function(){\n " . $func . "_sub(this);\n};\njQuery('[name\$=" . $selector . "\\[\\]]').live('click', " . $func . ");\njQuery('[name\$=" . $selector . "\\[\\]]').each(function(){\n " . $func . "_sub(this);\n});\n"; } else { if (substr($rule[0], 3, 4) != 'Attr') { // have to add for non attribute case. data_entry_helper::$late_javascript .= "\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').addClass('" . $rule[$i] . "');"; } } } } } } } } } if (!isset($options['speciesListInTextAttr'])) { return ''; } $ctrlArgs = explode(',', $options['speciesListInTextAttr']); data_entry_helper::$javascript .= "\nindiciaData.speciesListInTextSelector = '." . $ctrlArgs[0] . "';\nindiciaData.None = '" . lang::get('None') . "';\nindiciaData.speciesListInTextLabel = '" . lang::get('Add supporting plant species to list') . "';\nindiciaData.speciesListInTextSpeciesList = " . $ctrlArgs[1] . ";\nindiciaData.speciesListInTextMax = '" . $ctrlArgs[2] . "';\n"; return ''; }
protected static function get_form_sampleoccurrence($args, $node) { // attributes must be fetched after the entity to load is filled in - this is because the id gets filled in then! $cancelUrl = self::$currentUrl; $cancelUrl .= strpos($cancelUrl, '?') === false ? '?' : '&'; $cancelUrl .= "supersample_id=" . data_entry_helper::$entity_to_load['sample:parent_id']; $attributes = data_entry_helper::getAttributes(array('id' => data_entry_helper::$entity_to_load['sample:id'], 'valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => self::$auth['read'], 'survey_id' => $args['survey_id'])); if (self::$mode == MODE_EXISTING_OCCURRENCE && self::$gridmode == false && isset(data_entry_helper::$entity_to_load['sample:id'])) { $cloneEntity = data_entry_helper::$entity_to_load; $occList = data_entry_helper::preload_species_checklist_occurrences(data_entry_helper::$entity_to_load['sample:id'], self::$auth['read'], $args['occurrence_images']); foreach ($occList as $id => $taxon) { self::$occurrenceIds[] = $id; } if (count(self::$occurrenceIds) > 1) { self::$gridmode = true; data_entry_helper::$entity_to_load = $cloneEntity; } } // Make sure the form action points back to this page $r = "<form method=\"post\" id=\"entry_form\" action=\"" . self::$currentUrl . "\">\n"; // Get authorisation tokens to update the Warehouse, plus any other hidden data. $hiddens = self::$auth['write'] . "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n" . "<input type=\"hidden\" id=\"survey_id\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n" . "<input type=\"hidden\" id=\"parent_id\" name=\"sample:parent_id\" value=\"" . data_entry_helper::$entity_to_load['sample:parent_id'] . "\" />\n" . "<input type=\"hidden\" id=\"date\" name=\"sample:date\" value=\"" . data_entry_helper::$entity_to_load['sample:date'] . "\" />\n"; if (isset(data_entry_helper::$entity_to_load['sample:id'])) { $hiddens .= "<input type=\"hidden\" id=\"sample:id\" name=\"sample:id\" value=\"" . data_entry_helper::$entity_to_load['sample:id'] . "\" />\n"; } // Check if Record Status is included as a control. If not, then add it as a hidden. $arr = explode("\r\n", $args['structure']); if (!in_array('[record status]', $arr)) { $value = isset($args['defaults']['occurrence:record_status']) ? $args['defaults']['occurrence:record_status'] : 'C'; $hiddens .= "<input type=\"hidden\" id=\"occurrence:record_status\" name=\"occurrence:record_status\" value=\"{$value}\" />\n"; } // request automatic JS validation if (!isset($args['clientSideValidation']) || $args['clientSideValidation']) { data_entry_helper::enable_validation('entry_form'); } self::set_attribute_default_block($attributes); $tabs = self::get_all_tabs($args['occurrence_structure'], array()); $r .= "<div id=\"controls\">\n"; // Build a list of the tabs that actually have content $tabHtml = self::get_tab_html($tabs, self::$auth, $args, $attributes, $hiddens); // Output the dynamic tab headers $headerOptions = array('tabs' => array()); foreach ($tabHtml as $tab => $tabContent) { $alias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $tabtitle = lang::get("LANG_Tab_{$alias}"); if ($tabtitle == "LANG_Tab_{$alias}") { // if no translation provided, we'll just use the standard heading $tabtitle = $tab; } $headerOptions['tabs']['#' . $alias] = $tabtitle; } if ($args['interface'] != 'one_page') { $r .= data_entry_helper::tab_header($headerOptions); data_entry_helper::enable_tabs(array('divId' => 'controls', 'style' => $args['interface'], 'progressBar' => isset($args['tabProgress']) && $args['tabProgress'] == true)); } // Output the dynamic tab content $pageIdx = 0; foreach ($tabHtml as $tab => $tabContent) { // get a machine readable alias for the heading $tabalias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $r .= '<div id="' . $tabalias . '">' . "\n"; // For wizard include the tab title as a header. if ($args['interface'] != 'tabs') { $r .= '<h1>' . $headerOptions['tabs']['#' . $tabalias] . '</h1>'; } $r .= $tabContent; // Add any buttons required at the bottom of the tab if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('classRedisplay' => 'ui-widget-content ui-state-default ui-corner-all indicia-button tab-submit-redisplay', 'captionSaveRedisplay' => 'save and redisplay', 'divId' => 'controls', 'page' => $pageIdx === 0 ? 'first' : ($pageIdx == count($tabs) - 1 ? 'last' : 'middle'))); } elseif ($pageIdx == count($tabs) - 1 && !($args['interface'] == 'tabs' && $args['save_button_below_all_pages'])) { // last part of a non wizard interface must insert a save button, unless it is tabbed interface with save button beneath all pages $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save') . "\" />\n"; $r .= "<input type=\"submit\" name=\"navigate:newoccurrence\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save_and_New') . "\" />\n"; $r .= "<input type=\"button\" class=\"ui-state-default ui-corner-all\"value=\"" . lang::get('LANG_Cancel') . "\" onclick=\"window.location.href='" . $cancelUrl . "'\" >\n"; } $pageIdx++; $r .= "</div>\n"; } $r .= "</div>\n"; if ($args['interface'] == 'tabs' && $args['save_button_below_all_pages']) { $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save') . "\" />\n"; $r .= "<input type=\"submit\" name=\"navigate:newoccurrence\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save_and_New') . "\" />\n"; $r .= "<input type=\"button\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Cancel') . "\" onclick=\"window.location.href='" . $cancelUrl . "'\" >\n"; } if (!empty(data_entry_helper::$validation_errors)) { $r .= data_entry_helper::dump_remaining_errors(); } $r .= "</form>"; $url = self::$svcUrl . "/data/sample/" . data_entry_helper::$entity_to_load['sample:parent_id']; $url .= "?mode=json&view=detail&auth_token=" . self::$auth['read']['auth_token'] . "&nonce=" . self::$auth['read']['nonce']; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); if (isset($entity['error'])) { throw new Exception($entity['error']); } data_entry_helper::$javascript .= "\n// Create a vector layer to display the supersample location\n// the default edit layer is used for the subsamples\nSSStyleMap = new OpenLayers.StyleMap({\n \"default\": new OpenLayers.Style({\n fillColor: \"Green\",\n strokeColor: \"Black\",\n fillOpacity: 0.2,\n strokeWidth: 1\n })\n });\nSSLayer = new OpenLayers.Layer.Vector(\"" . lang::get("LANG_Supersample_Layer") . "\",\n {styleMap: SSStyleMap});\nSSparser = new OpenLayers.Format.WKT();\nSSfeature = SSparser.read('" . $entity[0]['wkt'] . "');\nSSLayer.addFeatures([SSfeature]);\n"; // The map can get initialised an awful lot later (eg when the tab it is on is displayed). // It is therefore virtually impossible to zoom to this supersample in as the code is not templated return $r; }