/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args) { $r = "<form method=\"post\">\n"; // Get authorisation tokens to update and read from the Warehouse. $r .= data_entry_helper::get_auth(1, 'password'); $readAuth = data_entry_helper::get_read_auth($args['website_id'], $args['password']); $r .= '<input type="hidden" name="website_id" value="' . $args['website_id'] . '" />' . "\n"; $r .= '<input type="hidden" name="sample:survey_id" value="' . $args['survey_id'] . '" />' . "\n"; $r .= "<input type=\"hidden\" id=\"record_status\" value=\"C\" />\n"; $r .= data_entry_helper::autocomplete(array('label' => 'Species', 'fieldname' => 'occurrence:taxa_taxon_list_id', 'table' => 'taxa_taxon_list', 'captionField' => 'taxon', 'valueField' => 'id', 'extraParams' => $readAuth + array('taxon_list_id' => $args['taxon_list_id']))); $r .= data_entry_helper::date_picker(array('label' => 'Date', 'fieldname' => 'sample:date')); $r .= data_entry_helper::map(); $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"Save\" />\n"; $r .= "</form>"; return $r; }
/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args) { data_entry_helper::enable_tabs(array('divId' => 'controls')); $r = "<form method=\"post\">\n"; // Get authorisation tokens to update and read from the Warehouse. $r .= data_entry_helper::get_auth($args['website_id'], $args['password']); $readAuth = data_entry_helper::get_read_auth($args['website_id'], $args['password']); $r .= "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n"; $r .= "<input type=\"hidden\" id=\"record_status\" name=\"record_status\" value=\"C\" />\n"; $r .= "<div id=\"controls\">\n"; // Create a list which jQuery can parse to create the tabs. $r .= "<ul>\r\n <li><a href=\"#recorder\"><span>Recorder</span></a></li>\r\n <li><a href=\"#site\"><span>Site</span></a></li>\r\n <li><a href=\"#species_tab_1\"><span>" . $args['tab_title_1'] . "</span></a></li>\n"; if ($args['list_id_2']) { $r .= "<li><a href=\"#species_tab_2\"><span>" . $args['tab_title_2'] . "</span></a></li>\n"; } if ($args['list_id_3']) { $r .= "<li><a href=\"#species_tab_3\"><span>" . $args['tab_title_3'] . "</span></a></li>\n"; } if ($args['list_id_4']) { $r .= "<li><a href=\"#species_tab_4\"><span>" . $args['tab_title_4'] . "</span></a></li>\n"; } $r .= "</ul>\n"; $r .= "<div id=\"recorder\">\n"; $r .= data_entry_helper::select(array('label' => 'Title', 'fieldname' => 'smpAttr:5', 'table' => 'termlists_term', 'captionField' => 'term', 'valueField' => 'id', 'extraParams' => $readAuth + array('termlist_external_key' => 'indicia:titles'))); $r .= data_entry_helper::text_input(array('label' => 'First name', 'fieldname' => 'smpAttr:6')); $r .= data_entry_helper::text_input(array('label' => 'Last name', 'fieldname' => 'smpAttr:7')); $r .= data_entry_helper::text_input(array('label' => 'Email', 'fieldname' => 'smpAttr:8')); // Postcode before address since entering the postcode auto-populates part of the address. $r .= data_entry_helper::postcode_textbox(array('label' => 'Postcode', 'fieldname' => 'smpAttr:10', 'linkedAddressBoxId' => 'address', 'hiddenFields' => false)); $r .= data_entry_helper::textarea(array('label' => 'Address', 'fieldname' => 'smpAttr:9', 'id' => 'address')); $r .= "</div>\n"; $r .= "<div id=\"site\">\n"; $r .= data_entry_helper::map(); $r .= data_entry_helper::date_picker(array('label' => 'Date', 'fieldname' => 'sample:date')); $r .= "</div>\n"; $r .= "<div id=\"species_tab_1\">\n"; $species_list_args = array('label' => 'Species', 'fieldname' => 'occurrence:taxa_taxon_list_id', 'table' => 'taxa_taxon_list', 'captionField' => 'taxon', 'valueField' => 'id', 'columns' => 2, 'extraParams' => $readAuth + array('taxon_list_id' => $args['list_id_1'])); $r .= data_entry_helper::species_checklist($species_list_args); $r .= "</div>\n"; $r .= "</div>\n"; $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"Save\" />\n"; $r .= "</form>"; return $r; }
/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args) { $r = "<form method=\"post\">\n"; // Get authorisation tokens to update and read from the Warehouse. $r .= data_entry_helper::get_auth($args['website_id'], $args['password']); $readAuth = data_entry_helper::get_read_auth($args['website_id'], $args['password']); $r .= "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n"; $r .= "<input type=\"hidden\" id=\"record_status\" name=\"record_status\" value=\"C\" />\n"; $r .= "<div id=\"controls\">\n"; if ($args['tabs']) { $r .= "<ul>\n <li><a href=\"#species\"><span>Species</span></a></li>\n <li><a href=\"#place\"><span>Place</span></a></li>\n <li><a href=\"#other\"><span>Other Information</span></a></li>\n </ul>\n"; data_entry_helper::enable_tabs(array('divId' => 'controls')); } $r .= "<div id=\"species\">\n"; $extraParams = $readAuth + array('taxon_list_id' => $args['list_id']); if ($args['preferred']) { $extraParams += array('preferred' => 't'); } $species_list_args = array('label' => 'Species', 'itemTemplate' => 'select_species', 'fieldname' => 'occurrence:taxa_taxon_list_id', 'table' => 'taxa_taxon_list', 'captionField' => 'taxon', 'valueField' => 'id', 'columns' => 2, 'extraParams' => $extraParams); // Dynamically generate the species selection control required. $r .= call_user_func(array('data_entry_helper', $args['species_ctrl']), $species_list_args); $r .= "</div>\n"; $r .= "<div id=\"place\">\n"; // for this form, use bing and no geoplanet lookup, since then it requires no API keys so is a good // quick demo of how things work. $mapOptions = array('presetLayers' => array('bing_aerial'), 'locate' => false); if ($args['tabs']) { $mapOptions['tabDiv'] = 'place'; } $r .= data_entry_helper::map($mapOptions); $r .= "</div>\n"; $r .= "<div id=\"other\">\n"; $r .= data_entry_helper::date_picker(array('label' => 'Date', 'fieldname' => 'sample:date')); $r .= data_entry_helper::select(array('label' => 'Survey', 'fieldname' => 'sample:survey_id', 'table' => 'survey', 'captionField' => 'title', 'valueField' => 'id', 'extraParams' => $readAuth)); $r .= data_entry_helper::textarea(array('label' => 'Comment', 'fieldname' => 'sample:comment', 'class' => 'wide')); $r .= "</div>\n"; $r .= "</div>\n"; $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"Save\" />\n"; $r .= "</form>"; return $r; }
/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args, $node) { global $user; // There is a language entry in the args parameter list: this is derived from the $language DRUPAL global. // It holds the 2 letter code, used to pick the language file from the lang subdirectory of prebuilt_forms. // There should be no explicitly output text in this file. // We must translate any field names and ensure that the termlists and taxonlists use the correct language. // For attributes, the caption is automatically translated by data_entry_helper. $logged_in = $user->uid > 0; $uid = $user->uid; $email = $user->mail; $username = $user->name; if (!user_access('IForm n' . $node->nid . ' access')) { return "<p>" . lang::get('LANG_Insufficient_Privileges') . "</p>"; } $r = ''; // Get authorisation tokens to update and read from the Warehouse. $readAuth = data_entry_helper::get_read_auth($args['website_id'], $args['password']); $svcUrl = data_entry_helper::$base_url . '/index.php/services'; drupal_add_js(drupal_get_path('module', 'iform') . '/media/js/jquery.form.js', 'module'); data_entry_helper::link_default_stylesheet(); data_entry_helper::add_resource('jquery_ui'); data_entry_helper::enable_validation('cc-1-collection-details'); // don't care about ID itself, just want resources if ($args['help_module'] != '' && $args['help_inclusion_function'] != '' && module_exists($args['help_module']) && function_exists($args['help_inclusion_function'])) { $use_help = true; data_entry_helper::$javascript .= call_user_func($args['help_inclusion_function']); } else { $use_help = false; } if ($args['ID_tool_module'] != '' && $args['ID_tool_inclusion_function'] != '' && module_exists($args['ID_tool_module']) && function_exists($args['ID_tool_inclusion_function'])) { $use_ID_tool = true; data_entry_helper::$javascript .= call_user_func($args['ID_tool_inclusion_function']); } else { $use_ID_tool = false; } // The only things that will be editable after the collection is saved will be the identifiaction of the flower/insects. // no id - just getting the attributes, rest will be filled in using AJAX $sample_attributes = data_entry_helper::getAttributes(array('valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $readAuth, 'survey_id' => $args['survey_id'])); $occurrence_attributes = data_entry_helper::getAttributes(array('valuetable' => 'occurrence_attribute_value', 'attrtable' => 'occurrence_attribute', 'key' => 'occurrence_id', 'fieldprefix' => 'occAttr', 'extraParams' => $readAuth, 'survey_id' => $args['survey_id'])); $location_attributes = data_entry_helper::getAttributes(array('valuetable' => 'location_attribute_value', 'attrtable' => 'location_attribute', 'key' => 'location_id', 'fieldprefix' => 'locAttr', 'extraParams' => $readAuth, 'survey_id' => $args['survey_id'])); $defAttrOptions = array('extraParams' => $readAuth, 'lookUpListCtrl' => 'radio_group', 'validation' => array('required'), 'language' => iform_lang_iso_639_2($args['language']), 'containerClass' => 'group-control-box', 'suffixTemplate' => 'nosuffix'); $language = iform_lang_iso_639_2($args['language']); global $indicia_templates; $indicia_templates['sref_textbox_latlong'] = '<label for="{idLat}">{labelLat}:</label>' . '<input type="text" id="{idLat}" name="{fieldnameLat}" {class} {disabled} value="{default}" />' . '<label for="{idLong}">{labelLong}:</label>' . '<input type="text" id="{idLong}" name="{fieldnameLong}" {class} {disabled} value="{default}" />'; $r .= data_entry_helper::loading_block_start(); // note we have to proxy the post. Every time a write transaction is carried out, the write nonce is trashed. // For security reasons we don't want to give the user the ability to generate their own nonce, so we use // the fact that the user is logged in to drupal as the main authentication/authorisation/identification // process for the user. The proxy packages the post into the correct format // // There are 2 types of submission: // When a user validates a panel using the validate button, the following panel is opened on success // When a user presses a modify button, the open panel gets validated, and the panel to be modified is opened. $r .= ' <div id="cc-1" class="poll-section"> <div id="cc-1-title" class="ui-accordion-header ui-helper-reset ui-state-active ui-corner-top poll-section-title"> <span id="cc-1-title-details">' . lang::get('LANG_Collection_Details') . '</span> <div class="right"> <div> <span id="cc-1-reinit-button" class="ui-state-default ui-corner-all reinit-button">' . lang::get('LANG_Reinitialise') . '</span> <span id="cc-1-mod-button" class="ui-state-default ui-corner-all mod-button">' . lang::get('LANG_Modify') . '</span> </div> </div> </div> <div id="cc-1-details" class="ui-accordion-content ui-helper-reset ui-widget-content ui-accordion-content-active"> <span id="cc-1-protocol-details"></span> </div> <div id="cc-1-body" class="ui-accordion-content ui-helper-reset ui-widget-content ui-accordion-content-active poll-section-body"> <form id="cc-1-collection-details" action="' . iform_ajaxproxy_url($node, 'loc-sample') . '" method="POST"> <input type="hidden" id="website_id" name="website_id" value="' . $args['website_id'] . '" /> <input type="hidden" id="imp-sref" name="location:centroid_sref" value="" /> <input type="hidden" id="imp-geom" name="location:centroid_geom" value="" /> <input type="hidden" id="imp-sref-system" name="location:centroid_sref_system" value="4326" /> <input type="hidden" id="sample:survey_id" name="sample:survey_id" value="' . $args['survey_id'] . '" /> ' . iform_pollenators::help_button($use_help, "collection-help-button", $args['help_function'], $args['help_collection_arg']) . ' <label for="location:name">' . lang::get('LANG_Collection_Name_Label') . '</label> <input type="text" id="location:name" name="location:name" value="" class="required"/> <input type="hidden" id="sample:location_name" name="sample:location_name" value=""/> ' . data_entry_helper::outputAttribute($sample_attributes[$args['protocol_attr_id']], $defAttrOptions) . ' <input type="hidden" name="sample:date" value="2010-01-01"/> <input type="hidden" id="smpAttr:' . $args['complete_attr_id'] . '" name="smpAttr:' . $args['complete_attr_id'] . '" value="0" /> <input type="hidden" id="smpAttr:' . $args['uid_attr_id'] . '" name="smpAttr:' . $args['uid_attr_id'] . '" value="' . $uid . '" /> <input type="hidden" id="smpAttr:' . $args['email_attr_id'] . '" name="smpAttr:' . $args['email_attr_id'] . '" value="' . $email . '" /> <input type="hidden" id="smpAttr:' . $args['username_attr_id'] . '" name="smpAttr:' . $args['username_attr_id'] . '" value="' . $username . '" /> <input type="hidden" id="locations_website:website_id" name="locations_website:website_id" value="' . $args['website_id'] . '" /> <input type="hidden" id="location:id" name="location:id" value="" disabled="disabled" /> <input type="hidden" id="sample:id" name="sample:id" value="" disabled="disabled" /> </form> <div id="cc-1-valid-button" class="ui-state-default ui-corner-all save-button">' . lang::get('LANG_Validate') . '</div> </div> <div style="display:none" /> <form id="cc-1-delete-collection" action="' . iform_ajaxproxy_url($node, 'sample') . '" method="POST"> <input type="hidden" name="website_id" value="' . $args['website_id'] . '" /> <input type="hidden" name="sample:survey_id" value="' . $args['survey_id'] . '" /> <input type="hidden" name="sample:id" value="" /> <input type="hidden" name="sample:date" value="2010-01-01"/> <input type="hidden" name="sample:location_id" value="" /> <input type="hidden" name="sample:deleted" value="t" /> </form> </div> <div id="cc-1-main-body" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active"> '; data_entry_helper::$javascript .= "\n\$.validator.messages.required = \"" . lang::get('validation_required') . "\";\nvar sessionCounter = 0;\n\n\$.fn.foldPanel = function(){\n\tthis.children('.poll-section-body').addClass('poll-hide');\n\tthis.children('.poll-section-footer').addClass('poll-hide');\n\tthis.children('.poll-section-title').find('.reinit-button').show();\n\tthis.children('.poll-section-title').find('.mod-button').show();\n\tthis.children('.photoReelContainer').addClass('ui-corner-all').removeClass('ui-corner-top')\n};\n\n\$.fn.unFoldPanel = function(){\n\tthis.children('.poll-section-body').removeClass('poll-hide');\n\tthis.children('.poll-section-footer').removeClass('poll-hide');\n\tthis.children('.poll-section-title').find('.mod-button').hide();\n\tthis.children('.photoReelContainer').addClass('ui-corner-top').removeClass('ui-corner-all')\n\twindow.scroll(0,0); // force the window to display the top.\n\t// any reinit button is left in place\n};\n\n// because the map has to be generated in a properly sized div, we can't use the normal hide/show functions.\n// just move the panels off to the side.\n\$.fn.showPanel = function(){\n\tthis.removeClass('poll-hide');\n\tthis.unFoldPanel();\n};\n\n\$.fn.hidePanel = function(){\n\tthis.addClass('poll-hide'); \n};\n\ninseeLayer = null;\n\ndefaultSref = '" . ((int) $args['map_centroid_lat'] > 0 ? $args['map_centroid_lat'] . 'N' : -(int) $args['map_centroid_lat'] . 'S') . ' ' . ((int) $args['map_centroid_long'] > 0 ? $args['map_centroid_long'] . 'E' : -(int) $args['map_centroid_long'] . 'W') . "';\ndefaultGeom = '';\n\$.getJSON('" . $svcUrl . "' + '/spatial/sref_to_wkt'+\n \t\t\t'?sref=' + defaultSref +\n \t\t\t'&system=' + jQuery('#imp-sref-system').val() +\n \t\t\t'&callback=?', function(data) {\n \tdefaultGeom = data.wkt;\n \t});\n\n\$.fn.resetPanel = function(){\n\tthis.find('.poll-section-body').removeClass('poll-hide');\n\tthis.find('.poll-section-footer').removeClass('poll-hide');\n\tthis.find('.reinit-button').show();\n\tthis.find('.mod-button').show();\n\tthis.find('.poll-image').empty();\n\tthis.find('.poll-session').empty();\n\n\t// resetForm does not reset the hidden fields. record_status, imp-sref-system, website_id and survey_id are not altered so do not reset.\n\t// hidden Attributes generally hold unchanging data, but the name needs to be reset (does it for non hidden as well).\n\t// hidden location:name are set in code anyway.\n\tthis.find('form').each(function(){\n\t\tjQuery(this).resetForm();\n\t\tjQuery(this).find('[name=sample\\:location_name],[name=location_image\\:path],[name=occurrence_image\\:path]').val('');\n\t\tjQuery(this).filter('#cc-1-collection-details').find('[name=sample\\:id],[name=location\\:id]').val('').attr('disabled', 'disabled');\n\t\tjQuery(this).find('[name=location_image\\:id],[name=occurrence\\:id],[name=occurrence_image\\:id]').val('').attr('disabled', 'disabled');\n\t\tjQuery(this).find('[name=sample\\:date]:hidden').val('2010-01-01');\t\t\n jQuery(this).find('input[name=locations_website\\:website_id]').removeAttr('disabled');\n\t\tjQuery(this).find('[name^=smpAttr\\:],[name^=locAttr\\:],[name^=occAttr\\:]').each(function(){\n\t\t\tvar name = jQuery(this).attr('name').split(':');\n\t\t\tjQuery(this).attr('name', name[0]+':'+name[1]);\n\t\t});\n\t\tjQuery(this).find('input[name=location\\:centroid_sref]').val('');\n\t\tjQuery(this).find('input[name=location\\:centroid_geom]').val('');\n });\t\n\tthis.find('.poll-dummy-form > input').val('');\n\tthis.find('.poll-dummy-form > select').val('');\n };\n\ncheckProtocolStatus = function(){\n\tif (jQuery('#cc-3-body').children().length === 1) {\n\t jQuery('#cc-3').find('.delete-button').hide();\n \t} else {\n\t\tjQuery('#cc-3').find('.delete-button').show();\n\t}\n\tif(jQuery('[name=smpAttr\\:" . $args['protocol_attr_id'] . "],[name^=smpAttr\\:" . $args['protocol_attr_id'] . "\\:]').filter(':first').filter('[checked]').length >0){\n\t jQuery('#cc-3').find('.add-button').hide();\n\t} else {\n\t jQuery('#cc-3').find('.add-button').show();\n \t}\n \tvar checkedProtocol = jQuery('[name=smpAttr\\:" . $args['protocol_attr_id'] . "],[name^=smpAttr\\:" . $args['protocol_attr_id'] . "\\:]').filter('[checked]').parent();\n if(jQuery('[name=location\\:name]').val() != '' && checkedProtocol.length > 0) {\n jQuery('#cc-1-title-details').empty().text(jQuery('#cc-1-collection-details input[name=location\\:name]:first').val());\n jQuery('#cc-1-protocol-details').empty().show().text(\"" . lang::get('LANG_Protocol_Title_Label') . " : \" + checkedProtocol.find('label')[0].innerHTML;\n } else {\n jQuery('#cc-1-title-details').empty().text(\"" . lang::get('LANG_Collection_Details') . "\");\n // TODO autogenerate a name\n jQuery('#cc-1-protocol-details').empty().hide();\n }\n};\n\nshowStationPanel = true;\n\n// The validate functionality for each panel is sufficiently different that we can't generalise a function\n// this is the one called when we don't want the panel following to be opened automatically.\nvalidateCollectionPanel = function(){\n\tif(jQuery('#cc-1-body').filter('.poll-hide').length > 0) return true; // body hidden so data already been validated successfully.\n\tif(!jQuery('#cc-1-body').find('form > input').valid()){ return false; }\n\t// no need to check protocol - if we are this far, we've already filled it in.\n \tshowStationPanel = false;\n\tjQuery('#cc-1-collection-details').submit();\n\treturn true;\n };\n\nvalidateRadio = function(name, formSel){\n var controls = jQuery(formSel).find('[name='+name+'],[name^='+name+'\\:]');\n\tcontrols.parent().parent().find('p').remove(); // remove existing errors\n if(controls.filter('[checked]').length < 1) {\n var label = \$('<p/>')\n\t\t\t\t.attr({'for': name})\n\t\t\t\t.addClass('radio-error')\n\t\t\t\t.html(\$.validator.messages.required);\n\t\tlabel.insertBefore(controls.filter(':first').parent());\n\t\treturn false;\n }\n return true;\n}\n\nvalidateRequiredField = function(name, formSel){\n var control = jQuery(formSel).find('[name='+name+']');\n\tcontrol.parent().find('.required-error').remove(); // remove existing errors\n if(control.val() == '') {\n var label = \$('<p/>')\n\t\t\t\t.attr({'for': name})\n\t\t\t\t.addClass('required-error')\n\t\t\t\t.html(\$.validator.messages.required);\n\t\tlabel.insertBefore(control);\n\t\treturn false;\n }\n return true;\n}\n\n\$('#cc-1-collection-details').ajaxForm({ \n // dataType identifies the expected content type of the server response \n dataType: 'json', \n // success identifies the function to invoke when the server response \n // has been received \n beforeSubmit: function(data, obj, options){\n \tvar valid = true;\n \tif (!jQuery('form#cc-1-collection-details > input').valid()) { valid = false; }\n \tif (!validateRadio('smpAttr\\:" . $args['protocol_attr_id'] . "', 'form#cc-1-collection-details')) { valid = false; }\n\t \tif ( valid == false ) return valid;\n \t\t\t// Warning this assumes that:\n \t\t\t// 1) the location:name is the sixth field in the form.\n \t\t\t// 1) the sample:location_name is the seventh field in the form.\n \t\t\tdata[6].value = data[5].value;\n \t\t\tif(data[1].value=='') data[1].value=defaultSref;\n \t\t\tif(data[2].value=='') data[2].value=defaultGeom;\n \t\t\tjQuery('#cc-2-floral-station > input[name=location\\:name]').val(data[5].value);\n \treturn true;\n \t\t},\n success: function(data){\n \tif(data.success == 'multiple records' && data.outer_table == 'location'){\n \t jQuery('#cc-1-collection-details > input[name=location\\:id]').removeAttr('disabled').val(data.outer_id);\n \t jQuery('#cc-1-collection-details > input[name=locations_website\\:website_id]').attr('disabled', 'disabled');\n \t jQuery('#cc-2-floral-station > input[name=location\\:id]').removeAttr('disabled').val(data.outer_id);\n \t \$.getJSON(\"" . $svcUrl . "\" + \"/data/sample\" +\n\t\t\t \"?mode=json&view=detail&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" +\n\t\t\t \"&location_id=\"+data.outer_id+\"&parent_id=NULL&callback=?\", function(data) {\n\t\t\t\t\tif (data.length>0) {\n\t\t\t \t\t jQuery('#cc-6-consult-collection').attr('href', '" . url('node/' . $args['gallery_node']) . "'+'?collection_id='+data[0].id);\n\t\t\t \t jQuery('#cc-1-collection-details > input[name=sample\\:id]').removeAttr('disabled').val(data[0].id);\n\t\t\t \t jQuery('#cc-2-floral-station > input[name=sample\\:id]').removeAttr('disabled').val(data[0].id);\n\t\t\t \t // In this case we use loadAttributes to set the names of the attributes to include the attribute_value id.\n \t \t\t\t\t\tloadAttributes('sample_attribute_value', 'sample_attribute_id', 'sample_id', 'sample\\:id', data[0].id, 'smpAttr');\n\t\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t \tcheckProtocolStatus();\n \t\t\$('#cc-1').foldPanel();\n \t\t\tif(showStationPanel){ \$('#cc-2').showPanel(); }\n\t\t \tshowStationPanel = true;\n \t} else {\n\t\t\t\tvar errorString = \"" . lang::get('LANG_Indicia_Warehouse_Error') . "\";\n\t\t\t\tif(data.error){\n\t\t\t\t\terrorString = errorString + ' : ' + data.error;\n\t\t\t\t}\n\t\t\t\tif(data.errors){\n\t\t\t\t\tfor (var i in data.errors)\n\t\t\t\t\t{\n\t\t\t\t\t\terrorString = errorString + ' : ' + data.errors[i];\n\t\t\t\t\t}\t\t\t\t\n\t\t\t\t}\n\t\t\t\talert(errorString);\n\t\t\t}\n } \n});\n\n\$('#cc-1-delete-collection').ajaxForm({ \n dataType: 'json', \n beforeSubmit: function(data, obj, options){\n \t\t\t// Warning this assumes that the data is fixed position:\n \t\tdata[2].value = jQuery('#cc-1-collection-details input[name=sample\\:id]').val();\n \t\tdata[3].value = jQuery('#cc-1-collection-details input[name=sample\\:date]').val();\n \t\tdata[4].value = jQuery('#cc-1-collection-details input[name=location\\:id]').val();\n \tif(data[2].value == '') return false;\n \treturn true;\n \t\t},\n success: function(data){\n\t\t\tjQuery('#cc-3-body').empty();\n \tjQuery('.poll-section').resetPanel();\n\t\t\tsessionCounter = 0;\n\t\t\taddSession();\n\t\t\tcheckProtocolStatus();\n\t\t\tjQuery('.poll-section').hidePanel();\n\t\t\tjQuery('.poll-image').empty();\n\t\t\tjQuery('#cc-1').showPanel();\n\t\t\tjQuery('.reinit-button').hide();\n\t\t\tjQuery('#map')[0].map.editLayer.destroyFeatures();\n \t\t} \n});\n\n\$('#cc-1-valid-button').click(function() {\n\tjQuery('#cc-1-collection-details').submit();\n});\n\n\$('#cc-1-reinit-button').click(function() {\n\tif(jQuery('form#cc-1-collection-details > input[name=sample\\:id]').filter('[disabled]').length > 0) { return } // sample id is disabled, so no data has been saved - do nothing.\n if (!jQuery('form#cc-1-collection-details > input').valid()) {\n \talert(\"" . lang::get('LANG_Unable_To_Reinit') . "\");\n return ;\n \t}\n\tif(confirm(\"" . lang::get('LANG_Confirm_Reinit') . "\")){\n\t\tjQuery('#cc-1-delete-collection').submit();\n\t}\n});\n\n"; // Flower Station section. $options = iform_map_get_map_options($args, $readAuth); $olOptions = iform_map_get_ol_options($args); // The maps internal projection will be left at its default of 900913. $options['searchLayer'] = 'true'; $options['initialFeatureWkt'] = null; $options['proxy'] = ''; // Switch to degrees, minutes, seconds for lat long. $options['latLongFormat'] = 'DMS'; $options['suffixTemplate'] = 'nosuffix'; $extraParams = $readAuth + array('taxon_list_id' => $args['flower_list_id'], 'orderby' => 'taxon'); $species_ctrl_args = array('label' => lang::get('LANG_Flower_Species'), 'fieldname' => 'flower:taxa_taxon_list_id', 'table' => 'taxa_taxon_list', 'captionField' => 'taxon', 'valueField' => 'id', 'columns' => 2, 'validation' => array('required'), 'blankText' => lang::get('LANG_Choose_Taxon'), 'extraParams' => $extraParams, 'suffixTemplate' => 'nosuffix'); $r .= ' <div id="cc-2" class="poll-section"> <div id="cc-2-title" class="ui-accordion-header ui-helper-reset ui-state-active ui-corner-all poll-section-title"><span>' . lang::get('LANG_Flower_Station') . '</span> <div class="right"> <span id="cc-2-mod-button" class="ui-state-default ui-corner-all mod-button">' . lang::get('LANG_Modify') . '</span> </div> </div> <div id="cc-2-body" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-top ui-accordion-content-active poll-section-body"> <div id="cc-2-flower" > <form id="cc-2-flower-upload" enctype="multipart/form-data" action="' . iform_ajaxproxy_url($node, 'media') . '" method="POST"> <input type="hidden" id="website_id" name="website_id" value="' . $args['website_id'] . '" /> <input name="upload_file" type="file" class="required" /> <input type="submit" value="' . lang::get('LANG_Upload_Flower') . '" class="btn-submit" /> </form> <div id="cc-2-flower-image" class="poll-image"></div> <div id="cc-2-flower-identify" class="poll-dummy-form"> ' . iform_pollenators::help_button($use_help, "flower-help-button", $args['help_function'], $args['help_flower_arg']) . ' <p><strong>' . lang::get('LANG_Identify_Flower') . '</strong></p> <label for="id-flower-later" class="follow-on">' . lang::get('LANG_ID_Flower_Later') . ' </label><input type="checkbox" id="id-flower-later" name="id-flower-later" /> ' . ($args['ID_tool_flower_url'] != '' && $args['ID_tool_flower_poll_dir'] ? '<label for="flower-id-button">' . lang::get('LANG_Flower_ID_Key_label') . ' :</label><span id="flower-id-button" class="ui-state-default ui-corner-all poll-id-button" >' . lang::get('LANG_Launch_ID_Key') . '</span>' : '') . '<span id="flower-id-cancel" class="ui-state-default ui-corner-all poll-id-cancel" >' . lang::get('LANG_Cancel_ID') . '</span> ' . data_entry_helper::select($species_ctrl_args) . ' <input type="text" name="flower:taxon_text_description" readonly="readonly"> </div> </div> <div class="poll-break"></div> <div id="cc-2-environment"> <form id="cc-2-environment-upload" enctype="multipart/form-data" action="' . iform_ajaxproxy_url($node, 'media') . '" method="POST"> <input type="hidden" id="website_id" name="website_id" value="' . $args['website_id'] . '" /> <input name="upload_file" type="file" class="required" /> <input type="submit" value="' . lang::get('LANG_Upload_Environment') . '" class="btn-submit" /> </form> <div id="cc-2-environment-image" class="poll-image"></div> </div> <form id="cc-2-floral-station" action="' . iform_ajaxproxy_url($node, 'loc-smp-occ') . '" method="POST"> <input type="hidden" id="website_id" name="website_id" value="' . $args['website_id'] . '" /> <input type="hidden" id="location:id" name="location:id" value="" /> <input type="hidden" id="location:name" name="location:name" value=""/> <input type="hidden" name="location:centroid_sref" /> <input type="hidden" name="location:centroid_geom" /> <input type="hidden" name="location:centroid_sref_system" value="4326" /> <input type="hidden" id="location_image:path" name="location_image:path" value="" /> <input type="hidden" id="sample:survey_id" name="sample:survey_id" value="' . $args['survey_id'] . '" /> <input type="hidden" id="sample:id" name="sample:id" value=""/> <input type="hidden" name="sample:date" value="2010-01-01"/> <input type="hidden" name="determination:taxa_taxon_list_id" value=""/> <input type="hidden" name="determination:taxon_text_description" value=""/> <input type="hidden" name="determination:cms_ref" value="' . $uid . '" /> <input type="hidden" name="determination:email_address" value="' . $email . '" /> <input type="hidden" name="determination:person_name" value="' . $username . '" /> <input type="hidden" name="occurrence:use_determination" value="Y"/> <input type="hidden" name="occurrence:record_status" value="C" /> <input type="hidden" id="location_image:id" name="location_image:id" value="" disabled="disabled" /> <input type="hidden" id="occurrence:id" name="occurrence:id" value="" disabled="disabled" /> <input type="hidden" id="determination:id" name="determination:id" value="" disabled="disabled" /> <input type="hidden" id="occurrence_image:id" name="occurrence_image:id" value="" disabled="disabled" /> <input type="hidden" id="occurrence_image:path" name="occurrence_image:path" value="" /> ' . data_entry_helper::outputAttribute($occurrence_attributes[$args['flower_type_attr_id']], array('extraParams' => $readAuth, 'lookUpListCtrl' => 'radio_group', 'sep' => ' ', 'language' => iform_lang_iso_639_2($args['language']), 'containerClass' => 'group-control-box', 'suffixTemplate' => 'nosuffix')) . data_entry_helper::outputAttribute($location_attributes[$args['distance_attr_id']], array('extraParams' => $readAuth, 'lookUpListCtrl' => 'radio_group', 'sep' => ' ', 'language' => iform_lang_iso_639_2($args['language']), 'containerClass' => 'group-control-box', 'suffixTemplate' => 'nosuffix')) . data_entry_helper::outputAttribute($location_attributes[$args['habitat_attr_id']], array('extraParams' => $readAuth, 'lookUpListCtrl' => 'checkbox_group', 'sep' => ' ', 'language' => iform_lang_iso_639_2($args['language']), 'containerClass' => 'group-control-box', 'suffixTemplate' => 'nosuffix')) . ' </form> <div class="poll-break"></div> <div> ' . iform_pollenators::help_button($use_help, "location-help-button", $args['help_function'], $args['help_location_arg']) . ' <div>' . lang::get('LANG_Location_Notes') . '</div> <div class="poll-map-container"> '; $r .= data_entry_helper::map_panel($options, $olOptions); $r .= ' </div> <div><div id="cc-2-location-entry"> ' . data_entry_helper::georeference_lookup(array('label' => lang::get('LANG_Georef_Label'), 'georefPreferredArea' => $args['georefPreferredArea'], 'georefCountry' => $args['georefCountry'], 'georefLang' => $args['language'], 'suffixTemplate' => 'nosuffix')) . ' <span >' . lang::get('LANG_Georef_Notes') . '</span> <label for="place:INSEE">' . lang::get('LANG_Or') . '</label> <input type="text" id="place:INSEE" name="place:INSEE" value="' . lang::get('LANG_INSEE') . '" onclick="if(this.value==\'' . lang::get('LANG_INSEE') . '\'){this.value=\'\'; this.style.color=\'#000\'}" onblur="if(this.value==\'\'){this.value=\'' . lang::get('LANG_INSEE') . '\'; this.style.color=\'#555\'}" /> <input type="button" id="search-insee-button" class="ui-corner-all ui-widget-content ui-state-default search-button" value="Search" /> ' . data_entry_helper::sref_textbox(array('srefField' => 'place:entered_sref', 'systemfield' => 'place:entered_sref_system', 'id' => 'place-sref', 'fieldname' => 'place:name', 'splitLatLong' => true, 'labelLat' => lang::get('Latitude'), 'fieldnameLat' => 'place:lat', 'labelLong' => lang::get('Longitude'), 'fieldnameLong' => 'place:long', 'idLat' => 'imp-sref-lat', 'idLong' => 'imp-sref-long', 'suffixTemplate' => 'nosuffix')) . ' </div></div> <div id="cc-2-loc-description"></div> </div> </div> <div id="cc-2-footer" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active poll-section-footer"> <div id="cc-2-valid-button" class="ui-state-default ui-corner-all save-button">' . lang::get('LANG_Validate_Flower') . '</div> </div> </div>'; // NB the distance attribute is left blank at the moment if unknown: TODO put in a checkbox : checked if blank for nsp data_entry_helper::$javascript .= "\n\nshowSessionsPanel = true;\n\nvar flowerTimer1;\nvar flowerTimer2;\nvar IDcounter = 0;\n\nflowerPoller = function(){\n\tflowerTimer1 = setTimeout('flowerPoller();', " . $args['ID_tool_poll_interval'] . ");\n\t\$.get('" . str_replace("{HOST}", $_SERVER['HTTP_HOST'], $args['ID_tool_flower_poll_dir']) . session_id() . "_'+IDcounter.toString(), function(data){\n var da = data.split('\\n');\n // first count number of returned items.\n // if > 1 put all into taxon_description.\n // if = 1 rip out the description, remove the formatting, scan the flower select for it, and set the value. Set the taxon description.\n\t da[1] = da[1].replace(/\\\\\\\\i\\{\\}/g, '').replace(/\\\\\\\\i0\\{\\}/g, '');\n var items = da[1].split(':');\n\t var count = items.length;\n\t if(items[count-1] == '') count--;\n\t if(count <= 0){\n\t \t// no valid stuff so blank it all out.\n\t \tjQuery('#cc-2-flower-identify > select[name=flower\\:taxa_taxon_list_id]').val('');\n\t \tjQuery('#cc-2-flower-identify > select[name=flower\\:taxon_text_description]').val('');\n\t } else if(count == 1){\n\t \tjQuery('#cc-2-flower-identify > select[name=flower\\:taxa_taxon_list_id]').val('');\n\t \tjQuery('#cc-2-flower-identify > select[name=flower\\:taxon_text_description]').val(items[0]);\n \t\tvar x = jQuery('#cc-2-flower-identify').find('option').filter('[text='+items[0]+']');\n\t \tif(x.length > 0){\n\t\t\tjQuery('#cc-2-flower-identify > select[name=flower\\:taxon_text_description]').val('');\n\t \t\tjQuery('#cc-2-flower-identify > select[name=flower\\:taxa_taxon_list_id]').val(x[0].value);\n \t\t}\n\t } else {\n\t \tjQuery('#cc-2-flower-identify > select[name=flower\\:taxa_taxon_list_id]').val('');\n\t \tjQuery('#cc-2-flower-identify > select[name=flower\\:taxon_text_description]').val(da[1]);\n\t }\n\t flowerReset();\n });\n};\nflowerReset = function(){\n\tclearTimeout(flowerTimer1);\n\tclearTimeout(flowerTimer2);\n\tjQuery('#flower-id-cancel').hide();\n};\n\njQuery('#flower-id-button').click(function(){\n\tIDcounter++;\n\tclearTimeout(flowerTimer1);\n\tclearTimeout(flowerTimer2);\n\twindow.open('" . $args['ID_tool_flower_url'] . session_id() . "_'+IDcounter.toString(),'','') \n\tflowerTimer1 = setTimeout('flowerPoller();', " . $args['ID_tool_poll_interval'] . ");\n\tflowerTimer2 = setTimeout('flowerReset();', " . $args['ID_tool_poll_timeout'] . ");\n\tjQuery('#flower-id-cancel').show();\n});\njQuery('#flower-id-cancel').click(function(){\n\tflowerReset();\n});\njQuery('#flower-id-cancel').hide();\n\njQuery('#search-insee-button').click(function(){\n\tif(inseeLayer != null)\n\t\tinseeLayer.destroy();\n\tvar filters = [];\n \tvar place = jQuery('input[name=place\\:INSEE]').val();\n \tif(place == '" . lang::get('LANG_INSEE') . "') return;\n \tfilters.push(new OpenLayers.Filter.Comparison({\n \t\t\ttype: OpenLayers.Filter.Comparison.EQUAL_TO ,\n \t\tproperty: 'INSEE_NEW',\n \t\tvalue: place\n \t\t}));\n \tfilters.push(new OpenLayers.Filter.Comparison({\n \t\t\ttype: OpenLayers.Filter.Comparison.EQUAL_TO ,\n \t\tproperty: 'INSEE_OLD',\n \t\tvalue: place\n \t\t}));\n\n\tvar strategy = new OpenLayers.Strategy.Fixed({preload: false, autoActivate: false});\n\tvar styleMap = new OpenLayers.StyleMap({\n \"default\": new OpenLayers.Style({\n fillColor: \"Red\",\n strokeColor: \"Red\",\n fillOpacity: 0,\n strokeWidth: 1\n })\n\t});\n\tinseeLayer = new OpenLayers.Layer.Vector('INSEE Layer', {\n\t\t styleMap: styleMap,\n strategies: [strategy],\n displayInLayerSwitcher: false,\n\t protocol: new OpenLayers.Protocol.WFS({\n url: '" . str_replace("{HOST}", $_SERVER['HTTP_HOST'], $args['INSEE_url']) . "',\n featurePrefix: '" . $args['INSEE_prefix'] . "',\n featureType: '" . $args['INSEE_type'] . "',\n geometryName:'the_geom',\n featureNS: '" . $args['INSEE_ns'] . "',\n srsName: 'EPSG:900913',\n version: '1.1.0' \n \t\t ,propertyNames: ['the_geom']\n \t\t\t})\n });\n\tinseeLayer.events.register('featuresadded', {}, function(a1){\n\t\tvar div = jQuery('#map')[0];\n\t\tdiv.map.searchLayer.destroyFeatures();\n\t\tvar bounds=inseeLayer.getDataExtent();\n \tvar dy = (bounds.top-bounds.bottom)/10;\n \tvar dx = (bounds.right-bounds.left)/10;\n \tbounds.top = bounds.top + dy;\n \tbounds.bottom = bounds.bottom - dy;\n \tbounds.right = bounds.right + dx;\n \tbounds.left = bounds.left - dx;\n \t// if showing a point, don't zoom in too far\n \tif (dy===0 && dx===0) {\n \t\tdiv.map.setCenter(bounds.getCenterLonLat(), div.settings.maxZoom);\n \t} else {\n \t\tdiv.map.zoomToExtent(bounds);\n \t}\n });\n\tinseeLayer.events.register('loadend', {}, function(){\n\t\tif(inseeLayer.features.length == 0){\n\t\t\talert(\"" . lang::get('LANG_NO_INSEE') . "\");\n\t\t}\n });\n jQuery('#map')[0].map.addLayer(inseeLayer);\n\tstrategy.load({filter: new OpenLayers.Filter.Logical({\n\t\t\t type: OpenLayers.Filter.Logical.OR,\n\t\t\t filters: filters\n\t\t \t })});\n});\n\nvalidateStationPanel = function(){\n\tvar myPanel = jQuery('#cc-2');\n\tvar valid = true;\n\tif(myPanel.filter('.poll-hide').length > 0) return true; // panel is not visible so no data to fail validation.\n\tif(myPanel.find('.poll-section-body').filter('.poll-hide').length > 0) return true; // body hidden so data already been validated successfully.\n\t// If no data entered also return true: this can only be the case when pressing the modify button on the collections panel\n\tif(jQuery('form#cc-2-floral-station > input[name=location_image\\:path]').val() == '' &&\n\t\t\tjQuery('form#cc-2-floral-station > input[name=occurrence\\:id]').val() == '' &&\n\t\t\tjQuery('form#cc-2-floral-station > input[name=occurrence_image\\:path]').val() == '' &&\n\t\t\tjQuery('#cc-2-flower-identify > select[name=flower\\:taxa_taxon_list_id]').val() == '' &&\n \t\tjQuery('[name=occAttr\\:" . $args['flower_type_attr_id'] . "],[name^=occAttr\\:" . $args['flower_type_attr_id'] . "\\:]').filter('[checked]').length == 0 &&\n \t\tjQuery('[name=locAttr\\:" . $args['habitat_attr_id'] . "],[name^=locAttr\\:" . $args['habitat_attr_id'] . "\\:]').filter('[checked]').length == 0 &&\n \t\tjQuery('[name=locAttr\\:" . $args['distance_attr_id'] . "],[name^=locAttr\\:" . $args['distance_attr_id'] . "\\:]').val() == '') {\n\t\tjQuery('#cc-2').foldPanel();\n\t\treturn true;\n\t}\n if(jQuery('form#cc-2-floral-station > input[name=location_image\\:path]').val() == '' ||\n\t\t\t\t\tjQuery('form#cc-2-floral-station > input[name=occurrence_image\\:path]').val() == ''){\n\t\talert(\"" . lang::get('LANG_Must_Provide_Pictures') . "\");\n\t\tvalid = false;\n\t}\n if(jQuery('#imp-geom').val() == '') {\n\t\talert(\"" . lang::get('LANG_Must_Provide_Location') . "\");\n\t\tvalid = false;\n\t}\n\tif (jQuery('#id-flower-later').attr('checked') == ''){\n\t\tif(!validateRequiredField('flower\\:taxa_taxon_list_id', '#cc-2-flower-identify')) { valid = false; }\n\t}\n\tif (!jQuery('form#cc-2-floral-station > input').valid()) { valid = false; }\n \tif (!validateRadio('occAttr\\:" . $args['flower_type_attr_id'] . "', 'form#cc-2-floral-station')) { valid = false; }\n \tif ( valid == false ) return valid;\n\tshowSessionsPanel = false;\n\tjQuery('form#cc-2-floral-station').submit();\n\treturn true;\n};\n\n// Flower upload picture form.\n\$('#cc-2-flower-upload').ajaxForm({ \n dataType: 'json', \n beforeSubmit: function(data, obj, options){\n \tif (!jQuery('form#cc-2-flower-upload').valid()) { return false; }\n \t\$('#cc-2-flower-image').empty();\n \t\$('#cc-2-flower-image').addClass('loading')\n },\n success: function(data){\n \tif(data.success == true){\n\t \t// There is only one file\n\t \tjQuery('form#cc-2-floral-station input[name=occurrence_image\\:path]').val(data.files[0]);\n\t \tvar img = new Image();\n\t \t\$(img).load(function () {\n \t\t\t\t\$(this).hide();\n \t\t\t\t\$('#cc-2-flower-image').removeClass('loading').append(this);\n \t\t\t\t\$(this).fadeIn();\n\t\t\t \t})\n\t\t\t\t .attr('src', '" . data_entry_helper::$base_url . data_entry_helper::$indicia_upload_path . "med-'+data.files[0])\n\t\t\t\t .css('max-width', \$('#cc-2-flower-image').width()).css('max-height', \$('#cc-2-flower-image').height())\n\t\t\t\t .css('vertical-align', 'middle').css('margin-left', 'auto').css('margin-right', 'auto').css('display', 'block');\n\t\t\t\tjQuery('#cc-2-flower-upload input[name=upload_file]').val('');\n\t\t\t} else {\n\t\t\t\tvar errorString = \"" . lang::get('LANG_Indicia_Warehouse_Error') . "\";\n\t \tjQuery('form#cc-2-floral-station input[name=occurrence_image\\:path]').val('');\n\t\t\t\t\$('#cc-2-flower-image').removeClass('loading');\n\t\t\t\tif(data.error){\n\t\t\t\t\terrorString = errorString + ' : ' + data.error;\n\t\t\t\t}\n\t\t\t\tif(data.errors){\n\t\t\t\t\tfor (var i in data.errors)\n\t\t\t\t\t{\n\t\t\t\t\t\terrorString = errorString + ' : ' + data.errors[i];\n\t\t\t\t\t}\t\t\t\t\n\t\t\t\t}\n\t\t\t\talert(errorString);\n\t\t\t}\n \t\t} \n});\n\n// Flower upload picture form.\n\$('#cc-2-environment-upload').ajaxForm({ \n dataType: 'json', \n beforeSubmit: function(data, obj, options){\n \tif (!jQuery('form#cc-2-environment-upload').valid()) { return false; }\n \t\$('#cc-2-environment-image').empty();\n \t\$('#cc-2-environment-image').addClass('loading')\n },\n success: function(data){\n \tif(data.success == true){\n\t \t// There is only one file\n\t \tjQuery('form#cc-2-floral-station input[name=location_image\\:path]').val(data.files[0]);\n\t \tvar img = new Image();\n\t \t\$(img).load(function () {\n \t\t\t\t\$(this).hide();\n \t\t\t\t\$('#cc-2-environment-image').removeClass('loading').append(this);\n \t\t\t\t\$(this).fadeIn();\n\t\t\t \t})\n\t\t\t\t .attr('src', '" . data_entry_helper::$base_url . data_entry_helper::$indicia_upload_path . "med-'+data.files[0])\n\t\t\t\t .css('max-width', \$('#cc-2-environment-image').width()).css('max-height', \$('#cc-2-environment-image').height())\n\t\t\t\t .css('vertical-align', 'middle').css('margin-left', 'auto').css('margin-right', 'auto').css('display', 'block');\n\t\t\t\tjQuery('#cc-2-environment-upload input[name=upload_file]').val('');\n\t\t\t} else {\n\t\t\t\tvar errorString = \"" . lang::get('LANG_Indicia_Warehouse_Error') . "\";\n\t \tjQuery('form#cc-2-floral-station input[name=location_image\\:path]').val('');\n\t\t\t\t\$('#cc-2-environment-image').removeClass('loading');\n\t\t\t\tif(data.error){\n\t\t\t\t\terrorString = errorString + ' : ' + data.error;\n\t\t\t\t}\n\t\t\t\tif(data.errors){\n\t\t\t\t\tfor (var i in data.errors)\n\t\t\t\t\t{\n\t\t\t\t\t\terrorString = errorString + ' : ' + data.errors[i];\n\t\t\t\t\t}\t\t\t\t\n\t\t\t\t}\n\t\t\t\talert(errorString);\n\t\t\t}\n } \n});\n\n\$('#cc-2-floral-station').ajaxForm({ \n dataType: 'json', \n beforeSubmit: function(data, obj, options){\n\t\tvar valid = true;\n \tif(jQuery('form#cc-2-floral-station > input[name=location_image\\:path]').val() == '' ||\n\t\t\t\t\tjQuery('form#cc-2-floral-station > input[name=occurrence_image\\:path]').val() == '' ){\n\t\t\talert(\"" . lang::get('LANG_Must_Provide_Pictures') . "\");\n\t\t\tvalid = false;\n\t\t}\n\t\tif(jQuery('#imp-geom').val() == '') {\n\t\t\talert(\"" . lang::get('LANG_Must_Provide_Location') . "\");\n\t\t\tvalid = false;\n\t\t}\n\t\tif (!jQuery('form#cc-2-floral-station > input').valid()) { valid = false; }\n \t\tif (!validateRadio('occAttr\\:" . $args['flower_type_attr_id'] . "', 'form#cc-2-floral-station')) { valid = false; }\n\t\t// DANGER this assumes certain positioning of the centroid sref and geom within the data array\n\t\tif(data[3].name != 'location:centroid_sref' || data[4].name != 'location:centroid_geom') {\n\t\t\talert('Internal error: imp-sref or imp-geom post location mismatch');\n\t\t\treturn false;\n\t\t}\n\t\tdata[3].value = jQuery('#imp-sref').val();\n\t\tdata[4].value = jQuery('#imp-geom').val();\n\t\tdata[10].value = jQuery('#cc-2-flower-identify > select[name=flower\\:taxa_taxon_list_id]').val();\n\t\tdata[11].value = jQuery('#cc-2-flower-identify > select[name=flower\\:taxon_text_description]').val();\n\t\tif (jQuery('#id-flower-later').attr('checked') == ''){\n\t\t\tif (!validateRequiredField('flower\\:taxa_taxon_list_id', '#cc-2-flower-identify')) { valid = false; }\n\t\t} else {\n\t\t\tdata.splice(10,5); // remove determination entries.\n\t\t}\n \t\tif ( valid == false ) return valid;\n\t\treturn true;\n\t},\n success: function(data){\n \tif(data.success == 'multiple records' && data.outer_table == 'sample'){\n \t\t// the sample and location ids are already fixed, so just need to populate the occurrence and image IDs, and rename the location and occurrence attribute.\n \t \$.getJSON(\"" . $svcUrl . "\" + \"/data/occurrence\" +\n\t\t \"?mode=json&view=detail&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" +\n\t\t \"&sample_id=\"+data.outer_id+\"&callback=?\", function(occdata) {\n\t\t\t\tif (occdata.length>0) {\n\t\t \tjQuery('#cc-2-floral-station > input[name=occurrence\\:id]').removeAttr('disabled').val(occdata[0].id);\n \t\t\t\tloadAttributes('occurrence_attribute_value', 'occurrence_attribute_id', 'occurrence_id', 'occurrence\\:id', occdata[0].id, 'occAttr');\n\t\t\t\t\t\$.getJSON(\"" . $svcUrl . "/data/occurrence_image/\" +\n \t\t\t\t\t\t\"?mode=json&view=list&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" +\n \t\t\t\t\t\t\"&occurrence_id=\"+occdata[0].id+\"&callback=?\", function(imgdata) {\n\t\t\t\t\t if (imgdata.length>0) {\n\t\t \t\t\tjQuery('#cc-2-floral-station > input[name=occurrence_image\\:id]').removeAttr('disabled').val(imgdata[0].id);\n\t\t \t\t}});\n\t\t }});\n\t\t var location_id = jQuery('#cc-2-floral-station > input[name=location\\:id]').val();\n \t\tloadAttributes('location_attribute_value', 'location_attribute_id', 'location_id', 'location\\:id', location_id, 'locAttr');\n\t\t\t\$.getJSON(\"" . $svcUrl . "/data/location_image/\" +\n \t\t\t\t\"?mode=json&view=list&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" +\n \t\t\t\t\"&location_id=\"+location_id+\"&callback=?\", function(data) {\n\t\t\t\tif (data.length>0) {\n\t\t \tjQuery('#cc-2-floral-station > input[name=location_image\\:id]').removeAttr('disabled').val(data[0].id);\n\t\t }});\n\t\t\tjQuery('#cc-2').foldPanel();\n\t\t\tif(showSessionsPanel) { jQuery('#cc-3').showPanel(); }\n\t\t\tshowSessionsPanel = true;\n } \n\t}\n});\n\n\$('#cc-2-valid-button').click(function() {\n\tjQuery('#cc-2-floral-station').submit();\n});\n\n"; // Sessions. $r .= ' <div id="cc-3" class="poll-section"> <div id="cc-3-title" class="ui-accordion-header ui-helper-reset ui-state-active ui-corner-all poll-section-title"><span>' . lang::get('LANG_Sessions_Title') . '</span> <div id="cc-3-mod-button" class="right ui-state-default ui-corner-all mod-button">' . lang::get('LANG_Modify') . '</div> </div> <div id="cc-3-body" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-top ui-accordion-content-active poll-section-body"> </div> <div id="cc-3-footer" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active poll-section-footer"> <div id="cc-3-add-button" class="ui-state-default ui-corner-all add-button">' . lang::get('LANG_Add_Session') . '</div> <div id="cc-3-valid-button" class="ui-state-default ui-corner-all save-button">' . lang::get('LANG_Validate_Session') . '</div> </div> </div> <div style="display:none" /> <form id="cc-3-delete-session" action="' . iform_ajaxproxy_url($node, 'sample') . '" method="POST"> <input type="hidden" name="website_id" value="' . $args['website_id'] . '" /> <input type="hidden" name="sample:survey_id" value="' . $args['survey_id'] . '" /> <input type="hidden" name="sample:id" value="" /> <input type="hidden" name="sample:date" value="2010-01-01"/> <input type="hidden" name="sample:location_id" value="" /> <input type="hidden" name="sample:deleted" value="t" /> </form> </div>'; data_entry_helper::$javascript .= "\n\$('#cc-3-delete-session').ajaxForm({ \n dataType: 'json', \n beforeSubmit: function(data, obj, options){\n \t\t\t// Warning this assumes that the data is fixed position:\n \t\tdata[4].value = jQuery('#cc-1-collection-details input[name=location\\:id]').val();\n \tif(data[2].value == '') return false;\n \treturn true;\n \t\t},\n success: function(data){\n \t\t} \n});\npopulateSessionSelect = function(){\n\tvar insectSessionSelect = jQuery('form#cc-4-main-form > select[name=occurrence\\:sample_id]');\n\tvar value = insectSessionSelect.val();\n\tinsectSessionSelect.empty();\n\t// NB at this point the attributes have been loaded so have full name.\n\t\$('.poll-session-form').each(function(i){\n\t\tjQuery('<option value=\"'+\n\t\t\t\tjQuery(this).children('input[name=sample\\:id]').val()+\n\t\t\t\t'\">'+\n\t\t\t\tjQuery(this).children('input[name=sample\\:date]').val()+\n\t\t\t\t' : '+\n\t\t\t\tjQuery(this).children('[name=smpAttr\\:" . $args['start_time_attr_id'] . "],[name^=smpAttr\\:" . $args['start_time_attr_id'] . "\\:]').val()+\n\t\t\t\t' > '+\n\t\t\t\tjQuery(this).children('[name=smpAttr\\:" . $args['end_time_attr_id'] . "],[name^=smpAttr\\:" . $args['end_time_attr_id'] . "\\:]').val()+\n\t\t\t\t'</option>')\n\t\t\t.appendTo(insectSessionSelect);\n\t});\n\tif(value)\n\t\tinsectSessionSelect.val(value);\n}\n\nvalidateAndSubmitOpenSessions = function(){\n\tvar valid = true;\n\t// only check the visible forms as rest have already been validated successfully.\n\t\$('.poll-session-form:visible').each(function(i){\n\t if (!jQuery(this).children('input').valid()) {\n\t \tvalid = false; }\n\t if (!jQuery('form#cc-2-floral-station > input').valid()) { valid = false; }\n \t\tif (!validateRadio('smpAttr\\:" . $args['sky_state_attr_id'] . "', this)) { valid = false; }\n \t\tif (!validateRadio('smpAttr\\:" . $args['temperature_attr_id'] . "', this)) { valid = false; }\n \t\tif (!validateRadio('smpAttr\\:" . $args['wind_attr_id'] . "', this)) { valid = false; }\n });\n\tif(valid == false) return false;\n\t\$('.poll-session-form:visible').submit();\n\treturn true;\n}\n\naddSession = function(){\n\tsessionCounter = sessionCounter + 1;\n\t// dynamically build the contents of the session block.\n\tvar newSession = jQuery('<div id=\"cc-3-session-'+sessionCounter+'\" class=\"poll-session\"/>')\n\t\t.appendTo('#cc-3-body');\n\tvar newTitle = jQuery('<div class=\"poll-session-title\">" . lang::get('LANG_Session') . " '+sessionCounter+'</div>')\n\t\t.appendTo(newSession);\n\tvar newModButton = jQuery('<div class=\"right ui-state-default ui-corner-all mod-button\">" . lang::get('LANG_Modify') . "</div>')\n\t\t.appendTo(newTitle).hide();\n\tvar newDeleteButton = jQuery('<div class=\"right ui-state-default ui-corner-all delete-button\">" . lang::get('LANG_Delete_Session') . "</div>')\n\t\t.appendTo(newTitle);\t\n\tnewModButton.click(function() {\n\t\tif(!validateAndSubmitOpenSessions()) return false;\n\t\tvar session=\$(this).parents('.poll-session');;\n\t\tsession.show();\n\t\tsession.children().show();\n\t\tsession.children(':first').children(':first').hide(); // this is the mod button itself\n });\n var formContainer = jQuery('<div />').appendTo(newSession);\n var newForm = jQuery('<form action=\"" . iform_ajaxproxy_url($node, 'sample') . "\" method=\"POST\" class=\"poll-session-form\" />').appendTo(formContainer);\n\tjQuery('<input type=\"hidden\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />').appendTo(newForm);\n\tjQuery('<input type=\"hidden\" name=\"sample:survey_id\" value=\"" . $args['survey_id'] . "\" />').appendTo(newForm);\n\tjQuery('<input type=\"hidden\" name=\"sample:parent_id\" />').appendTo(newForm).val(jQuery('#cc-1-collection-details > input[name=sample\\:id]').val());\n\tjQuery('<input type=\"hidden\" name=\"sample:location_id\" />').appendTo(newForm).val(jQuery('#cc-1-collection-details > input[name=location\\:id]').val());\n\tjQuery('<input type=\"hidden\" name=\"sample:id\" value=\"\" disabled=\"disabled\" />').appendTo(newForm);\n"; if ($use_help) { data_entry_helper::$javascript .= "\n\tvar helpDiv = jQuery('<div class=\"right ui-state-default ui-corner-all help-button\">" . lang::get('LANG_Help_Button') . "</div>');\n\thelpDiv.click(function(){\n\t\t" . $args['help_function'] . "(" . $args['help_session_arg'] . ");\n\t});\n\thelpDiv.appendTo(newForm);"; } data_entry_helper::$javascript .= "\n\tvar dateAttr = '" . str_replace("\n", "", data_entry_helper::date_picker(array('label' => lang::get('LANG_Date'), 'id' => '<id>', 'fieldname' => 'sample:date', 'class' => 'vague-date-picker required', 'suffixTemplate' => 'nosuffix'))) . "';\n\tvar dateID = 'cc-3-session-date-'+sessionCounter;\n\tjQuery(dateAttr.replace(/<id>/g, dateID)).appendTo(newForm);\n jQuery('#'+dateID).datepicker({\n\t\tdateFormat : 'yy-mm-dd',\n\t\tconstrainInput: false,\n\t\tmaxDate: '0'\n\t});\n jQuery('" . data_entry_helper::outputAttribute($sample_attributes[$args['start_time_attr_id']], $defAttrOptions) . "').appendTo(newForm);\n\tjQuery('" . data_entry_helper::outputAttribute($sample_attributes[$args['end_time_attr_id']], $defAttrOptions) . "').appendTo(newForm);\n\tjQuery('" . data_entry_helper::outputAttribute($sample_attributes[$args['sky_state_attr_id']], $defAttrOptions) . "').appendTo(newForm);\n\tjQuery('" . data_entry_helper::outputAttribute($sample_attributes[$args['temperature_attr_id']], $defAttrOptions) . "').appendTo(newForm);\n\tjQuery('" . data_entry_helper::outputAttribute($sample_attributes[$args['wind_attr_id']], $defAttrOptions) . "').appendTo(newForm);\n\tjQuery('" . data_entry_helper::outputAttribute($sample_attributes[$args['shade_attr_id']], $defAttrOptions) . "').appendTo(newForm);\n\tnewDeleteButton.click(function() {\n\t\tvar container = \$(this).parent().parent();\n\t\tjQuery('#cc-3-delete-session').find('[name=sample\\:id]').val(container.find('[name=sample\\:id]').val());\n\t\tjQuery('#cc-3-delete-session').find('[name=sample\\:date]').val(container.find('[name=sample\\:date]').val());\n\t\tjQuery('#cc-3-delete-session').find('[name=sample\\:location_id]').val(container.find('[name=sample\\:location_id]').val());\n\t\tif(container.find('[name=sample\\:id]').filter('[disabled]').length == 0){\n\t\t\t\$.getJSON(\"" . $svcUrl . "/data/occurrence/\" +\n\t\t\t\t\t\"?mode=json&view=detail&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" +\n\t\t\t\t\t\"&sample_id=\"+container.find('[name=sample\\:id]').val()+\"&callback=?\", function(insectData) {\n\t\t\t\tif (insectData.length>0) {\n\t\t\t\t\talert(\"" . lang::get('LANG_Cant_Delete_Session') . "\");\n\t\t\t\t} else if(confirm(\"" . lang::get('LANG_Confirm_Session_Delete') . "\")){\n\t\t\t\t\tjQuery('#cc-3-delete-session').submit();\n\t\t\t\t\tcontainer.remove();\n\t\t\t\t\tcheckProtocolStatus();\n\t\t\t\t}\n\t\t\t});\n\t\t} else if(confirm(\"" . lang::get('LANG_Confirm_Session_Delete') . "\")){\n\t\t\tcontainer.remove();\n\t\t\tcheckProtocolStatus();\n\t\t}\n });\n newForm.ajaxForm({ \n \tdataType: 'json',\n \tbeforeSubmit: function(data, obj, options){\n \t\tvar valid = true;\n \t\tif (!obj.find('input').valid()) {\n \t\t\tvalid = false; }\n \t\tif (!validateRadio('smpAttr\\:" . $args['sky_state_attr_id'] . "', obj)) { valid = false; }\n \t\t\tif (!validateRadio('smpAttr\\:" . $args['temperature_attr_id'] . "', obj)) { valid = false; }\n \t\t\tif (!validateRadio('smpAttr\\:" . $args['wind_attr_id'] . "', obj)) { valid = false; }\n \t\tdata[2].value = jQuery('#cc-1-collection-details > input[name=sample\\:id]').val();\n\t\t\tdata[3].value = jQuery('#cc-1-collection-details > input[name=location\\:id]').val();\n\t\t\treturn valid;\n\t\t},\n \t success: function(data, status, form){\n \t // TODO: error condition handling, eg no date.\n \t \tvar thisSession = form.parents('.poll-session');\n \t\tif(data.success == 'multiple records' && data.outer_table == 'sample'){\n \t \t form.children('input[name=sample\\:id]').removeAttr('disabled').val(data.outer_id);\n \t \t loadAttributes('sample_attribute_value', 'sample_attribute_id', 'sample_id', 'sample\\:id', data.outer_id, 'smpAttr');\n \t}\n\t\t\tthisSession.show();\n\t\t\tthisSession.children(':first').show().find('*').show();\n\t\t\tthisSession.children().not(':first').hide();\n \t\t}\n\t});\n\tcheckProtocolStatus();\n return(newSession);\n};\n\nvalidateSessionsPanel = function(){\n\tif(jQuery('#cc-3').filter('.poll-hide').length > 0) return true; // panel is not visible so no data to fail validation.\n\tif(jQuery('#cc-3').find('.poll-section-body').filter('.poll-hide').length > 0) return true; // body hidden so data already been validated successfully.\n\tvar openSession = jQuery('.poll-session-form:visible');\n\tif(openSession.length > 0){\n\t\tif(jQuery('input[name=sample\\:id]', openSession).val() == '' &&\n\t\t\t\tjQuery('input[name=sample\\:date]', openSession).val() == '" . lang::get('click here') . "' &&\n\t\t\t\tjQuery('[name=smpAttr\\:" . $args['start_time_attr_id'] . "],[name^=smpAttr\\:" . $args['start_time_attr_id'] . "\\:]', openSession).val() == '' &&\n\t\t\t\tjQuery('[name=smpAttr\\:" . $args['end_time_attr_id'] . "],[name^=smpAttr\\:" . $args['end_time_attr_id'] . "\\:]', openSession).val() == '' &&\n\t\t\t\tjQuery('[name=smpAttr\\:" . $args['sky_state_attr_id'] . "],[name^=smpAttr\\:" . $args['sky_state_attr_id'] . "\\:]', openSession).filter('[checked]').length == 0 &&\n \t\t\tjQuery('[name=smpAttr\\:" . $args['temperature_attr_id'] . "],[name^=smpAttr\\:" . $args['temperature_attr_id'] . "\\:]', openSession).filter('[checked]').length == 0 &&\n \t\t\tjQuery('[name=smpAttr\\:" . $args['wind_attr_id'] . "],[name^=smpAttr\\:" . $args['wind_attr_id'] . "\\:]', openSession).filter('[checked]').length == 0) {\n\t\t\t// NB shade is a boolean, and always has one set (default no)\n \t\tjQuery('#cc-3').foldPanel();\n\t\t\treturn true;\n\t\t}\n\t}\n\t// not putting in an empty data set check here - user can delete the session if needed, and there must be at least one.\n\tif(!validateAndSubmitOpenSessions()) return false;\n\tjQuery('#cc-3').foldPanel();\n\tpopulateSessionSelect();\n\treturn true;\n};\njQuery('#cc-3-valid-button').click(function(){\n\tif(!validateAndSubmitOpenSessions()) return;\n\tjQuery('#cc-3').foldPanel();\n\tjQuery('#cc-4').showPanel();\n\tpopulateSessionSelect();\n});\njQuery('#cc-3-add-button').click(function(){\n\tif(!validateAndSubmitOpenSessions()) return;\n\taddSession();\n});\n\njQuery('.mod-button').click(function() {\n\t// first close all the other panels, ensuring any data is saved.\n\tif(!validateCollectionPanel() || !validateStationPanel() || !validateSessionsPanel() || !validateInsectPanel())\n\t\treturn;\n\tjQuery('#cc-5').hidePanel();\n\tjQuery(this).parents('.poll-section-title').parent().unFoldPanel(); //slightly complicated because cc-1 contains the rest.\n});\n\n"; $extraParams = $readAuth + array('taxon_list_id' => $args['insect_list_id'], 'orderby' => 'taxon'); $species_ctrl_args = array('label' => lang::get('LANG_Insect_Species'), 'fieldname' => 'insect:taxa_taxon_list_id', 'table' => 'taxa_taxon_list', 'captionField' => 'taxon', 'valueField' => 'id', 'columns' => 2, 'validation' => array('required'), 'blankText' => lang::get('LANG_Choose_Taxon'), 'extraParams' => $extraParams, 'suffixTemplate' => 'nosuffix'); $r .= ' <div id="cc-4" class="poll-section"> <div id="cc-4-title" class="ui-accordion-header ui-helper-reset ui-state-active ui-corner-all poll-section-title">' . lang::get('LANG_Photos') . ' <div id="cc-4-mod-button" class="right ui-state-default ui-corner-all mod-button">' . lang::get('LANG_Modify') . '</div> </div> <div id="cc-4-photo-reel" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-top ui-accordion-content-active photoReelContainer" > </div> <div id="cc-4-body" class="ui-accordion-content ui-helper-reset ui-widget-content ui-accordion-content-active poll-section-body"> <div id="cc-4-insect"> <form id="cc-4-insect-upload" enctype="multipart/form-data" action="' . iform_ajaxproxy_url($node, 'media') . '" method="POST"> <input type="hidden" id="website_id" name="website_id" value="' . $args['website_id'] . '" /> <input name="upload_file" type="file" class="required" /> <input type="submit" value="' . lang::get('LANG_Upload_Insect') . '" class="btn-submit" /> </form> <div id="cc-4-insect-image" class="poll-image"></div> <div id="cc-4-insect-identify" class="poll-dummy-form"> ' . iform_pollenators::help_button($use_help, "insect-help-button", $args['help_function'], $args['help_insect_arg']) . ' <p><strong>' . lang::get('LANG_Identify_Insect') . '</strong></p> <label for="id-insect-later" class="follow-on">' . lang::get('LANG_ID_Insect_Later') . ' </label><input type="checkbox" id="id-insect-later" name="id-insect-later" /> ' . ($args['ID_tool_insect_url'] != '' && $args['ID_tool_insect_poll_dir'] ? '<label for="insect-id-button">' . lang::get('LANG_Insect_ID_Key_label') . ' :</label><span id="insect-id-button" class="ui-state-default ui-corner-all poll-id-button" >' . lang::get('LANG_Launch_ID_Key') . '</span>' : '') . '<span id="insect-id-cancel" class="ui-state-default ui-corner-all poll-id-cancel" >' . lang::get('LANG_Cancel_ID') . '</span>' . data_entry_helper::select($species_ctrl_args) . ' <input type="text" name="insect:taxon_text_description" readonly="readonly"> </div> </div> <div class="poll-break"></div> <form id="cc-4-main-form" action="' . iform_ajaxproxy_url($node, 'occurrence') . '" method="POST" > <input type="hidden" id="website_id" name="website_id" value="' . $args['website_id'] . '" /> <input type="hidden" id="occurrence_image:path" name="occurrence_image:path" value="" /> <input type="hidden" id="occurrence:record_status" name="occurrence:record_status" value="C" /> <input type="hidden" name="occurrence:use_determination" value="Y"/> <input type="hidden" name="determination:taxa_taxon_list_id" value=""/> <input type="hidden" name="determination:taxon_text_description" value=""/> <input type="hidden" name="determination:cms_ref" value="' . $uid . '" /> <input type="hidden" name="determination:email_address" value="' . $email . '" /> <input type="hidden" name="determination:person_name" value="' . $username . '" /> <input type="hidden" id="occurrence:id" name="occurrence:id" value="" disabled="disabled" /> <input type="hidden" id="determination:id" name="determination:id" value="" disabled="disabled" /> <input type="hidden" id="occurrence_image:id" name="occurrence_image:id" value="" disabled="disabled" /> <label for="occurrence:sample_id">' . lang::get('LANG_Session') . '</label> <select id="occurrence:sample_id" name="occurrence:sample_id" value="" class="required" /></select> ' . data_entry_helper::textarea(array('label' => lang::get('LANG_Comment'), 'fieldname' => 'occurrence:comment', 'suffixTemplate' => 'nosuffix')) . data_entry_helper::outputAttribute($occurrence_attributes[$args['number_attr_id']], $defAttrOptions) . data_entry_helper::outputAttribute($occurrence_attributes[$args['foraging_attr_id']], $defAttrOptions) . ' </form> <span id="cc-4-valid-insect-button" class="ui-state-default ui-corner-all save-button">' . lang::get('LANG_Validate_Insect') . '</span> <span id="cc-4-delete-insect-button" class="ui-state-default ui-corner-all delete-button">' . lang::get('LANG_Delete_Insect') . '</span> </div> <div id="cc-4-footer" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active poll-section-footer"> <div id="cc-4-valid-photo-button" class="ui-state-default ui-corner-all save-button">' . lang::get('LANG_Validate_Photos') . '</div> </div> </div> <div style="display:none" /> <form id="cc-4-delete-insect" action="' . iform_ajaxproxy_url($node, 'occurrence') . '" method="POST"> <input type="hidden" name="website_id" value="' . $args['website_id'] . '" /> <input type="hidden" name="occurrence:use_determination" value="Y"/> <input type="hidden" name="occurrence:id" value="" /> <input type="hidden" name="occurrence:sample_id" value="" /> <input type="hidden" name="occurrence:deleted" value="t" /> </form> </div>'; data_entry_helper::$javascript .= "\nloadInsectPanel = null;\n\nvar insectTimer1;\nvar insectTimer2;\n\ninsectPoller = function(){\n\tinsectTimer1 = setTimeout('insectPoller();', " . $args['ID_tool_poll_interval'] . ");\n\t\$.get('" . str_replace("{HOST}", $_SERVER['HTTP_HOST'], $args['ID_tool_insect_poll_dir']) . session_id() . "_'+IDcounter.toString(), function(data){\n\tvar da = data.split('\\n');\n // first count number of returned items.\n // if > 1 put all into taxon_description.\n // if = 1 rip out the description, remove the formatting, scan the flower select for it, and set the value. Set the taxon description.\n\t da[1] = da[1].replace(/\\\\\\\\i\\{\\}/g, '').replace(/\\\\\\\\i0\\{\\}/g, '');\n var items = da[1].split(':');\n\t var count = items.length;\n\t if(items[count-1] == '') count--;\n\t if(count <= 0){\n\t \t// no valid stuff so blank it all out.\n\t \tjQuery('#cc-4-insect-identify > select[name=insect\\:taxa_taxon_list_id]').val('');\n\t \tjQuery('#cc-4-flower-identify > select[name=insect\\:taxon_text_description]').val('');\n\t } else if(count == 1){\n\t \tjQuery('#cc-4-insect-identify > select[name=insect\\:taxa_taxon_list_id]').val('');\n\t \tjQuery('#cc-4-insect-identify > select[name=insect\\:taxon_text_description]').val(items[0]);\n\t \tvar x = jQuery('#cc-4-insect-identify').find('option').filter('[text='+items[0]+']');\n\t \tif(x.length > 0){\n\t\t \tjQuery('#cc-4-insect-identify > select[name=insect\\:taxon_text_description]').val('');\n\t \t\tjQuery('#cc-4-insect-identify > select[name=insect\\:taxa_taxon_list_id]').val(x[0].value);\n \t\t}\n\t } else {\n\t \tjQuery('#cc-4-insect-identify > select[name=insect\\:taxa_taxon_list_id]').val('');\n\t \tjQuery('#cc-4-insect-identify > select[name=insect\\:taxon_text_description]').val(da[1]);\n\t }\n\t insectReset();\n });\n};\ninsectReset = function(){\n\tclearTimeout(insectTimer1);\n\tclearTimeout(insectTimer2);\n\tjQuery('#insect-id-cancel').hide();\n};\n\njQuery('#insect-id-button').click(function(){\n\tIDcounter++;\n\tclearTimeout(insectTimer1);\n\tclearTimeout(insectTimer2);\n\twindow.open('" . $args['ID_tool_insect_url'] . session_id() . "_'+IDcounter.toString(),'','') \n\tinsectTimer1 = setTimeout('insectPoller();', " . $args['ID_tool_poll_interval'] . ");\n\tinsectTimer2 = setTimeout('insectReset();', " . $args['ID_tool_poll_timeout'] . ");\n\tjQuery('#insect-id-cancel').show();\n});\njQuery('#insect-id-cancel').click(function(){\n\tinsectReset();\n});\njQuery('#insect-id-cancel').hide();\n\n \n// Insect upload picture form.\n\$('#cc-4-insect-upload').ajaxForm({ \n dataType: 'json', \n beforeSubmit: function(data, obj, options){\n \tif(jQuery('#cc-4-insect-upload input[name=upload_file]').val() == '')\n \t\treturn false;\n \t\$('#cc-4-insect-image').empty();\n \t\$('#cc-4-insect-image').addClass('loading')\n },\n success: function(data){\n \tif(data.success == true){\n\t \t// There is only one file\n\t \tjQuery('form#cc-4-main-form input[name=occurrence_image\\:path]').val(data.files[0]);\n\t \tvar img = new Image();\n\t \t\$(img).load(function () {\n \t\t\t\t\$(this).hide();\n \t\t\t\t\$('#cc-4-insect-image').removeClass('loading').append(this);\n \t\t\t\t\$(this).fadeIn();\n\t\t\t \t})\n\t\t\t\t .attr('src', '" . data_entry_helper::$base_url . data_entry_helper::$indicia_upload_path . "med-'+data.files[0])\n\t\t\t\t .css('max-width', \$('#cc-4-insect-image').width()).css('max-height', \$('#cc-4-insect-image').height())\n\t\t\t\t .css('vertical-align', 'middle').css('margin-left', 'auto').css('margin-right', 'auto').css('display', 'block');\n\t\t\t\tjQuery('#cc-4-insect-upload input[name=upload_file]').val('');\n\t\t\t} else {\n\t\t\t\tvar errorString = \"" . lang::get('LANG_Indicia_Warehouse_Error') . "\";\n\t \tjQuery('form#cc-4-main-form input[name=occurrence_image\\:path]').val('');\n\t\t\t\t\$('#cc-4-insect-image').removeClass('loading');\n\t\t\t\tif(data.error){\n\t\t\t\t\terrorString = errorString + ' : ' + data.error;\n\t\t\t\t}\n\t\t\t\tif(data.errors){\n\t\t\t\t\tfor (var i in data.errors)\n\t\t\t\t\t{\n\t\t\t\t\t\terrorString = errorString + ' : ' + data.errors[i];\n\t\t\t\t\t}\t\t\t\t\n\t\t\t\t}\n\t\t\t\talert(errorString);\n\t\t\t}\n } \n});\n\n\$('#cc-4-main-form').ajaxForm({ \n dataType: 'json', \n beforeSubmit: function(data, obj, options){\n \tvar valid = true;\n\t\tif (!jQuery('form#cc-4-main-form > input').valid()) { valid = false; }\n\t\tif (!validateRequiredField('occurrence\\:sample_id', 'form#cc-4-main-form')) { valid = false; }\n\t\tif (!validateRadio('occAttr\\:" . $args['number_attr_id'] . "', obj)) { valid = false; }\n \tif(data[1].value == '' ){\n\t\t\talert(\"" . lang::get('LANG_Must_Provide_Insect_Picture') . "\");\n\t\t\tvalid = false;\n\t\t}\n\t\tdata[4].value = jQuery('select[name=insect\\:taxa_taxon_list_id]').val();\n\t\tdata[5].value = jQuery('select[name=insect\\:taxon_text_description]').val();\n\t\tif (jQuery('#id-insect-later').attr('checked') == ''){\n\t\t\tif (!validateRequiredField('insect\\:taxa_taxon_list_id', '#cc-4-insect-identify')) { valid = false; }\n\t\t} else {\n\t\t\tdata.splice(4,5); // remove determination entries.\n\t\t}\n\t\treturn valid;\n\t},\n success: function(data){\n \tif(data.success == 'multiple records' && data.outer_table == 'occurrence'){\n \t\t// if the currently highlighted thumbnail is blank, add the new insect.\n \t\tvar thumbnail = jQuery('[occId='+data.outer_id+']');\n \t\tif(thumbnail.length == 0){\n \t\t\taddToPhotoReel(data.outer_id);\n \t\t} else {\n \t\t\tupdatePhotoReel(thumbnail, data.outer_id);\n \t\t\t}\n\t\t\tif(loadInsectPanel == null){\n\t\t\t\tclearInsect();\n\t\t\t} else {\n\t\t\t\tloadInsect(loadInsectPanel);\n\t\t\t}\n\t\t\tloadInsectPanel=null;\n\t\t\twindow.scroll(0,0);\n }\n\t}\n});\n\nvalidateInsectPanel = function(){\n\tif(jQuery('#cc-4').filter('.poll-hide').length > 0) return true; // panel is not visible so no data to fail validation.\n\tif(jQuery('#cc-4-body').filter('.poll-hide').length > 0) return true; // body hidden so data already been validated successfully.\n\tif(!validateInsect()){ return false; }\n \tjQuery('#cc-4').foldPanel();\n\treturn true;\n};\n\nclearInsect = function(){\n\tjQuery('#cc-4-main-form').resetForm();\n\tjQuery('[name=insect\\:taxa_taxon_list_id]').val('');\n\tjQuery('[name=insect\\:taxon_text_description]').val('');\n jQuery('#id-insect-later').removeAttr('checked').removeAttr('disabled');\n jQuery('#cc-4-main-form').find('[name=determination:cms_ref]').val('" . $uid . "');\n jQuery('#cc-4-main-form').find('[name=determination:email_address]').val('" . $email . "');\n jQuery('#cc-4-main-form').find('[name=determination:person_name]').val('" . $username . "'); \n jQuery('#cc-4-main-form').find('[name=occurrence_image\\:path]').val('');\n\tjQuery('#cc-4-main-form').find('[name=occurrence\\:id],[name=occurrence_image\\:id],[name=determination\\:id]').val('').attr('disabled', 'disabled');\n jQuery('#cc-4-main-form').find('[name=occurrence_image\\:path]').val('');\n\tjQuery('#cc-4-main-form').find('[name^=occAttr\\:]').each(function(){\n\t\tvar name = jQuery(this).attr('name').split(':');\n\t\tjQuery(this).attr('name', name[0]+':'+name[1]);\n\t});\n jQuery('#cc-4-insect-image').empty();\n};\n\nloadInsect = function(id){\n\tclearInsect();\n\t\$.getJSON(\"" . $svcUrl . "/data/occurrence/\" + id +\n \"?mode=json&view=detail&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "&callback=?\", function(data) {\n\t if (data.length>0) {\n\t jQuery('form#cc-4-main-form > input[name=occurrence\\:id]').removeAttr('disabled').val(data[0].id);\n\t jQuery('form#cc-4-main-form > [name=occurrence\\:sample_id]').val(data[0].sample_id);\n\t\t\tjQuery('form#cc-4-main-form > textarea[name=occurrence\\:comment]').val(data[0].comment);\n\t\t\tloadAttributes('occurrence_attribute_value', 'occurrence_attribute_id', 'occurrence_id', 'occurrence\\:id', data[0].id, 'occAttr');\n \t\tloadImage('occurrence_image', 'occurrence_id', 'occurrence\\:id', data[0].id, '#cc-4-insect-image');\n \t\t}\n\t});\n\t\$.getJSON(\"" . $svcUrl . "/data/determination?occurrence_id=\" + id +\n \"&mode=json&view=list&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "&callback=?\", function(data) {\n\t if (data.length>0) {\n\t \tjQuery('#id-insect-later').removeAttr('checked').attr('disabled', 'disabled');\n\t jQuery('form#cc-4-main-form > input[name=determination\\:id]').removeAttr('disabled').val(data[0].id);\n\t jQuery('form#cc-4-main-form > input[name=determination\\:cms_ref]').val(data[0].cms_ref);\n\t jQuery('form#cc-4-main-form > input[name=determination\\:email_address]').val(data[0].email_address);\n\t jQuery('form#cc-4-main-form > input[name=determination\\:person_name]').val(data[0].person_name);\n \t\tjQuery('[name=insect\\:taxa_taxon_list_id]').val(data[0].taxa_taxon_list_id);\n \t\tjQuery('[name=insect\\:taxon_text_description]').val(data[0].taxon_text_description);\n \t\t} else\n \t\t\tjQuery('#id-insect-later').attr('checked', 'checked').removeAttr('disabled');\n\t});\t\n}\n\nupdatePhotoReel = function(container, occId){\n\tcontainer.empty();\n\t\$.getJSON(\"" . $svcUrl . "/data/occurrence_image\" +\n \t\t\t\"?mode=json&view=list&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" +\n \t\t\t\"&occurrence_id=\" + occId + \"&callback=?\", function(imageData) {\n\t\tif (imageData.length>0) {\n\t\t\tvar img = new Image();\n\t\t\tjQuery(img).attr('src', '" . data_entry_helper::$base_url . data_entry_helper::$indicia_upload_path . "thumb-'+imageData[0].path)\n\t\t\t .attr('width', container.width()).attr('height', container.height()).addClass('thumb-image').appendTo(container);\n\t\t}\n\t});\n\t\$.getJSON(\"" . $svcUrl . "/data/determination\" + \n \t\t\"?mode=json&view=list&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" + \n \t\t\"&occurrence_id=\" + occId + \"&deleted=f&callback=?\", function(detData) {\n\t if (detData.length==0) {\n\t \t// no determination records, so no attempt made at identification. Put up a question mark.\n\t\t\tjQuery('<span>?</span>').addClass('thumb-text').appendTo(container);\n\t\t}\n\t});\n}\n\naddToPhotoReel = function(occId){\n\t// last photo in list is the blank empty one. Add to just before this.\n\tvar container = jQuery('<div/>').addClass('thumb').insertBefore('.blankPhoto').attr('occId', occId.toString()).click(function () {setInsect(this, occId)});\n\tupdatePhotoReel(container, occId);\n}\n\nsetInsect = function(context, id){\n\t// first close all the other panels, ensuring any data is saved.\n\tif(!validateCollectionPanel() || !validateStationPanel() || !validateSessionsPanel())\n\t\treturn;\n\t\t\n\tif(jQuery('#cc-4-body').filter('.poll-hide').length > 0) {\n\t\tjQuery('div#cc-4').unFoldPanel();\n\t\tloadInsect(id);\n\t} else {\n\t\tloadInsectPanel=id;\n\t\tif(!validateInsect()){\n\t\t\tloadInsectPanel=null;\n\t\t\treturn;\n\t\t} \n\t}\n\tjQuery('.currentPhoto').removeClass('currentPhoto');\n\tjQuery('[occId='+id+']').addClass('currentPhoto');\n};\n\nsetNoInsect = function(){\n\t// first close all the other panels, ensuring any data is saved.\n\tif(!validateCollectionPanel() || !validateStationPanel() || !validateSessionsPanel())\n\t\treturn;\n\t\t\n\tif(jQuery('#cc-4-body').filter('.poll-hide').length > 0)\n\t\tjQuery('div#cc-4').unFoldPanel();\n\telse\n\t\tif(!validateInsect()){ return ; }\n\t// At this point the empty panel is displayed, as it is reset after a successful validate.\t\n\tjQuery('.currentPhoto').removeClass('currentPhoto');\n\tjQuery('.blankPhoto').addClass('currentPhoto');\n};\n\ncreatePhotoReel = function(div){\n\tjQuery(div).empty();\n\tjQuery('<div/>').addClass('blankPhoto thumb currentPhoto').appendTo(div).click(setNoInsect);\n}\n\ncreatePhotoReel('#cc-4-photo-reel');\n\n// TODO separate photoreel out into own js\n\nvalidateInsect = function(){\n\t// TODO will have to expand when use key.\n\tif(jQuery('form#cc-4-main-form > input[name=occurrence\\:id]').val() == '' &&\n\t\t\tjQuery('form#cc-4-main-form > input[name=occurrence_image\\:path]').val() == '' &&\n\t\t\tjQuery('[name=insect\\:taxa_taxon_list_id]').val() == '' &&\n\t\t\tjQuery('form#cc-4-main-form > textarea[name=occurrence\\:comment]').val() == '' &&\n\t\t\tjQuery('[name=occAttr\\:" . $args['number_attr_id'] . "],[name^=occAttr\\:" . $args['number_attr_id'] . "\\:]').filter('[checked]').length == 0){\n\t\tif(loadInsectPanel != null){\n\t\t\tloadInsect(loadInsectPanel);\n\t\t}\n\t\tloadInsectPanel=null;\n\t\treturn true;\n\t}\n\tvar valid = true;\n if (!jQuery('form#cc-4-main-form > input').valid()) { return false; }\n \tif (!validateRadio('occAttr\\:" . $args['number_attr_id'] . "', 'form#cc-4-main-form')) { valid = false; }\n\t\tif (jQuery('#id-insect-later').attr('checked') == ''){\n\t\t\tif (!validateRequiredField('insect\\:taxa_taxon_list_id', '#cc-4-insect-identify')) { valid = false; }\n\t\t}\n \tif (!validateRequiredField('occurrence\\:sample_id', 'form#cc-4-main-form')) { valid = false; }\n\tif(jQuery('form#cc-4-main-form input[name=occurrence_image\\:path]').val() == ''){\n\t\talert(\"" . lang::get('LANG_Must_Provide_Insect_Picture') . "\");\n\t\tvalid = false;;\n\t}\n\tif(valid == false) return false;\n\tjQuery('form#cc-4-main-form').submit();\n\treturn true;\n }\n\n\$('#cc-4-valid-insect-button').click(validateInsect);\n\n\$('#cc-4-delete-insect-button').click(function() {\n\tvar container = \$(this).parent().parent();\n\tjQuery('#cc-4-delete-insect').find('[name=occurrence\\:id]').val(jQuery('#cc-4-main-form').find('[name=occurrence\\:id]').val());\n\tjQuery('#cc-4-delete-insect').find('[name=occurrence\\:sample_id]').val(jQuery('#cc-4-main-form').find('[name=occurrence\\:sample_id]').val());\n\tif(confirm(\"" . lang::get('LANG_Confirm_Insect_Delete') . "\")){\n\t\tif(jQuery('#cc-4-main-form').find('[name=occurrence\\:id]').filter('[disabled]').length == 0){\n\t\t\tjQuery('#cc-4-delete-insect').submit();\n\t\t\tjQuery('.currentPhoto').remove();\n\t\t\tjQuery('.blankPhoto').addClass('currentPhoto');\n\t\t}\n\t\tclearInsect();\n\t}\n});\n\n\$('#cc-4-delete-insect').ajaxForm({ \n dataType: 'json', \n beforeSubmit: function(data, obj, options){\n \t\t\t// Warning this assumes that the data is fixed position:\n \tif(data[2].value == '') return false;\n \treturn true;\n \t\t},\n success: function(data){\n \t\t} \n});\n\n\$('#cc-4-valid-photo-button').click(function(){\n\tif(!validateInsect()) return;\n\tjQuery('#cc-4').foldPanel();\n\tjQuery('#cc-5').showPanel();\n\tvar numInsects = jQuery('#cc-4-photo-reel').find('.thumb').length - 1; // ignore blank\n\tvar numUnidentified = jQuery('#cc-4-photo-reel').find('.thumb-text').length;\n\tif(jQuery('#id-flower-later').attr('checked') != '' || numInsects==0 || (numUnidentified/numInsects > (1-(" . $args['percent_insects'] . "/100.0)))){\n\t\tjQuery('#cc-5-good').hide();\n\t\tjQuery('#cc-5-bad').show();\n\t\tjQuery('#cc-5-complete-collection').hide();\n\t\tjQuery('#cc-5-trailer').hide();\n } else {\n \tjQuery('#cc-5-good').show();\n\t\tjQuery('#cc-5-bad').hide();\n\t\tjQuery('#cc-5-complete-collection').show();\n\t\tjQuery('#cc-5-trailer').show();\n\t}\n});\n"; $r .= ' <div id="cc-5" class="poll-section"> <div id="cc-5-body" class="ui-accordion-header ui-helper-reset ui-state-active ui-corner-all poll-section-body"> <p id="cc-5-good">' . lang::get('LANG_Can_Complete_Msg') . '</p> <p id="cc-5-bad">' . lang::get('LANG_Cant_Complete_Msg') . '</p> <div style="display:none" /> <form id="cc-5-collection" action="' . iform_ajaxproxy_url($node, 'sample') . '" method="POST"> <input type="hidden" name="website_id" value="' . $args['website_id'] . '" /> <input type="hidden" name="sample:survey_id" value="' . $args['survey_id'] . '" /> <input type="hidden" name="sample:id" value="" /> <input type="hidden" name="sample:date" value="2010-01-01"/> <input type="hidden" name="sample:location_id" value="" /> <input type="hidden" id="smpAttr:' . $args['complete_attr_id'] . '" name="smpAttr:' . $args['complete_attr_id'] . '" value="1" /> </form> </div> <div id="cc-5-complete-collection" class="ui-state-default ui-corner-all complete-button">' . lang::get('LANG_Complete_Collection') . '</div> </div> <div id="cc-5-trailer" class="poll-section-trailer"> <p>' . lang::get('LANG_Trailer_Head') . '</p> <ul> <li>' . lang::get('LANG_Trailer_Point_1') . '</li> <li>' . lang::get('LANG_Trailer_Point_2') . '</li> <li>' . lang::get('LANG_Trailer_Point_3') . '</li> <li>' . lang::get('LANG_Trailer_Point_4') . '</li> </ul> </div> </div>'; data_entry_helper::$javascript .= "\n\$('#cc-5-collection').ajaxForm({ \n dataType: 'json', \n beforeSubmit: function(data, obj, options){\n \t\tdata[2].value = jQuery('#cc-1-collection-details input[name=sample\\:id]').val();\n \t\tvar date_start = '';\n \t\tvar date_end = '';\n \t\tjQuery('.poll-session').find('[name=sample\\:date]').each(function(index, el){\n \t\t\tvar value = \$(this).val();\n \t\t\tif(date_start == '' || date_start > value) {\n \t\t\t\tdate_start = value;\n \t\t\t}\n \t\t\tif(date_end == '' || date_end < value) {\n \t\t\t\tdate_end = value;\n \t\t\t}\n \t\t\t});\n \t\t\tif(date_start == date_end){\n\t \t\tdata[3].value = date_start;\n\t \t} else {\n\t \t\tdata[3].value = date_start+' to '+date_end;\n \t\t\t}\n\t \tjQuery('[name=sample\\:date]:hidden').val(data[3].value);\n \t\t\tdata[4].value = jQuery('#cc-1-collection-details input[name=location\\:id]').val();\n \t\tdata[5].name = jQuery('#cc-1-collection-details input[name^=smpAttr\\:" . $args['complete_attr_id'] . "\\:]').attr('name');\n \treturn true;\n \t\t},\n success: function(data){\n\t\t\t\$('#cc-6').showPanel();\n \t\t} \n});\n\$('#cc-5-complete-collection').click(function(){\n\tjQuery('#cc-2,#cc-3,#cc-4,#cc-5').hidePanel();\n\tjQuery('.reinit-button').hide();\n\tjQuery('.mod-button').hide();\n\tjQuery('#cc-5-collection').submit();\n});\n"; $r .= ' <div id="cc-6" class="poll-section"> <div id="cc-6-body" class="ui-accordion-header ui-helper-reset ui-state-active ui-corner-top poll-section-body"> <p>' . lang::get('LANG_Final_1') . '</p> <p>' . lang::get('LANG_Final_2') . '</p> </div> <div id="cc-6-footer" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active poll-section-footer"> <a id="cc-6-consult-collection" href="" class="ui-state-default ui-corner-all link-button">' . lang::get('LANG_Consult_Collection') . '</a> <a href="' . url('node/' . $node->nid) . '" class="ui-state-default ui-corner-all link-button">' . lang::get('LANG_Create_New_Collection') . '</a> </div> </div> </div></div>'; data_entry_helper::$javascript .= "\n \t\t\t\nloadAttributes = function(attributeTable, attributeKey, key, keyName, keyValue, prefix){\n\tvar form = jQuery('input[name='+keyName+'][value='+keyValue+']').parent();\n\tvar checkboxes = jQuery('[name^='+prefix+'\\:]', form).filter(':checkbox').removeAttr('checked');\n\tcheckboxes.each(function(){\n\t\tvar name = jQuery(this).attr('name').split(':');\n\t\tif(name.length > 2)\n\t\t\tjQuery(this).attr('name', name[0]+':'+name[1]+'[]');\n\t});\n\t\n\t\$.getJSON(\"" . $svcUrl . "/data/\" + attributeTable +\n \t\t\t\"?mode=json&view=list&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" +\n \t\t\t\"&\" + key + \"=\" + keyValue + \"&callback=?\", function(attrdata) {\n\t\tif (attrdata.length>0) {\n\t\t\tvar form = jQuery('input[name='+keyName+'][value='+keyValue+']').parent();\n\t\t\tfor (var i=0;i<attrdata.length;i++){\n\t\t\t\tif (attrdata[i].id && (attrdata[i].iso == null || attrdata[i].iso == '' || attrdata[i].iso == '" . $language . "')){\n\t\t\t\t\tvar checkboxes = jQuery('[name='+prefix+'\\:'+attrdata[i][attributeKey]+'\\[\\]],[name^='+prefix+'\\:'+attrdata[i][attributeKey]+':]', form).filter(':checkbox');\n\t\t\t\t\tvar radiobuttons = jQuery('[name='+prefix+'\\:'+attrdata[i][attributeKey]+'],[name^='+prefix+'\\:'+attrdata[i][attributeKey]+':]', form).filter(':radio');\n\t\t\t\t\tif(radiobuttons.length > 0){\n\t\t\t\t\t\tradiobuttons\n\t\t\t\t\t\t\t.attr('name', prefix+':'+attrdata[i][attributeKey]+':'+attrdata[i].id)\n\t\t\t\t\t\t\t.filter('[value='+attrdata[i].raw_value+']')\n\t\t\t\t\t\t\t.attr('checked', 'checked');\n\t\t\t\t\t} else \tif(checkboxes.length > 0){\n\t\t\t\t\t\tvar checkbox = checkboxes.filter('[value='+attrdata[i].raw_value+']')\n\t\t\t\t\t\t\t.attr('name', prefix+':'+attrdata[i][attributeKey]+':'+attrdata[i].id)\n\t\t\t\t\t\t\t.attr('checked', 'checked');\n\t\t\t\t\t} else {\n\t\t\t\t\t\tjQuery('[name='+prefix+'\\:'+attrdata[i][attributeKey]+']', form)\n\t\t\t\t\t\t\t.attr('name', prefix+':'+attrdata[i][attributeKey]+':'+attrdata[i].id)\n\t\t\t\t\t\t\t.val(attrdata[i].raw_value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcheckProtocolStatus();\n\t\tpopulateSessionSelect();\n\t});\n}\n\nloadImage = function(imageTable, key, keyName, keyValue, target){\n\t\t\t\t\t// location_image, location_id, location:id, 1, #cc-4-insect-image\n\t\$.getJSON(\"" . $svcUrl . "/data/\" + imageTable +\n \t\t\t\"?mode=json&view=list&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" +\n \t\t\t\"&\" + key + \"=\" + keyValue + \"&callback=?\", function(imageData) {\n\t\tif (imageData.length>0) {\n\t\t\tvar form = jQuery('input[name='+keyName+'][value='+keyValue+']').parent();\n\t\t\tjQuery('[name='+imageTable+'\\:id]', form).val(imageData[0].id).removeAttr('disabled');\n\t\t\tjQuery('[name='+imageTable+'\\:path]', form).val(imageData[0].path);\n\t\t\tvar img = new Image();\n\t\t\t\$(img).load(function () {\n \t\t\t\$(target).empty().append(this);\n\t\t\t })\n\t\t\t .attr('src', '" . data_entry_helper::$base_url . data_entry_helper::$indicia_upload_path . "med-'+imageData[0].path)\n\t\t\t\t.css('max-width', \$(target).width()).css('max-height', \$(target).height()).css('display', 'block')\n\t\t\t\t.css('vertical-align', 'middle').css('margin-left', 'auto').css('margin-right', 'auto');\n\t\t}\n\t});\n}\n\n// load in any existing incomplete collection.\n// general philosophy is that you are taken back to the stage last verified.\n// Load in the first if there are more than one. Use the internal report which provides my collections.\n// Requires that there is an attribute for completeness, and one for the CMS\n// load the data in the order it is entered, so can stop when get to the point where the user finished.\n// have to reset the entire form first...\njQuery('.poll-section').resetPanel();\n// Default state: hide everything except the collection details block.\njQuery('.poll-section').hidePanel();\njQuery('#cc-1').showPanel();\njQuery('.reinit-button').hide();\naddSession();\n\njQuery.getJSON(\"" . $svcUrl . "\" + \"/report/requestReport?report=poll_my_collections.xml&reportSource=local&mode=json\" +\n\t\t\t\"&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"] . "\" + \n\t\t\t\"&survey_id=" . $args['survey_id'] . "&userID_attr_id=" . $args['uid_attr_id'] . "&userID=" . $uid . "&complete_attr_id=" . $args['complete_attr_id'] . "&callback=?\", function(data) {\n\tif (data.length>0) {\n\t\tvar i;\n \tfor ( i=0;i<data.length;i++) {\n \t\tif(data[i].completed == '0'){\n \t\t jQuery('#cc-6-consult-collection').attr('href', '" . url('node/' . $args['gallery_node']) . "'+'?collection_id='+data[i].id);\n \t\t\t// load up collection details: existing ID, location name and protocol\n \t\t\tjQuery('#cc-1-collection-details,#cc-2').find('input[name=sample\\:id]').val(data[i].id).removeAttr('disabled');\n \t\t\t// main sample date is only set when collection is completed, so leave default.\n \t\t\tloadAttributes('sample_attribute_value', 'sample_attribute_id', 'sample_id', 'sample\\:id', data[i].id, 'smpAttr');\n \t\t\t\t\$.getJSON(\"" . $svcUrl . "/data/location/\" + data[i].location_id +\n \t\t\t\t\t\"?mode=json&view=detail&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" +\n \t\t\t\t\t\"&callback=?\", function(locationdata) {\n\t\t \t\tif (locationdata.length>0) {\n\t\t \t\t\tjQuery('input[name=location\\:id]').val(locationdata[0].id).removeAttr('disabled');\n\t \t\t\t\tjQuery('input[name=location\\:name]').val(locationdata[0].name);\n \t\t\t\t\tjQuery('input[name=sample\\:location_name]').val(locationdata[0].name); // make sure the 2 coincide\n\t \t\t\t\t// NB the location geometry is stored in centroid, due to restrictions in location model.\n\t \t\t\t\tjQuery('input[name=location\\:centroid_sref]').val(locationdata[0].centroid_sref);\n\t \t\t\t\tjQuery('input[name=location\\:centroid_sref_system]').val(locationdata[0].centroid_sref_system);\n\t \t\t\t\tjQuery('input[name=location\\:centroid_geom]').val(locationdata[0].centroid_geom);\n\t \t\t\t\tjQuery('input[name=locations_website\\:website_id]').attr('disabled', 'disabled');\n\t \t\t\t\tloadAttributes('location_attribute_value', 'location_attribute_id', 'location_id', 'location\\:id', locationdata[0].id, 'locAttr');\n \t \t\t\t\tloadImage('location_image', 'location_id', 'location\\:id', locationdata[0].id, '#cc-2-environment-image');\n\t\t\t\t\t\tjQuery('#imp-sref').change();\n\t\t\t\t var parts=locationdata[0].centroid_sref.split(' ');\n \t\t\t\t\t\tjQuery('input[name=place\\:lat]').val(parts[0]);\n\t\t\t\t\t\tjQuery('input[name=place\\:long]').val(parts[1]);\n \t\t\t\t\t}\n \t\t\t\t});\n \t\t\t\t\$.getJSON(\"" . $svcUrl . "/data/occurrence/\" +\n \t\t\t\t\t\"?mode=json&view=detail&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" +\n \t\t\t\t\t\"&sample_id=\"+data[i].id+\"&callback=?\", function(flowerData) {\n \t\t\t// there will only be an occurrence if the floral station panel has previously been displayed & validated. \n\t\t \t\tif (flowerData.length>0) {\n \t\t\t\t\t\t\$('#cc-1').foldPanel();\n \t\t\t\t\t\t\$('#cc-2').showPanel();\n\t\t \t\t\tjQuery('form#cc-2-floral-station > input[name=occurrence\\:sample_id]').val(data[i].id);\n\t\t \t\t\tjQuery('form#cc-2-floral-station > input[name=occurrence\\:id]').val(flowerData[0].id).removeAttr('disabled');\n\t\t \t\t\tloadAttributes('occurrence_attribute_value', 'occurrence_attribute_id', 'occurrence_id', 'occurrence\\:id', flowerData[0].id, 'occAttr');\n \t \t\t\t\tloadImage('occurrence_image', 'occurrence_id', 'occurrence\\:id', flowerData[0].id, '#cc-2-flower-image');\n\n \t \t\t\t\t\$.getJSON(\"" . $svcUrl . "/data/determination\" + \n \t \t\t\t\t\t\t\"?mode=json&view=list&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "&occurrence_id=\"+flowerData[0].id+\"&deleted=f&callback=?\",\n \t \t\t\t\t\tfunction(detData) {\n\t \t\t\t \t\tif (detData.length>0) {\n\t\t\t\t\t\t\t\tjQuery('#id-flower-later').removeAttr('checked').attr('disabled', 'disabled');\n\t \t\t\t \t\t\tjQuery('form#cc-2-floral-station > input[name=determination\\:id]').val(detData[0].id).removeAttr('disabled');\n\t\t \t\t\t\t\tjQuery('form#cc-2-floral-station > input[name=determination\\:cms_ref]').val(detData[0].cms_ref);\n\t\t\t\t\t\t\t\tjQuery('form#cc-2-floral-station > input[name=determination\\:email_address]').val(detData[0].email_address);\n\t\t\t\t\t\t\t\tjQuery('form#cc-2-floral-station > input[name=determination\\:person_name]').val(detData[0].person_name);\n\t\t\t\t\t\t\t\tjQuery('select[name=flower\\:taxa_taxon_list_id]').val(detData[0].taxa_taxon_list_id);\n\t\t\t\t\t\t\t\tjQuery('select[name=flower\\:taxon_text_description]').val(detData[0].taxon_text_description);\n \t\t\t\t\t\t\t} else {\n\t \t\t\t \t\t\tjQuery('form#cc-2-floral-station > input[name=determination\\:id]').val('').attr('disabled', 'disabled');\n\t\t\t\t\t\t\t\tjQuery('#id-flower-later').attr('checked', 'checked').removeAttr('disabled');\n\t\t\t\t\t\t\t}\n \t\t\t\t\t\t});\n\n \t \t\t\t\t\$.getJSON(\"" . $svcUrl . "/data/sample\" + \n \t \t\t\t\t\t\"?mode=json&view=detail&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "&parent_id=\"+data[i].id+\"&callback=?\", function(sessiondata) {\n\t \t\t\t \t\tif (sessiondata.length>0) {\n\t\t\t\t\t\t\t\tjQuery('#cc-2').foldPanel();\n\t\t\t\t\t\t\t\tsessionCounter = 0;\n\t\t\t\t\t\t\t\tjQuery('#cc-3-body').empty();\n \t\t\t\t\t\t\t\t\$('#cc-3').showPanel();\n\t\t\t\t\t\t\t\tfor (var i=0;i<sessiondata.length;i++){\n\t\t\t\t\t\t\t\t\tvar thisSession = addSession();\n\t\t\t\t\t\t\t\t\tjQuery('input[name=sample\\:id]', thisSession).val(sessiondata[i].id).removeAttr('disabled');\n\t\t\t\t\t\t\t\t\tjQuery('input[name=sample\\:date]', thisSession).val(sessiondata[i].date_start);\n \t\t\t\t\t\t\t\tloadAttributes('sample_attribute_value', 'sample_attribute_id', 'sample_id', 'sample\\:id', sessiondata[i].id, 'smpAttr');\n \t\t\t\t\t\t\t\t\t// fold this session.\n \t\t\t\t\t\t\t\t\tthisSession.show();\n\t\t\t\t\t\t\t\t\tthisSession.children(':first').show().children().show();\n\t\t\t\t\t\t\t\t\tthisSession.children().not(':first').hide();\n\t\t\t\t\t\t\t\t\t\$.getJSON(\"" . $svcUrl . "/data/occurrence/\" +\n \t\t\t\t\t\t\t\t\t\"?mode=json&view=detail&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "&orderby=id\" +\n \t\t\t\t\t\t\t\t\t\"&sample_id=\"+sessiondata[i].id+\"&callback=?\", function(insectData) {\n\t\t \t\t\t\t\t\t\tif (insectData.length>0) {\n \t\t\t\t\t\t\t\t\t\t\tfor (var j=0;j<insectData.length;j++){\n\t\t\t\t\t\t\t\t\t\t\t\taddToPhotoReel(insectData[j].id);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t \t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n \t\t\t\t\t\t\t\t\$('#cc-3').foldPanel();\n \t\t\t\t\t\t\t\t\$('#cc-4').showPanel();\n\t\t\t\t\t\t\t\tpopulateSessionSelect();\n \t\t\t\t\t \t\t}\n \t\t\t\t\t \t\t\$('.loading-panel').remove();\n\t\t\t\t\t\t\t\$('.loading-hide').removeClass('loading-hide');\n\t\t\t\t\t\t});\n \t \t\t\t} else {\n \t \t\t\t\t\$('.loading-panel').remove();\n\t\t\t\t\t\t\$('.loading-hide').removeClass('loading-hide');\n \t \t\t\t}\n \t\t\t\t});\n\t\t\t\t// only use the first one which is not complete..\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (i >= data.length) {\n\t\t\t\$('.loading-panel').remove();\n\t\t\t\$('.loading-hide').removeClass('loading-hide');\n \t\t}\n\t} else {\n\t\t\$('.loading-panel').remove();\n\t\t\$('.loading-hide').removeClass('loading-hide');\n\t}\n});\n \n "; // because of the use of getJson to retrieve the data - which is asynchronous, the use of the normal loading_block_end // is not practical - it will do its stuff before the data is loaded, defeating the purpose. Also it uses hide (display:none) // which is a no-no in relation to the map. This means we have to dispense with the slow fade in. // it is also complicated by the attibutes and images being loaded asynchronously - and non-linearly. // Do the best we can! data_entry_helper::$onload_javascript .= "jQuery('#map')[0].map.searchLayer.events.register('featuresadded', {}, function(a1){\n\tif(inseeLayer != null)\n\t\tinseeLayer.destroyFeatures();\n});\njQuery('#map')[0].map.editLayer.events.register('featuresadded', {}, function(a1){\n\tif(inseeLayer != null)\n\t\tinseeLayer.destroy();\n\t\t\n \tvar filter = new OpenLayers.Filter.Spatial({\n \t\t\ttype: OpenLayers.Filter.Spatial.CONTAINS ,\n \t\tproperty: 'the_geom',\n \t\tvalue: jQuery('#map')[0].map.editLayer.features[0].geometry\n \t\t});\n\n\tvar strategy = new OpenLayers.Strategy.Fixed({preload: false, autoActivate: false});\n\tvar styleMap = new OpenLayers.StyleMap({\n \"default\": new OpenLayers.Style({\n fillColor: \"Red\",\n strokeColor: \"Red\",\n fillOpacity: 0,\n strokeWidth: 1\n })\n\t});\n\tinseeLayer = new OpenLayers.Layer.Vector('INSEE Layer', {\n\t\t styleMap: styleMap,\n strategies: [strategy],\n displayInLayerSwitcher: false,\n\t protocol: new OpenLayers.Protocol.WFS({\n url: '" . str_replace("{HOST}", $_SERVER['HTTP_HOST'], $args['INSEE_url']) . "',\n\t featurePrefix: '" . $args['INSEE_prefix'] . "',\n featureType: '" . $args['INSEE_type'] . "',\n geometryName:'the_geom',\n featureNS: '" . $args['INSEE_ns'] . "',\n srsName: 'EPSG:900913',\n version: '1.1.0' \n \t\t ,propertyNames: ['the_geom', 'NOM', 'INSEE_NEW', 'DEPT_NUM', 'DEPT_NOM', 'REG_NUM', 'REG_NOM']\n \t\t\t})\n });\n inseeLayer.events.register('featuresadded', {}, function(a1){\n \tjQuery('#cc-2-loc-description').empty();\n \tjQuery('<span>'+a1.features[0].attributes.NOM+' ('+a1.features[0].attributes.INSEE_NEW+'), '+a1.features[0].attributes.DEPT_NOM+' ('+a1.features[0].attributes.DEPT_NUM+'), '+a1.features[0].attributes.REG_NOM+' ('+a1.features[0].attributes.REG_NUM+')</span>').appendTo('#cc-2-loc-description');\n });\n\tjQuery('#map')[0].map.addLayer(inseeLayer);\n\tstrategy.load({filter: filter});\n});\n\n"; global $indicia_templates; $r .= $indicia_templates['loading_block_end']; return $r; }
public static function get_occurrences_form($args, $node, $response) { global $user; data_entry_helper::add_resource('jquery_form'); data_entry_helper::add_resource('jquery_ui'); data_entry_helper::add_resource('json'); data_entry_helper::add_resource('autocomplete'); $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); // did the parent sample previously exist? Default is no. $parentSampleId = null; $existing = false; if (isset($_POST['sample:id'])) { // have just posted an edit to the existing parent sample, so can use it to get the parent location id. $parentSampleId = $_POST['sample:id']; $existing = true; } else { if (isset($response['outer_id'])) { // have just posted a new parent sample, so can use it to get the parent location id. $parentSampleId = $response['outer_id']; } else { $parentSampleId = $_GET['sample_id']; $existing = true; } } if (!$parentSampleId || $parentSampleId == '') { return 'Could not determine the parent sample.'; } // find any attributes that apply to Timed Count Count samples. $sampleMethods = helper_base::get_termlist_terms($auth, 'indicia:sample_methods', array('Timed Count Count')); if (count($sampleMethods) == 0) { return 'The sample method "Timed Count Count" must be defined in the termlist in order to use this form.'; } $attributes = data_entry_helper::getAttributes(array('valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'], 'sample_method_id' => $sampleMethods[0]['id'], 'multiValue' => false)); if (!isset(data_entry_helper::$validation_errors)) { // the parent sample and at least one sub-sample have already been created: can't cache in case a new subsample (Count) added. data_entry_helper::load_existing_record($auth['read'], 'sample', $parentSampleId); $d = new DateTime(data_entry_helper::$entity_to_load['sample:date']); data_entry_helper::$entity_to_load['sample:date'] = $d->format('Y'); // using the report returns the attributes as well. $subSamples = data_entry_helper::get_population_data(array('report' => 'library/samples/samples_list_for_parent_sample', 'extraParams' => $auth['read'] + array('sample_id' => $parentSampleId, 'date_from' => '', 'date_to' => '', 'sample_method_id' => '', 'smpattrs' => implode(',', array_keys($attributes))), 'nocache' => true)); // subssamples ordered by id desc, so reorder by date asc. usort($subSamples, "iform_timed_count_subsample_cmp"); for ($i = 0; $i < count($subSamples); $i++) { data_entry_helper::$entity_to_load['C' . ($i + 1) . ':sample:id'] = $subSamples[$i]['sample_id']; data_entry_helper::$entity_to_load['C' . ($i + 1) . ':sample:date'] = $subSamples[$i]['date']; // this is in correct format foreach ($subSamples[$i] as $field => $value) { if (preg_match('/^attr_sample_/', $field)) { $parts = explode('_', $field); if ($subSamples[$i]['attr_id_sample_' . $parts[2]] != null) { data_entry_helper::$entity_to_load['C' . ($i + 1) . ':smpAttr:' + $parts[2] + ':' + $subSamples[$i]['attr_id_sample_' . $parts[2]]] = $value; } } } } } data_entry_helper::$javascript .= "indiciaData.speciesList = " . $args['taxon_list_id'] . ";\n"; if (!empty($args['taxon_filter_field']) && !empty($args['taxon_filter'])) { data_entry_helper::$javascript .= "indiciaData.speciesListFilterField = '" . $args['taxon_filter_field'] . "';\n"; $filterLines = helper_base::explode_lines($args['taxon_filter']); data_entry_helper::$javascript .= "indiciaData.speciesListFilterValues = '" . json_encode($filterLines) . "';\n"; } data_entry_helper::$javascript .= "\r\nindiciaData.indiciaSvc = '" . data_entry_helper::$base_url . "';\n"; data_entry_helper::$javascript .= "indiciaData.readAuth = {nonce: '" . $auth['read']['nonce'] . "', auth_token: '" . $auth['read']['auth_token'] . "'};\n"; data_entry_helper::$javascript .= "indiciaData.parentSample = " . $parentSampleId . ";\n"; data_entry_helper::$javascript .= "indiciaData.occAttrId = " . $args['occurrence_attribute_id'] . ";\n"; if ($existing) { // Only need to load the occurrences for a pre-existing sample $o = data_entry_helper::get_population_data(array('report' => 'library/occurrences/occurrences_list_for_parent_sample', 'extraParams' => $auth['read'] + array('view' => 'detail', 'sample_id' => $parentSampleId, 'survey_id' => '', 'date_from' => '', 'date_to' => '', 'taxon_group_id' => '', 'smpattrs' => '', 'occattrs' => $args['occurrence_attribute_id']), 'nocache' => true)); // the report is ordered id desc. REverse it $o = array_reverse($o); } else { $o = array(); } // empty array of occurrences when no creating a new sample. // we pass through the read auth. This makes it possible for the get_submission method to authorise against the warehouse // without an additional (expensive) warehouse call. // pass a param that sets the next page to display $r = "<form method='post' id='subsamples'>" . $auth['write'] . "\r\n<input type='hidden' name='page' value='occurrences'/>\r\n<input type='hidden' name='read_nonce' value='" . $auth['read']['nonce'] . "'/>\r\n<input type='hidden' name='read_auth_token' value='" . $auth['read']['auth_token'] . "'/>\r\n<input type='hidden' name='website_id' value='" . $args['website_id'] . "'/>\r\n<input type='hidden' name='sample:id' value='" . data_entry_helper::$entity_to_load['sample:id'] . "'/>\r\n<input type='hidden' name='sample:survey_id' value='" . $args['survey_id'] . "'/>\r\n<input type='hidden' name='sample:date' value='" . data_entry_helper::$entity_to_load['sample:date'] . "'/>\r\n<input type='hidden' name='sample:entered_sref' value='" . data_entry_helper::$entity_to_load['sample:entered_sref'] . "'/>\r\n<input type='hidden' name='sample:entered_sref_system' value='" . data_entry_helper::$entity_to_load['sample:entered_sref_system'] . "'/>\r\n<input type='hidden' name='sample:geom' value='" . data_entry_helper::$entity_to_load['sample:geom'] . "'/>\r\n"; if (isset($args['custom_attribute_options']) && $args['custom_attribute_options']) { $blockOptions = get_attr_options_array_with_user_data($args['custom_attribute_options']); } else { $blockOptions = array(); } for ($i = 0; $i < $args['numberOfCounts']; $i++) { $subSampleId = isset($subSamples[$i]) ? $subSamples[$i]['sample_id'] : null; $r .= "<fieldset id=\"count-{$i}\"><legend>" . lang::get('Count ') . ($i + 1) . "</legend>"; if ($subSampleId) { $r .= "<input type='hidden' name='C" . ($i + 1) . ":sample:id' value='" . $subSampleId . "'/>"; } $r .= '<input type="hidden" name="C' . ($i + 1) . ':sample:sample_method_id" value="' . $sampleMethods[0]['id'] . '" />'; if ($subSampleId || isset(data_entry_helper::$entity_to_load['C' . ($i + 1) . ':sample:date']) && data_entry_helper::$entity_to_load['C' . ($i + 1) . ':sample:date'] != '') { $dateValidation = array('required', 'date'); } else { $dateValidation = array('date'); } $r .= data_entry_helper::date_picker(array('label' => lang::get('Date'), 'fieldname' => 'C' . ($i + 1) . ':sample:date', 'validation' => $dateValidation)); data_entry_helper::$javascript .= "\$('#C" . ($i + 1) . "\\\\:sample\\\\:date' ).datepicker( 'option', 'minDate', new Date(" . data_entry_helper::$entity_to_load['sample:date'] . ", 1 - 1, 1) );\r\n\$('#C" . ($i + 1) . "\\\\:sample\\\\:date' ).datepicker( 'option', 'maxDate', new Date(" . data_entry_helper::$entity_to_load['sample:date'] . ", 12 - 1, 31) );\n"; if (!$subSampleId && $i) { $r .= "<p>" . lang::get('You must enter the date before you can enter any further information.') . '</p>'; data_entry_helper::$javascript .= "\$('#C" . ($i + 1) . "\\\\:sample\\\\:date' ).change(function(){\r\n myFieldset = \$(this).addClass('required').closest('fieldset');\r\n myFieldset.find('.smp-input,[name=taxonLookupControl]').removeAttr('disabled'); // leave the count fields as are.\r\n});\n"; } if ($subSampleId && $i) { $r .= "<label for='C" . ($i + 1) . ":sample:deleted'>Delete this count:</label>\r\n<input id='C" . ($i + 1) . ":sample:deleted' type='checkbox' value='t' name='C" . ($i + 1) . ":sample:deleted'><br />\r\n<p>" . lang::get('Setting this will delete this count when the page is saved.') . '</p>'; } foreach ($attributes as $attr) { if (strcasecmp($attr['untranslatedCaption'], 'Unconfirmed Individuals') == 0) { continue; } // output the attribute - tag it with a class & id to make it easy to find from JS. $attrOpts = array_merge(isset($blockOptions[$attr['fieldname']]) ? $blockOptions[$attr['fieldname']] : array(), array('class' => 'smp-input smpAttr-' . ($i + 1), 'id' => 'C' . ($i + 1) . ':' . $attr['fieldname'], 'fieldname' => 'C' . ($i + 1) . ':' . $attr['fieldname'], 'extraParams' => $auth['read'])); // we need process validation specially: deh expects an array, we have a string... if (isset($attrOpts['validation']) && is_string($attrOpts['validation'])) { $attrOpts['validation'] = explode(';', $attrOpts['validation']); } // if there is an existing value, set it and also ensure the attribute name reflects the attribute value id. if (isset($subSampleId)) { // but have to take into account possibility that this field has been blanked out, so deleting the attribute. if (isset($subSamples[$i]['attr_id_sample_' . $attr['attributeId']]) && $subSamples[$i]['attr_id_sample_' . $attr['attributeId']] != '') { $attrOpts['fieldname'] = 'C' . ($i + 1) . ':' . $attr['fieldname'] . ':' . $subSamples[$i]['attr_id_sample_' . $attr['attributeId']]; $attr['default'] = $subSamples[$i]['attr_sample_' . $attr['attributeId']]; } } else { if ($i) { $attrOpts['disabled'] = "disabled=\"disabled\""; } } $r .= data_entry_helper::outputAttribute($attr, $attrOpts); } $r .= '<table id="timed-counts-input-' . $i . '" class="ui-widget">'; $r .= '<thead><tr><th class="ui-widget-header">' . lang::get('Species') . '</th><th class="ui-widget-header">' . lang::get('Count') . '</th><th class="ui-widget-header"></th></tr></thead>'; $r .= '<tbody class="ui-widget-content">'; $occs = array(); // not very many occurrences so no need to optimise. if (isset($subSampleId) && $existing && count($o) > 0) { foreach ($o as $oc) { if ($oc['sample_id'] == $subSampleId) { $occs[] = $oc; } } } for ($j = 0; $j < $args['numberOfSpecies']; $j++) { $rowClass = ''; // O<i>:<j>:<ttlid>:<occid>:<attrid>:<attrvalid> if (isset($occs[$j])) { $taxon = $occs[$j]['common'] . ' (' . $occs[$j]['taxon'] . ')'; $fieldname = 'O' . ($i + 1) . ':' . ($j + 1) . ':' . $occs[$j]['taxa_taxon_list_id'] . ':' . $occs[$j]['occurrence_id'] . ':' . $args['occurrence_attribute_id'] . ':' . $occs[$j]['attr_id_occurrence_' . $args['occurrence_attribute_id']]; $value = $occs[$j]['attr_occurrence_' . $args['occurrence_attribute_id']]; } else { $taxon = ''; $fieldname = 'O' . ($i + 1) . ':' . ($j + 1) . ':--ttlid--:--occid--:' . $args['occurrence_attribute_id'] . ':--valid--'; $value = ''; } $r .= '<tr ' . $rowClass . '>' . '<td><input id="TLC-' . ($i + 1) . '-' . ($j + 1) . '" name="taxonLookupControl" value="' . $taxon . '" ' . (!$j && (!$i || $subSampleId) || $taxon ? 'class="required"' : '') . ' ' . (!$subSampleId && $i ? 'disabled="disabled"' : '') . '>' . (!$j && (!$i || $subSampleId) || $taxon ? '<span class="deh-required">*</span>' : '') . '</td>' . '<td><input name="' . $fieldname . '" id="occ-' . ($i + 1) . '-' . ($j + 1) . '" value="' . $value . '" class="occValField integer ' . (!$j && (!$i || $subSampleId) || $taxon ? 'required' : '') . '" ' . (!$subSampleId && $i || $taxon == '' && ($i || $j) ? 'disabled="disabled"' : '') . ' min=0 >' . (!$j && (!$i || $subSampleId) || $taxon ? '<span class="deh-required">*</span>' : '') . '</td>' . '<td>' . (!$j ? '' : '<div class="ui-state-default remove-button">' . lang::get('Remove this Species entry') . '</div>') . '</td>' . '</tr>'; $rowClass = $rowClass == '' ? 'class="alt-row"' : ''; data_entry_helper::$javascript .= "bindSpeciesAutocomplete(\"TLC-" . ($i + 1) . "-" . ($j + 1) . "\",\"occ-" . ($i + 1) . "-" . ($j + 1) . "\",\"" . data_entry_helper::$base_url . "index.php/services/data\", \"" . $args['taxon_list_id'] . "\",\r\n indiciaData.speciesListFilterField, indiciaData.speciesListFilterValues, {\"auth_token\" : \"" . $auth['read']['auth_token'] . "\", \"nonce\" : \"" . $auth['read']['nonce'] . "\"}, 25);\n"; } foreach ($attributes as $attr) { if (strcasecmp($attr['untranslatedCaption'], 'Unconfirmed Individuals')) { continue; } // output the attribute - tag it with a class & id to make it easy to find from JS. $attrOpts = array('class' => 'smp-input smpAttr-' . ($i + 1), 'id' => 'C' . ($i + 1) . ':' . $attr['fieldname'], 'fieldname' => 'C' . ($i + 1) . ':' . $attr['fieldname'], 'extraParams' => $auth['read']); // if there is an existing value, set it and also ensure the attribute name reflects the attribute value id. if (isset($subSampleId)) { // but have to take into account possibility that this field has been blanked out, so deleting the attribute. if (isset($subSamples[$i]['attr_id_sample_' . $attr['attributeId']]) && $subSamples[$i]['attr_id_sample_' . $attr['attributeId']] != '') { $attrOpts['fieldname'] = 'C' . ($i + 1) . ':' . $attr['fieldname'] . ':' . $subSamples[$i]['attr_id_sample_' . $attr['attributeId']]; $attr['default'] = $subSamples[$i]['attr_sample_' . $attr['attributeId']]; } } else { if ($i) { $attrOpts['disabled'] = "disabled=\"disabled\""; } } $r .= '<tr ' . $rowClass . '>' . '<td>' . $attr['caption'] . '</td>'; unset($attr['caption']); $r .= '<td>' . data_entry_helper::outputAttribute($attr, $attrOpts) . '</td>' . '<td></td>' . '</tr>'; } $r .= '</tbody></table>'; if ($i && !$subSampleId) { $r .= '<button type="button" class="clear-button ui-state-default ui-corner-all smp-input" disabled="disabled" />' . lang::get('Clear this count') . '</button>'; } $r .= '</fieldset>'; } $r .= '<input type="submit" value="' . lang::get('Save') . '" />'; $r .= '<a href="' . $args['summary_page'] . '"><button type="button" class="ui-state-default ui-corner-all" />' . lang::get('Cancel') . '</button></a></form>'; data_entry_helper::enable_validation('subsamples'); data_entry_helper::$javascript .= "initButtons();\n"; return $r; }
/** * Get the date control. */ protected static function get_control_date($auth, $args, $tabAlias, $options) { 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. //Note this only affects the loading of the date itself when the form initially loads, the format displayed as soon as the //date picker is selected is determined by Drupal's settings. // @todo The date format should be a global configurable option. $d = new DateTime(data_entry_helper::$entity_to_load['sample:date']); data_entry_helper::$entity_to_load['sample:date'] = $d->format(helper_base::$date_format); } if ($args['language'] != 'en') { data_entry_helper::add_resource('jquery_ui_' . $args['language']); } // this will autoload the jquery_ui resource. The date_picker does not have access to the args. if (lang::get('LANG_Date_Explanation') != 'LANG_Date_Explanation') { data_entry_helper::$javascript .= "\njQuery('[name=sample\\:date]').next().after('<span class=\"date-explanation\"> " . lang::get('LANG_Date_Explanation') . "</span>');\n"; } return data_entry_helper::date_picker(array_merge(array('label' => lang::get('LANG_Date'), 'fieldname' => 'sample:date', 'default' => isset($args['defaults']['sample:date']) ? $args['defaults']['sample:date'] : ''), $options)); }
/** * Returns controls for defining the date range of a group if this option is enabled. * @param array $args Form configuration arguments * @return string HTML to output */ private static function dateControls($args) { $r = ''; if ($args['include_dates']) { $r .= data_entry_helper::date_picker(array('label' => ucfirst(lang::get('{1} active from', self::$groupType)), 'fieldname' => 'group:from_Date', 'suffixTemplate' => 'nosuffix')); $r .= data_entry_helper::date_picker(array('label' => lang::get('to'), 'fieldname' => 'group:to_Date', 'labelClass' => 'auto', 'helpText' => lang::get('Specify the period during which the {1} was active.', self::$groupType))); } return ''; }
public static function get_sample_form($args, $node, $response) { global $user; if (!module_exists('iform_ajaxproxy')) { return 'This form must be used in Drupal with the Indicia AJAX Proxy module enabled.'; } iform_load_helpers(array('map_helper')); $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); $sampleId = isset($_GET['sample_id']) ? $_GET['sample_id'] : null; $locationId = null; if ($sampleId) { data_entry_helper::load_existing_record($auth['read'], 'sample', $sampleId, 'detail', false, true); $locationId = data_entry_helper::$entity_to_load['sample:location_id']; } else { // location ID also might be in the $_POST data after a validation save of a new record if (isset($_POST['sample:location_id'])) { $locationId = $_POST['sample:location_id']; } } $url = explode('?', $args['my_obs_page'], 2); $params = NULL; $fragment = NULL; // fragment is always at the end. if (count($url) > 1) { $params = explode('#', $url[1], 2); if (count($params) > 1) { $fragment = $params[1]; } $params = $params[0]; } else { $url = explode('#', $url[0], 2); if (count($url) > 1) { $fragment = $url[1]; } } $args['my_obs_page'] = url($url[0], array('query' => $params, 'fragment' => $fragment, 'absolute' => TRUE)); $r = '<form method="post" id="sample">'; $r .= $auth['write']; $r .= '<input type="hidden" name="page" value="mainSample"/>'; $r .= '<input type="hidden" name="website_id" value="' . $args['website_id'] . '"/>'; if (isset(data_entry_helper::$entity_to_load['sample:id'])) { $r .= '<input type="hidden" name="sample:id" value="' . data_entry_helper::$entity_to_load['sample:id'] . '"/>'; } $r .= '<input type="hidden" name="sample:survey_id" value="' . $args['survey_id'] . '"/>'; $r .= '<div id="cols" class="ui-helper-clearfix"><div class="left" style="width: ' . (98 - (isset($args['percent_width']) ? $args['percent_width'] : 50)) . '%">'; // Output only the locations for this website and location type. $availableSites = data_entry_helper::get_population_data(array('report' => 'library/locations/locations_list', 'extraParams' => $auth['read'] + array('website_id' => $args['website_id'], 'location_type_id' => $args['locationType'], 'locattrs' => 'CMS User ID', 'attr_location_cms_user_id' => $user->uid), 'nocache' => true)); // convert the report data to an array for the lookup, plus one to pass to the JS so it can keep the map updated $sitesLookup = array(); $sitesIds = array(); $sitesJs = array(); foreach ($availableSites as $site) { $sitesLookup[$site['location_id']] = $site['name']; $sitesIds[] = $site['location_id']; } $sites = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $auth['read'] + array('website_id' => $args['website_id'], 'id' => $sitesIds, 'view' => 'detail'))); foreach ($sites as $site) { $sitesJs[$site['id']] = $site; } data_entry_helper::$javascript .= "indiciaData.sites = " . json_encode($sitesJs) . ";\n"; if ($locationId) { $r .= '<input type="hidden" name="sample:location_id" id="sample_location_id" value="' . $locationId . '"/>'; // for reload of existing, don't let the user switch the square as that could mess everything up. $r .= '<label>' . lang::get('1km square') . ':</label><span>' . $sitesJs[$locationId]['name'] . '</span><br/>' . lang::get('<p class="ui-state-highlight page-notice ui-corner-all">Please use the map to select a more precise location for your timed observation.</p>'); } else { $options = array('label' => lang::get('Select 1km square'), 'validation' => array('required'), 'blankText' => lang::get('Please select'), 'lookupValues' => $sitesLookup, 'id' => "sample_location_id"); // if ($locationId) $options['default'] = $locationId; $r .= data_entry_helper::location_select($options) . lang::get('<p class="ui-state-highlight page-notice ui-corner-all">After selecting the 1km square, use the map to select a more precise location for your timed observation.</p>'); } // [spatial reference] $systems = array(); foreach (explode(',', str_replace(' ', '', $args['spatial_systems'])) as $system) { $systems[$system] = lang::get("sref:{$system}"); } $r .= data_entry_helper::sref_and_system(array('label' => lang::get('Grid Ref'), 'systems' => $systems)); $r .= data_entry_helper::file_box(array('table' => 'sample_image', 'readAuth' => $auth['read'], 'caption' => lang::get('Upload photo(s) of timed search area'))); $sampleMethods = helper_base::get_termlist_terms($auth, 'indicia:sample_methods', array('Field Observation')); $attributes = data_entry_helper::getAttributes(array('id' => $sampleId, 'valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'], 'sample_method_id' => $sampleMethods[0]['id'])); $r .= get_user_profile_hidden_inputs($attributes, $args, '', $auth['read']); if (isset($_GET['date'])) { $r .= '<input type="hidden" name="sample:date" value="' . $_GET['date'] . '"/>'; $r .= '<label>' . lang::get('Date') . ':</label> <span class="value-label">' . $_GET['date'] . '</span><br/>'; } else { 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'), 'fieldname' => 'sample:date')); } // are there any option overrides for the custom attributes? if (isset($args['custom_attribute_options']) && $args['custom_attribute_options']) { $blockOptions = get_attr_options_array_with_user_data($args['custom_attribute_options']); } else { $blockOptions = array(); } $r .= get_attribute_html($attributes, $args, array('extraParams' => $auth['read']), null, $blockOptions); $r .= '<input type="hidden" name="sample:sample_method_id" value="' . $sampleMethods[0]['id'] . '" />'; $r .= '<input type="submit" value="' . lang::get('Next') . '" />'; $r .= '<a href="' . $args['my_obs_page'] . '" class="button">' . lang::get('Cancel') . '</a>'; if (isset(data_entry_helper::$entity_to_load['sample:id'])) { $r .= '<button id="delete-button" type="button" class="ui-state-default ui-corner-all" />' . lang::get('Delete') . '</button>'; } $r .= "</div>"; // left $r .= '<div class="right" style="width: ' . (isset($args['percent_width']) ? $args['percent_width'] : 50) . '%">'; // [place search] $georefOpts = iform_map_get_georef_options($args, $auth['read']); $georefOpts['label'] = lang::get('Search for Place on Map'); // can't use place search without the driver API key if ($georefOpts['driver'] == 'geoplanet' && empty(helper_config::$geoplanet_api_key)) { $r .= '<span style="display: none;">The form structure includes a place search but needs a geoplanet api key.</span>'; } else { $r .= data_entry_helper::georeference_lookup($georefOpts); } // [map] $options = iform_map_get_map_options($args, $auth['read']); if (!empty(data_entry_helper::$entity_to_load['sample:wkt'])) { $options['initialFeatureWkt'] = data_entry_helper::$entity_to_load['sample:wkt']; } $olOptions = iform_map_get_ol_options($args); if (!isset($options['standardControls'])) { $options['standardControls'] = array('layerSwitcher', 'panZoomBar'); } $r .= map_helper::map_panel($options, $olOptions); data_entry_helper::$javascript .= "\nmapInitialisationHooks.push(function(mapdiv) {\n var defaultStyle = new OpenLayers.Style({pointRadius: 6,fillOpacity: 0,strokeColor: \"Red\",strokeWidth: 1});\n var SiteStyleMap = new OpenLayers.StyleMap({\"default\": defaultStyle});\n indiciaData.SiteLayer = new OpenLayers.Layer.Vector('1km square',{styleMap: SiteStyleMap, displayInLayerSwitcher: true});\n mapdiv.map.addLayer(indiciaData.SiteLayer);\n if(jQuery('#sample_location_id').length > 0) {\n if(jQuery('#sample_location_id').val() != ''){\n var parser = new OpenLayers.Format.WKT();\n var feature = parser.read(indiciaData.sites[jQuery('#sample_location_id').val()].geom);\n indiciaData.SiteLayer.addFeatures([feature]);\n // for existing data we zoom on the site, not this parent location\n } \n jQuery('#sample_location_id').change(function(){\n indiciaData.SiteLayer.destroyFeatures();\n if(jQuery('#sample_location_id').val() != ''){\n var parser = new OpenLayers.Format.WKT();\n var feature = parser.read(indiciaData.sites[jQuery('#sample_location_id').val()].geom);\n indiciaData.SiteLayer.addFeatures([feature]);\n var layerBounds = indiciaData.SiteLayer.getDataExtent().clone(); // use a clone\n indiciaData.SiteLayer.map.zoomToExtent(layerBounds);\n }\n });\n }\n});\n"; $r .= "</div>"; // right $r .= '</form>'; // Recorder Name - assume Easy Login uid if (function_exists('module_exists') && module_exists('easy_login')) { $userId = hostsite_get_user_field('indicia_user_id'); // For non easy login test only $userId = 1; foreach ($attributes as $attrID => $attr) { if (strcasecmp('Recorder Name', $attr["untranslatedCaption"]) == 0 && !empty($userId)) { // determining which you have used is difficult from a services based autocomplete, esp when the created_by_id is not available on the data. data_entry_helper::add_resource('autocomplete'); data_entry_helper::$javascript .= "bindRecorderNameAutocomplete(" . $attrID . ", '" . $userId . "', '" . data_entry_helper::$base_url . "', '" . $args['survey_id'] . "', '" . $auth['read']['auth_token'] . "', '" . $auth['read']['nonce'] . "');\n"; } } } if (isset(data_entry_helper::$entity_to_load['sample:id'])) { // allow deletes if sample id is present. data_entry_helper::$javascript .= "jQuery('#delete-button').click(function(){\n if(confirm(\"" . lang::get('Are you sure you want to delete this walk?') . "\")){\n jQuery('#delete-form').submit();\n } // else do nothing.\n});\n"; // note we only require bare minimum in order to flag a sample as deleted. $r .= '<form method="post" id="delete-form" style="display: none;">'; $r .= $auth['write']; $r .= '<input type="hidden" name="page" value="delete"/>'; $r .= '<input type="hidden" name="website_id" value="' . $args['website_id'] . '"/>'; $r .= '<input type="hidden" name="sample:id" value="' . data_entry_helper::$entity_to_load['sample:id'] . '"/>'; $r .= '<input type="hidden" name="sample:deleted" value="t"/>'; $r .= '</form>'; } data_entry_helper::enable_validation('sample'); return $r; }
private static function get_control_identifier($auth, $args, $tabalias, $options) { $fieldPrefix = !empty($options['fieldprefix']) ? $options['fieldprefix'] : ''; $r = ''; $r .= '<h3 id="' . $fieldPrefix . 'header" class="idn:accordion:header"><a href="#">' . $options['identifierName'] . '</a></h2>'; $r .= '<div id="' . $fieldPrefix . 'panel" class="idn:accordion:panel">'; $r .= '<input type="hidden" name="' . $fieldPrefix . 'identifier:identifier_type_id" value="' . $options['identifierTypeId'] . '" />' . "\n"; $r .= '<input type="hidden" name="' . $fieldPrefix . 'identifier:coded_value" id="' . $fieldPrefix . 'identifier:coded_value" class="identifier_coded_value" value="" />' . "\n"; $val = isset(data_entry_helper::$entity_to_load[$fieldPrefix . 'identifier:id']) ? data_entry_helper::$entity_to_load[$fieldPrefix . 'identifier:id'] : '0'; $r .= '<input type="hidden" name="' . $fieldPrefix . 'identifier:id" id="' . $fieldPrefix . 'identifier:id" class="identifier_id" value="' . $val . '" />' . "\n"; if (isset(data_entry_helper::$entity_to_load[$fieldPrefix . 'identifiers_subject_observation:id'])) { $r .= '<input type="hidden" id="' . $fieldPrefix . 'identifiers_subject_observation:id" name="' . $fieldPrefix . 'identifiers_subject_observation:id" ' . 'value="' . data_entry_helper::$entity_to_load[$fieldPrefix . 'identifiers_subject_observation:id'] . '" />' . "\n"; } // checkbox - (now hidden by CSS, probably should refactor to hidden input?) $r .= data_entry_helper::checkbox(array_merge(array('label' => '', 'fieldname' => $fieldPrefix . 'identifier:checkbox', 'class' => 'identifier_checkbox identifierRequired noDuplicateIdentifiers'), $options)); // loop through the requested attributes and output an appropriate control $classes = $options['class']; foreach ($options['attrList'] as $attribute) { // find the definition of this attribute $found = false; if ($attribute['attrType'] === 'idn') { foreach ($options['idnAttributeTypes'] as $attrType) { if ($attrType['id'] === $attribute['typeId']) { $found = true; break; } } } else { if ($attribute['attrType'] === 'iso') { foreach ($options['isoAttributeTypes'] as $attrType) { if ($attrType['id'] === $attribute['typeId']) { $found = true; break; } } } } if (!$found) { throw new exception(lang::get('Unknown ' . $attribute['attrType'] . ' attribute type id [' . $attribute['typeId'] . '] specified for ' . $options['identifierName'] . ' in Identifier Attributes array.')); } // setup any locking if (!empty($attribute['lockable']) && $attribute['lockable'] === true) { $options['lockable'] = $options['identifiers_lockable']; } // setup any data filters if ($attribute['attrType'] === 'idn' && $options['baseColourId'] == $attribute['typeId']) { if (!empty($args['base_colours'])) { // filter the colours available $query = array('in' => array('id', $args['base_colours'])); } $attr_name = 'base-colour'; } elseif ($attribute['attrType'] === 'idn' && $options['textColourId'] == $attribute['typeId']) { if (!empty($args['text_colours'])) { // filter the colours available $query = array('in' => array('id', $args['text_colours'])); } $attr_name = 'text-colour'; } elseif ($attribute['attrType'] === 'idn' && $options['positionId'] == $attribute['typeId']) { $attr_name = 'position'; if (count($args['position']) > 0) { // filter the identifier position available $query = array('in' => array('id', $args['position'])); } } elseif ($attribute['attrType'] === 'idn' && $options['sequenceId'] == $attribute['typeId']) { $attr_name = 'sequence'; $options['maxlength'] = $options['seq_maxlength'] ? $options['seq_maxlength'] : ''; if ($options['seq_format_class']) { $options['class'] = empty($options['class']) ? $options['seq_format_class'] : (strstr($options['class'], $options['seq_format_class']) ? $options['class'] : $options['class'] . ' ' . $options['seq_format_class']); } } elseif ($attribute['attrType'] === 'iso' && $options['conditionsId'] == $attribute['typeId']) { // filter the identifier conditions available if ($options['identifierTypeId'] == $args['neck_collar_type'] && !empty($args['neck_collar_conditions'])) { $query = array('in' => array('id', $args['neck_collar_conditions'])); } elseif ($options['identifierTypeId'] == $args['enscribed_colour_ring_type'] && !empty($args['coloured_ring_conditions'])) { $query = array('in' => array('id', $args['coloured_ring_conditions'])); } elseif ($options['identifierTypeId'] == $args['metal_ring_type'] && !empty($args['metal_ring_conditions'])) { $query = array('in' => array('id', $args['metal_ring_conditions'])); } $attr_name = 'conditions'; } // add classes as identifiers $options['class'] = empty($options['class']) ? $options['classprefix'] . $attr_name : (strstr($options['class'], $options['classprefix'] . $attr_name) ? $options['class'] : $options['class'] . ' ' . $options['classprefix'] . $attr_name); $options['class'] = $options['class'] . ' idn-' . $attr_name; if ($attribute['attrType'] === 'idn' && ($options['baseColourId'] == $attribute['typeId'] || $options['textColourId'] == $attribute['typeId'])) { $options['class'] = strstr($options['class'], 'select_colour') ? $options['class'] : $options['class'] . ' select_colour'; $options['class'] = strstr($options['class'], 'textAndBaseMustDiffer') ? $options['class'] : $options['class'] . ' textAndBaseMustDiffer'; } if ($attribute['attrType'] === 'idn' && $options['sequenceId'] == $attribute['typeId']) { $options['class'] = strstr($options['class'], 'identifier_sequence') ? $options['class'] : $options['class'] . ' identifier_sequence'; } if (!empty($attribute['hidden']) && $attribute['hidden'] === true) { $dataType = 'H'; // hidden if (!empty($attribute['hiddenValue'])) { $dataDefault = $attribute['hiddenValue']; } else { $dataDefault = ''; } } else { $dataType = $attrType['data_type']; } // output an appropriate control for the attribute data type switch ($dataType) { case 'D': case 'V': $r .= data_entry_helper::date_picker(array_merge(array('label' => lang::get($attrType['caption']), 'fieldname' => $fieldPrefix . $attribute['attrType'] . 'Attr:' . $attrType['id']), $options)); break; case 'L': $filter = array('termlist_id' => $attrType['termlist_id']); if (!empty($query)) { $filter += array('query' => json_encode($query)); } $extraParams = array_merge($filter, $auth['read']); if ($attribute['attrType'] === 'iso' && $options['conditionsId'] == $attribute['typeId']) { $fieldname = $fieldPrefix . $attribute['attrType'] . 'Attr:' . $attrType['id']; $default = array(); // if this attribute exists on DB, we need to write a hidden with id appended to fieldname and set defaults for checkboxes if (is_array(data_entry_helper::$entity_to_load)) { $stored_keys = preg_grep('/^' . $fieldname . ':[0-9]+$/', array_keys(data_entry_helper::$entity_to_load)); foreach ($stored_keys as $stored_key) { $r .= '<input type="hidden" name="' . $stored_key . '" value="" />'; $default[] = array('fieldname' => $stored_key, 'default' => data_entry_helper::$entity_to_load[$stored_key]); unset(data_entry_helper::$entity_to_load[$stored_key]); } } $r .= data_entry_helper::checkbox_group(array_merge(array('label' => lang::get($attrType['caption']), 'fieldname' => $fieldname, 'table' => 'termlists_term', 'captionField' => 'term', 'valueField' => 'id', 'default' => $default, 'extraParams' => $extraParams), $options)); } else { $r .= data_entry_helper::select(array_merge(array('label' => lang::get($attrType['caption']), 'fieldname' => $fieldPrefix . $attribute['attrType'] . 'Attr:' . $attrType['id'], 'table' => 'termlists_term', 'captionField' => 'term', 'valueField' => 'id', 'blankText' => '<Please select>', 'extraParams' => $extraParams), $options)); } break; case 'B': $r .= data_entry_helper::checkbox(array_merge(array('label' => lang::get($attrType['caption']), 'fieldname' => $fieldPrefix . $attribute['attrType'] . 'Attr:' . $attrType['id']), $options)); break; case 'H': // Any multi-value attributes shown as hidden will be single-valued // so transform the array to a scalar $fieldname = $fieldPrefix . $attribute['attrType'] . 'Attr:' . $attrType['id']; if (!empty(data_entry_helper::$entity_to_load[$fieldname]) && is_array(data_entry_helper::$entity_to_load[$fieldname])) { data_entry_helper::$entity_to_load[$fieldname] = data_entry_helper::$entity_to_load[$fieldname][0]; } $r .= data_entry_helper::hidden_text(array_merge(array('fieldname' => $fieldname, 'default' => $dataDefault), $options)); break; default: $r .= data_entry_helper::text_input(array_merge(array('label' => lang::get($attrType['caption']), 'fieldname' => $fieldPrefix . $attribute['attrType'] . 'Attr:' . $attrType['id']), $options)); } $options['class'] = $classes; if (isset($options['maxlength'])) { unset($options['maxlength']); } if (isset($options['lockable'])) { unset($options['lockable']); } } $r .= '</div>'; return $r; }
/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args, $node) { global $user; $logged_in = $user->uid > 0; $r = ''; // Get authorisation tokens to update and read from the Warehouse. $writeAuth = data_entry_helper::get_auth($args['website_id'], $args['password']); $readAuth = data_entry_helper::get_read_auth($args['website_id'], $args['password']); $svcUrl = data_entry_helper::$base_url . '/index.php/services'; $mode = 0; // default mode : display survey selector // mode 1: display new sample // mode 2: display existing sample $loadID = null; $displayThisOcc = true; // when populating from the DB rather than POST we have to be // careful with selection object, as geom in wrong format. if ($_POST) { if (!is_null(data_entry_helper::$entity_to_load)) { $mode = 2; // errors with new sample, entity poulated with post, so display this data. } // else valid save, so go back to gridview: default mode 0 } else { if (array_key_exists('sample_id', $_GET)) { $mode = 2; $loadID = $_GET['sample_id']; } else { if (array_key_exists('newSample', $_GET)) { $mode = 1; data_entry_helper::$entity_to_load = array(); } } // else default to mode 0 } /////////////////////////////////////////////////////////////////// // default mode 0 : display survey selector /////////////////////////////////////////////////////////////////// if ($mode == 0) { // Create the Sample list datagrid for this user. drupal_add_js(drupal_get_path('module', 'iform') . '/media/js/hasharray.js', 'module'); drupal_add_js(drupal_get_path('module', 'iform') . '/media/js/jquery.datagrid.js', 'module'); drupal_add_js("jQuery(document).ready(function(){\n \$('div#smp_grid').indiciaDataGrid('rpt:mnhnl_collab_list_samples', {\n indiciaSvc: '" . $svcUrl . "',\n dataColumns: ['location_name', 'entered_sref', 'date', 'num_occurrences', 'completed'],\n reportColumnTitles: {location_name : '" . lang::get('LANG_Location') . "', entered_sref : '" . lang::get('LANG_Spatial_ref') . "', date : '" . lang::get('LANG_Date') . "', num_occurrences : '" . lang::get('LANG_Num_Occurrences') . "', completed : '" . lang::get('LANG_Completed') . "'},\n actionColumns: {" . lang::get('LANG_Edit') . " : \"" . url('node/' . $node->nid, array('query' => 'sample_id=�id�')) . "\"},\n auth : { nonce : '" . $readAuth['nonce'] . "', auth_token : '" . $readAuth['auth_token'] . "'},\n parameters : {\n \t\t\tsurvey_id : '" . $args['survey_id'] . "',\n \t\t\tuserID_attr_id : '" . $args['uid_attr_id'] . "',\n \t\t\tuserID : '" . $user->uid . "'\n \t\t\t\t},\n itemsPerPage : 12 \n });\n});\n\n", 'inline'); $r .= '<div id="sampleList" class="mnhnl-btw-datapanel"><div id="smp_grid"></div>'; $r .= '<form><input type="button" value="' . lang::get('LANG_Add_Sample') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'newSample')) . '\'"></form></div>'; $r .= "</div>\n"; return $r; } /////////////////////////////////////////////////////////////////// data_entry_helper::$javascript .= "\n// Create vector layers: one to display the location onto, and another for the occurrence list\n// the default edit layer is used for the occurrences themselves\nlocStyleMap = new OpenLayers.StyleMap({\n \"default\": new OpenLayers.Style({\n fillColor: \"Green\",\n strokeColor: \"Black\",\n fillOpacity: 0.3,\n strokeWidth: 1\n })\n });\nlocationLayer = new OpenLayers.Layer.Vector(\"" . lang::get("LANG_Location_Layer") . "\",\n {styleMap: locStyleMap});\n"; if ($loadID) { // Can't cache these as data may have just changed data_entry_helper::$entity_to_load['occurrence:record_status'] = 'I'; $url = $svcUrl . '/data/sample/' . $loadID; $url .= "?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); // Attributes should be loaded by get_attributes. data_entry_helper::$entity_to_load = array(); foreach ($entity[0] as $key => $value) { data_entry_helper::$entity_to_load['sample:' . $key] = $value; } $url = $svcUrl . '/data/occurrence'; $url .= "?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"] . "&sample_id=" . $loadID . "&deleted=FALSE"; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entities = json_decode(curl_exec($session), true); foreach ($entities as $entity) { data_entry_helper::$entity_to_load['occurrence:record_status'] = $entity['record_status']; data_entry_helper::$entity_to_load['sc:' . $entity['taxa_taxon_list_id'] . ':' . $entity['id'] . ':present'] = true; } data_entry_helper::$entity_to_load['sample:geom'] = ''; // value received from db is not WKT, which is assumed by all the code. data_entry_helper::$entity_to_load['sample:date'] = data_entry_helper::$entity_to_load['sample:date_start']; // bit of a bodge to get around vague dates. } $defAttrOptions = array('extraParams' => $readAuth); // $r .= "<h1>MODE = ".$mode."</h1>"; // $r .= "<h2>readOnly = ".$readOnly."</h2>"; $r = "<form method=\"post\" id=\"entry_form\">\n"; // Get authorisation tokens to update and read from the Warehouse. $r .= $writeAuth; $r .= "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n"; $r .= "<input type=\"hidden\" id=\"sample:survey_id\" name=\"sample:survey_id\" value=\"" . $args['survey_id'] . "\" />\n"; if (array_key_exists('sample:id', data_entry_helper::$entity_to_load)) { $r .= "<input type=\"hidden\" id=\"sample:id\" name=\"sample:id\" value=\"" . data_entry_helper::$entity_to_load['sample:id'] . "\" />\n"; } // request automatic JS validation data_entry_helper::enable_validation('entry_form'); $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' => $readAuth, 'survey_id' => $args['survey_id'])); if ($logged_in) { // If logged in, output some hidden data about the user $uid = $user->uid; $email = $user->mail; $username = $user->name; $uid_attr_id = $args['uid_attr_id']; $email_attr_id = $args['email_attr_id']; $username_attr_id = $args['username_attr_id']; // This assumes that we have the following attributes : no built in error checking. $r .= "<input type=\"hidden\" name=\"" . $attributes[$uid_attr_id]['fieldname'] . "\" value=\"{$uid}\" />\n"; $r .= "<input type=\"hidden\" name=\"" . $attributes[$email_attr_id]['fieldname'] . "\" value=\"{$email}\" />\n"; $r .= "<input type=\"hidden\" name=\"" . $attributes[$username_attr_id]['fieldname'] . "\" value=\"{$username}\" />\n"; } $r .= "<div id=\"controls\">\n"; if ($args['interface'] != 'one_page') { $r .= "<ul>\n"; if (!$logged_in) { $r .= ' <li><a href="#about_you"><span>' . lang::get('LANG_About_You_Tab') . "</span></a></li>\n"; } $r .= ' <li><a href="#species"><span>' . lang::get('LANG_Species_Tab') . "</span></a></li>\n"; $r .= ' <li><a href="#place"><span>' . lang::get('LANG_Place_Tab') . "</span></a></li>\n"; $r .= ' <li><a href="#other"><span>' . lang::get('LANG_Other_Information_Tab') . "</span></a></li>\n"; $r .= "</ul>\n"; data_entry_helper::enable_tabs(array('divId' => 'controls', 'style' => $args['interface'])); } //////////////////////////////////////////////////////////////////////////////////////////////////////////// if (!$logged_in) { $r .= "<div id=\"about_you\">\n"; $r .= '<p class="page-notice ui-state-highlight ui-corner-all">' . lang::get('LANG_About_You_Tab_Instructions') . "</p>"; $defAttrOptions['class'] = 'control-width-4'; $r .= data_entry_helper::outputAttribute($attributes[$args['first_name_attr_id']], $defAttrOptions); $r .= data_entry_helper::outputAttribute($attributes[$args['surname_attr_id']], $defAttrOptions); $r .= data_entry_helper::outputAttribute($attributes[$args['email_attr_id']], $defAttrOptions); $r .= data_entry_helper::outputAttribute($attributes[$args['phone_attr_id']], $defAttrOptions); if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => 'first')); } unset($defAttrOptions['class']); $r .= "</div>\n"; } //////////////////////////////////////////////////////////////////////////////////////////////////////////// global $indicia_templates; $indicia_templates['taxon_label'] = '<div class="biota"><span class="nobreak sci binomial"><em>{taxon}</em></span> {authority}</div>'; $r .= "<div id=\"species\">\n"; $r .= '<p class="page-notice ui-state-highlight ui-corner-all">' . lang::get('LANG_Species_Tab_Instructions') . "</p>"; $extraParams = $readAuth + array('taxon_list_id' => $args['list_id']); $species_list_args = array('label' => lang::get('occurrence:taxa_taxon_list_id'), 'fieldname' => 'occurrence:taxa_taxon_list_id', 'table' => 'taxa_taxon_list', 'captionField' => 'taxon', 'valueField' => 'id', 'columns' => 1, 'view' => 'detail', 'parentField' => 'parent_id', 'occAttrs' => explode(',', $args['checklist_attributes']), 'extraParams' => $extraParams, 'survey_id' => $args['survey_id']); $r .= data_entry_helper::species_checklist($species_list_args); $r .= "<label for=\"sample:comment\">" . lang::get('LANG_Sample_Comment_Label') . "</label><input type=\"text\" id=\"sample:comment\" name=\"sample:comment\" value=\"" . data_entry_helper::$entity_to_load['sample:comment'] . "\" />\n"; if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => $user->id == 0 ? 'first' : 'middle')); } $r .= "</div>\n"; //////////////////////////////////////////////////////////////////////////////////////////////////////////// $r .= "<div id=\"place\">\n"; $r .= '<p class="page-notice ui-state-highlight ui-corner-all">' . lang::get('LANG_Place_Tab_Instructions') . "</p>"; // Build the array of spatial reference systems into a format Indicia can use. $systems = array(); $list = explode(',', str_replace(' ', '', $args['spatial_systems'])); foreach ($list as $system) { $systems[$system] = lang::get($system); } $r .= data_entry_helper::sref_and_system(array('label' => lang::get('LANG_SRef_Label'), 'systems' => $systems)); $location_list_args = array('label' => lang::get('LANG_Location_Label'), 'view' => 'detail', 'extraParams' => array_merge(array('view' => 'detail', 'orderby' => 'name'), $extraParams)); $r .= call_user_func(array('data_entry_helper', $args['location_ctrl']), $location_list_args); $r .= data_entry_helper::georeference_lookup(array('label' => lang::get('LANG_Georef_Label'), 'georefPreferredArea' => $args['georefPreferredArea'], 'georefCountry' => $args['georefCountry'], 'georefLang' => $args['language'])); $options = iform_map_get_map_options($args, $readAuth); $options['layers'][] = 'locationLayer'; $olOptions = iform_map_get_ol_options($args); $r .= data_entry_helper::map_panel($options, $olOptions); if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls')); } $r .= "</div>\n"; //////////////////////////////////////////////////////////////////////////////////////////////////////////// $r .= "<div id=\"other\">\n"; $r .= '<p class="page-notice ui-state-highlight ui-corner-all">' . lang::get('LANG_Other_Information_Tab_Instructions') . "</p>"; $r .= data_entry_helper::date_picker(array('label' => lang::get('LANG_Date'), 'fieldname' => 'sample:date')); $r .= data_entry_helper::outputAttribute($attributes[$args['biotope_attr_id']], $defAttrOptions); $r .= data_entry_helper::outputAttribute($attributes[$args['voucher_attr_id']], $defAttrOptions); $values = array('I', 'C'); // not initially doing V=Verified $r .= '<label for="occurrence:record_status">' . lang::get('LANG_Record_Status_Label') . '</label><select id="occurrence:record_status" name="occurrence:record_status">'; foreach ($values as $value) { $r .= '<option value="' . $value . '"'; if (isset(data_entry_helper::$entity_to_load['occurrence:record_status'])) { if (data_entry_helper::$entity_to_load['occurrence:record_status'] == $value) { $r .= ' selected="selected"'; } } $r .= '>' . lang::get('LANG_Record_Status_' . $value) . '</option>'; } $r .= '</select>'; // TODO image upload - not sure how to do this as images are attached to occurrences, and occurrences // are embedded in the species list. // $r .= "<label for='occurrence:image'>".lang::get('LANG_Image_Label')."</label>\n". // data_entry_helper::image_upload('occurrence:image'); $r .= '<br/><br/>'; if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => 'last')); } else { $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save') . "\" />\n"; } $r .= "</div>\n"; $r .= "</div>\n"; if (!empty(data_entry_helper::$validation_errors)) { $r .= data_entry_helper::dump_remaining_errors(); } $r .= "</form>"; // may need to keep following code for location change functionality data_entry_helper::$onload_javascript .= "\n \nlocationChange = function(obj){\n\tlocationLayer.destroyFeatures();\n\tif(obj.value != ''){\n\t\tjQuery.getJSON(\"" . $svcUrl . "\" + \"/data/location/\"+obj.value +\n\t\t\t\"?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"] . "\" +\n\t\t\t\"&callback=?\", function(data) {\n if (data.length>0) {\n \tvar parser = new OpenLayers.Format.WKT();\n \tfor (var i=0;i<data.length;i++)\n\t\t\t\t{\n\t \t\t\tif(data[i].centroid_geom){\n\t\t\t\t\t\tfeature = parser.read(data[i].centroid_geom);\n\t\t\t\t\t\tcentre = feature.geometry.getCentroid();\n\t\t\t\t\t\tcentrefeature = new OpenLayers.Feature.Vector(centre, {}, {label: data[i].name});\n\t\t\t\t\t\tlocationLayer.addFeatures([feature, centrefeature]); \n\t\t\t\t\t}\n\t\t\t\t\tif(data[i].boundary_geom){\n\t\t\t\t\t\tfeature = parser.read(data[i].boundary_geom);\n\t\t\t\t\t\tfeature.style = {strokeColor: \"Blue\",\n \t \tstrokeWidth: 2,\n \t\t\t\t\t\t\tlabel: (data[i].centroid_geom ? \"\" : data[i].name)};\n\t\t\t\t\t\tlocationLayer.addFeatures([feature]);\n \t\t\t\t\t}\n \t\t\t\tlocationLayer.map.zoomToExtent(locationLayer.getDataExtent());\n \t\t\t\t}\n\t\t\t}\n\t\t});\n }\n};\njQuery('#imp-location').unbind('change');\njQuery('#imp-location').change(function(){\n\tlocationChange(this);\n});\n// upload location & sref initial values into map.\njQuery('#imp-location').change();\njQuery('#imp-sref').change();\n\n"; return $r; }
/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args) { global $user; $logged_in = $user->uid > 0; // Get authorisation tokens to update and read from the Warehouse. $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); $readAuth = $auth['read']; // enable image viewing with FancyBox - only required if the file box is enabled //data_entry_helper::$javascript .= "jQuery(\"a.fancybox\").fancybox();\n"; $r = "\n<form method=\"post\" id=\"entry_form\">\n"; if (isset($_GET['taxa_taxon_list_id']) || isset($_GET['taxon_external_key'])) { if (isset($_GET['taxa_taxon_list_id'])) { $filter = array('id' => $_GET['taxa_taxon_list_id']); } else { $filter = array('external_key' => $_GET['taxon_external_key']); } $species = data_entry_helper::get_population_data(array('table' => 'taxa_taxon_list', 'extraParams' => $readAuth + $filter + array('taxon_list_id' => $args['list_id'], 'view' => 'detail', 'preferred' => 't'))); // we need only one result, but there could be more than one picture, therefore multiple rows $uniqueMeaning = false; if (count($species) == 1) { $uniqueMeaning = $species[0]['taxon_meaning_id']; } if (count($species) > 1) { $uniqueMeaning = $species[0]['taxon_meaning_id']; foreach ($species as $item) { if ($item['taxon_meaning_id'] != $uniqueMeaning) { $uniqueMeaning = false; } } } if ($uniqueMeaning) { // now we have the meaning_id, we need to fetch the actual species in the chosen common name $speciesCommon = data_entry_helper::get_population_data(array('table' => 'taxa_taxon_list', 'extraParams' => $readAuth + array('taxon_meaning_id' => $uniqueMeaning, 'language_iso' => iform_lang_iso_639_2($user->lang), 'view' => 'detail'))); $r .= '<div class="ui-widget ui-widget-content ui-corner-all page-notice ui-helper-clearfix">'; $nameString = ($species[0]['language_iso'] == 'lat' ? '<em>' : '') . $species[0]['taxon'] . ($species[0]['language_iso'] == 'lat' ? '</em>' : ''); if (count($speciesCommon) >= 1) { // use a common name if we have one $nameString = $speciesCommon[0]['taxon'] . ' (' . $nameString . ')'; } if (!empty($species[0]['description_in_list'])) { $r .= '<div class="page-notice">' . lang::get('you are recording a', $nameString) . '</div>'; } $taxa_taxon_list_id = $species[0]['id']; $images_path = data_entry_helper::$base_url . (isset(data_entry_helper::$indicia_upload_path) ? data_entry_helper::$indicia_upload_path : 'upload/'); foreach ($species as $item) { if (!empty($item['image_path'])) { $r .= '<a class="fancybox left" href="' . $images_path . $item['image_path'] . '" style="margin: 0 1em 1em;">'; $r .= '<img width="100" src="' . $images_path . 'thumb-' . $item['image_path'] . '" />'; $r .= '</a>'; } } if (!empty($species[0]['description_in_list'])) { $r .= '<p>' . $species[0]['description_in_list'] . "</p>"; } else { $r .= '<p>' . lang::get('you are recording a', $nameString) . '</p>'; } $r .= "</div>\n"; } else { $r .= "<p>The species not be identified uniquely from the URL parameters.</p>\n"; } } // request automatic JS validation data_entry_helper::enable_validation('entry_form'); $r .= "<div id=\"controls\">\n"; if ($args['interface'] != 'one_page') { $r .= "<ul>\n"; if (!$logged_in) { $r .= ' <li><a href="#about_you"><span>' . lang::get('about you') . "</span></a></li>\n"; } if (!isset($taxa_taxon_list_id)) { $r .= ' <li><a href="#species"><span>' . lang::get('what did you see') . "</span></a></li>\n"; } $r .= ' <li><a href="#place"><span>' . lang::get('where was it') . "</span></a></li>\n"; $r .= ' <li><a href="#other"><span>' . lang::get('other information') . "</span></a></li>\n"; $r .= "</ul>\n"; data_entry_helper::enable_tabs(array('divId' => 'controls', 'style' => $args['interface'])); } if ($user->uid == 0) { $r .= "<fieldset id=\"about_you\">\n"; $r .= '<p class="page-notice ui-state-highlight ui-corner-all">' . lang::get('about you tab instructions') . "</p>"; $r .= data_entry_helper::text_input(array('label' => lang::get('first name'), 'fieldname' => 'smpAttr:' . $args['first_name_attr_id'], 'class' => 'control-width-4')); $r .= data_entry_helper::text_input(array('label' => lang::get('surname'), 'fieldname' => 'smpAttr:' . $args['surname_attr_id'], 'class' => 'control-width-4')); $r .= data_entry_helper::text_input(array('label' => lang::get('email'), 'fieldname' => 'smpAttr:' . $args['email_attr_id'], 'class' => 'control-width-4')); $r .= data_entry_helper::text_input(array('label' => lang::get('phone number'), 'fieldname' => 'smpAttr:' . $args['phone_attr_id'], 'class' => 'control-width-4')); if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => 'first')); } $r .= "</fieldset>\n"; } // the species tab is ommitted if the page is called with a taxon in the querystring parameters if (isset($taxa_taxon_list_id)) { $r .= "<input type=\"hidden\" name=\"occurrence:taxa_taxon_list_id\" value=\"{$taxa_taxon_list_id}\"/>\n"; } else { $r .= "<fieldset id=\"species\">\n"; $r .= '<p class="page-notice ui-state-highlight ui-corner-all">' . lang::get('species tab instructions') . "</p>"; $extraParams = $readAuth + array('taxon_list_id' => $args['list_id']); if ($args['preferred']) { $extraParams += array('preferred' => 't'); } if ($args['restrict_species_to_users_lang']) { $extraParams += array('language_iso' => iform_lang_iso_639_2($user->lang)); } $species_list_args = array('label' => lang::get('occurrence:taxa_taxon_list_id'), 'fieldname' => 'occurrence:taxa_taxon_list_id', 'table' => 'taxa_taxon_list', 'captionField' => 'taxon', 'valueField' => 'id', 'columns' => 2, 'view' => 'detail', 'parentField' => 'parent_id', 'extraParams' => $extraParams); if ($args['species_ctrl'] == 'tree_browser') { // change the node template to include images global $indicia_templates; $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', $args['species_ctrl']), $species_list_args); if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => $user->id == 0 ? 'first' : 'middle')); } $r .= "</fieldset>\n"; } $r .= "<fieldset id=\"place\">\n"; // Output all our hidden data here, because this tab is always present $r .= $auth['write']; if ($logged_in) { // If logged in, output some hidden data about the user $r .= iform_user_get_hidden_inputs($args); } // if the species being recorded is a fixed species defined in the URL, then output a hidden if (isset($taxa_taxon_list_id)) { $r .= "<input type=\"hidden\" name=\"occurrence:taxa_taxon_list_id'\" value=\"" . $taxa_taxon_list_id . "\" />\n"; } $r .= "<input type=\"hidden\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n"; $r .= "<input type=\"hidden\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n"; $r .= "<input type=\"hidden\" name=\"record_status\" value=\"" . $args['record_status'] . "\" />\n"; $r .= '<p class="page-notice ui-state-highlight ui-corner-all">' . lang::get('place tab instructions') . "</p>"; // Build the array of spatial reference systems into a format Indicia can use. $systems = array(); $list = explode(',', str_replace(' ', '', $args['spatial_systems'])); foreach ($list as $system) { $systems[$system] = lang::get($system); } $r .= data_entry_helper::georeference_lookup(iform_map_get_georef_options($args, $auth['read'])); $r .= data_entry_helper::sref_and_system(array('label' => lang::get('sample:entered_sref'), 'systems' => $systems)); // retrieve options for the IndiciaMapPanel, and optionally options for OpenLayers. $options = iform_map_get_map_options($args, $readAuth); $options['tabDiv'] = 'place'; $olOptions = iform_map_get_ol_options($args); $options['scroll_wheel_zoom'] = false; $r .= data_entry_helper::map_panel($options, $olOptions); if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => $user->id == 0 && isset($taxa_taxon_list_id) ? 'first' : 'middle')); } $r .= "</fieldset>\n"; $r .= "<fieldset id=\"other\">\n"; $r .= '<p class="page-notice ui-state-highlight ui-corner-all">' . lang::get('other tab instructions') . "</p>"; $r .= data_entry_helper::date_picker(array('label' => lang::get('Date'), 'fieldname' => 'sample:date')); $r .= data_entry_helper::file_box(array('caption' => 'Upload your photos', 'readAuth' => $readAuth, 'resizeWidth' => 1024, 'resizeHeight' => 768, 'table' => 'occurrence_image', 'tabDiv' => 'other', 'runtimes' => array('html5', 'html4'))); // Dynamically create a control for the abundance, unless overridden for this species if (isset($species) && count($species) > 0 && trim($args['abundance_overrides']) !== '') { $overrides = explode("\n", $args['abundance_overrides']); foreach ($overrides as $override) { $tokens = explode(':', $override); if ($tokens[0] == $species[0]['taxon']) { // remove the default abundance attribute behaviour $args['abundance_attr_id'] = ''; if (trim($tokens[1]) !== '') { $attrIds = explode(',', $tokens[1]); $attributes = data_entry_helper::getAttributes(array('id' => null, 'valuetable' => 'occurrence_attribute_value', 'attrtable' => 'occurrence_attribute', 'key' => 'occurrence_id', 'fieldprefix' => "occAttr", 'extraParams' => $readAuth + array('query' => urlencode(json_encode(array('in' => array('id', $attrIds))))), 'survey_id' => $args['survey_id'])); foreach ($attributes as $attribute) { $r .= data_entry_helper::outputAttribute($attribute, array('language' => iform_lang_iso_639_2($user->lang), 'booleanCtrl' => 'checkbox')); } } } } } if (!empty($args['abundance_attr_id'])) { $abundance_args = array('label' => lang::get('abundance'), 'fieldname' => 'occAttr:' . $args['abundance_attr_id'], 'table' => 'termlists_term', 'captionField' => 'term', 'valueField' => 'id', 'extraParams' => $readAuth + array('termlist_id' => $args['abundance_termlist_id']), 'size' => 6, 'sep' => '<br/>'); $r .= call_user_func(array('data_entry_helper', $args['abundance_ctrl']), $abundance_args); } $r .= data_entry_helper::textarea(array('label' => lang::get('sample:comment'), 'fieldname' => 'sample:comment', 'class' => 'wide')); $r .= '<div class="footer">' . data_entry_helper::checkbox(array('label' => lang::get('happy for contact'), 'labelClass' => 'auto', 'fieldname' => 'smpAttr:' . $args['contact_attr_id'])) . '</div>'; if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => 'last')); } else { $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"Save\" />\n"; } $r .= "</fieldset>\n"; $r .= "</div>\n"; $r .= "</form>"; return $r; }
); } </script> </head> <body> <div id="wrap"> <h1>Record Card Header</h1> <p>Please enter summary information for your record card below.</p> <form action="list.php" method="post"> <fieldset> <legend>Card Header</legend> <label for="date">Date:</label> <?php echo data_entry_helper::date_picker('sample:date'); ?> <br/> <div id="map"></div> <div id="panel" class="olControlPanel"></div><span id="mousePos"></span> <label for="smpAttr:1">Weather:</label> <input type="text" id="smpAttr:1" name="smpAttr:1" class="wide" /> <br/> <label for="smpAttr:3">Surroundings:</label> <?php echo data_entry_helper::select("smpAttr:3", 'termlists_term', 'term', 'id', $readAuth + array('termlist_id' => 2)); ?> <br/> <input type="submit" value="Next" class="auto" /> </fieldset> </form>
// Get authorisation tokens to update and read from the Warehouse. $auth = data_entry_helper::get_read_write_auth($config['website_id'], $config['password']); echo $auth['write']; $readAuth = $auth['read']; ?> <input type='hidden' name='website_id' value='<?php echo $config['website_id']; ?> ' /> <input type='hidden' name='survey_id' value='<?php echo $config['survey_id']; ?> ' /> <input type='hidden' name='occurrence:record_status' value='C' /> <?php echo data_entry_helper::date_picker(array('label' => 'Date', 'fieldname' => 'sample:date')); echo data_entry_helper::sref_and_system(array('label' => 'Grid Ref', 'fieldname' => 'sample:entered_sref')); ?> <div class="smaller"> <?php echo data_entry_helper::species_checklist(array('listId' => $config['species_checklist_taxon_list'], 'lookupListId' => $config['species_checklist_alt_list'], 'extraParams' => $readAuth, 'survey_id' => $config['survey_id'])); ?> </div> <br /> <input type='submit' value='Save' /> </form> </div> </body> <?php echo data_entry_helper::dump_javascript();
if (array_key_exists('attributes', $values) && count($values['attributes']) > 0) { ?> <fieldset> <legend>Custom Attributes</legend> <ol> <?php foreach ($values['attributes'] as $attr) { $name = 'idnAttr:' . $attr['identifier_attribute_id']; // if this is an existing attribute, tag it with the attribute value record id so we can re-save it if ($attr['id']) { $name .= ':' . $attr['id']; } switch ($attr['data_type']) { case 'D': case 'V': echo data_entry_helper::date_picker(array('label' => $attr['caption'], 'fieldname' => $name, 'default' => $attr['value'])); break; case 'L': echo data_entry_helper::select(array('label' => $attr['caption'], 'fieldname' => $name, 'default' => $attr['raw_value'], 'lookupValues' => $values['terms_' . $attr['termlist_id']], 'blankText' => '<Please select>')); break; case 'B': echo data_entry_helper::checkbox(array('label' => $attr['caption'], 'fieldname' => $name, 'default' => $attr['value'])); break; default: echo data_entry_helper::text_input(array('label' => $attr['caption'], 'fieldname' => $name, 'default' => $attr['value'])); } } ?> </ol> </fieldset> <?php
/** * Return the generated form output. * @param array $args List of parameter values passed through to the form depending on how the form has been configured. * This array always contains a value for language. * @param object $nid The Drupal node object's ID. * @param array $response When this form is reloading after saving a submission, contains the response from the service call. * Note this does not apply when redirecting (in this case the details of the saved object are in the $_GET data). * @return Form HTML. */ public static function get_form($args, $nid, $response = null) { drupal_add_js(iform_client_helpers_path() . "prebuilt_forms/js/easy_download_2.js"); drupal_add_css(iform_client_helpers_path() . "prebuilt_forms/css/easy_download_2.css"); $conn = iform_get_connection_details($nid); $args = array_merge(array('download_administered_groups' => 'indicia data admin', 'download_group_types' => ''), $args); $readAuth = data_entry_helper::get_read_auth($conn['website_id'], $conn['password']); if (data_entry_helper::$js_read_tokens === null) { data_entry_helper::$js_read_tokens = $readAuth; } if (!empty($_POST) && !empty($_POST['format'])) { self::do_data_services_download($args, $nid); } $types = self::get_download_types($args); $formats = self::get_download_formats($args); if (count($types) === 0) { return 'This download page is configured so that no download type options are available.'; } if (count($formats) === 0) { return 'This download page is configured so that no download format options are available.'; } $reload = data_entry_helper::get_reload_link_parts(); $reloadPath = $reload['path']; if (count($reload['params'])) { $reloadPath .= '?' . helper_base::array_to_query_string($reload['params']); } $r = '<form method="POST" action="' . $reloadPath . '">'; $r .= '<fieldset id="download-type-fieldset"><legend>' . lang::get('Records to download') . '</legend>'; if (count($types) === 1) { $r .= '<input type="hidden" name="download-type" id="download-type" value="' . implode('', array_keys($types)) . '"/>'; hostsite_set_page_title(lang::get('Download {1}', strtolower(implode('', $types)))); } else { $r .= data_entry_helper::select(array('fieldname' => 'download-type', 'label' => lang::get('Download type'), 'lookupValues' => $types, 'class' => 'control-width-5', 'helpText' => 'Select the type of download you require, i.e. the purpose for the data. This defines which records are available to download.')); } $r .= data_entry_helper::select(array('fieldname' => 'download-subfilter', 'label' => lang::get('Filter to apply'), 'lookupValues' => array(), 'class' => 'control-width-5', 'helpText' => lang::get('Optionally select from the available filters. Filters you create on the Explore pages will be available here.'))); $r .= "</fieldset>\n"; $r .= '<fieldset><legend>' . lang::get('Limit the records') . '</legend>'; // Hub // TODO may run into URL size limits $vocabulary = taxonomy_vocabulary_machine_name_load('hubs'); $terms = entity_load('taxonomy_term', FALSE, array('vid' => $vocabulary->vid)); // the hub is driven by a user field, stored as tid. $hubList = array('' => lang::get('<All>')); foreach ($terms as $term) { // TODO Cache $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'user')->fieldCondition('field_preferred_training_hub', 'tid', $term->tid); $result = $query->execute(); // This gives us the list of users which are in the hub: CMS user ID: now convert to indicia user id $userIDList = array(); if (count($result) > 0) { $cmsUserIDs = array_keys($result['user']); foreach ($cmsUserIDs as $cmsUserID) { $user_data = user_load($cmsUserID); // TODO Making assumption about language if (!empty($user_data->field_indicia_user_id['und'][0]['value'])) { $userIDList[] = $user_data->field_indicia_user_id['und'][0]['value']; } } if (count($userIDList) > 0) { $hubList[implode(',', $userIDList)] = $term->tid . ' ' . $term->name; } } } $r .= data_entry_helper::select(array('fieldname' => 'user_id_list', 'label' => lang::get('Hub to include'), 'helpText' => 'Choose a Hub, or <All> to not filter by Hub. This is driven off the users currently allocated to the hub. This currently does not apply to the NBN download.', 'lookupValues' => $hubList, 'class' => 'control-width-5')); // End Cocoast Hub if (empty($args['survey_id'])) { // put up an empty surveys drop down. AJAX will populate it. $r .= data_entry_helper::select(array('fieldname' => 'survey_id', 'label' => lang::get('Survey to include'), 'helpText' => 'Choose a survey, or <All> to not filter by survey.', 'lookupValues' => array(), 'class' => 'control-width-5')); } else { $r .= '<input type="hidden" name="survey_id" value="' . $args['survey_id'] . '"/>'; } // Let the user pick the date range to download. $r .= data_entry_helper::select(array('label' => lang::get('Date field'), 'fieldname' => 'date_type', 'lookupValues' => array('recorded' => lang::get('Field record date'), 'input' => lang::get('Input date'), 'edited' => lang::get('Last changed date'), 'verified' => 'Verification status change date'), 'helpText' => 'If filtering on date, which date field would you like to filter on?')); $r .= data_entry_helper::date_picker(array('fieldname' => 'date_from', 'label' => lang::get('Start Date'), 'helpText' => 'Leave blank for no start date filter', 'class' => 'control-width-4')); $r .= data_entry_helper::date_picker(array('fieldname' => 'date_to', 'label' => lang::get('End Date'), 'helpText' => 'Leave blank for no end date filter', 'class' => 'control-width-4')); $r .= '</fieldset>'; if (!empty($args['custom_formats'])) { $customFormats = json_decode($args['custom_formats'], true); foreach ($customFormats as $idx => $format) { if (empty($format['permission']) || hostsite_user_has_permission($format['permission'])) { $formats["custom-{$idx}"] = lang::get(isset($format['title']) ? $format['title'] : 'Untitled format'); } } } if (count($formats) > 1) { $r .= '<fieldset><legend>' . lang::get('Select a format to download') . '</legend>'; $keys = array_keys($formats); $r .= data_entry_helper::radio_group(array('fieldname' => 'format', 'lookupValues' => $formats, 'default' => $keys[0])); $r .= '</fieldset>'; } else { // only allowed 1 format, so no need for a selection control $keys = array_keys($formats); $r .= '<input type="hidden" name="format" value="' . array_pop($keys) . '"/>'; } $r .= '<input type="submit" value="' . lang::get('Download') . '"/></form>'; data_entry_helper::$javascript .= 'indiciaData.ajaxUrl="' . url('iform/ajax/easy_download_2') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.nid = "' . $nid . "\";\n"; data_entry_helper::$javascript .= "setAvailableDownloadFilters();\n"; return $r; }
/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args, $node, $response = null) { global $user; $logged_in = $user->uid > 0; $r = ''; // Get authorisation tokens to update and read from the Warehouse. $writeAuth = data_entry_helper::get_auth($args['website_id'], $args['password']); $readAuth = data_entry_helper::get_read_auth($args['website_id'], $args['password']); $svcUrl = data_entry_helper::$base_url . '/index.php/services'; $presetLayers = array(); // read out the activated preset layers if (isset($args['preset_layers'])) { foreach ($args['preset_layers'] as $layer => $active) { if ($active !== 0) { $presetLayers[] = $layer; } } } // When invoked by GET there are the following modes: // Not logged in: Display an information message. // No additional arguments: display the survey selector. // Additional argument - newSample: display the main page, no occurrence or occurrence list tabs. Survey tab active. // Additional argument - sample_id=<id>: display the main page, fill in the main sample details, "Add Occurrence" tab present, survey tab active. // Additional argument - occurrence_id=<id>: display the main page, fill in the main sample details, "Add Occurrence" tab active. $mode = 0; // default mode : display survey selector // mode 1: display new sample: no occurrence list or add occurrence tabs. Survey tab active // mode 2: display existing sample. Survey tab active. No occurence details filled in. // mode 3: display existing occurrence. Add Occurrence tab active. Occurence details filled in. // mode 4: NO LONGER USED. display Occurrence List. Occurrence List tab active. No occurence details filled in. $readOnly = false; // On top of this, things can be flagged as readonly. RO mode 2+4 means no Add Occurrence tab. if (!$logged_in) { return lang::get('LANG_not_logged_in'); } $parentSample = array(); $parentErrors = null; $parentLoadID = null; $childSample = array(); $childErrors = null; $childLoadID = null; $saveErrors = data_entry_helper::$validation_errors; $thisOccID = -1; // IDs have to be >0, so this is outside the valid range $displayThisOcc = true; // when populating from the DB rather than POST we have to be // careful with selection object, as geom in wrong format. if ($_POST) { if (array_key_exists('website_id', $_POST)) { // Indicia POST, already handled. if (array_key_exists('newSample', $_GET)) { if (!is_null(data_entry_helper::$entity_to_load)) { $mode = 1; // errors with new sample, entity populated with post, so display this data. $parentSample = data_entry_helper::$entity_to_load; $parentErrors = $saveErrors; } else { // else new sample just saved, so reload it ready to add occurrences // OR, child sample/occurrence saved against new parent sample, in which case parent sample is in the post. $mode = 2; $parentLoadID = array_key_exists('sample:parent_id', $_POST) ? $_POST['sample:parent_id'] : $response['outer_id']; } } else { // could have saved parent sample or child sample/occurrence pair. if (array_key_exists('sample:parent_id', $_POST)) { // have saved child sample/occurrence pair $parentLoadID = $_POST['sample:parent_id']; // load the parent sample. $mode = 3; if (isset(data_entry_helper::$entity_to_load)) { // errors so display Edit Occurrence page. $childSample = data_entry_helper::$entity_to_load; $childErrors = $saveErrors; $displayThisOcc = false; if ($childSample['occurrence:id']) { $thisOccID = $childSample['occurrence:id']; } } } else { // saved parent record. display updated parent, no child. $mode = 2; // display parent sample details, whether errors or not. if (isset(data_entry_helper::$entity_to_load)) { // errors so use posted data. $parentSample = data_entry_helper::$entity_to_load; $parentErrors = $saveErrors; } else { $parentLoadID = $_POST['sample:id']; // load the parent sample. } } } } else { // non Indicia POST, in this case must be the location allocations. add check to ensure we don't corrept the data by accident if (iform_loctools_checkaccess($node, 'admin') && array_key_exists('mnhnlbtw', $_POST)) { iform_loctools_deletelocations($node); foreach ($_POST as $key => $value) { $parts = explode(':', $key); if ($parts[0] == 'location' && $value) { iform_loctools_insertlocation($node, $value, $parts[1]); } } } } } else { if (array_key_exists('sample_id', $_GET)) { $mode = 2; $parentLoadID = $_GET['sample_id']; } else { if (array_key_exists('occurrence_id', $_GET)) { $mode = 3; $childLoadID = $_GET['occurrence_id']; $thisOccID = $childLoadID; } else { if (array_key_exists('newSample', $_GET)) { $mode = 1; } } } // else default to mode 0 } // define layers for all maps. // each argument is a comma separated list eg: // "Name:Lux Outline,URL:http://localhost/geoserver/wms,LAYERS:indicia:nation2,SRS:EPSG:2169,FORMAT:image/png,minScale:0,maxScale:1000000,units:m"; $optionArray_1 = array(); $optionArray_2 = array(); $options = explode(',', $args['layer1']); foreach ($options as $option) { $parts = explode(':', $option); $optionName = $parts[0]; unset($parts[0]); $optionsArray_1[$optionName] = implode(':', $parts); } $options = explode(',', $args['layer2']); foreach ($options as $option) { $parts = explode(':', $option); $optionName = $parts[0]; unset($parts[0]); $optionsArray_2[$optionName] = implode(':', $parts); } data_entry_helper::$javascript .= "\n// Create Layers.\n// Base Layers first.\nvar WMSoptions = {\n LAYERS: '" . $optionsArray_1['LAYERS'] . "',\n SERVICE: 'WMS',\n VERSION: '1.1.0',\n STYLES: '',\n SRS: '" . $optionsArray_1['SRS'] . "',\n FORMAT: '" . $optionsArray_1['FORMAT'] . "'\n };\nbaseLayer_1 = new OpenLayers.Layer.WMS('" . $optionsArray_1['Name'] . "',\n '" . iform_proxy_url($optionsArray_1['URL']) . "',\n WMSoptions, {\n minScale: " . $optionsArray_1['minScale'] . ",\n maxScale: " . $optionsArray_1['maxScale'] . ",\n units: '" . $optionsArray_1['units'] . "',\n isBaseLayer: true,\n singleTile: true\n });\nWMSoptions = {\n LAYERS: '" . $optionsArray_2['LAYERS'] . "',\n SERVICE: 'WMS',\n VERSION: '1.1.0',\n STYLES: '',\n SRS: '" . $optionsArray_2['SRS'] . "',\n FORMAT: '" . $optionsArray_2['FORMAT'] . "'\n };\nbaseLayer_2 = new OpenLayers.Layer.WMS('" . $optionsArray_2['Name'] . "',\n '" . iform_proxy_url($optionsArray_2['URL']) . "',\n WMSoptions, {\n minScale: " . $optionsArray_2['minScale'] . ",\n maxScale: " . $optionsArray_2['maxScale'] . ",\n units: '" . $optionsArray_2['units'] . "',\n isBaseLayer: true,\n singleTile: true\n });\n// Create vector layers: one to display the location onto, and another for the occurrence list\n// the default edit layer is used for the occurrences themselves\nlocStyleMap = new OpenLayers.StyleMap({\n \"default\": new OpenLayers.Style({\n fillColor: \"Green\",\n strokeColor: \"Black\",\n fillOpacity: 0.2,\n strokeWidth: 1\n })\n });\nlocationLayer = new OpenLayers.Layer.Vector(\"" . lang::get("LANG_Location_Layer") . "\",\n {styleMap: locStyleMap});\noccStyleMap = new OpenLayers.StyleMap({\n \"default\": new OpenLayers.Style({\n pointRadius: 3,\n fillColor: \"Red\",\n fillOpacity: 0.3,\n strokeColor: \"Red\",\n strokeWidth: 1\n }) });\noccListLayer = new OpenLayers.Layer.Vector(\"" . lang::get("LANG_Occurrence_List_Layer") . "\",\n {styleMap: occStyleMap});\n"; // Work out list of locations this user can see. $locations = iform_loctools_listlocations($node); /////////////////////////////////////////////////////////////////// // default mode 0 : display survey selector and locations allocator /////////////////////////////////////////////////////////////////// if ($mode == 0) { // If the user has permissions, add tabs so can choose to see // locations allocator $tabs = array('#surveyList' => lang::get('LANG_Surveys')); if (iform_loctools_checkaccess($node, 'admin')) { $tabs['#setLocations'] = lang::get('LANG_Allocate_Locations'); } if (iform_loctools_checkaccess($node, 'superuser')) { $tabs['#downloads'] = lang::get('LANG_Download'); } if (count($tabs) > 1) { $r .= "<div id=\"controls\">\n"; $r .= data_entry_helper::enable_tabs(array('divId' => 'controls', 'active' => '#surveyList')); $r .= "<div id=\"temp\"></div>"; $r .= data_entry_helper::tab_header(array('tabs' => $tabs)); } if ($locations == 'all') { $useloclist = 'NO'; $loclist = '-1'; } else { // an empty list will cause an sql error, lids must be > 0, so push a -1 to prevent the error. if (empty($locations)) { $locations[] = -1; } $useloclist = 'YES'; $loclist = implode(',', $locations); } // Create the Survey list datagrid for this user. drupal_add_js(drupal_get_path('module', 'iform') . '/media/js/hasharray.js', 'module'); drupal_add_js(drupal_get_path('module', 'iform') . '/media/js/jquery.datagrid.js', 'module'); drupal_add_js("jQuery(document).ready(function(){\n \$('div#smp_grid').indiciaDataGrid('rpt:mnhnl_btw_list_samples', {\n indiciaSvc: '" . $svcUrl . "',\n dataColumns: ['location_name', 'date', 'num_visit', 'num_occurrences', 'num_taxa'],\n reportColumnTitles: {location_name : '" . lang::get('LANG_Transect') . "', date : '" . lang::get('LANG_Date') . "', num_visit : '" . lang::get('LANG_Visit_No') . "', num_occurrences : '" . lang::get('LANG_Num_Occurrences') . "', num_taxa : '" . lang::get('LANG_Num_Species') . "'},\n actionColumns: {" . lang::get('LANG_Show') . " : \"" . url('node/' . $node->nid, array('query' => 'sample_id=£id£')) . "\"},\n auth : { nonce : '" . $readAuth['nonce'] . "', auth_token : '" . $readAuth['auth_token'] . "'},\n parameters : { survey_id : '" . $args['survey_id'] . "', visit_attr_id : '" . $args['sample_visit_number_id'] . "', closed_attr_id : '" . $args['sample_closure_id'] . "', use_location_list : '" . $useloclist . "', locations : '" . $loclist . "'},\n itemsPerPage : 12,\n condCss : {field : 'closed', value : '0', css: 'mnhnl-btw-highlight'},\n cssOdd : ''\n });\n});\n\n", 'inline'); $r .= '<div id="surveyList" class="mnhnl-btw-datapanel"><div id="smp_grid"></div>'; $r .= '<form><input type="button" value="' . lang::get('LANG_Add_Survey') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'newSample')) . '\'"></form></div>'; // Add the locations allocator if user has admin rights. if (iform_loctools_checkaccess($node, 'admin')) { $r .= '<div id="setLocations" class="mnhnl-btw-datapanel"><form method="post">'; $r .= "<input type=\"hidden\" id=\"mnhnlbtw\" name=\"mnhnlbtw\" value=\"mnhnlbtw\" />\n"; $url = $svcUrl . '/data/location'; $url .= "?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"] . "&parent_id=NULL&orderby=name"; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entities = json_decode(curl_exec($session), true); $userlist = iform_loctools_listusers($node); if (!empty($entities)) { foreach ($entities as $entity) { if (!$entity["parent_id"]) { // only assign parent locations. $r .= "\n<label for=\"location:" . $entity["id"] . "\">" . $entity["name"] . ":</label><select id=\"location:" . $entity["id"] . "\" name=\"location:" . $entity["id"] . "\">"; $r .= "<option value=\"\" ><" . lang::get('LANG_Not_Allocated') . "></option>"; $defaultuserid = iform_loctools_getuser($node, $entity["id"]); foreach ($userlist as $uid => $a_user) { if ($uid == $defaultuserid) { $selected = 'selected="selected"'; } else { $selected = ''; } $r .= "<option value=\"" . $uid . "\" " . $selected . ">" . $a_user->name . "</option>"; } $r .= "</select>"; } } } $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save_Location_Allocations') . "\" />\n"; $r .= "</form></div>"; } // Add the downloader if user has manager (superuser) rights. if (iform_loctools_checkaccess($node, 'superuser')) { $r .= '<div id="downloads" class="mnhnl-btw-datapanel">'; $r .= "<form method=\"post\" action=\"" . data_entry_helper::$base_url . "/index.php/services/report/requestReport?report=mnhnl_btw_transect_direction_report.xml&reportSource=local&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth['nonce'] . "&mode=csv\">"; $r .= '<p>' . lang::get('LANG_Direction_Report') . '</p>'; $r .= "<input type=\"hidden\" id=\"params\" name=\"params\" value='{\"survey_id\":" . $args['survey_id'] . ", \"direction_attr_id\":" . $args['sample_walk_direction_id'] . ", \"closed_attr_id\":" . $args['sample_closure_id'] . "}' />"; $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Direction_Report_Button') . "\">"; $r .= "</form>"; $r .= "<form method=\"post\" action=\"" . data_entry_helper::$base_url . "/index.php/services/report/requestReport?report=mnhnl_btw_download_report.xml&reportSource=local&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth['nonce'] . "&mode=csv\">"; $r .= '<p>' . lang::get('LANG_Initial_Download') . '</p>'; $r .= "<input type=\"hidden\" id=\"params\" name=\"params\" value='{\"survey_id\":" . $args['survey_id'] . ", \"closed_attr_id\":" . $args['sample_closure_id'] . ", \"download\": \"INITIAL\"}' />"; $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Initial_Download_Button') . "\">"; $r .= "</form>"; $r .= "<form method=\"post\" action=\"" . data_entry_helper::$base_url . "/index.php/services/report/requestReport?report=mnhnl_btw_download_report.xml&reportSource=local&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth['nonce'] . "&mode=csv\">"; $r .= '<p>' . lang::get('LANG_Confirm_Download') . '</p>'; $r .= "<input type=\"hidden\" id=\"params\" name=\"params\" value='{\"survey_id\":" . $args['survey_id'] . ", \"closed_attr_id\":" . $args['sample_closure_id'] . ", \"download\": \"CONFIRM\"}' />"; $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Confirm_Download_Button') . "\">"; $r .= "</form>"; $r .= "<form method=\"post\" action=\"" . data_entry_helper::$base_url . "/index.php/services/report/requestReport?report=mnhnl_btw_download_report.xml&reportSource=local&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth['nonce'] . "&mode=csv\">"; $r .= '<p>' . lang::get('LANG_Final_Download') . '</p>'; $r .= "<input type=\"hidden\" id=\"params\" name=\"params\" value='{\"survey_id\":" . $args['survey_id'] . ", \"closed_attr_id\":" . $args['sample_closure_id'] . ", \"download\": \"FINAL\"}' />"; $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Final_Download_Button') . "\">"; $r .= "</form></div>"; } // Create Map $r .= "<div class=\"mnhnl-btw-mappanel\">\n"; $r .= data_entry_helper::map_panel(array('presetLayers' => $presetLayers, 'layers' => array('baseLayer_1', 'baseLayer_2', 'locationLayer'), 'initialFeatureWkt' => null, 'width' => 'auto', 'height' => 490, 'editLayer' => false, 'initial_lat' => $args['map_centroid_lat'], 'initial_long' => $args['map_centroid_long'], 'initial_zoom' => (int) $args['map_zoom'], 'scroll_wheel_zoom' => false), array('projection' => $args['map_projection'])); // Add locations to the map on the locations layer. // Zoom in to area which contains the users locations. if ($locations != 'all') { data_entry_helper::$javascript .= "locationList = [" . implode(',', $locations) . "];\n"; } data_entry_helper::$javascript .= "\n// upload locations into map.\n// Change the location control requests the location's geometry to place on the map.\n\$.getJSON(\"{$svcUrl}\" + \"/data/location\" +\n \"?mode=json&view=detail&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" +\n \"&parent_id=NULL&callback=?\", function(data) {\n // store value in saved field?\n locationLayer.destroyFeatures();\n if (data.length>0) {\n var newFeatures = [];\n var feature;\n var parser = new OpenLayers.Format.WKT();\n for (var i=0;i<data.length;i++)\n {\n"; if ($locations != 'all') { // include restriction on locations if user does not have full access. data_entry_helper::$javascript .= "\n for(var j=0; j<locationList.length; j++) {\n if(locationList[j] == data[i].id || locationList[j] == data[i].parent_id) {"; } data_entry_helper::$javascript .= "\n if(data[i].boundary_geom){\n " . self::readBoundaryJs('data[i].boundary_geom', $args['map_projection']) . "\n feature.style = {label: data[i].name,\n strokeColor: \"Blue\",\n strokeWidth: 2};\n newFeatures.push(feature);\n }\n"; if ($locations != 'all') { data_entry_helper::$javascript .= "\n }\n }\n"; } data_entry_helper::$javascript .= "\n }\n locationLayer.addFeatures(newFeatures);\n locationLayer.map.zoomToExtent(locationLayer.getDataExtent());\n }\n});\n\$('#controls').bind('tabsshow', function(event, ui) {\n var y = \$('.mnhnl-btw-datapanel:visible').outerHeight(true) + \$('.mnhnl-btw-datapanel:visible').position().top;\n if(y < \$('.mnhnl-btw-mappanel').outerHeight(true)+ \$('.mnhnl-btw-mappanel').position().top){\n y = \$('.mnhnl-btw-mappanel').outerHeight(true)+ \$('.mnhnl-btw-mappanel').position().top;\n }\n \$('#controls').height(y - \$('#controls').position().top);\n});\n"; $r .= "</div>\n"; if (count($tabs) > 1) { $r .= "</div>"; } return $r; } /////////////////////////////////////////////////////////////////// $occReadOnly = false; if ($childLoadID) { $url = $svcUrl . '/data/occurrence/' . $childLoadID; $url .= "?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); $childSample = array(); foreach ($entity[0] as $key => $value) { $childSample['occurrence:' . $key] = $value; } if ($entity[0]['downloaded_flag'] == 'F') { // Final download complete, now readonly $occReadOnly = true; } $url = $svcUrl . '/data/sample/' . $childSample['occurrence:sample_id']; $url .= "?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); foreach ($entity[0] as $key => $value) { $childSample['sample:' . $key] = $value; } $childSample['sample:geom'] = ''; // value received from db is not WKT, which is assumed by all the code. $thisOccID = $childLoadID; // this will be used to load the occurrence into the editlayer. $childSample['taxon'] = $childSample['occurrence:taxon']; $parentLoadID = $childSample['sample:parent_id']; } if ($parentLoadID) { $url = $svcUrl . '/data/sample/' . $parentLoadID; $url .= "?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); $parentSample = array(); foreach ($entity[0] as $key => $value) { $parentSample['sample:' . $key] = $value; } if (is_array($locations) && !in_array($entity[0]["location_id"], $locations)) { return '<p>' . lang::get('LANG_No_Access_To_Location') . '</p>'; } if ($entity[0]["parent_id"]) { return '<p>' . lang::get('LANG_No_Access_To_Sample') . '</p>'; } $parentSample['sample:date'] = $parentSample['sample:date_start']; // bit of a bodge // default values for attributes from DB are picked up automatically. } $childSample['sample:date'] = $parentSample['sample:date']; // enforce a match between child and parent sample dates data_entry_helper::$entity_to_load = $parentSample; data_entry_helper::$validation_errors = $parentErrors; $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' => $readAuth)); $closedFieldName = $attributes[$args['sample_closure_id']]['fieldname']; $closedFieldValue = data_entry_helper::check_default_value($closedFieldName, array_key_exists('default', $attributes[$args['sample_closure_id']]) ? $attributes[$args['sample_closure_id']]['default'] : '0'); // default is not closed $adminPerm = 'IForm node ' . $node->nid . ' admin'; if ($closedFieldValue == '1' && !user_access($adminPerm)) { // sample has been closed, no admin perms. Everything now set to read only. $readOnly = true; $disabledText = "disabled=\"disabled\""; $defAttrOptions = array('extraParams' => $readAuth, 'disabled' => $disabledText); } else { // sample open. $disabledText = ""; $defAttrOptions = array('extraParams' => $readAuth); } data_entry_helper::enable_validation('SurveyForm'); $r .= "<div id=\"controls\">\n"; $activeTab = 'survey'; if ($mode == 3 || $mode == 2) { $activeTab = 'occurrence'; } // Set Up form tabs. if ($mode == 4) { $activeTab = 'occurrenceList'; } $r .= data_entry_helper::enable_tabs(array('divId' => 'controls', 'active' => $activeTab)); $r .= "<div id=\"temp\"></div>"; $r .= data_entry_helper::tab_header(array('tabs' => array('#survey' => lang::get('LANG_Survey'), '#occurrence' => lang::get($readOnly || $occReadOnly ? 'LANG_Show_Occurrence' : (isset($childSample['sample:id']) ? 'LANG_Edit_Occurrence' : 'LANG_Add_Occurrence')), '#occurrenceList' => lang::get('LANG_Occurrence_List')))); // Set up main Survey Form. $r .= "<div id=\"survey\" class=\"mnhnl-btw-datapanel\">\n"; if ($readOnly) { $r .= "<strong>" . lang::get('LANG_Read_Only_Survey') . "</strong>"; } $r .= "<form id=\"SurveyForm\" method=\"post\">\n"; $r .= $writeAuth; $r .= "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n"; $r .= "<input type=\"hidden\" id=\"sample:survey_id\" name=\"sample:survey_id\" value=\"" . $args['survey_id'] . "\" />\n"; $r .= iform_user_get_hidden_inputs($args); if (array_key_exists('sample:id', data_entry_helper::$entity_to_load)) { $r .= "<input type=\"hidden\" id=\"sample:id\" name=\"sample:id\" value=\"" . data_entry_helper::$entity_to_load['sample:id'] . "\" />\n"; } $defAttrOptions['validation'] = array('required'); $defAttrOptions['suffixTemplate'] = 'requiredsuffix'; if ($locations == 'all') { $locOptions = array_merge(array('label' => lang::get('LANG_Transect')), $defAttrOptions); $locOptions['extraParams'] = array_merge(array('parent_id' => 'NULL', 'view' => 'detail', 'orderby' => 'name'), $locOptions['extraParams']); $r .= data_entry_helper::location_select($locOptions); } else { // can't use location select due to location filtering. $r .= "<label for=\"imp-location\">" . lang::get('LANG_Transect') . ":</label>\n<select id=\"imp-location\" name=\"sample:location_id\" " . $disabled_text . " class=\" \" >"; $url = $svcUrl . '/data/location'; $url .= "?mode=json&view=detail&parent_id=NULL&orderby=name&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entities = json_decode(curl_exec($session), true); if (!empty($entities)) { foreach ($entities as $entity) { if (in_array($entity["id"], $locations)) { if ($entity["id"] == data_entry_helper::$entity_to_load['sample:location_id']) { $selected = 'selected="selected"'; } else { $selected = ''; } $r .= "<option value=\"" . $entity["id"] . "\" " . $selected . ">" . $entity["name"] . "</option>"; } } } $r .= "</select><span class=\"deh-required\">*</span><br />"; } $languageFilteredAttrOptions = $defAttrOptions + array('language' => iform_lang_iso_639_2($args['language'])); $r .= data_entry_helper::outputAttribute($attributes[$args['sample_walk_direction_id']], $languageFilteredAttrOptions); $r .= data_entry_helper::outputAttribute($attributes[$args['sample_reliability_id']], $languageFilteredAttrOptions); $r .= data_entry_helper::outputAttribute($attributes[$args['sample_visit_number_id']], array_merge($languageFilteredAttrOptions, array('default' => 1, 'noBlankText' => true))); if ($readOnly) { $r .= data_entry_helper::text_input(array_merge($defAttrOptions, array('label' => lang::get('LANG_Date'), 'fieldname' => 'sample:date', 'disabled' => $disabledText))); } else { $r .= data_entry_helper::date_picker(array('label' => lang::get('LANG_Date'), 'fieldname' => 'sample:date', 'class' => 'vague-date-picker', 'suffixTemplate' => 'requiredsuffix')); } $r .= data_entry_helper::outputAttribute($attributes[$args['sample_wind_id']], $languageFilteredAttrOptions); $r .= data_entry_helper::outputAttribute($attributes[$args['sample_precipitation_id']], $languageFilteredAttrOptions); $r .= data_entry_helper::outputAttribute($attributes[$args['sample_temperature_id']], array_merge($defAttrOptions, array('suffixTemplate' => 'nosuffix'))); $r .= " degC<span class=\"deh-required\">*</span><br />"; $r .= data_entry_helper::outputAttribute($attributes[$args['sample_cloud_id']], $defAttrOptions); $r .= data_entry_helper::outputAttribute($attributes[$args['sample_start_time_id']], array_merge($defAttrOptions, array('suffixTemplate' => 'nosuffix'))); $r .= " hh:mm<span class=\"deh-required\">*</span><br />"; $r .= data_entry_helper::outputAttribute($attributes[$args['sample_end_time_id']], array_merge($defAttrOptions, array('suffixTemplate' => 'nosuffix'))); $r .= " hh:mm<span class=\"deh-required\">*</span><br />"; unset($defAttrOptions['suffixTemplate']); unset($defAttrOptions['validation']); if (user_access($adminPerm)) { // users with admin permissions can override the closing of the // sample by unchecking the checkbox. // Because this is attached to the sample, we have to include the sample required fields in the // the post. This means they can't be disabled, so we enable all fields in this case. // Normal users can only set this to closed, and they do this using a button/hidden field. $r .= data_entry_helper::outputAttribute($attributes[$args['sample_closure_id']], $defAttrOptions); } else { // hidden closed $r .= "<input type=\"hidden\" id=\"" . $closedFieldName . "\" name=\"" . $closedFieldName . "\" value=\"" . $closedFieldValue . "\" />\n"; } if (!empty(data_entry_helper::$validation_errors)) { $r .= data_entry_helper::dump_remaining_errors(); } $escaped_id = str_replace(':', '\\\\:', $closedFieldName); if (!$readOnly) { $r .= "<input type=button id=\"close1\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save_Survey_Details') . "\";\n onclick=\"var result = \$('#SurveyForm input').valid();\n var result2 = \$('#SurveyForm select').valid();\n if (!result || !result2) {\n return;\n }\n jQuery('#SurveyForm').submit();\">\n"; if (!user_access($adminPerm) && $mode != 1) { $r .= "<input type=button id=\"close2\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save_Survey_And_Close') . "\"\n onclick=\"if(confirm('" . lang::get('LANG_Close_Survey_Confirm') . "')){\n var result = \$('#SurveyForm input').valid();\n var result2 = \$('#SurveyForm select').valid();\n if (!result || !result2) {\n return;\n }\n jQuery('#" . $escaped_id . "').val('1');\n jQuery('#SurveyForm').submit();\n };\">\n"; } } $r .= "</form>"; $r .= "</div>\n"; // Set up Occurrence List tab: don't include when creating a new sample as it will have no occurrences // Grid populated at a later point $r .= "<div id=\"occurrenceList\" class=\"mnhnl-btw-datapanel\">\n"; if ($mode != 1) { drupal_add_js(drupal_get_path('module', 'iform') . '/media/js/hasharray.js', 'module'); drupal_add_js(drupal_get_path('module', 'iform') . '/media/js/jquery.datagrid.js', 'module'); $r .= '<div id="occ_grid"></div>'; $r .= "<form method=\"post\" action=\"" . data_entry_helper::$base_url . "/index.php/services/report/requestReport?report=mnhnl_btw_occurrences_report.xml&reportSource=local&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth['nonce'] . "&mode=csv\">"; $r .= "<input type=\"hidden\" id=\"params\" name=\"params\" value='{\"survey_id\":" . $args['survey_id'] . ", \"sample_id\":" . data_entry_helper::$entity_to_load['sample:id'] . "}' />"; $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Download_Occurrences') . "\">"; $r .= "</FORM>"; } else { $r .= '<p>' . lang::get('LANG_Page_Not_Available') . '</p>'; } $r .= '</div>'; // Set up Occurrence tab: don't allow entry of a new occurrence until after top level sample is saved. $r .= "<div id=\"occurrence\" class=\"mnhnl-btw-datapanel\">\n"; if ($mode != 1 && ($mode != 2 && $mode != 4 || $readOnly == false)) { data_entry_helper::$entity_to_load = $childSample; data_entry_helper::$validation_errors = $childErrors; $attributes = data_entry_helper::getAttributes(array('id' => data_entry_helper::$entity_to_load['occurrence:id'], 'valuetable' => 'occurrence_attribute_value', 'attrtable' => 'occurrence_attribute', 'key' => 'occurrence_id', 'fieldprefix' => 'occAttr', 'extraParams' => $readAuth)); if ($occReadOnly) { $r .= "<strong>" . lang::get('LANG_Read_Only_Occurrence') . "</strong>"; $disabledText = "disabled=\"disabled\""; $defAttrOptions['disabled'] = $disabledText; } else { if ($readOnly) { $r .= "<strong>" . lang::get('LANG_Read_Only_Survey') . "</strong>"; } } $r .= "<form method=\"post\">\n"; $r .= $writeAuth; $r .= "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n"; $r .= "<input type=\"hidden\" id=\"sample:survey_id\" name=\"sample:survey_id\" value=\"" . $args['survey_id'] . "\" />\n"; $r .= "<input type=\"hidden\" id=\"sample:parent_id\" name=\"sample:parent_id\" value=\"" . $parentSample['sample:id'] . "\" />\n"; $r .= "<input type=\"hidden\" id=\"sample:date\" name=\"sample:date\" value=\"" . data_entry_helper::$entity_to_load['sample:date'] . "\" />\n"; if (array_key_exists('sample:id', data_entry_helper::$entity_to_load)) { $r .= "<input type=\"hidden\" id=\"sample:id\" name=\"sample:id\" value=\"" . data_entry_helper::$entity_to_load['sample:id'] . "\" />\n"; } if (array_key_exists('occurrence:id', data_entry_helper::$entity_to_load)) { $r .= "<input type=\"hidden\" id=\"occurrence:id\" name=\"occurrence:id\" value=\"" . data_entry_helper::$entity_to_load['occurrence:id'] . "\" />\n"; } $r .= "<input type=\"hidden\" id=\"occurrence:record_status\" name=\"occurrence:record_status\" value=\"C\" />\n"; $r .= "<input type=\"hidden\" id=\"occurrence:downloaded_flag\" name=\"occurrence:downloaded_flag\" value=\"N\" />\n"; $extraParams = $readAuth + array('taxon_list_id' => $args['list_id']); $species_ctrl_args = array('label' => lang::get('LANG_Species'), 'fieldname' => 'occurrence:taxa_taxon_list_id', 'table' => 'taxa_taxon_list', 'captionField' => 'taxon', 'valueField' => 'id', 'columns' => 2, 'extraParams' => $extraParams, 'suffixTemplate' => 'requiredsuffix', 'disabled' => $disabledText, 'defaultCaption' => data_entry_helper::$entity_to_load['occurrence:taxon']); $r .= data_entry_helper::autocomplete($species_ctrl_args); $r .= data_entry_helper::outputAttribute($attributes[$args['occurrence_confidence_id']], array_merge($languageFilteredAttrOptions, array('noBlankText' => ''))); $r .= data_entry_helper::sref_and_system(array('label' => lang::get('LANG_Spatial_ref'), 'systems' => array('2169' => 'Luref (Gauss Luxembourg)'), 'suffixTemplate' => 'requiredsuffix')); $r .= "<p>" . lang::get('LANG_Click_on_map') . "</p>"; $r .= data_entry_helper::outputAttribute($attributes[$args['occurrence_count_id']], array_merge($defAttrOptions, array('default' => 1, 'suffixTemplate' => 'requiredsuffix'))); $r .= data_entry_helper::outputAttribute($attributes[$args['occurrence_approximation_id']], $defAttrOptions); $r .= data_entry_helper::outputAttribute($attributes[$args['occurrence_territorial_id']], array_merge($defAttrOptions, array('default' => 1))); $r .= data_entry_helper::outputAttribute($attributes[$args['occurrence_atlas_code_id']], $languageFilteredAttrOptions); $r .= data_entry_helper::outputAttribute($attributes[$args['occurrence_overflying_id']], $defAttrOptions); $r .= data_entry_helper::textarea(array('label' => lang::get('LANG_Comment'), 'fieldname' => 'occurrence:comment', 'disabled' => $disabledText)); if (!empty(data_entry_helper::$validation_errors)) { $r .= data_entry_helper::dump_remaining_errors(); } if (!$readOnly && !$occReadOnly) { $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save_Occurrence_Details') . "\" />\n"; } $r .= "</form>\n"; $escaped_terr_id = str_replace(':', '\\\\:', $attributes[$args['occurrence_territorial_id']]['fieldname']); $escaped_atlas_id = str_replace(':', '\\\\:', $attributes[$args['occurrence_atlas_code_id']]['fieldname']); data_entry_helper::$javascript .= "\nsetAtlasStatus = function() {\n if (jQuery(\"input[name='" . $escaped_terr_id . "']:checked\").val() == '0') {\n jQuery('#" . $escaped_atlas_id . "').val('');\n } else {\n if(jQuery('#" . $escaped_atlas_id . "').val() == '') {\n // Find the BB02 option (depends on the language what val it has)\n var bb02;\n jQuery.each(jQuery('#" . $escaped_atlas_id . " option'), function(index, option) {\n if (option.text.substr(0,4)=='BB02') {\n bb02 = option.value;\n return; // just from the each loop\n }\n });\n jQuery('#" . $escaped_atlas_id . "').val(bb02);\n }\n }\n};\nsetAtlasStatus();\njQuery(\"input[name='" . $escaped_terr_id . "']\").change(setAtlasStatus);\n"; } else { $r .= '<p>' . lang::get('LANG_Page_Not_Available') . '</p>'; } $r .= '</div>'; // add map panel. $r .= "<div class=\"mnhnl-btw-mappanel\">\n"; $r .= data_entry_helper::map_panel(array('presetLayers' => $presetLayers, 'layers' => array('baseLayer_1', 'baseLayer_2', 'locationLayer', 'occListLayer'), 'initialFeatureWkt' => null, 'width' => 'auto', 'height' => 490, 'initial_lat' => $args['map_centroid_lat'], 'initial_long' => $args['map_centroid_long'], 'initial_zoom' => (int) $args['map_zoom'], 'scroll_wheel_zoom' => false), array('projection' => $args['map_projection'])); // for timing reasons, all the following has to be done after the map is loaded. // 1) feature selector for occurrence list must have the map present to attach the control // 2) location placer must have the location layer populated and the map present in // order to zoom the map into the location. // 3) occurrence list feature adder must have map present in order to zoom into any // current selection. data_entry_helper::$onload_javascript .= "\nvar control = new OpenLayers.Control.SelectFeature(occListLayer);\noccListLayer.map.addControl(control);\nfunction onPopupClose(evt) {\n // 'this' is the popup.\n control.unselect(this.feature);\n}\nfunction onFeatureSelect(evt) {\n feature = evt.feature;\n popup = new OpenLayers.Popup.FramedCloud(\"featurePopup\",\n feature.geometry.getBounds().getCenterLonLat(),\n new OpenLayers.Size(100,100),\n feature.attributes.taxon + \" (\" + feature.attributes.count + \")\",\n null, true, onPopupClose);\n feature.popup = popup;\n popup.feature = feature;\n feature.layer.map.addPopup(popup);\n}\nfunction onFeatureUnselect(evt) {\n feature = evt.feature;\n if (feature.popup) {\n popup.feature = null;\n feature.layer.map.removePopup(feature.popup);\n feature.popup.destroy();\n feature.popup = null;\n }\n}\n\noccListLayer.events.on({\n 'featureselected': onFeatureSelect,\n 'featureunselected': onFeatureUnselect\n});\n\ncontrol.activate();\n\nlocationChange = function(obj){\n locationLayer.destroyFeatures();\n if(obj.value != ''){\n jQuery.getJSON(\"" . $svcUrl . "\" + \"/data/location/\"+obj.value +\n \"?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"] . "\" +\n \"&callback=?\", function(data) {\n if (data.length>0) {\n var parser = new OpenLayers.Format.WKT();\n for (var i=0;i<data.length;i++)\n {\n if(data[i].centroid_geom){\n " . self::readBoundaryJs('data[i].centroid_geom', $args['map_projection']) . "\n feature.style = {label: data[i].name,\n\t\t\t\t\t\t strokeColor: \"Green\",\n strokeWidth: 2,\n fillOpacity: 0};\n centre = feature.geometry.getCentroid();\n centrefeature = new OpenLayers.Feature.Vector(centre, {}, {label: data[i].name});\n locationLayer.addFeatures([feature, centrefeature]);\n }\n if(data[i].boundary_geom){\n " . self::readBoundaryJs('data[i].boundary_geom', $args['map_projection']) . "\n feature.style = {strokeColor: \"Blue\", strokeWidth: 2};\n locationLayer.addFeatures([feature]);\n }\n locationLayer.map.zoomToExtent(locationLayer.getDataExtent());\n }\n }\n });\n jQuery.getJSON(\"" . $svcUrl . "\" + \"/data/location\" +\n \"?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"] . "&callback=?&parent_id=\"+obj.value, function(data) {\n if (data.length>0) {\n var parser = new OpenLayers.Format.WKT();\n for (var i=0;i<data.length;i++)\n {\n if(data[i].centroid_geom){\n " . self::readBoundaryJs('data[i].centroid_geom', $args['map_projection']) . "\n locationLayer.addFeatures([feature]);\n }\n if(data[i].boundary_geom){\n " . self::readBoundaryJs('data[i].boundary_geom', $args['map_projection']) . "\n feature.style = {label: data[i].name,\n labelAlign: \"cb\",\n strokeColor: \"Blue\",\n strokeWidth: 2};\n locationLayer.addFeatures([feature]);\n }\n }\n }\n });\n }\n};\n// upload location initial value into map.\njQuery('#imp-location').each(function(){\n locationChange(this);\n});\njQuery('#imp-location').unbind('change');\njQuery('#imp-location').change(function(){\n locationChange(this);\n});\nvar selected = \$('#controls').tabs('option', 'selected');\n\n// Only leave the click control activated for edit/add occurrence tab.\nif(selected != 1){\n locationLayer.map.editLayer.clickControl.deactivate();\n}\n\$('#controls').bind('tabsshow', function(event, ui) {\n if(ui.index == 1)\n {\n locationLayer.map.editLayer.clickControl.activate();\n }\n else\n {\n locationLayer.map.editLayer.clickControl.deactivate();\n }\n }\n);\n"; if ($mode != 1) { data_entry_helper::$onload_javascript .= "\nactivateAddList = 1;\n\naddListFeature = function(div, r, record, count) {\n if(activateAddList == 0)\n return;\n if(r == count)\n activateAddList = 0;\n var parser = new OpenLayers.Format.WKT();\n " . self::readBoundaryJs('record.geom', $args['map_projection']) . "\n if(record.id != " . $thisOccID . " || 1==" . ($readOnly ? 1 : 0) . " || 1==" . ($occReadOnly ? 1 : 0) . "){\n feature.attributes.id = record.id;\n feature.attributes.taxon = record.taxon;\n feature.attributes.count = record.count;\n occListLayer.addFeatures([feature]);\n if(record.id == " . $thisOccID . "){\n var bounds=feature.geometry.getBounds();\n locationLayer.map.setCenter(bounds.getCenterLonLat());\n }\n } else {\n if(" . ($displayThisOcc ? 1 : 0) . "){\n locationLayer.map.editLayer.destroyFeatures();\n locationLayer.map.editLayer.addFeatures([feature]);\n var bounds=feature.geometry.getBounds()\n var centre=bounds.getCenterLonLat();\n locationLayer.map.setCenter(centre);\n }\n }\n};\nhighlight = function(id){\n if(id == " . $thisOccID . "){\n if(occListLayer.map.editLayer.features.length > 0){\n var bounds=occListLayer.map.editLayer.features[0].geometry.getBounds()\n var centre=bounds.getCenterLonLat();\n occListLayer.map.setCenter(centre);\n return;\n }\n }\n for(var i = 0; i < occListLayer.features.length; i++){\n if(occListLayer.features[i].attributes.id == id){\n control.unselectAll();\n var bounds=occListLayer.features[i].geometry.getBounds()\n var centre=bounds.getCenterLonLat();\n occListLayer.map.setCenter(centre);\n control.select(occListLayer.features[i]);\n return;\n }\n }\n}\n\$('div#occ_grid').indiciaDataGrid('rpt:mnhnl_btw_list_occurrences', {\n indiciaSvc: '" . $svcUrl . "',\n dataColumns: ['taxon', 'territorial', 'count'],\n reportColumnTitles: {taxon : '" . lang::get('LANG_Species') . "', territorial : '" . lang::get('LANG_Territorial') . "', count : '" . lang::get('LANG_Count') . "'},\n actionColumns: {'" . lang::get('LANG_Show') . "' : \"" . url('node/' . $node->nid, array('query' => 'occurrence_id=£id£')) . "\",\n '" . lang::get('LANG_Highlight') . "' : \"script:highlight(£id£);\"},\n auth : { nonce : '" . $readAuth['nonce'] . "', auth_token : '" . $readAuth['auth_token'] . "'},\n parameters : { survey_id : '" . $args['survey_id'] . "',\n parent_id : '" . $parentSample['sample:id'] . "',\n territorial_attr_id : '" . $args['occurrence_territorial_id'] . "',\n count_attr_id : '" . $args['occurrence_count_id'] . "'},\n itemsPerPage : 12,\n callback : addListFeature ,\n cssOdd : ''\n });\n\n// activateAddList = 0;\n\n"; } $r .= "</div><div><form><input type=\"button\" value=\"" . lang::get('LANG_Return') . "\" onclick=\"window.location.href='" . url('node/' . $node->nid, array('query' => 'Main')) . "'\"></form></div></div>\n"; return $r; }
protected static function tab_your_plots($args, $auth) { $r = data_entry_helper::date_picker(array('label' => 'Date of visit', 'fieldname' => 'sample:date', 'class' => 'ui-state-highlight')); $r .= self::output_habitats_block('Path', 'path', $auth, $args); $r .= data_entry_helper::wizard_buttons(array('divId' => 'tabs', 'page' => 'middle')); return $r; }
/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args, $node, $response = null) { global $user; global $custom_terms; $logged_in = $user->uid > 0; $r = ''; // Get authorisation tokens to update and read from the Warehouse. $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); $readAuth = $auth['read']; $svcUrl = data_entry_helper::$base_url . '/index.php/services'; drupal_add_js(drupal_get_path('module', 'iform') . '/media/js/jquery.form.js', 'module'); data_entry_helper::link_default_stylesheet(); data_entry_helper::add_resource('jquery_ui'); $language = iform_lang_iso_639_2($args['language']); if ($args['language'] != 'en') { data_entry_helper::add_resource('jquery_ui_' . $args['language']); } // If not logged in: Display an information message. // This form should only be called in POST mode when setting the location allocation. // All other posting is now done via AJAX. // When invoked by GET there are the following modes: // No additional arguments: mode 0. // Additional argument - new : mode 1. // Additional argument - sample_id=<id> : mode 2. // Additional argument - occurrence_id=<id> : mode 3. // Additional arguments - merge_sample_id1=<id>&merge_sample_id2=<id> : mode 2.1 $mode = 0; // default mode : output survey selector // mode 1: output the main Data Entry page: occurrence list or add/edit occurrence tabs hidden. "Survey" tab active // mode 2: output the main Data Entry page, display existing sample. Active tab determined by iform params. No occurence details filled in. // mode 2.1: sample 2 has all its occurrences merged into sample 1. sample 2 is then flagged as deleted. sample 1 is then viewed as in normal mode 2. // mode 3: output the main Data Entry page, display existing occurrence. "Edit Occurrence" tab active. Occurence details filled in. $surveyReadOnly = false; // On top of this, things can be flagged as readonly. RO mode 2+4 means no Add Occurrence tab. if (!$logged_in) { return lang::get('LANG_not_logged_in'); } $parentSample = array(); $parentLoadID = null; $childSample = array(); $childLoadID = null; $thisOccID = -1; // IDs have to be >0, so this is outside the valid range // Load up attribute details $sample_walk_direction_id = self::getAttrID($auth, $args, 'sample', self::ATTR_WALK); $sample_reliability_id = self::getAttrID($auth, $args, 'sample', self::ATTR_RELIABILITY); $sample_visit_number_id = self::getAttrID($auth, $args, 'sample', self::ATTR_VISIT); $sample_wind_id = self::getAttrID($auth, $args, 'sample', self::ATTR_WIND); $sample_precipitation_id = self::getAttrID($auth, $args, 'sample', self::ATTR_RAIN); $sample_temperature_id = self::getAttrID($auth, $args, 'sample', self::ATTR_TEMP); $sample_cloud_id = self::getAttrID($auth, $args, 'sample', self::ATTR_CLOUD); $sample_start_time_id = self::getAttrID($auth, $args, 'sample', self::ATTR_START_TIME); $sample_end_time_id = self::getAttrID($auth, $args, 'sample', self::ATTR_END_TIME); $sample_closure_id = self::getAttrID($auth, $args, 'sample', self::ATTR_CLOSED); $uid_attr_id = self::getAttrID($auth, $args, 'sample', self::ATTR_UID); $email_attr_id = self::getAttrID($auth, $args, 'sample', self::ATTR_EMAIL); $username_attr_id = self::getAttrID($auth, $args, 'sample', self::ATTR_USERNAME); $occurrence_confidence_id = self::getAttrID($auth, $args, 'occurrence', self::ATTR_CONFIDENCE); $occurrence_count_id = self::getAttrID($auth, $args, 'occurrence', self::ATTR_COUNT); $occurrence_approximation_id = self::getAttrID($auth, $args, 'occurrence', self::ATTR_APPROXIMATION); $occurrence_territorial_id = self::getAttrID($auth, $args, 'occurrence', self::ATTR_TERRITORIAL); $occurrence_atlas_code_id = self::getAttrID($auth, $args, 'occurrence', self::ATTR_ATLAS_CODE); $occurrence_overflying_id = self::getAttrID($auth, $args, 'occurrence', self::ATTR_OVERFLYING); if (!$sample_closure_id) { return '<p>This form must be used with a survey which has the "' . self::ATTR_CLOSED . '" sample attribute allocated to it. Survey_id = ' . $args['survey_id']; } if (!$uid_attr_id) { return '<p>This form must be used with a survey which has the "' . self::ATTR_UID . '" sample attribute allocated to it. Survey_id = ' . $args['survey_id']; } if (!$email_attr_id) { return '<p>This form must be used with a survey which has the "' . self::ATTR_EMAIL . '" sample attribute allocated to it. Survey_id = ' . $args['survey_id']; } if (!$username_attr_id) { return '<p>This form must be used with a survey which has the "' . self::ATTR_USERNAME . '" sample attribute allocated to it. Survey_id = ' . $args['survey_id']; } if (!$sample_walk_direction_id) { return '<p>This form must be used with a survey which has the "' . self::ATTR_WALK . '" sample attribute allocated to it. Survey_id = ' . $args['survey_id']; } if (!$sample_visit_number_id) { return '<p>This form must be used with a survey which has the "' . self::ATTR_VISIT . '" sample attribute allocated to it. Survey_id = ' . $args['survey_id']; } if (!$occurrence_count_id) { return '<p>This form must be used with a survey which has the "' . self::ATTR_COUNT . '" occurrence attribute allocated to it. Survey_id = ' . $args['survey_id']; } if (!$occurrence_territorial_id) { return '<p>This form must be used with a survey which has the "' . self::ATTR_TERRITORIAL . '" occurrence attribute allocated to it. Survey_id = ' . $args['survey_id']; } if (!$occurrence_atlas_code_id) { return '<p>This form must be used with a survey which has the "' . self::ATTR_ATLAS_CODE . '" occurrence attribute allocated to it. Survey_id = ' . $args['survey_id']; } if ($_POST) { if (!array_key_exists('website_id', $_POST)) { // non Indicia POST, in this case must be the location allocations. add check to ensure we don't corrept the data by accident if (iform_loctools_checkaccess($node, 'admin') && array_key_exists('mnhnlbtw', $_POST)) { iform_loctools_deletelocations($node); foreach ($_POST as $key => $value) { $parts = explode(':', $key); if ($parts[0] == 'location' && $value) { iform_loctools_insertlocation($node, $value, $parts[1]); } } } } } else { if (array_key_exists('merge_sample_id1', $_GET) && array_key_exists('merge_sample_id2', $_GET) && user_access($args['edit_permission'])) { $mode = 2; // first check can access the 2 samples given $parentLoadID = $_GET['merge_sample_id1']; $url = $svcUrl . '/data/sample/' . $parentLoadID . "?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); if (count($entity) == 0 || $entity[0]["parent_id"]) { return '<p>' . lang::get('LANG_No_Access_To_Sample') . ' ' . $parentLoadID . '</p>'; } // The check for id2 is slightly different: there is the possiblity that someone will F5/refresh their browser, after the transfer and delete have taken place. // In this case we carry on, but do not do the transfer and delete. $url = $svcUrl . '/data/sample/' . $_GET['merge_sample_id2'] . "?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); if (count($entity) > 0 && !$entity[0]["parent_id"]) { // now get child samples and point to new parent. $url = $svcUrl . '/data/sample?mode=json&view=detail&auth_token=' . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"] . '&parent_id=' . $_GET['merge_sample_id2']; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entities = json_decode(curl_exec($session), true); if (count($entities) > 0) { foreach ($entities as $entity) { $Model = data_entry_helper::wrap(array('id' => $entity['id'], 'parent_id' => $_GET['merge_sample_id1']), 'sample'); $request = data_entry_helper::$base_url . "/index.php/services/data/save"; $postargs = 'submission=' . json_encode($Model) . '&auth_token=' . $auth['write_tokens']['auth_token'] . '&nonce=' . $auth['write_tokens']['nonce'] . '&persist_auth=true'; $postresponse = data_entry_helper::http_post($request, $postargs, false); // the response array will always feature an output, which is the actual response or error message. if it is not json format, assume error text, and json encode that. $response = $postresponse['output']; if (!json_decode($response, true)) { return "<p>" . lang::get('LANG_Error_When_Moving_Sample') . ": id " . $entity['id'] . " : " . $response; } } } // finally delete the no longer used sample $Model = data_entry_helper::wrap(array('id' => $_GET['merge_sample_id2'], 'deleted' => 'true'), 'sample'); $request = data_entry_helper::$base_url . "/index.php/services/data/save"; $postargs = 'submission=' . json_encode($Model) . '&auth_token=' . $auth['write_tokens']['auth_token'] . '&nonce=' . $auth['write_tokens']['nonce'] . '&persist_auth=true'; $postresponse = data_entry_helper::http_post($request, $postargs, false); // the response array will always feature an output, which is the actual response or error message. if it is not json format, assume error text, and json encode that. $response = $postresponse['output']; if (!json_decode($response, true)) { return "<p>" . lang::get('LANG_Error_When_Deleting_Sample') . ": id " . $entity['id'] . " : " . $response; } } } else { if (array_key_exists('sample_id', $_GET)) { $mode = 2; $parentLoadID = $_GET['sample_id']; } else { if (array_key_exists('occurrence_id', $_GET)) { $mode = 3; $childLoadID = $_GET['occurrence_id']; $thisOccID = $childLoadID; } else { if (array_key_exists('new', $_GET)) { $mode = 1; } } } } // else default to mode 0 } // define language strings so they can be used for validation translation. data_entry_helper::$javascript .= "var translations = [\n"; foreach ($custom_terms as $key => $value) { if (substr($key, 0, 4) != "LANG") { data_entry_helper::$javascript .= " {key: \"" . $key . "\", translated: \"" . $value . "\"},\n"; } } data_entry_helper::$javascript .= "];\n"; // define layers for all maps. // each argument is a comma separated list eg: // "Name:Lux Outline,URL:http://localhost/geoserver/wms,LAYERS:indicia:nation2,SRS:EPSG:2169,FORMAT:image/png,minScale:0,maxScale:1000000,units:m"; $optionsArray_Location = array(); $options = explode(',', $args['locationLayer']); foreach ($options as $option) { $parts = explode(':', $option); $optionName = $parts[0]; unset($parts[0]); $optionsArray_Location[$optionName] = implode(':', $parts); } // Work out list of locations this user can see. $locations = iform_loctools_listlocations($node); if ($locations != 'all') { data_entry_helper::$javascript .= "var locationList = [" . implode(',', $locations) . "];\n"; } drupal_add_js(drupal_get_path('module', 'iform') . '/media/js/hasharray.js', 'module'); drupal_add_js(drupal_get_path('module', 'iform') . '/media/js/jquery.datagrid.js', 'module'); if (method_exists(get_called_class(), 'getHeaderHTML')) { $r .= call_user_func(array(get_called_class(), 'getHeaderHTML'), $args); } // Work out list of locations this user can see. // $locations = iform_loctools_listlocations($node); /////////////////////////////////////////////////////////////////// // default mode 0 : display a page with tabs for survey selector, // locations allocator and reports (last two require permissions) /////////////////////////////////////////////////////////////////// if ($mode == 0) { // If the user has permissions, add tabs so can choose to see // locations allocator $tabs = array('#surveyList' => lang::get('LANG_Surveys')); if (iform_loctools_checkaccess($node, 'admin')) { $tabs['#setLocations'] = lang::get('LANG_Allocate_Locations'); } if (iform_loctools_checkaccess($node, 'superuser')) { $tabs['#downloads'] = lang::get('LANG_Download'); } if (count($tabs) > 1) { $r .= "<div id=\"controls\">" . data_entry_helper::enable_tabs(array('divId' => 'controls', 'active' => '#surveyList')) . "<div id=\"temp\"></div>"; $r .= data_entry_helper::tab_header(array('tabs' => $tabs)); } if ($locations == 'all') { $useloclist = 'NO'; $loclist = '-1'; } else { // an empty list will cause an sql error, lids must be > 0, so push a -1 to prevent the error. if (empty($locations)) { $locations[] = -1; } $useloclist = 'YES'; $loclist = implode(',', $locations); } // Create the Survey list datagrid for this user. drupal_add_js("jQuery(document).ready(function(){\n \$('div#smp_grid').indiciaDataGrid('rpt:reports_for_prebuilt_forms/MNHNL/mnhnl_btw_list_samples', {\n indiciaSvc: '" . $svcUrl . "',\n dataColumns: ['location_name', 'date', 'num_visit', 'num_occurrences', 'num_taxa'],\n reportColumnTitles: {location_name : '" . lang::get('LANG_Transect') . "', date : '" . lang::get('LANG_Date') . "', num_visit : '" . lang::get('LANG_Visit_No') . "', num_occurrences : '" . lang::get('LANG_Num_Occurrences') . "', num_taxa : '" . lang::get('LANG_Num_Species') . "'},\n actionColumns: {" . lang::get('LANG_Show') . " : \"" . url('node/' . $node->nid, array('query' => 'sample_id=£id£')) . "\"},\n auth : { nonce : '" . $readAuth['nonce'] . "', auth_token : '" . $readAuth['auth_token'] . "'},\n parameters : { survey_id : '" . $args['survey_id'] . "', visit_attr_id : '" . $sample_visit_number_id . "', closed_attr_id : '" . $sample_closure_id . "', use_location_list : '" . $useloclist . "', locations : '" . $loclist . "'},\n itemsPerPage : 12,\n condCss : {field : 'closed', value : '0', css: 'mnhnl-btw-highlight'},\n cssOdd : ''\n });\n});\n ", 'inline'); data_entry_helper::$javascript .= "\n// Create Layers.\nvar locationListLayer;\nmapInitialisationHooks.push(function (div) {\n \"use strict\";"; if ($locations == 'all' || $loclist != '-1') { data_entry_helper::$javascript .= "\n var WMSoptions = {SERVICE: 'WMS', VERSION: '1.1.0', STYLES: '',\n SRS: div.map.projection.proj.srsCode, /* Now takes it from map */\n FORMAT: '" . $optionsArray_Location['FORMAT'] . "',\n TRANSPARENT: 'true', "; if ($locations != 'all') { // when given a restricted feature list we have to use the feature id to filter in order to not go over 2000 char limit on the URL // Can only generate the feature id if we access a table directly, not through a view. Go direct to the locations table. // don't need to worry about parent_id in this case as we know exactly which features we want. // need to use btw_transects view for unrestricted so we can filter by parent_id=NULL. $locFeatures = array(); foreach ($locations as $location) { $locFeatures[] = "locations." . $location; } data_entry_helper::$javascript .= "\n LAYERS: 'indicia:locations',\n FEATUREID: '" . implode(',', $locFeatures) . "'"; } else { data_entry_helper::$javascript .= " LAYERS: '" . $optionsArray_Location['LAYERS'] . "', CQL_FILTER: 'website_id=" . $args['website_id'] . "'"; } data_entry_helper::$javascript .= "\n };\n locationListLayer = new OpenLayers.Layer.WMS('" . $optionsArray_Location['Name'] . "',\n '" . (function_exists(iform_proxy_url) ? iform_proxy_url($optionsArray_Location['URL']) : $optionsArray_Location['URL']) . "',\n WMSoptions, {\n minScale: " . $optionsArray_Location['minScale'] . ",\n maxScale: " . $optionsArray_Location['maxScale'] . ",\n units: '" . $optionsArray_Location['units'] . "',\n isBaseLayer: false,\n singleTile: true\n });\n div.map.addLayer(locationListLayer);\n});\n"; } $r .= ' <div id="surveyList" class="mnhnl-btw-datapanel"><div id="smp_grid"></div> <form><input type="button" value="' . lang::get('LANG_Add_Survey') . '" onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'new')) . '\'"></form></div>'; // Add the locations allocator if user has admin rights. if (iform_loctools_checkaccess($node, 'admin')) { $r .= ' <div id="setLocations" class="mnhnl-btw-datapanel"> <form method="post"> <input type="hidden" id="mnhnlbtw" name="mnhnlbtw" value="mnhnlbtw" />'; $url = $svcUrl . '/data/location?mode=json&view=detail&auth_token=' . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"] . "&parent_id=NULL&orderby=name&columns=id,name,parent_id"; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entities = json_decode(curl_exec($session), true); $userlist = iform_loctools_listusers($node); if (!empty($entities)) { foreach ($entities as $entity) { if (!$entity["parent_id"]) { // only assign parent locations. $r .= "\n<label for=\"location:" . $entity["id"] . "\">" . $entity["name"] . ":</label><select id=\"location:" . $entity["id"] . "\" name=\"location:" . $entity["id"] . "\"><option value=\"\" ><" . lang::get('LANG_Not_Allocated') . "></option>"; $defaultuserid = iform_loctools_getuser($node, $entity["id"]); foreach ($userlist as $uid => $a_user) { $r .= "<option value=\"" . $uid . "\" " . ($uid == $defaultuserid ? 'selected="selected" ' : '') . ">" . $a_user->name . "</option>"; } $r .= "</select>"; } } } $r .= "\n <input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('Save Location Allocations') . "\" />\n </form>\n </div>"; } // Add the downloader if user has manager (superuser) rights. if (iform_loctools_checkaccess($node, 'superuser')) { $r .= ' <div id="downloads" class="mnhnl-btw-datapanel"> <form method="post" action="' . data_entry_helper::$base_url . '/index.php/services/report/requestReport?report=reports_for_prebuilt_forms/MNHNL/mnhnl_btw_transect_direction_report.xml&reportSource=local&auth_token=' . $readAuth['auth_token'] . '&nonce=' . $readAuth['nonce'] . '&mode=csv"> <p>' . lang::get('LANG_Direction_Report') . '</p> <input type="hidden" name="params" value=\'{"survey_id":' . $args['survey_id'] . ', "direction_attr_id":' . $sample_walk_direction_id . ', "closed_attr_id":' . $sample_closure_id . '}\' /> <input type="submit" class="ui-state-default ui-corner-all" value="' . lang::get('LANG_Direction_Report_Button') . '"> </form> <form method="post" action="' . data_entry_helper::$base_url . '/index.php/services/report/requestReport?report=reports_for_prebuilt_forms/MNHNL/mnhnl_btw_verified_data_report.xml&reportSource=local&auth_token=' . $readAuth['auth_token'] . '&nonce=' . $readAuth['nonce'] . '&mode=csv"> <p>' . lang::get('LANG_Verified_Data_Report') . '</p> <input type="hidden" name="params" value=\'{"survey_id":' . $args['survey_id'] . '}\' /> <input type="submit" class="ui-state-default ui-corner-all" value="' . lang::get('LANG_Verified_Data_Report_Button') . '"> </form> <form method="post" action="' . data_entry_helper::$base_url . '/index.php/services/report/requestReport?report=reports_for_prebuilt_forms/MNHNL/mnhnl_btw_download_report_2.xml&reportSource=local&auth_token=' . $readAuth['auth_token'] . '&nonce=' . $readAuth['nonce'] . '&mode=csv"> <p>' . lang::get('LANG_Initial_Download') . '</p> <input type="hidden" name="params" value=\'{"survey_id":' . $args['survey_id'] . ', "closed_attr_id":' . $sample_closure_id . ', "download": "INITIAL", "quality": "!R", "occattrs": "' . $occurrence_confidence_id . ',' . $occurrence_count_id . ',' . $occurrence_approximation_id . ',' . $occurrence_territorial_id . ',' . $occurrence_atlas_code_id . ',' . $occurrence_overflying_id . '", "smpattrs" : "' . $sample_walk_direction_id . ',' . $sample_reliability_id . ',' . $sample_visit_number_id . ',' . $sample_wind_id . ',' . $sample_precipitation_id . ',' . $sample_temperature_id . ',' . $sample_cloud_id . ',' . $sample_start_time_id . ',' . $sample_end_time_id . ',' . $sample_closure_id . ',' . $uid_attr_id . ',' . $email_attr_id . ',' . $username_attr_id . '"}\' /> <input type="submit" class="ui-state-default ui-corner-all" value="' . lang::get('LANG_Initial_Download_Button') . '"> </form> <form method="post" action="' . data_entry_helper::$base_url . '/index.php/services/report/requestReport?report=reports_for_prebuilt_forms/MNHNL/mnhnl_btw_download_report_2.xml&reportSource=local&auth_token=' . $readAuth['auth_token'] . '&nonce=' . $readAuth['nonce'] . '&mode=csv"> <p>' . lang::get('LANG_Confirm_Download') . '</p> <input type="hidden" name="params" value=\'{"survey_id":' . $args['survey_id'] . ', "closed_attr_id":' . $sample_closure_id . ', "download": "CONFIRM", "quality": "V", "occattrs": "' . $occurrence_confidence_id . ',' . $occurrence_count_id . ',' . $occurrence_approximation_id . ',' . $occurrence_territorial_id . ',' . $occurrence_atlas_code_id . ',' . $occurrence_overflying_id . '", "smpattrs" : "' . $sample_walk_direction_id . ',' . $sample_reliability_id . ',' . $sample_visit_number_id . ',' . $sample_wind_id . ',' . $sample_precipitation_id . ',' . $sample_temperature_id . ',' . $sample_cloud_id . ',' . $sample_start_time_id . ',' . $sample_end_time_id . ',' . $sample_closure_id . ',' . $uid_attr_id . ',' . $email_attr_id . ',' . $username_attr_id . '"}\' /> <input type="submit" class="ui-state-default ui-corner-all" value="' . lang::get('LANG_Confirm_Download_Button') . '"> </form> <form method="post" action="' . data_entry_helper::$base_url . '/index.php/services/report/requestReport?report=reports_for_prebuilt_forms/MNHNL/mnhnl_btw_download_report_2.xml&reportSource=local&auth_token=' . $readAuth['auth_token'] . '&nonce=' . $readAuth['nonce'] . '&mode=csv"> <p>' . lang::get('LANG_Final_Download') . '</p> <input type="hidden" name="params" value=\'{"survey_id":' . $args['survey_id'] . ', "closed_attr_id":' . $sample_closure_id . ', "download": "FINAL", "quality": "V", "occattrs": "' . $occurrence_confidence_id . ',' . $occurrence_count_id . ',' . $occurrence_approximation_id . ',' . $occurrence_territorial_id . ',' . $occurrence_atlas_code_id . ',' . $occurrence_overflying_id . '", "smpattrs" : "' . $sample_walk_direction_id . ',' . $sample_reliability_id . ',' . $sample_visit_number_id . ',' . $sample_wind_id . ',' . $sample_precipitation_id . ',' . $sample_temperature_id . ',' . $sample_cloud_id . ',' . $sample_start_time_id . ',' . $sample_end_time_id . ',' . $sample_closure_id . ',' . $uid_attr_id . ',' . $email_attr_id . ',' . $username_attr_id . '"}\' /> <input type="submit" class="ui-state-default ui-corner-all" value="' . lang::get('LANG_Final_Download_Button') . '"> </form> <form method="post" action="' . data_entry_helper::$base_url . '/index.php/services/report/requestReport?report=reports_for_prebuilt_forms/MNHNL/mnhnl_btw_download_report_2.xml&reportSource=local&auth_token=' . $readAuth['auth_token'] . '&nonce=' . $readAuth['nonce'] . '&mode=csv"> <p>' . lang::get('LANG_Complete_Final_Download') . '</p> <input type="hidden" name="params" value=\'{"survey_id":' . $args['survey_id'] . ', "closed_attr_id":' . $sample_closure_id . ', "download": "OFF", "quality": "NA", "occattrs": "' . $occurrence_confidence_id . ',' . $occurrence_count_id . ',' . $occurrence_approximation_id . ',' . $occurrence_territorial_id . ',' . $occurrence_atlas_code_id . ',' . $occurrence_overflying_id . '", "smpattrs" : "' . $sample_walk_direction_id . ',' . $sample_reliability_id . ',' . $sample_visit_number_id . ',' . $sample_wind_id . ',' . $sample_precipitation_id . ',' . $sample_temperature_id . ',' . $sample_cloud_id . ',' . $sample_start_time_id . ',' . $sample_end_time_id . ',' . $sample_closure_id . ',' . $uid_attr_id . ',' . $email_attr_id . ',' . $username_attr_id . '"}\' /> <input type="submit" class="ui-state-default ui-corner-all" value="' . lang::get('LANG_Complete_Final_Download_Button') . '"> </form> </div>'; } // Create Map $options = iform_map_get_map_options($args, $readAuth); $olOptions = iform_map_get_ol_options($args); // if($locations == 'all' || $loclist != '-1') // $options['layers'] = array('locationListLayer'); $options['searchLayer'] = 'false'; $options['editLayer'] = 'false'; $options['initialFeatureWkt'] = null; $options['proxy'] = ''; $options['scroll_wheel_zoom'] = false; $options['width'] = 'auto'; // TBD remove from arglist $r .= "<div class=\"mnhnl-btw-mappanel\">\n" . data_entry_helper::map_panel($options, $olOptions) . "</div>\n"; data_entry_helper::$javascript .= "\n\$('#controls').bind('tabsshow', function(event, ui) {\n var y = \$('.mnhnl-btw-datapanel:visible').outerHeight(true) + \$('.mnhnl-btw-datapanel:visible').position().top;\n if(y < \$('.mnhnl-btw-mappanel').outerHeight(true)+ \$('.mnhnl-btw-mappanel').position().top){\n y = \$('.mnhnl-btw-mappanel').outerHeight(true)+ \$('.mnhnl-btw-mappanel').position().top;\n }\n \$('#controls').height(y - \$('#controls').position().top);\n});\n"; if (count($tabs) > 1) { // close tabs div if present $r .= "</div>"; } if (method_exists(get_called_class(), 'getTrailerHTML')) { $r .= call_user_func(array(get_called_class(), 'getTrailerHTML'), $args); } return $r; } /////////////////////////////////////////////////////////////////// // At this point there are 3 modes: // Adding a new survey // editing/showing an existing survey // editing/showing an existing occurrence // First load the occurrence (and its position sample) if provided // Then load the parent sample if provided, or derived from occurrence. // $occReadOnly is set if the occurrence has been downloaded. Not even an admin user can modify it in this case. data_entry_helper::$javascript .= "\n// Create Layers.\nvar locationLayer, occListLayer, control;\nmapInitialisationHooks.push(function (div) {\n \"use strict\";\n // Create vector layers: one to display the location onto, and another for the occurrence list\n // the default edit layer is used for the occurrences themselves\n var locStyleMap = new OpenLayers.StyleMap({\n 'default': new OpenLayers.Style({\n fillColor: 'Green',\n strokeColor: 'Black',\n fillOpacity: 0.2,\n strokeWidth: 1\n })});\n locationLayer = new OpenLayers.Layer.Vector('" . lang::get("LANG_Location_Layer") . "', {styleMap: locStyleMap});\n var occStyleMap = new OpenLayers.StyleMap({\n 'default': new OpenLayers.Style({\n pointRadius: 3,\n fillColor: 'Red',\n fillOpacity: 0.3,\n strokeColor: 'Red',\n strokeWidth: 1\n })});\n occListLayer = new OpenLayers.Layer.Vector(\"" . lang::get("LANG_Occurrence_List_Layer") . "\", {styleMap: occStyleMap});\n div.map.addLayer(locationLayer);\n div.map.addLayer(occListLayer);\n var control = new OpenLayers.Control.SelectFeature(occListLayer);\n occListLayer.map.addControl(control);\n function onPopupClose(evt) {\n // 'this' is the popup.\n control.unselect(this.feature);\n }\n function onFeatureSelect(evt) {\n feature = evt.feature;\n popup = new OpenLayers.Popup.FramedCloud(\"featurePopup\",\n feature.geometry.getBounds().getCenterLonLat(),\n new OpenLayers.Size(100,100),\n feature.attributes.taxon + \" (\" + feature.attributes.count + \")\",\n null, true, onPopupClose);\n feature.popup = popup;\n popup.feature = feature;\n feature.layer.map.addPopup(popup);\n }\n function onFeatureUnselect(evt) {\n feature = evt.feature;\n if (feature.popup) {\n popup.feature = null;\n feature.layer.map.removePopup(feature.popup);\n feature.popup.destroy();\n feature.popup = null;\n }\n }\n occListLayer.events.on({\n 'featureselected': onFeatureSelect,\n 'featureunselected': onFeatureUnselect\n });\n control.activate();\n});\n"; $occReadOnly = false; $childSample = array(); if ($childLoadID) { // load the occurrence and its associated sample (which holds the position) $url = $svcUrl . '/data/occurrence/' . $childLoadID; $url .= "?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); if (count($entity) == 0) { return '<p>' . lang::get('LANG_No_Access_To_Occurrence') . '</p>'; } foreach ($entity[0] as $key => $value) { $childSample['occurrence:' . $key] = $value; } if ($entity[0]['downloaded_flag'] == 'F') { // Final download complete, now readonly $occReadOnly = true; } $url = $svcUrl . '/data/sample/' . $childSample['occurrence:sample_id']; $url .= "?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); if (count($entity) == 0) { return '<p>' . lang::get('LANG_No_Access_To_Occurrence') . '</p>'; } foreach ($entity[0] as $key => $value) { $childSample['sample:' . $key] = $value; } $childSample['sample:geom'] = ''; // value received from db is not WKT, which is assumed by all the code. $childSample['taxon'] = $childSample['occurrence:taxon']; $parentLoadID = $childSample['sample:parent_id']; } $parentSample = array(); if ($parentLoadID) { // load the container master sample $url = $svcUrl . '/data/sample/' . $parentLoadID; $url .= "?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); if (count($entity) == 0) { return '<p>' . lang::get('LANG_No_Access_To_Sample') . '</p>'; } foreach ($entity[0] as $key => $value) { $parentSample['sample:' . $key] = $value; } if (is_array($locations) && !in_array($entity[0]["location_id"], $locations)) { return '<p>' . lang::get('LANG_No_Access_To_Location') . '</p>'; } if ($entity[0]["parent_id"]) { return '<p>' . lang::get('LANG_No_Access_To_Sample') . '</p>'; } $parentSample['sample:date'] = $parentSample['sample:date_start']; // bit of a bodge $childSample['sample:date'] = $parentSample['sample:date']; // enforce a match between child and parent sample dates // default values for attributes from DB are picked up automatically. } data_entry_helper::$entity_to_load = $parentSample; $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' => $readAuth)); $closedFieldName = $attributes[$sample_closure_id]['fieldname']; $closedFieldValue = data_entry_helper::check_default_value($closedFieldName, array_key_exists('default', $attributes[$sample_closure_id]) ? $attributes[$sample_closure_id]['default'] : '0'); // default is not closed if ($closedFieldValue == '') { $closedFieldValue = '0'; } if ($closedFieldValue == '1' && !user_access($args['edit_permission'])) { // sample has been closed, no admin perms. Everything now set to read only. $surveyReadOnly = true; $disabledText = "disabled=\"disabled\""; $defAttrOptions = array('extraParams' => $readAuth, 'disabled' => $disabledText); } else { // sample editable. Admin users can modify closed samples. $disabledText = ""; $defAttrOptions = array('extraParams' => $readAuth); } // with the AJAX code, we deal with the validation semi manually: Form name is meant be invalid as we only want code included. data_entry_helper::enable_validation(null); $r .= "<div id=\"controls\">\n"; $activeTab = 'survey'; // mode 1 = new Sample, display sample. if ($mode == 2) { // have specified a sample ID if ($args["on_edit_survey_nav"] == "survey") { $activeTab = 'survey'; } else { if ($surveyReadOnly || $args["on_edit_survey_nav"] == "list") { $activeTab = 'occurrenceList'; } else { $activeTab = 'occurrence'; } } if ($surveyReadOnly) { data_entry_helper::$javascript .= "jQuery('#occ-form').hide();"; } } else { if ($mode == 3) { // have specified an occurrence ID $activeTab = 'occurrence'; } } // Set Up form tabs. $r .= data_entry_helper::enable_tabs(array('divId' => 'controls', 'active' => $activeTab)); $r .= "<div id=\"temp\"></div>"; $r .= data_entry_helper::tab_header(array('tabs' => array('#survey' => lang::get('LANG_Survey'), '#occurrence' => lang::get($surveyReadOnly || $occReadOnly ? 'LANG_Show_Occurrence' : (isset($childSample['sample:id']) ? 'LANG_Edit_Occurrence' : 'LANG_Add_Occurrence')), '#occurrenceList' => lang::get('LANG_Occurrence_List')))); // Set up main Survey Form. $r .= "<div id=\"survey\" class=\"mnhnl-btw-datapanel\">\n <p id=\"read-only-survey\"><strong>" . lang::get('LANG_Read_Only_Survey') . "</strong></p>"; if (user_access($args['edit_permission']) && array_key_exists('sample:id', data_entry_helper::$entity_to_load)) { // check for other surveys of same date/transect: only if admin user. $url = $svcUrl . '/data/sample?mode=json&view=detail&auth_token=' . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"] . "&date_start=" . $parentSample['sample:date_start'] . "&location_id=" . $parentSample['sample:location_id']; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); if (count($entity) > 1) { // ignore ourselves! $r .= "<div id=\"mergeSurveys\"><p><strong>" . lang::get('LANG_Found_Mergable_Surveys') . "</strong></p>"; foreach ($entity as $survey) { if ($survey['id'] != $parentSample['sample:id']) { $r .= "<form action=\"" . url('node/' . $node->nid, array()) . "\" method=\"get\"><input type=\"submit\" value=\"" . lang::get('LANG_Merge_With_ID') . " " . $survey['id'] . "\"><input type=\"hidden\" name=\"merge_sample_id1\" value=\"" . $parentSample['sample:id'] . "\" /><input type=\"hidden\" name=\"merge_sample_id2\" value=\"" . $survey['id'] . "\" /></form>"; } } $r .= "</div>"; } } $r .= "<form id=\"SurveyForm\" action=\"" . iform_ajaxproxy_url($node, 'sample') . "\" method=\"post\">\n <input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n <input type=\"hidden\" id=\"sample:survey_id\" name=\"sample:survey_id\" value=\"" . $args['survey_id'] . "\" />"; if (array_key_exists('sample:id', data_entry_helper::$entity_to_load)) { $r .= "<input type=\"hidden\" id=\"sample:id\" name=\"sample:id\" value=\"" . data_entry_helper::$entity_to_load['sample:id'] . "\" />\n"; } else { $r .= "<input type=\"hidden\" id=\"sample:id\" name=\"sample:id\" value=\"\" disabled=\"disabled\" />\n"; // GvB 19/Nov/2012 : change to user detail defaults // logic is now much simpler, and they are only included/created if the sample is new. $fieldName = $attributes[$uid_attr_id]['fieldname']; $fieldValue = data_entry_helper::check_default_value($fieldName, $user->uid); $r .= "<input type=\"hidden\" name=\"" . $fieldName . "\" value=\"" . $fieldValue . "\" />\n"; $fieldName = $attributes[$email_attr_id]['fieldname']; $fieldValue = data_entry_helper::check_default_value($fieldName, $user->mail); $r .= "<input type=\"hidden\" name=\"" . $fieldName . "\" value=\"" . $fieldValue . "\" />\n"; $fieldName = $attributes[$username_attr_id]['fieldname']; $fieldValue = data_entry_helper::check_default_value($fieldName, $user->name); $r .= "<input type=\"hidden\" name=\"" . $fieldName . "\" value=\"" . $fieldValue . "\" />\n"; } $defAttrOptions['validation'] = array('required'); if ($locations == 'all') { $locOptions = array_merge(array('label' => lang::get('LANG_Transect')), $defAttrOptions); $locOptions['extraParams'] = array_merge(array('parent_id' => 'NULL', 'view' => 'detail', 'orderby' => 'name'), $locOptions['extraParams']); $r .= data_entry_helper::location_select($locOptions); } else { // can't use location select due to location filtering. $r .= "<label for=\"imp-location\">" . lang::get('LANG_Transect') . ":</label>\n<select id=\"imp-location\" name=\"sample:location_id\" " . $disabled_text . " class=\" \" >"; $url = $svcUrl . '/data/location?mode=json&view=detail&parent_id=NULL&orderby=name&auth_token=' . $readAuth['auth_token'] . '&nonce=' . $readAuth["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entities = json_decode(curl_exec($session), true); if (!empty($entities)) { foreach ($entities as $entity) { if (in_array($entity["id"], $locations)) { if ($entity["id"] == data_entry_helper::$entity_to_load['sample:location_id']) { $selected = 'selected="selected"'; } else { $selected = ''; } $r .= "<option value=\"" . $entity["id"] . "\" " . $selected . ">" . $entity["name"] . "</option>"; } } } $r .= "</select><span class=\"deh-required\">*</span><br />"; } $languageFilteredAttrOptions = $defAttrOptions + array('language' => iform_lang_iso_639_2($args['language'])); $r .= data_entry_helper::outputAttribute($attributes[$sample_walk_direction_id], $languageFilteredAttrOptions) . ($sample_reliability_id ? data_entry_helper::outputAttribute($attributes[$sample_reliability_id], $languageFilteredAttrOptions) : "<span style=\"display: none;\">Sample attribute '" . self::ATTR_RELIABILITY . "' not assigned to this survey</span>") . data_entry_helper::outputAttribute($attributes[$sample_visit_number_id], array_merge($languageFilteredAttrOptions, array('default' => 1, 'noBlankText' => true))); 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 $d = new DateTime(data_entry_helper::$entity_to_load['sample:date']); data_entry_helper::$entity_to_load['sample:date'] = $d->format('d/m/Y'); } if ($args['language'] != 'en') { data_entry_helper::add_resource('jquery_ui_' . $args['language']); } // this will autoload the jquery_ui resource. The date_picker does not have access to the args. if ($surveyReadOnly) { $r .= data_entry_helper::text_input(array_merge($defAttrOptions, array('label' => lang::get('LANG_Date'), 'fieldname' => 'sample:date', 'disabled' => $disabledText))); } else { $r .= data_entry_helper::date_picker(array('label' => lang::get('LANG_Date'), 'fieldname' => 'sample:date', 'class' => 'vague-date-picker')); } $r .= ($sample_wind_id ? data_entry_helper::outputAttribute($attributes[$sample_wind_id], $languageFilteredAttrOptions) : "<span style=\"display: none;\">Sample attribute '" . self::ATTR_WIND . "' not assigned to this survey</span>") . ($sample_precipitation_id ? data_entry_helper::outputAttribute($attributes[$sample_precipitation_id], $languageFilteredAttrOptions) : "<span style=\"display: none;\">Sample attribute '" . self::ATTR_RAIN . "' not assigned to this survey</span>") . ($sample_temperature_id ? data_entry_helper::outputAttribute($attributes[$sample_temperature_id], array_merge($defAttrOptions, array('suffixTemplate' => 'nosuffix'))) . "<span class=\"attr-trailer\"> °C</span><br />" : "<span style=\"display: none;\">Sample attribute '" . self::ATTR_TEMP . "' not assigned to this survey</span>") . ($sample_cloud_id ? data_entry_helper::outputAttribute($attributes[$sample_cloud_id], $defAttrOptions) : "<span style=\"display: none;\">Sample attribute '" . self::ATTR_CLOUD . "' not assigned to this survey</span>") . ($sample_start_time_id ? data_entry_helper::outputAttribute($attributes[$sample_start_time_id], array_merge($defAttrOptions, array('suffixTemplate' => 'nosuffix'))) . "<span class=\"attr-trailer\"> hh:mm</span><br />" : "<span style=\"display: none;\">Sample attribute '" . self::ATTR_START_TIME . "' not assigned to this survey</span>") . ($sample_end_time_id ? data_entry_helper::outputAttribute($attributes[$sample_end_time_id], array_merge($defAttrOptions, array('suffixTemplate' => 'nosuffix'))) . "<span class=\"attr-trailer\"> hh:mm</span><br />" : "<span style=\"display: none;\">Sample attribute '" . self::ATTR_END_TIME . "' not assigned to this survey</span>"); data_entry_helper::$javascript .= "\njQuery('.attr-trailer').prev('br').remove();\n"; unset($defAttrOptions['suffixTemplate']); unset($defAttrOptions['validation']); if (user_access($args['edit_permission'])) { // users with admin permissions can override the closing of the // sample by unchecking the checkbox. // Because this is attached to the sample, we have to include the sample required fields in the // the post. This means they can't be disabled, so we enable all fields in this case. // Normal users can only set this to closed, and they do this using a button/hidden field. $r .= data_entry_helper::outputAttribute($attributes[$sample_closure_id], $defAttrOptions); // In addition admin users can delete a survey/sample. $r .= data_entry_helper::checkbox(array('label' => lang::get('Deleted'), 'fieldname' => 'sample:deleted', 'id' => 'main-sample-deleted')); } else { // hidden closed $r .= "<input type=\"hidden\" id=\"main-sample-closed\" name=\"" . $closedFieldName . "\" value=\"" . $closedFieldValue . "\" />\n"; } data_entry_helper::$javascript .= "\n\$.validator.messages.required = \"" . lang::get('validation_required') . "\";\n\$.validator.defaults.onsubmit = false; // override default - so that we handle all submission validation.\n"; if (!$surveyReadOnly) { // NB that we don't even include the buttons when readonly. data_entry_helper::$javascript .= "\njQuery('#read-only-survey').hide();\njQuery('#ro-sur-occ-warn').hide();\n"; $r .= "<input type=button id=\"close1\" class=\"ui-state-default ui-corner-all \" value=\"" . lang::get('LANG_Save_Survey_Details') . "\";\n onclick=\"var result = \$('#SurveyForm input').valid();\n var result2 = \$('#SurveyForm select').valid();\n if (!result || !result2) {\n return;\n }\n jQuery('#close1').addClass('loading-button');\n jQuery('#SurveyForm').submit();\">\n"; if (!user_access($args['edit_permission'])) { if ($mode == 1) { data_entry_helper::$javascript .= "jQuery('#close2').hide();\n"; } $r .= "<input type=button id=\"close2\" class=\"ui-state-default ui-corner-all \" value=\"" . lang::get('LANG_Save_Survey_And_Close') . "\"\n onclick=\"if(confirm('" . lang::get('LANG_Close_Survey_Confirm') . "')){\n var result = \$('#SurveyForm input').valid();\n var result2 = \$('#SurveyForm select').valid();\n if (!result || !result2) {\n return;\n }\n jQuery('#main-sample-closed').val('1');\n jQuery('#close2').addClass('loading-button');\n jQuery('#SurveyForm').submit();\n };\">\n"; } } $r .= "</form></div>\n"; data_entry_helper::$javascript .= "\nalertIndiciaError = function(data){\n\tvar errorString = \"" . lang::get('LANG_Indicia_Warehouse_Error') . "\";\n\tif(data.error){\terrorString = errorString + ' : ' + data.error;\t}\n\tif(data.errors){\n\t\tfor (var i in data.errors){\n\t\t\terrorString = errorString + ' : ' + data.errors[i];\n\t\t}\n\t}\n\talert(errorString);\n\t// the most likely cause is authentication failure - eg the read authentication has timed out.\n\t// prevent further use of the form:\n\t\$('.loading-panel').remove();\n\t\$('.loading-hide').removeClass('loading-hide');\n};\nerrorPos = null;\nclearErrors = function(formSel) {\n\tjQuery(formSel).find('.inline-error').remove();\n\terrorPos = null;\n};\nmyScrollTo = function(selector){\n\tjQuery(selector).filter(':visible').each(function(){\n\t\tif(errorPos == null || jQuery(this).offset().top < errorPos){\n\t\t\terrorPos = jQuery(this).offset().top;\n\t\t\twindow.scroll(0,errorPos);\n\t\t}\n\t});\n};\nmyScrollToError = function(){\n\tjQuery('.inline-error,.error').filter(':visible').prev().each(function(){\n\t\tif(errorPos == null || jQuery(this).offset().top < errorPos){\n\t\t\terrorPos = jQuery(this).offset().top;\n\t\t\twindow.scroll(0,errorPos);\n\t\t}\n\t});\n};\njQuery('#SurveyForm').ajaxForm({\n\tasync: false,\n\tdataType: 'json',\n beforeSubmit: function(data, obj, options){\n \tvar valid = true;\n \tclearErrors('form#SurveyForm');\n \tif (!jQuery('form#SurveyForm > input').valid()) {\n\t\t\tmyScrollToError();\n \t\t\tjQuery('.loading-button').removeClass('loading-button');\n\t\t\treturn false;\n \t\t};\n \t\tSurveyFormRetVal = true;\n \t\tif(jQuery('#main-sample-deleted:checked').length == 0){ // only do check if not deleting\n jQuery.ajax({ // now check if there are any other samples with this combination of date and location\n type: 'GET',\n url: \"" . $svcUrl . "/data/sample?mode=json&view=detail\" +\n \"&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" +\n \"&orderby=id&callback=?&location_id=\"+jQuery('#imp-location').val()+\"&date_start=\"+jQuery('#SurveyForm [name=sample\\:date]').val(),\n data: {},\n success: function(detData) {\n for(i=0, j=0; i< detData.length; i++){\n if(detData[i].id != jQuery('#SurveyForm [name=sample\\:id]').val()) j++;\n }\n if(j) {\n \tSurveyFormRetVal = confirm(\"" . lang::get('LANG_Survey_Already_Exists') . "\");\n }\n },\n dataType: 'json',\n async: false\n });\n }\n\t\treturn SurveyFormRetVal;\n\t},\n success: function(data){\n // this will leave all the fields populated.\n \tif(data.success == 'multiple records' && data.outer_table == 'sample'){\n jQuery('#occ-form').show();\n jQuery('#na-occ-warn,#mergeSurveys').hide();"; if (!user_access($args['edit_permission'])) { // don't need to worry about record_status value for non admins as they can't modify when closed. data_entry_helper::$javascript .= "\n if(jQuery('#main-sample-closed').val() == '1'){\n jQuery('#read-only-survey,#ro-sur-occ-warn').show();\n jQuery('#close1,#close2,#occ-form').hide(); //can't enter any more occurrences\n jQuery('#SurveyForm').children().attr('disabled','disabled');\n };\n"; } else { data_entry_helper::$javascript .= "\n jQuery('#occurrence\\\\:record_status').val(jQuery('#smpAttr\\\\:" . $attributes[$sample_closure_id]['attributeId'] . ":checked').length > 0 ? 'C' : 'I');\n if(jQuery('#main-sample-deleted:checked').length > 0){\n jQuery('#return-to-main').click();\n return;\n };\n"; } data_entry_helper::$javascript .= "// If sample_id filled in -> we have a previously saved collection, so possibly have subsamples.\nif(jQuery('#SurveyForm > input[name=sample\\:id]').val() != ''){\n // Put up warning dialogue that we are checking the subsamples: include a progress bar: set to zero%.\n var dialog = \$('<span id=\"subsample-progress-span\"><p>'+\"" . lang::get('Please wait whilst some data integrity checks are carried out.') . "\"+'</p><div id=\"subsample-progress\"></div></span>').dialog({ title: \"" . lang::get('Checks') . "\", zIndex: 4000 });\n jQuery('#subsample-progress').progressbar({value: 0});\n jQuery.ajax({ // get all subsamples/occurrences to check if the dates match\n type: 'GET',\n url: \"" . $svcUrl . "/report/requestReport?report=library/occurrences/occurrences_list_for_parent_sample.xml&reportSource=local&mode=json&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" +\n \"&callback=?&sample_id=\"+data.outer_id+\"&survey_id=&date_from=&date_to=&taxon_group_id=&smpattrs=&occattrs=\",\n data: {},\n success: function(subData) {\n jQuery('#subsample-progress').data('max',subData.length+1);\n var mainDate = \$.datepicker.formatDate('yy-mm-dd', jQuery('#SurveyForm > input[name=sample\\:date]').datepicker(\"getDate\"));\n for(i=0; i< subData.length; i++){ // loop through all subsamples\n jQuery('#subsample-progress').progressbar('option','value',(i+1)*100/jQuery('#subsample-progress').data('max'));\n var values = {};\n var url = '';\n // Check if date on subsamples matches supersample date: if not set up a post array for the sample, with correct date.\n if(subData[i].date_start != mainDate){\n values['sample:id']=subData[i].sample_id;\n values['sample:date']=mainDate;\n url=\"" . iform_ajaxproxy_url($node, 'sample') . "\";\n }\n"; // Send AJAX request to set occurrence to 'C' if closed : use sync if (!user_access($args['edit_permission'])) { data_entry_helper::$javascript .= " if(jQuery('#main-sample-closed').val() == '1'){\n"; } else { data_entry_helper::$javascript .= " if(jQuery('#smpAttr\\\\:" . $attributes[$sample_closure_id]['attributeId'] . ":checked').length > 0){\n"; } // If records are already verified, they are left verified, as if the records themselves are saved // they will flagged as no longer verified: But have to force a re verification if date is changed. data_entry_helper::$javascript .= "\n if(subData[i].record_status == 'I' || typeof values['sample:id'] != 'undefined'){\n values['occurrence:id']=subData[i].occurrence_id;\n values['occurrence:record_status']='C';\n url=(url == '' ? \"" . iform_ajaxproxy_url($node, 'occurrence') . "\" : \"" . iform_ajaxproxy_url($node, 'smp-occ') . "\");\n }\n } else { // any occurrences on unclosed collections must be flagged as 'I' - reopening unverifies.\n if(subData[i].record_status != 'I'){\n values['occurrence:id']=subData[i].occurrence_id;\n values['occurrence:record_status']='I';\n url=(url == '' ? \"" . iform_ajaxproxy_url($node, 'occurrence') . "\" : \"" . iform_ajaxproxy_url($node, 'smp-occ') . "\");\n }\n }\n if(url!=''){\n values['website_id']=" . $args['website_id'] . ";\n jQuery.ajax({ type: 'POST', url: url, data: values, dataType: 'json', async: false});\n }\n }\n },\n dataType: 'json',\n async: false\n });\n dialog.dialog('close');\n dialog.dialog('destroy');\n jQuery('#subsample-progress-span').remove();\n}\n\n\t\t\twindow.scroll(0,0);\n jQuery('#SurveyForm > input[name=sample\\:id]').removeAttr('disabled').val(data.outer_id);\n jQuery('#occ-form > input[name=sample\\:parent_id]').val(data.outer_id);\n jQuery('#occ-form > input[name=sample\\:date]').val(jQuery('#SurveyForm > input[name=sample\\:date]').val());\n loadAttributes('sample_attribute_value', 'sample_attribute_id', 'sample_id', data.outer_id, 'smpAttr');\n switch(\"" . $args["on_save_survey_nav"] . "\"){\n\t\t\t\tcase \"list\":\n\t\t\t\t\tvar a = \$('ul.ui-tabs-nav a')[2];\n\t\t\t\t\t\$(a).click();\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"survey\":\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:"; if (!user_access($args['edit_permission'])) { data_entry_helper::$javascript .= "\n\t\t\t\t\tif(jQuery('#main-sample-closed').val() == 0){\n\t\t\t\t\t\tvar a = \$('ul.ui-tabs-nav a')[1];\n\t\t\t\t\t\t\$(a).click();\n\t\t\t\t\t};"; } else { data_entry_helper::$javascript .= "\n\t\t\t\t\tvar a = \$('ul.ui-tabs-nav a')[1];\n\t\t\t\t\t\$(a).click();"; } data_entry_helper::$javascript .= "\n\t\t\t\t\tbreak;\n\t\t\t}\n } else {\n\t\t\tif(data.error){\n\t\t\t\tvar lastIndex = data.error.lastIndexOf('Validation error');\n \t\t\tif (lastIndex != -1 && lastIndex == (data.error.length - 16)){\n\t\t\t\t\tif(data.errors){\n\t\t\t\t\t\t// TODO translation\n\t\t\t\t\t\tfor (i in data.errors){\n\t\t\t\t\t\t\tvar label = \$('<p/>').addClass('inline-error').html(data.errors[i]);\n\t\t\t\t\t\t\tlabel.insertAfter('[name='+i+']');\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmyScrollToError();\n\t\t\t\t\t\treturn;\n \t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\talertIndiciaError(data);\n }\n\t},\n complete: function (){\n \t\tjQuery('.loading-button').removeClass('loading-button');\n \t}\n});\n// In this case, all the samples attributes are on the survey tab, and all the occurrence attributes are on the occurrence tab. No need to worry about getting the correct form.\nloadAttributes = function(attributeTable, attributeKey, key, keyValue, prefix){\n jQuery.ajax({\n type: \"GET\",\n url: \"" . $svcUrl . "/data/\" + attributeTable + \"?mode=json&view=list\" +\n \t\"&reset_timeout=true&nonce=" . $readAuth['nonce'] . "&auth_token=" . $readAuth['auth_token'] . "\" +\n \t\t\t\"&\" + key + \"=\" + keyValue + \"&callback=?\",\n data: {},\n success: (function(attrPrefix, attrKey) {\n var retVal = function(attrdata) {\n if(!(attrdata instanceof Array)){\n alertIndiciaError(attrdata);\n } else if (attrdata.length>0) {\n for (var i=0;i<attrdata.length;i++){\n // in all cases if the attribute already has the <prefix>:<X>:<Y> format name we leave. Other wise we update <prefix>:<X> to <prefix>:<X>:<Y>\n // We leave all values unchanged.\n // need to be careful about Cloud: this is a drop down, but it is not language specific: the termlist is\n // always in english, so the iso won't match.\n if (attrdata[i].id){\n if (attrdata[i].iso == null || attrdata[i].iso == '') // no iso - not a look up.\n jQuery('[name='+attrPrefix+'\\:'+attrdata[i][attrKey]+']').attr('name', attrPrefix+':'+attrdata[i][attrKey]+':'+attrdata[i].id);\n else {\n if (attrdata[i].iso == '" . $language . "') // this is our actual language so OK\n jQuery('[name='+attrPrefix+'\\:'+attrdata[i][attrKey]+']').attr('name', attrPrefix+':'+attrdata[i][attrKey]+':'+attrdata[i].id);\n else {// not our language: look up all the other attrs, and if we don't find one of this id for our language, use this one.\n var found = false;\n for (var j=0;j<attrdata.length;j++)\n found = found || (i!=j && attrdata[i][attrKey] == attrdata[j][attrKey] && attrdata[j].iso == '" . $language . "');\n if(!found)\n jQuery('[name='+attrPrefix+'\\:'+attrdata[i][attrKey]+']').attr('name', attrPrefix+':'+attrdata[i][attrKey]+':'+attrdata[i].id);\n }\n }\n }\n }\n }};\n return retVal;\n })(prefix, attributeKey),\n\t\tdataType: 'json',\n\t async: false\n\t});\n}"; // Set up Occurrence List tab: don't include when creating a new sample as it will have no occurrences // Grid populated at a later point $r .= "<div id=\"occurrenceList\" class=\"mnhnl-btw-datapanel\"><div id=\"occ_grid\"></div>\n <form method=\"post\" action=\"" . data_entry_helper::$base_url . "/index.php/services/report/requestReport?report=reports_for_prebuilt_forms/MNHNL/mnhnl_btw_occurrences_report.xml&reportSource=local&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth['nonce'] . "&mode=csv\">\n <input type=\"hidden\" id=\"params\" name=\"params\" value='{\"survey_id\":" . $args['survey_id'] . ", \"sample_id\":" . data_entry_helper::$entity_to_load['sample:id'] . "}' />\n <input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Download_Occurrences') . "\">\n </form></div>"; if ($occReadOnly) { // NB that we don't even include the buttons when readonly. data_entry_helper::$javascript .= "\njQuery('#ro-occ-occ-warn').show();\njQuery('#ro-sur-occ-warn').hide();\n"; } else { data_entry_helper::$javascript .= "\njQuery('#ro-occ-occ-warn').hide();\n"; } if ($mode == 1) { data_entry_helper::$javascript .= "jQuery('#occ-form').hide();"; } else { data_entry_helper::$javascript .= "jQuery('#na-occ-warn').hide();"; } // Set up Occurrence tab: don't allow entry of a new occurrence until after top level sample is saved. data_entry_helper::$entity_to_load = $childSample; $attributes = data_entry_helper::getAttributes(array('id' => data_entry_helper::$entity_to_load['occurrence:id'], 'valuetable' => 'occurrence_attribute_value', 'attrtable' => 'occurrence_attribute', 'key' => 'occurrence_id', 'fieldprefix' => 'occAttr', 'extraParams' => $readAuth)); $extraParams = $readAuth + array('taxon_list_id' => $args['list_id'], 'view' => 'detail', 'query' => urlencode(json_encode(array('in' => array('language_iso', array('lat', iform_lang_iso_639_2($args['language']))))))); if ($occReadOnly) { // if the occurrence has been downloaded, no one can modify it. $disabledText = "disabled=\"disabled\""; $defAttrOptions['disabled'] = $disabledText; } $species_ctrl_args = array('label' => lang::get('LANG_Species'), 'fieldname' => 'occurrence:taxa_taxon_list_id', 'table' => 'taxa_taxon_list', 'captionField' => 'taxon', 'valueField' => 'id', 'columns' => 2, 'extraParams' => $extraParams, 'disabled' => $disabledText, 'defaultCaption' => data_entry_helper::$entity_to_load['occurrence:taxon']); $r .= " <div id=\"occurrence\" class=\"mnhnl-btw-datapanel\">\n <p id=\"ro-occ-occ-warn\"><strong>" . lang::get('LANG_Read_Only_Occurrence') . "</strong></p>\n <p id=\"ro-sur-occ-warn\"><strong>" . lang::get('LANG_Read_Only_Survey') . "</strong></p>\n <p id=\"na-occ-warn\"><strong>" . lang::get('LANG_Page_Not_Available') . "</strong></p>\n <form method=\"post\" id=\"occ-form\" action=\"" . iform_ajaxproxy_url($node, 'smp-occ') . "\" >\n <input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n <input type=\"hidden\" id=\"sample:survey_id\" name=\"sample:survey_id\" value=\"" . $args['survey_id'] . "\" />\n <input type=\"hidden\" id=\"sample:parent_id\" name=\"sample:parent_id\" value=\"" . $parentSample['sample:id'] . "\" />\n <input type=\"hidden\" id=\"sample:date\" name=\"sample:date\" value=\"" . data_entry_helper::$entity_to_load['sample:date'] . "\" />\n <input type=\"hidden\" id=\"sample:id\" name=\"sample:id\" value=\"" . data_entry_helper::$entity_to_load['sample:id'] . "\" />\n <input type=\"hidden\" id=\"occurrence:id\" name=\"occurrence:id\" value=\"" . data_entry_helper::$entity_to_load['occurrence:id'] . "\" />\n <input type=\"hidden\" id=\"occurrence:record_status\" name=\"occurrence:record_status\" value=\"" . ($closedFieldValue == '0' ? 'I' : 'C') . "\" />\n <input type=\"hidden\" id=\"occurrence:downloaded_flag\" name=\"occurrence:downloaded_flag\" value=\"N\" />\n " . data_entry_helper::autocomplete($species_ctrl_args) . "\n " . ($occurrence_confidence_id ? data_entry_helper::outputAttribute($attributes[$occurrence_confidence_id], array_merge($languageFilteredAttrOptions, array('noBlankText' => ''))) : "<span style=\"display: none;\">Occurrence attribute '" . self::ATTR_CONFIDENCE . "' not assigned to this survey</span>") . "\n " . data_entry_helper::sref_and_system(array('label' => lang::get('LANG_Spatial_ref'), 'systems' => array('2169' => 'Luref (Gauss Luxembourg)'))) . "\n <p>" . lang::get('LANG_Click_on_map') . "</p>\n " . data_entry_helper::outputAttribute($attributes[$occurrence_count_id], array_merge($defAttrOptions, array('default' => 1))) . "\n " . ($occurrence_approximation_id ? data_entry_helper::outputAttribute($attributes[$occurrence_approximation_id], $defAttrOptions) : "<span style=\"display: none;\">Occurrence attribute '" . self::ATTR_APPROXIMATION . "' not assigned to this survey</span>") . "\n " . data_entry_helper::outputAttribute($attributes[$occurrence_territorial_id], array_merge($defAttrOptions, array('default' => 1, 'id' => 'occ-territorial'))) . "\n " . data_entry_helper::outputAttribute($attributes[$occurrence_atlas_code_id], $languageFilteredAttrOptions) . "\n " . ($occurrence_overflying_id ? data_entry_helper::outputAttribute($attributes[$occurrence_overflying_id], $defAttrOptions) : "<span style=\"display: none;\">Occurrence attribute '" . self::ATTR_OVERFLYING . "' not assigned to this survey</span>") . "\n " . data_entry_helper::textarea(array('label' => lang::get('LANG_Comment'), 'fieldname' => 'occurrence:comment', 'disabled' => $disabledText)); if (!$surveyReadOnly && !$occReadOnly) { if ($mode == 3) { $r .= data_entry_helper::checkbox(array('label' => lang::get('Delete'), 'fieldname' => 'sample:deleted', 'id' => 'occ-sample-deleted')); } $r .= "<input type=\"submit\" id=\"occ-submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save_Occurrence_Details') . "\" />"; } $r .= " </form>\n"; data_entry_helper::$javascript .= "\n// because of ID tracking it is easier to rebuild entire list etc.\nretriggerGrid = function(){\n \$('div#occ_grid').empty();\n occListLayer.destroyFeatures();\n activateAddList = 1;\n thisOccID = -1;\n \$('div#occ_grid').indiciaDataGrid('rpt:reports_for_prebuilt_forms/MNHNL/mnhnl_btw_list_occurrences', {\n indiciaSvc: '" . $svcUrl . "',\n dataColumns: ['taxon', 'territorial', 'count'],\n reportColumnTitles: {taxon : '" . lang::get('LANG_Species') . "', territorial : '" . lang::get('LANG_Territorial') . "', count : '" . lang::get('LANG_Count') . "'},\n actionColumns: {'" . lang::get('LANG_Show') . "' : \"" . url('node/' . $node->nid, array('query' => 'occurrence_id=£id£')) . "\",\n '" . lang::get('LANG_Highlight') . "' : \"script:highlight(£id£);\"},\n auth : { nonce : '" . $readAuth['nonce'] . "', auth_token : '" . $readAuth['auth_token'] . "'},\n parameters : { survey_id : '" . $args['survey_id'] . "',\n parent_id : jQuery('#SurveyForm [name=sample\\:id]').val(),\n territorial_attr_id : '" . $occurrence_territorial_id . "',\n count_attr_id : '" . $occurrence_count_id . "'},\n itemsPerPage : 12,\n callback : addListFeature ,\n cssOdd : ''\n });\n}\n\njQuery('#occ-form').ajaxForm({\n\tasync: false,\n\tdataType: 'json',\n beforeSubmit: function(data, obj, options){\n \tvar valid = true;\n \tclearErrors('form#occ-form');\n \tif (!jQuery('form#occ-form > input').valid()) { valid = false; }\n \tif (!jQuery('form#occ-form > select').valid()) { valid = false; }\n \tif(!valid) {\n\t\t\tmyScrollToError();\n\t\t\treturn false;\n\t\t};\n\t\tjQuery('#occ-submit').addClass('loading-button');\n\t\treturn true;\n\t},\n success: function(data){\n // this will leave all the fields populated.\n \tif(data.success == 'multiple records' && data.outer_table == 'sample'){\n\t\t\twindow.scroll(0,0);\n\t\t\t// cant use reset form, as returns it to original values: if this was called with occurrence_id =<x> then it would repopulate with original occurrence's values\n\t\t\t// website_id, survey_id, record_status, downloaded_flag, sample:entered_sref_system are constants and are left alone. parent_id, date are only set referring to parent sample.\n\t\t\tjQuery('form#occ-form').find('[name^=occAttr\\:]').each(function(){\n\t\t\t\tvar name = jQuery(this).attr('name').split(':');\n\t\t\t\tjQuery(this).attr('name', name[0]+':'+name[1]);\n\t\t\t});\n\t\t\tjQuery('form#occ-form').find('[name=occurrence\\:id],[name=sample\\:id]').val('').attr('disabled', 'disabled');\n\t\t\tjQuery('form#occ-form').find('[name=occurrence\\:taxa_taxon_list_id],[name=occurrence\\:taxa_taxon_list_id\\:taxon],[name=sample\\:entered_sref],[name=sample\\:geom],[name=occurrence\\:comment]').val('');\n\t\t\tjQuery('form#occ-form').find('[name=occAttr\\:" . $occurrence_confidence_id . "]').find('option').removeAttr('selected');\n\t\t\tjQuery('form#occ-form').find('[name=occAttr\\:" . $occurrence_count_id . "]').val('1');\n\t\t\tjQuery('form#occ-form').find('input[name=occAttr\\:" . $occurrence_approximation_id . "],input[name=occAttr\\:" . $occurrence_overflying_id . "]').removeAttr('checked','checked');\n\t\t\tjQuery('form#occ-form').find('#occ-territorial').attr('checked','checked');\n\t\t\tjQuery('label[for=occ-sample-deleted]').remove(); // sample deleted only applicable when editing an existing occurrence. After saving reverts to Add Occurreence: no delete. Remove label then actual checkbox\n\t\t\tjQuery('form#occ-form').find('[name=sample\\:deleted]').remove(); // This removes both parts of the checkbox.\n\t\t\tsetAtlasStatus();\n\t\t\tretriggerGrid();\n\t\t\tlocationLayer.map.editLayer.destroyFeatures();\n\t\t\tvar a = \$('ul.ui-tabs-nav a')[1];\n\t\t\t\$(a).empty().html('<span>" . lang::get('LANG_Add_Occurrence') . "</span>');\n\t\t\tswitch(\"" . $args["on_save_occurrence_nav"] . "\"){\n\t\t\t\tcase \"list\":\n\t\t\t\t\ta = \$('ul.ui-tabs-nav a')[2];\n\t\t\t\t\t\$(a).click();\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"survey\":\n\t\t\t\t\ta = \$('ul.ui-tabs-nav a')[0];\n\t\t\t\t\t\$(a).click();\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tbreak;\n\t\t\t}\n } else {\n\t\t\tif(data.error){\n\t\t\t\tvar lastIndex = data.error.lastIndexOf('Validation error');\n \t\t\tif (lastIndex != -1 && lastIndex == (data.error.length - 16)){\n\t\t\t\t\tif(data.errors){\n\t\t\t\t\t\t// TODO translation\n\t\t\t\t\t\tfor (i in data.errors){\n\t\t\t\t\t\t\tvar label = \$('<p/>').addClass('inline-error').html(data.errors[i]);\n\t\t\t\t\t\t\tlabel.insertAfter('[name='+i+']');\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmyScrollToError();\n\t\t\t\t\t\treturn;\n \t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\talertIndiciaError(data);\n }\n\t},\n complete: function (){\n \t\tjQuery('.loading-button').removeClass('loading-button');\n \t}\n});\nsetAtlasStatus = function() {\n if (jQuery(\"#occ-territorial:checked\").length == 0) {\n jQuery(\"select[name=occAttr\\:" . $occurrence_atlas_code_id . "],select[name^=occAttr\\:" . $occurrence_atlas_code_id . "\\:]\").val('');\n } else {\n if(jQuery(\"select[name=occAttr\\:" . $occurrence_atlas_code_id . "],select[name^=occAttr\\:" . $occurrence_atlas_code_id . "\\:]\").val() == '') {\n // Find the BB02 option (depends on the language what val it has)\n var bb02;\n jQuery.each(jQuery(\"select[name=occAttr\\:" . $occurrence_atlas_code_id . "],select[name^=occAttr\\:" . $occurrence_atlas_code_id . "\\:]\").find('option'), function(index, option) {\n if (option.text.substr(0,4)=='BB02') {\n bb02 = option.value;\n return; // just from the each loop\n }\n });\n jQuery(\"select[name=occAttr\\:" . $occurrence_atlas_code_id . "],select[name^=occAttr\\:" . $occurrence_atlas_code_id . "\\:]\").val(bb02);\n }\n }\n};\njQuery(\"#occ-territorial\").change(setAtlasStatus);\nif(\$.browser.msie) {\n jQuery(\"#occ-territorial\").click(function() {\n \$(this).change();\n });\n}\n\n"; if ($mode != 3) { data_entry_helper::$javascript .= "setAtlasStatus();\n"; } // reset the atlas when not looking at a old occurrence. $r .= '</div>'; // add map panel. $options = iform_map_get_map_options($args, $readAuth); $olOptions = iform_map_get_ol_options($args); // $options['layers'] = array('locationLayer', 'occListLayer'); $options['searchLayer'] = 'false'; $options['initialFeatureWkt'] = null; $options['proxy'] = ''; $options['scroll_wheel_zoom'] = false; $options['width'] = 'auto'; // TBD remove from arglist $r .= "<div class=\"mnhnl-btw-mappanel\">\n"; $r .= data_entry_helper::map_panel($options, $olOptions); // for timing reasons, all the following has to be done after the map is loaded. // 1) feature selector for occurrence list must have the map present to attach the control // 2) location placer must have the location layer populated and the map present in // order to zoom the map into the location. // 3) occurrence list feature adder must have map present in order to zoom into any // current selection. data_entry_helper::$onload_javascript .= "\n\n\nlocationChange = function(obj){\n locationLayer.destroyFeatures();\n if(obj.value != ''){\n jQuery.getJSON(\"" . $svcUrl . "\" + \"/data/location/\"+obj.value +\n \"?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"] . "\" +\n \"&callback=?\", function(data) {\n if (data.length>0) {\n var parser = new OpenLayers.Format.WKT();\n for (var i=0;i<data.length;i++)\n {\n if(data[i].centroid_geom){\n " . self::readBoundaryJs('data[i].centroid_geom', $args['map_projection']) . "\n feature.style = {label: data[i].name,\n\t\t\t\t\t\t strokeColor: \"Green\",\n strokeWidth: 2,\n fillOpacity: 0};\n centre = feature.geometry.getCentroid();\n centrefeature = new OpenLayers.Feature.Vector(centre, {}, {label: data[i].name});\n locationLayer.addFeatures([feature, centrefeature]);\n }\n if(data[i].boundary_geom){\n " . self::readBoundaryJs('data[i].boundary_geom', $args['map_projection']) . "\n feature.style = {strokeColor: \"Blue\", strokeWidth: 2};\n locationLayer.addFeatures([feature]);\n }\n locationLayer.map.zoomToExtent(locationLayer.getDataExtent());\n }\n }\n });\n jQuery.getJSON(\"" . $svcUrl . "\" + \"/data/location\" +\n \"?mode=json&view=detail&auth_token=" . $readAuth['auth_token'] . "&nonce=" . $readAuth["nonce"] . "&callback=?&parent_id=\"+obj.value, function(data) {\n if (data.length>0) {\n var parser = new OpenLayers.Format.WKT();\n for (var i=0;i<data.length;i++)\n {\n if(data[i].centroid_geom){\n " . self::readBoundaryJs('data[i].centroid_geom', $args['map_projection']) . "\n locationLayer.addFeatures([feature]);\n }\n if(data[i].boundary_geom){\n " . self::readBoundaryJs('data[i].boundary_geom', $args['map_projection']) . "\n feature.style = {label: data[i].name,\n labelAlign: \"cb\",\n strokeColor: \"Blue\",\n strokeWidth: 2};\n locationLayer.addFeatures([feature]);\n }\n }\n }\n });\n }\n};\n// upload location initial value into map.\njQuery('#imp-location').each(function(){\n locationChange(this);\n});\njQuery('#imp-location').unbind('change');\njQuery('#imp-location').change(function(){\n locationChange(this);\n});\nvar selected = \$('#controls').tabs('option', 'selected');\n\n// Only leave the click control activated for edit/add occurrence tab.\nif(selected != 1){\n locationLayer.map.editLayer.clickControl.deactivate();\n}\n\$('#controls').bind('tabsshow', function(event, ui) {\n if(ui.index == 1)\n {\n locationLayer.map.editLayer.clickControl.activate();\n }\n else\n {\n locationLayer.map.editLayer.clickControl.deactivate();\n }\n }\n);\nactivateAddList = 1;\nthisOccID = " . $thisOccID . ";\naddListFeature = function(div, r, record, count) {\n if(activateAddList == 0)\n return;\n if(r == count)\n activateAddList = 0;\n var parser = new OpenLayers.Format.WKT();\n " . self::readBoundaryJs('record.geom', $args['map_projection']) . "\n if(record.id != thisOccID || 1==" . ($surveyReadOnly ? 1 : 0) . " || 1==" . ($occReadOnly ? 1 : 0) . "){\n feature.attributes.id = record.id;\n feature.attributes.taxon = record.taxon;\n feature.attributes.count = record.count;\n occListLayer.addFeatures([feature]);\n if(record.id == " . $thisOccID . "){\n var bounds=feature.geometry.getBounds();\n locationLayer.map.setCenter(bounds.getCenterLonLat());\n }\n } else {\n locationLayer.map.editLayer.destroyFeatures();\n locationLayer.map.editLayer.addFeatures([feature]);\n var bounds=feature.geometry.getBounds()\n var centre=bounds.getCenterLonLat();\n locationLayer.map.setCenter(centre);\n }\n};\nhighlight = function(id){\n if(id == " . $thisOccID . "){\n if(occListLayer.map.editLayer.features.length > 0){\n var bounds=occListLayer.map.editLayer.features[0].geometry.getBounds()\n var centre=bounds.getCenterLonLat();\n occListLayer.map.setCenter(centre);\n return;\n }\n }\n for(var i = 0; i < occListLayer.features.length; i++){\n if(occListLayer.features[i].attributes.id == id){\n control.unselectAll();\n var bounds=occListLayer.features[i].geometry.getBounds()\n var centre=bounds.getCenterLonLat();\n occListLayer.map.setCenter(centre);\n control.select(occListLayer.features[i]);\n return;\n }\n }\n}\n"; if ($mode != 1) { data_entry_helper::$onload_javascript .= "\n\$('div#occ_grid').indiciaDataGrid('rpt:reports_for_prebuilt_forms/MNHNL/mnhnl_btw_list_occurrences', {\n indiciaSvc: '" . $svcUrl . "',\n dataColumns: ['taxon', 'territorial', 'count'],\n reportColumnTitles: {taxon : '" . lang::get('LANG_Species') . "', territorial : '" . lang::get('LANG_Territorial') . "', count : '" . lang::get('LANG_Count') . "'},\n actionColumns: {'" . lang::get('LANG_Show') . "' : \"" . url('node/' . $node->nid, array('query' => 'occurrence_id=£id£')) . "\",\n '" . lang::get('LANG_Highlight') . "' : \"script:highlight(£id£);\"},\n auth : { nonce : '" . $readAuth['nonce'] . "', auth_token : '" . $readAuth['auth_token'] . "'},\n parameters : { survey_id : '" . $args['survey_id'] . "',\n parent_id : '" . $parentSample['sample:id'] . "',\n territorial_attr_id : '" . $occurrence_territorial_id . "',\n count_attr_id : '" . $occurrence_count_id . "'},\n itemsPerPage : 12,\n callback : addListFeature ,\n cssOdd : ''\n });\n\n// activateAddList = 0;\n\n"; } $r .= "</div><div><form><input id=\"return-to-main\" type=\"button\" value=\"" . lang::get('LANG_Return') . "\" onclick=\"window.location.href='" . url('node/' . $node->nid, array('query' => 'Main')) . "'\"></form></div></div>\n"; if (method_exists(get_called_class(), 'getTrailerHTML')) { $r .= call_user_func(array(get_called_class(), 'getTrailerHTML'), $args); } return $r; }
/** * Returns controls for defining the date range of a group if this option is enabled. * @param array $args Form configuration arguments * @return string HTML to output */ private static function dateControls($args) { $r = ''; if ($args['include_dates']) { $r .= '<p>' . lang::get('If the {1} will only be active for a limited period of time (e.g. an event or bioblitz) ' . 'then please fill in the start and or end date of this period in the controls below. This helps to prevent people joining after ' . 'the {2}.', self::$groupType, lang::get('group is no longer active')) . '</p>'; $r .= '<div id="ctrl-wrap-group-from-to" class="form-row ctrl-wrap">'; $r .= data_entry_helper::date_picker(array('label' => ucfirst(lang::get('{1} active from', self::$groupType)), 'fieldname' => 'group:from_date', 'controlWrapTemplate' => 'justControl', 'helpText' => lang::get('LANG_From_Field_Instruct'))); $r .= data_entry_helper::date_picker(array('label' => lang::get('to'), 'fieldname' => 'group:to_date', 'labelClass' => 'auto', 'controlWrapTemplate' => 'justControl', 'helpText' => lang::get('LANG_To_Field_Instruct'))); $r .= '</div>'; } return $r; }
public static function get_sample_form($args, $node, $response) { global $user; if (!module_exists('iform_ajaxproxy')) { return 'This form must be used in Drupal with the Indicia AJAX Proxy module enabled.'; } iform_load_helpers(array('map_helper')); $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); $sampleId = isset($_GET['sample_id']) ? $_GET['sample_id'] : null; if ($sampleId) { data_entry_helper::load_existing_record($auth['read'], 'sample', $sampleId); $locationId = data_entry_helper::$entity_to_load['sample:location_id']; } else { $locationId = isset($_GET['site']) ? $_GET['site'] : null; // location ID also might be in the $_POST data after a validation save of a new record if (!$locationId && isset($_POST['sample:location_id'])) { $locationId = $_POST['sample:location_id']; } } $url = explode('?', $args['my_walks_page'], 2); $params = NULL; $fragment = NULL; // fragment is always at the end. if (count($url) > 1) { $params = explode('#', $url[1], 2); if (count($params) > 1) { $fragment = $params[1]; } $params = $params[0]; } else { $url = explode('#', $url[0], 2); if (count($url) > 1) { $fragment = $url[1]; } } $args['my_walks_page'] = url($url[0], array('query' => $params, 'fragment' => $fragment, 'absolute' => TRUE)); $r = '<form method="post" id="sample">'; $r .= $auth['write']; // we pass through the read auth. This makes it possible for the get_submission method to authorise against the warehouse // without an additional (expensive) warehouse call, so it can get location details. $r .= '<input type="hidden" name="page" value="mainSample"/>'; $r .= '<input type="hidden" name="read_nonce" value="' . $auth['read']['nonce'] . '"/>'; $r .= '<input type="hidden" name="read_auth_token" value="' . $auth['read']['auth_token'] . '"/>'; $r .= '<input type="hidden" name="website_id" value="' . $args['website_id'] . '"/>'; if (isset(data_entry_helper::$entity_to_load['sample:id'])) { $r .= '<input type="hidden" name="sample:id" value="' . data_entry_helper::$entity_to_load['sample:id'] . '"/>'; } $r .= '<input type="hidden" name="sample:survey_id" value="' . $args['survey_id'] . '"/>'; if (isset($args['include_map_samples_form']) && $args['include_map_samples_form']) { $r .= '<div id="cols" class="ui-helper-clearfix"><div class="left" style="width: ' . (98 - (isset($args['percent_width']) ? $args['percent_width'] : 50)) . '%">'; } if ($locationId) { $site = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $auth['read'] + array('view' => 'detail', 'id' => $locationId, 'deleted' => 'f'))); $site = $site[0]; $r .= '<input type="hidden" name="sample:location_id" value="' . $locationId . '"/>'; $r .= '<input type="hidden" name="sample:entered_sref" value="' . $site['centroid_sref'] . '"/>'; $r .= '<input type="hidden" name="sample:entered_sref_system" value="' . $site['centroid_sref_system'] . '"/>'; } if ($locationId && (isset(data_entry_helper::$entity_to_load['sample:id']) || isset($_GET['site']))) { // for reload of existing or the the site is specified in the URL, don't let the user switch the transect as that would mess everything up. $r .= '<label>' . lang::get('Transect') . ':</label> <span class="value-label">' . $site['name'] . '</span><br/>'; } else { // Output only the locations for this website and transect type. Note we load both transects and sections, just so that // we always use the same warehouse call and therefore it uses the cache. $typeTerms = array(empty($args['transect_type_term']) ? 'Transect' : $args['transect_type_term'], empty($args['section_type_term']) ? 'Section' : $args['section_type_term']); $locationTypes = helper_base::get_termlist_terms($auth, 'indicia:location_types', $typeTerms); $siteParams = $auth['read'] + array('website_id' => $args['website_id'], 'location_type_id' => $locationTypes[0]['id']); if ((!isset($args['user_locations_filter']) || $args['user_locations_filter']) && (!isset($args['managerPermission']) || !user_access($args['managerPermission']))) { $siteParams += array('locattrs' => 'CMS User ID', 'attr_location_cms_user_id' => $user->uid); } else { $siteParams += array('locattrs' => ''); } $availableSites = data_entry_helper::get_population_data(array('report' => 'library/locations/locations_list', 'extraParams' => $siteParams, 'nocache' => true)); // convert the report data to an array for the lookup, plus one to pass to the JS so it can keep the hidden sref fields updated $sitesLookup = array(); $sitesJs = array(); foreach ($availableSites as $site) { $sitesLookup[$site['location_id']] = $site['name']; $sitesJs[$site['location_id']] = $site; } // bolt in branch locations. Don't assume that branch list is superset of normal sites list. // Only need to do if not a manager - they have already fetched the full list anyway. if (isset($args['branch_assignment_permission']) && user_access($args['branch_assignment_permission']) && $siteParams['locattrs'] != '') { $siteParams['locattrs'] = 'Branch CMS User ID'; $siteParams['attr_location_branch_cms_user_id'] = $user->uid; unset($siteParams['attr_location_cms_user_id']); $availableSites = data_entry_helper::get_population_data(array('report' => 'library/locations/locations_list', 'extraParams' => $siteParams, 'nocache' => true)); foreach ($availableSites as $site) { $sitesLookup[$site['location_id']] = $site['name']; $sitesJs[$site['location_id']] = $site; } natcasesort($sitesLookup); // merge into original list in alphabetic order. } data_entry_helper::$javascript .= "indiciaData.sites = " . json_encode($sitesJs) . ";\n"; $options = array('label' => lang::get('Select Transect'), 'validation' => array('required'), 'blankText' => lang::get('please select'), 'lookupValues' => $sitesLookup); if ($locationId) { $options['default'] = $locationId; } $r .= data_entry_helper::location_select($options); } if (!$locationId) { $r .= '<input type="hidden" name="sample:entered_sref" value="" id="entered_sref"/>'; $r .= '<input type="hidden" name="sample:entered_sref_system" value="" id="entered_sref_system"/>'; // sref values for the sample will be populated automatically when the submission is built. } $sampleMethods = helper_base::get_termlist_terms($auth, 'indicia:sample_methods', array('Transect')); $attributes = data_entry_helper::getAttributes(array('id' => $sampleId, 'valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'], 'sample_method_id' => $sampleMethods[0]['id'])); $r .= get_user_profile_hidden_inputs($attributes, $args, '', $auth['read']); if (isset($_GET['date'])) { $r .= '<input type="hidden" name="sample:date" value="' . $_GET['date'] . '"/>'; $r .= '<label>' . lang::get('Date') . ':</label> <span class="value-label">' . $_GET['date'] . '</span><br/>'; } else { 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'), 'fieldname' => 'sample:date')); } // are there any option overrides for the custom attributes? if (isset($args['custom_attribute_options']) && $args['custom_attribute_options']) { $blockOptions = get_attr_options_array_with_user_data($args['custom_attribute_options']); } else { $blockOptions = array(); } $r .= get_attribute_html($attributes, $args, array('extraParams' => $auth['read']), null, $blockOptions); $r .= '<input type="hidden" name="sample:sample_method_id" value="' . $sampleMethods[0]['id'] . '" />'; $r .= '<input type="submit" value="' . lang::get('Next') . '" />'; $r .= '<a href="' . $args['my_walks_page'] . '" class="button">' . lang::get('Cancel') . '</a>'; if (isset(data_entry_helper::$entity_to_load['sample:id'])) { $r .= '<button id="delete-button" type="button" class="ui-state-default ui-corner-all" />' . lang::get('Delete') . '</button>'; } if (isset($args['include_map_samples_form']) && $args['include_map_samples_form']) { $r .= "</div>" . '<div class="right" style="width: ' . (isset($args['percent_width']) ? $args['percent_width'] : 50) . '%">'; // no place search: [map] $options = iform_map_get_map_options($args, $auth['read']); if (!empty(data_entry_helper::$entity_to_load['sample:wkt'])) { $options['initialFeatureWkt'] = data_entry_helper::$entity_to_load['sample:wkt']; } $olOptions = iform_map_get_ol_options($args); if (!isset($options['standardControls'])) { $options['standardControls'] = array('layerSwitcher', 'panZoomBar'); } $r .= map_helper::map_panel($options, $olOptions); $r .= "</div>"; // right } $r .= '</form>'; // Recorder Name - assume Easy Login uid if (function_exists('module_exists') && module_exists('easy_login')) { $userId = hostsite_get_user_field('indicia_user_id'); // For non easy login test only $userId = 1; foreach ($attributes as $attrID => $attr) { if (strcasecmp('Recorder Name', $attr["untranslatedCaption"]) == 0 && !empty($userId)) { // determining which you have used is difficult from a services based autocomplete, esp when the created_by_id is not available on the data. data_entry_helper::add_resource('autocomplete'); data_entry_helper::$javascript .= "bindRecorderNameAutocomplete(" . $attrID . ", '" . $userId . "', '" . data_entry_helper::$base_url . "', '" . $args['survey_id'] . "', '" . $auth['read']['auth_token'] . "', '" . $auth['read']['nonce'] . "');\n"; } } } if (isset(data_entry_helper::$entity_to_load['sample:id'])) { // allow deletes if sample id is present. data_entry_helper::$javascript .= "jQuery('#delete-button').click(function(){\n if(confirm(\"" . lang::get('Are you sure you want to delete this walk?') . "\")){\n jQuery('#delete-form').submit();\n } // else do nothing.\n});\n"; // note we only require bare minimum in order to flag a sample as deleted. $r .= '<form method="post" id="delete-form" style="display: none;">'; $r .= $auth['write']; $r .= '<input type="hidden" name="page" value="delete"/>'; $r .= '<input type="hidden" name="website_id" value="' . $args['website_id'] . '"/>'; $r .= '<input type="hidden" name="sample:id" value="' . data_entry_helper::$entity_to_load['sample:id'] . '"/>'; $r .= '<input type="hidden" name="sample:deleted" value="t"/>'; $r .= '</form>'; } data_entry_helper::enable_validation('sample'); return $r; }
/** * Get the date control. */ protected static function get_control_date($auth, $args, $tabAlias, $options) { 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'); } if ($args['language'] != 'en') { data_entry_helper::add_resource('jquery_ui_' . $args['language']); } // this will autoload the jquery_ui resource. The date_picker does not have access to the args. if (lang::get('LANG_Date_Explanation') != 'LANG_Date_Explanation') { data_entry_helper::$javascript .= "\njQuery('[name=sample\\:date]').next().after('<span class=\"date-explanation\"> " . lang::get('LANG_Date_Explanation') . "</span>');\n"; } return data_entry_helper::date_picker(array_merge(array('label' => lang::get('LANG_Date'), 'fieldname' => 'sample:date', 'default' => isset($args['defaults']['sample:date']) ? $args['defaults']['sample:date'] : ''), $options)); }
/** * Get the date control. */ private static function get_control_date($auth, $args, $tabalias, $options) { return data_entry_helper::date_picker(array_merge(array('label' => lang::get('LANG_Date'), 'fieldname' => 'sample:date', 'default' => isset($args['defaults']['sample:date']) ? $args['defaults']['sample:date'] : ''), $options)); }
/** * Return the generated form output. * @param array $args List of parameter values passed through to the form depending on how the form has been configured. * This array always contains a value for language. * @param object $node The Drupal node object. * @param array $response When this form is reloading after saving a submission, contains the response from the service call. * Note this does not apply when redirecting (in this case the details of the saved object are in the $_GET data). * @return Form HTML. */ public static function get_form($args, $node, $response = null) { $conn = iform_get_connection_details($node); data_entry_helper::$js_read_tokens = data_entry_helper::get_read_auth($conn['website_id'], $conn['password']); if (!empty($_POST) && !empty($_POST['format'])) { self::do_data_services_download($args, $node); } $conn = iform_get_connection_details($node); data_entry_helper::$js_read_tokens = data_entry_helper::get_read_auth($conn['website_id'], $conn['password']); $types = self::get_download_types($args); $formats = self::get_download_formats($args); if (count($types) === 0) { return 'This download page is configured so that no download type options are available.'; } if (count($formats) === 0) { return 'This download page is configured so that no download format options are available.'; } $reload = data_entry_helper::get_reload_link_parts(); $reloadPath = $reload['path']; if (count($reload['params'])) { $reloadPath .= '?' . helper_base::array_to_query_string($reload['params']); } $r = '<form method="POST" action="' . $reloadPath . '">'; $r .= '<fieldset id="download-type-fieldset"><legend>' . lang::get('Records to download') . '</legend>'; if (count($types) === 1) { $r .= '<input type="hidden" name="download-type" id="download-type" value="' . implode('', array_keys($types)) . '"/>'; hostsite_set_page_title(lang::get('Download {1}', strtolower(implode('', $types)))); } else { $r .= data_entry_helper::select(array('fieldname' => 'download-type', 'label' => lang::get('Download type'), 'lookupValues' => $types, 'class' => 'control-width-5', 'helpText' => 'Select the type of download you require, i.e. the purpose for the data. This defines which records are available to download.')); } $r .= data_entry_helper::select(array('fieldname' => 'download-subfilter', 'label' => lang::get('Filter to apply'), 'lookupValues' => array(), 'class' => 'control-width-5', 'helpText' => lang::get('Optionally select from the available filters. Filters you create on the Explore pages will be available here.'))); $r .= "</fieldset>\n"; $r .= '<fieldset><legend>' . lang::get('Limit the records') . '</legend>'; if (empty($args['survey_id'])) { // put up an empty surveys drop down. AJAX will populate it. $r .= data_entry_helper::select(array('fieldname' => 'survey_id', 'label' => lang::get('Survey to include'), 'helpText' => 'Choose a survey, or <all> to not filter by survey.', 'lookupValues' => array(), 'class' => 'control-width-5')); } else { $r .= '<input type="hidden" name="survey_id" value="' . $args['survey_id'] . '"/>'; } // Let the user pick the date range to download. $r .= data_entry_helper::select(array('label' => lang::get('Date field'), 'fieldname' => 'date_type', 'lookupValues' => array('recorded' => lang::get('Field record date'), 'input' => lang::get('Input date'), 'edited' => lang::get('Last changed date'), 'verified' => 'Verification status change date'), 'helpText' => 'If filtering on date, which date field would you like to filter on?')); $r .= data_entry_helper::date_picker(array('fieldname' => 'date_from', 'label' => lang::get('Start Date'), 'helpText' => 'Leave blank for no start date filter', 'class' => 'control-width-4')); $r .= data_entry_helper::date_picker(array('fieldname' => 'date_to', 'label' => lang::get('End Date'), 'helpText' => 'Leave blank for no end date filter', 'class' => 'control-width-4')); $r .= '</fieldset>'; if (!empty($args['custom_formats'])) { $customFormats = json_decode($args['custom_formats'], true); foreach ($customFormats as $idx => $format) { if (empty($format['permission']) || user_access($format['permission'])) { $formats["custom-{$idx}"] = lang::get(isset($format['title']) ? $format['title'] : 'Untitled format'); } } } if (count($formats) > 1) { $r .= '<fieldset><legend>' . lang::get('Select a format to download') . '</legend>'; $keys = array_keys($formats); $r .= data_entry_helper::radio_group(array('fieldname' => 'format', 'lookupValues' => $formats, 'default' => $keys[0])); $r .= '</fieldset>'; } else { // only allowed 1 format, so no need for a selection control $keys = array_keys($formats); $r .= '<input type="hidden" name="format" value="' . array_pop($keys) . '"/>'; } $r .= '<input type="submit" value="' . lang::get('Download') . '"/></form>'; data_entry_helper::$javascript .= 'indiciaData.ajaxUrl="' . url('iform/ajax/easy_download_2') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.nid = "' . $node->nid . "\";\n"; data_entry_helper::$javascript .= "setAvailableDownloadFilters();\n"; return $r; }
public static function get_sample_form($args, $node, $response) { global $user; if (!module_exists('iform_ajaxproxy')) { return 'This form must be used in Drupal with the Indicia AJAX Proxy module enabled.'; } require_once dirname(dirname(__FILE__)) . '/map_helper.php'; $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); $sampleId = isset($_GET['sample_id']) ? $_GET['sample_id'] : null; if ($sampleId) { data_entry_helper::load_existing_record($auth['read'], 'sample', $sampleId); $locationId = data_entry_helper::$entity_to_load['sample:location_id']; } else { $locationId = isset($_GET['site']) ? $_GET['site'] : null; // location ID also might be in the $_POST data after a validation save of a new record if (!$locationId && isset($_POST['sample:location_id'])) { $locationId = $_POST['sample:location_id']; } } $r .= '<form method="post" id="sample">'; $r .= $auth['write']; // we pass through the read auth. This makes it possible for the get_submission method to authorise against the warehouse // without an additional (expensive) warehouse call, so it can get location details. $r .= '<input type="hidden" name="read_nonce" value="' . $auth['read']['nonce'] . '"/>'; $r .= '<input type="hidden" name="read_auth_token" value="' . $auth['read']['auth_ token'] . '"/>'; $r .= '<input type="hidden" name="website_id" value="' . $args['website_id'] . '"/>'; if (isset(data_entry_helper::$entity_to_load['sample:id'])) { $r .= '<input type="hidden" name="sample:id" value="' . data_entry_helper::$entity_to_load['sample:id'] . '"/>'; } $r .= '<input type="hidden" name="sample:survey_id" value="' . $args['survey_id'] . '"/>'; // pass a param that sets the next page to display $r .= '<input type="hidden" name="page" value="grid"/>'; if ($locationId) { $site = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $auth['read'] + array('view' => 'detail', 'id' => $locationId, 'deleted' => 'f'))); $site = $site[0]; $r .= '<input type="hidden" name="sample:location_id" value="' . $locationId . '"/>'; $r .= '<input type="hidden" name="sample:entered_sref" value="' . $site['centroid_sref'] . '"/>'; $r .= '<input type="hidden" name="sample:entered_sref_system" value="' . $site['centroid_sref_system'] . '"/>'; } if ($locationId && isset(data_entry_helper::$entity_to_load['sample:id'])) { // for reload of existing, don't let the user switch the transect as that would mess everything up. $r .= '<label>' . lang::get('Transect') . ':</label><span>' . $site['name'] . '</span><br/>'; } else { // Output only the locations for this website and transect type. Note we load both transects and sections, just so that // we always use the same warehouse call and therefore it uses the cache. $locationTypes = helper_base::get_termlist_terms($auth, 'indicia:location_types', array('Transect', 'Transect Section')); $availableSites = data_entry_helper::get_population_data(array('report' => 'library/locations/locations_list', 'extraParams' => $auth['read'] + array('website_id' => $args['website_id'], 'location_type_id' => $locationTypes[0]['id'], 'locattrs' => 'CMS User ID', 'attr_location_cms_user_id' => $user->uid), 'nocache' => true)); // convert the report data to an array for the lookup, plus one to pass to the JS so it can keep the hidden sref fields updated $sitesLookup = array(); $sitesJs = array(); foreach ($availableSites as $site) { $sitesLookup[$site['location_id']] = $site['name']; $sitesJs[$site['location_id']] = $site; } data_entry_helper::$javascript .= "indiciaData.sites = " . json_encode($sitesJs) . ";\n"; $options = array('label' => lang::get('Select Transect'), 'validation' => array('required'), 'blankText' => lang::get('please select'), 'lookupValues' => $sitesLookup); if ($locationId) { $options['default'] = $locationId; } $r .= data_entry_helper::location_select($options); } if (!$locationId) { $r .= '<input type="hidden" name="sample:entered_sref" value="" id="entered_sref"/>'; $r .= '<input type="hidden" name="sample:entered_sref_system" value="" id="entered_sref_system"/>'; // sref values for the sample will be populated automatically when the submission is built. } $r .= data_entry_helper::date_picker(array('label' => lang::get('Date'), 'fieldname' => 'sample:date')); $sampleMethods = helper_base::get_termlist_terms($auth, 'indicia:sample_methods', array('Transect')); $attributes = data_entry_helper::getAttributes(array('id' => $sampleId, 'valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id'], 'sample_method_id' => $sampleMethods[0]['id'])); $r .= get_attribute_html($attributes, $args, array('extraParams' => $auth['read'])); $r .= '<input type="hidden" name="sample:sample_method_id" value="' . $sampleMethods[0]['id'] . '" />'; $r .= '<input type="submit" value="' . lang::get('Next') . '" class="ui-state-default ui-corner-all" />'; $r .= '</form>'; data_entry_helper::enable_validation('sample'); return $r; }
/** * Returns a control to insert onto a parameters form. * @param string $key The unique identifier of this control. * @param array $info Configuration options for the parameter as defined in the report, including the * description, display (label), default and datatype. * @param array $options Control options array * @param array $tools Any tools to be embedded in the map toolbar are returned in this * parameter rather than as the return result of the function. * @return string The HTML for the form parameter. */ private static function get_params_form_control($key, $info, $options, &$tools) { $r = ''; $fieldPrefix = isset($options['fieldNamePrefix']) ? $options['fieldNamePrefix'] . '-' : ''; $ctrlOptions = array('label' => lang::get($info['display']), 'helpText' => $options['helpText'] ? $info['description'] : '', 'fieldname' => $fieldPrefix . $key, 'nocache' => isset($options['nocache']) && $options['nocache']); // If this parameter is in the URL or post data, put it in the control instead of the original default if (isset($options['defaults'][$key])) { $ctrlOptions['default'] = $options['defaults'][$key]; } elseif (isset($info['default'])) { $ctrlOptions['default'] = $info['default']; } if ($info['datatype'] == 'idlist') { // idlists are not for human input so use a hidden. $r .= "<input type=\"hidden\" name=\"{$fieldPrefix}{$key}\" value=\"" . self::get_preset_param($options, $key) . "\" class=\"" . $fieldPrefix . "idlist-param\" />\n"; } elseif (isset($options['extraParams']) && array_key_exists($key, $options['extraParams'])) { $r .= "<input type=\"hidden\" name=\"{$fieldPrefix}{$key}\" value=\"" . self::get_preset_param($options, $key) . "\" />\n"; } elseif ($info['datatype'] == 'lookup' && isset($info['population_call'])) { // population call is colon separated, of the form direct|report:table|view|report:idField:captionField:params(key=value,key=value,...) $popOpts = explode(':', $info['population_call']); $extras = array(); // if there are any extra parameters on the report lookup call, apply them if (count($popOpts) >= 5) { // because any extra params might contain colons, any colons from item 5 onwards are considered part of the extra params. So we // have to take the remaining items and re-implode them, then split them by commas instead. E.g. population call could be set to // direct:term:id:term:term=a:b - in this case option 5 (term=a:b) is not to be split by colons. $extraItems = explode(',', implode(':', array_slice($popOpts, 4))); foreach ($extraItems as $extraItem) { $extraItem = explode('=', $extraItem); $extras[$extraItem[0]] = $extraItem[1]; } } // allow local page configuration to apply extra restrictions on the return values: e.g. only return some location_types from the termlist if (isset($options['param_lookup_extras']) && isset($options['param_lookup_extras'][$key])) { foreach ($options['param_lookup_extras'][$key] as $param => $value) { // direct table access can handle 'in' statements, reports can't. $extras[$param] = $popOpts[0] == 'direct' ? $value : (is_array($value) ? implode(',', $value) : $value); } // $extras[$param] = $value; } $ctrlOptions = array_merge($ctrlOptions, array('valueField' => $popOpts[2], 'captionField' => $popOpts[3], 'blankText' => '<please select>', 'extraParams' => $options['readAuth'] + $extras)); if ($popOpts[0] == 'direct') { $ctrlOptions['table'] = $popOpts[1]; } else { $ctrlOptions['report'] = $popOpts[1]; } if (isset($info['linked_to']) && isset($info['linked_filter_field'])) { $ctrlOptions['filterIncludesNulls'] = false; //exclude null entries from filter field by default if (isset($options['extraParams']) && array_key_exists($info['linked_to'], $options['extraParams'])) { // if the control this is linked to is hidden because it has a preset value, just use that value as a filter on the // population call for this control $ctrlOptions = array_merge($ctrlOptions, array('extraParams' => array_merge($ctrlOptions['extraParams'], array('query' => json_encode(array('in' => array($info['linked_filter_field'] => array($options['extraParams'][$info['linked_to']], null)))))))); } else { // otherwise link the 2 controls $ctrlOptions = array_merge($ctrlOptions, array('parentControlId' => $fieldPrefix . $info['linked_to'], 'filterField' => $info['linked_filter_field'], 'parentControlLabel' => $options['form'][$info['linked_to']]['display'])); } } //If user has set option, then make any lookup parameter an autocomplete, note that autocomplete controls also have a "selectMode" //which is why there is a further option provided if you want to use that mode. if (!empty($options['forceLookupParamAutocomplete']) && $options['forceLookupParamAutocomplete'] == true) { if (!empty($options['forceLookupParamAutocompleteSelectMode']) && $options['forceLookupParamAutocompleteSelectMode'] == true) { $ctrlOptions['selectMode'] = true; } $r .= data_entry_helper::autocomplete($ctrlOptions); } else { $r .= data_entry_helper::select($ctrlOptions); } } elseif ($info['datatype'] == 'lookup' && isset($info['lookup_values'])) { // Convert the lookup values into an associative array $lookups = explode(',', $info['lookup_values']); $lookupsAssoc = array(); foreach ($lookups as $lookup) { $lookup = explode(':', $lookup); $lookupsAssoc[$lookup[0]] = $lookup[1]; } $ctrlOptions = array_merge($ctrlOptions, array('blankText' => '<' . lang::get('please select') . '>', 'lookupValues' => $lookupsAssoc)); //If user has set option, then make any lookup parameter an autocomplete, note that autocomplete controls also have a "selectMode" //which is why there is a further option provided if you want to use that mode. if (!empty($options['forceLookupParamAutocomplete']) && $options['forceLookupParamAutocomplete'] == true) { if (!empty($options['forceLookupParamAutocompleteSelectMode']) && $options['forceLookupParamAutocompleteSelectMode'] == true) { $ctrlOptions['selectMode'] = true; } $r .= data_entry_helper::autocomplete($ctrlOptions); } else { $r .= data_entry_helper::select($ctrlOptions); } } elseif ($info['datatype'] == 'date') { $r .= data_entry_helper::date_picker($ctrlOptions); } elseif ($info['datatype'] == 'geometry') { $tools = array('Polygon', 'Line', 'Point'); } elseif ($info['datatype'] == 'polygon') { $tools = array('Polygon'); } elseif ($info['datatype'] == 'line') { $tools = array('Line'); } elseif ($info['datatype'] == 'point') { $tools = array('Point'); } else { if (method_exists('data_entry_helper', $info['datatype'])) { $ctrl = $info['datatype']; $r .= data_entry_helper::$ctrl($ctrlOptions); } else { $r .= data_entry_helper::text_input($ctrlOptions); } } return $r; }
private static function get_params_form_control($key, $info, $options, &$tools) { $r = ''; $fieldPrefix = isset($options['fieldNamePrefix']) ? $options['fieldNamePrefix'] . '-' : ''; $ctrlOptions = array('label' => $info['display'], 'helpText' => $options['helpText'] ? $info['description'] : '', 'fieldname' => $fieldPrefix . $key); // If this parameter is in the URL or post data, put it in the control instead of the original default if (isset($options['defaults'][$key])) { $ctrlOptions['default'] = $options['defaults'][$key]; } elseif (isset($info['default'])) { $ctrlOptions['default'] = $info['default']; } if ($info['datatype'] == 'idlist') { // idlists are not for human input so use a hidden. $r .= "<input type=\"hidden\" name=\"{$fieldPrefix}{$key}\" value=\"" . $options['presetParams'][$key] . "\" class=\"" . $fieldPrefix . "idlist-param\" />\n"; } elseif (isset($options['presetParams']) && array_key_exists($key, $options['presetParams'])) { $r .= "<input type=\"hidden\" name=\"{$fieldPrefix}{$key}\" value=\"" . $options['presetParams'][$key] . "\" />\n"; } elseif ($info['datatype'] == 'lookup' && isset($info['population_call'])) { // population call is colon separated, of the form direct|report:table|view|report:idField:captionField:params(key=value,key=value,...) $popOpts = explode(':', $info['population_call']); $extras = array(); // if there are any extra parameters on the report lookup call, apply them if (count($popOpts) >= 5) { // because any extra params might contain colons, any colons from item 5 onwards are considered part of the extra params. So we // have to take the remaining items and re-implode them, then split them by commas instead. E.g. population call could be set to // direct:term:id:term:term=a:b - in this case option 5 (term=a:b) is not to be split by colons. $extraItems = explode(',', implode(':', array_slice($popOpts, 4))); foreach ($extraItems as $extraItem) { $extraItem = explode('=', $extraItem); $extras[$extraItem[0]] = $extraItem[1]; } } $ctrlOptions = array_merge($ctrlOptions, array('valueField' => $popOpts[2], 'captionField' => $popOpts[3], 'blankText' => '<' . lang::get('please select') . '>', 'extraParams' => $options['readAuth'] + $extras)); if ($popOpts[0] == 'direct') { $ctrlOptions['table'] = $popOpts[1]; } else { $ctrlOptions['report'] = $popOpts[1]; } if (isset($info['linked_to']) && isset($info['linked_filter_field'])) { if (isset($options['presetParams']) && array_key_exists($info['linked_to'], $options['presetParams'])) { // if the control this is linked to is hidden because it has a preset value, just use that value as a filter on the // population call for this control $ctrlOptions = array_merge($ctrlOptions, array('extraParams' => array_merge($ctrlOptions['extraParams'], array($info['linked_filter_field'] => $options['presetParams'][$info['linked_to']])))); } else { // otherwise link the 2 controls $ctrlOptions = array_merge($ctrlOptions, array('parentControlId' => $fieldPrefix . $info['linked_to'], 'filterField' => $info['linked_filter_field'], 'parentControlLabel' => $options['form'][$info['linked_to']]['display'])); } } $r .= data_entry_helper::select($ctrlOptions); } elseif ($info['datatype'] == 'lookup' && isset($info['lookup_values'])) { // Convert the lookup values into an associative array $lookups = explode(',', $info['lookup_values']); $lookupsAssoc = array(); foreach ($lookups as $lookup) { $lookup = explode(':', $lookup); $lookupsAssoc[$lookup[0]] = $lookup[1]; } $ctrlOptions = array_merge($ctrlOptions, array('blankText' => '<' . lang::get('please select') . '>', 'lookupValues' => $lookupsAssoc)); $r .= data_entry_helper::select($ctrlOptions); } elseif ($info['datatype'] == 'date') { $r .= data_entry_helper::date_picker($ctrlOptions); } elseif ($info['datatype'] == 'geometry') { $tools = array('Polygon', 'Line', 'Point'); } elseif ($info['datatype'] == 'polygon') { $tools = array('Polygon'); } elseif ($info['datatype'] == 'line') { $tools = array('Line'); } elseif ($info['datatype'] == 'point') { $tools = array('Point'); } else { $r .= data_entry_helper::text_input($ctrlOptions); } return $r; }
/** * Return the generated form output. * @param array $args List of parameter values passed through to the form depending on how the form has been configured. * This array always contains a value for language. * @param object $node The Drupal node object. * @param array $response When this form is reloading after saving a submission, contains the response from the service call. * Note this does not apply when redirecting (in this case the details of the saved object are in the $_GET data). * @return Form HTML. */ public static function get_form($args, $node, $response = null) { // Do they have expert access? $expert = function_exists('user_access') && user_access($args['permission']); $conn = iform_get_connection_details($node); $readAuth = data_entry_helper::get_read_auth($conn['website_id'], $conn['password']); // Find out which types of filters and formats are available to the user $filters = self::get_filters($args, $readAuth); $formats = array(); if ($args['csv_format'] === 'yes' || $args['csv_format'] === 'expert' && $expert) { $formats[] = 'csv'; } if ($args['tsv_format'] === 'yes' || $args['tsv_format'] === 'expert' && $expert) { $formats[] = 'tsv'; } if ($args['kml_format'] === 'yes' || $args['kml_format'] === 'expert' && $expert) { $formats[] = 'kml'; } if ($args['gpx_format'] === 'yes' || $args['gpx_format'] === 'expert' && $expert) { $formats[] = 'gpx'; } if ($args['nbn_format'] === 'yes' || $args['nbn_format'] === 'expert' && $expert) { $formats[] = 'nbn'; } if (count($filters) === 0) { return 'This download page is configured so that no filter options are available.'; } if (count($formats) === 0) { return 'This download page is configured so that no download format options are available.'; } if (!empty($_POST)) { self::do_download($args, $filters); } iform_load_helpers(array('data_entry_helper')); $reload = data_entry_helper::get_reload_link_parts(); $reloadPath = $reload['path']; if (count($reload['params'])) { $reloadPath .= '?' . helper_base::array_to_query_string($reload['params']); } $r = '<form method="POST" action="' . $reloadPath . '">'; $r .= '<fieldset><legend>' . lang::get('Filters') . '</legend>'; if (count($filters) === 0) { return 'This download page is configured so that no filter options are available.'; } elseif (count($filters) === 1) { $r .= '<input type="hidden" name="user-filter" value="' . implode('', array_keys($filters)) . '"/>'; // Since there is only one option, we may as well tell the user what it is. drupal_set_title(implode('', array_values($filters))); if (implode('', array_keys($filters)) === 'mine') { $r .= '<p>' . lang::get('Use this form to download your own records.') . '</p>'; } } else { $r .= data_entry_helper::radio_group(array('label' => lang::get('User filter'), 'fieldname' => 'user-filter', 'lookupValues' => $filters, 'default' => empty($_POST['user-filter']) ? 'mine' : $_POST['user-filter'])); } if (empty($args['survey_id'])) { // A survey picker when downloading my data $r .= '<div id="survey_all">'; $r .= data_entry_helper::select(array('fieldname' => 'survey_id_all', 'label' => lang::get('Survey to include'), 'table' => 'survey', 'valueField' => 'id', 'captionField' => 'title', 'helpText' => 'Choose a survey, or <all> to not filter by survey.', 'blankText' => '<all>', 'class' => 'control-width-4', 'extraParams' => $readAuth + array('sharing' => 'data_flow', 'orderby' => 'title'))); $r .= '</div>'; // A survey picker when downloading data you are an expert for $surveys_expertise = hostsite_get_user_field('surveys_expertise'); if ($surveys_expertise) { $surveys_expertise = unserialize($surveys_expertise); $surveysFilter = array('query' => json_encode(array('in' => array('id' => $surveys_expertise)))); } else { // no filter as there are no specific surveys this user is an expert for $surveysFilter = array(); } $r .= '<div id="survey_expertise">'; $r .= data_entry_helper::select(array('fieldname' => 'survey_id_expert', 'label' => lang::get('Survey to include'), 'table' => 'survey', 'valueField' => 'id', 'captionField' => 'title', 'helpText' => 'Choose a survey, or <all> to not filter by survey.', 'blankText' => '<all>', 'class' => 'control-width-4', 'extraParams' => $readAuth + array('sharing' => 'verification', 'orderby' => 'title') + $surveysFilter)); $r .= '</div>'; } // Let the user pick the date range to download. $r .= data_entry_helper::date_picker(array('fieldname' => 'date_from', 'label' => lang::get('Start Date'), 'helpText' => 'Leave blank for no start date filter', 'class' => 'control-width-4')); $r .= data_entry_helper::date_picker(array('fieldname' => 'date_to', 'label' => lang::get('End Date'), 'helpText' => 'Leave blank for no end date filter', 'class' => 'control-width-4')); $r .= '</fieldset>'; $r .= '<fieldset><legend>' . lang::get('Downloads') . '</legend>'; $r .= '<label>Download options:</label>'; if (in_array('csv', $formats)) { $r .= '<input class="inline-control" type="submit" name="format" value="' . lang::get('Spreadsheet (CSV)') . '"/>'; } if (in_array('tsv', $formats)) { $r .= '<input class="inline-control" type="submit" name="format" value="' . lang::get('Tab Separated File (TSV)') . '"/>'; } if (in_array('kml', $formats)) { $r .= '<input class="inline-control" type="submit" name="format" value="' . lang::get('Google Earth File') . '"/>'; } if (in_array('gpx', $formats)) { $r .= '<input class="inline-control" type="submit" name="format" value="' . lang::get('GPS Track File') . '"/>'; } if (in_array('nbn', $formats)) { $r .= '<input class="inline-control" type="submit" name="format" value="' . lang::get('NBN Format') . '"/>'; $r .= '<p class="helpText">' . lang::get('Note that the NBN format download will only include verified data and excludes records where the date or spatial reference is not compatible with the NBN Gateway.') . '</p>'; } $r .= '</fieldset></form>'; return $r; }
/** * Return the generated form output. * @param array $args List of parameter values passed through to the form depending on how the form has been configured. * This array always contains a value for language. * @param object $node The Drupal node object. * @param array $response When this form is reloading after saving a submission, contains the response from the service call. * Note this does not apply when redirecting (in this case the details of the saved object are in the $_GET data). * @return Form HTML. * @todo: Implement this method */ public static function get_form($args, $node, $response = null) { global $indicia_templates, $user; data_entry_helper::enable_validation('entry_form'); $url = !empty($_SERVER['HTTPS']) ? "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] : "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $r = data_entry_helper::loading_block_start(); $r .= "<form method=\"post\" id=\"entry_form\" action=\"{$url}\">\n"; $readAuth = data_entry_helper::get_read_auth($args['website_id'], $args['password']); $r .= "<div id=\"controls\">\n"; if ($args['interface'] != 'one_page') { $r .= "<ul>\n"; if ($user->uid == 0) { $r .= ' <li><a href="#about_you"><span>' . lang::get('about you') . "</span></a></li>\n"; } $r .= ' <li><a href="#species"><span>' . lang::get('what did you see') . "</span></a></li>\n"; $r .= ' <li><a href="#place"><span>' . lang::get('where was it') . "</span></a></li>\n"; $r .= ' <li><a href="#other"><span>' . lang::get('other information') . "</span></a></li>\n"; $r .= "</ul>\n"; data_entry_helper::enable_tabs(array('divId' => 'controls', 'style' => $args['interface'])); } if ($user->uid == 0) { $r .= "<fieldset id=\"about_you\">\n"; if ($args['interface'] == 'one_page') { $r .= '<legend>' . lang::get('about you') . '</legend>'; } $r .= data_entry_helper::text_input(array('label' => lang::get('first name'), 'fieldname' => 'smpAttr:' . $args['first_name_attr_id'], 'class' => 'control-width-4', 'validation' => array('required'))); $r .= data_entry_helper::text_input(array('label' => lang::get('surname'), 'fieldname' => 'smpAttr:' . $args['surname_attr_id'], 'class' => 'control-width-4', 'validation' => array('required'))); $r .= data_entry_helper::text_input(array('label' => lang::get('phone number'), 'fieldname' => 'smpAttr:' . $args['phone_attr_id'], 'class' => 'control-width-4')); $r .= data_entry_helper::text_input(array('label' => lang::get('email'), 'fieldname' => 'smpAttr:' . $args['email_attr_id'], 'class' => 'control-width-4 optional', 'validation' => array('email'))); if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => 'first')); } $r .= "</fieldset>\n"; } // Species tab $r .= "<fieldset id=\"species\">\n"; if ($args['interface'] == 'one_page') { $r .= '<legend>' . lang::get('what did you see') . '</legend>'; } $species_list_args = array('label' => lang::get('Species'), 'fieldname' => 'occurrence:taxa_taxon_list_id', 'table' => 'taxa_taxon_list', 'captionField' => 'taxon', 'valueField' => 'id', 'listId' => $args['species_list_id'], 'columns' => 1, 'parentField' => 'parent_id', 'checkboxCol' => false, 'occAttrs' => array($args['abundance_attr_id']), 'extraParams' => $readAuth + array('view' => 'detail', 'orderby' => 'taxonomic_sort_order'), 'survey_id' => $args['survey_id'], 'header' => false, 'view' => 'detail', 'PHPtaxonLabel' => true); // Build a nice template to show a picture of each species, with fancybox. data_entry_helper::add_resource('fancybox'); data_entry_helper::$javascript .= "jQuery('a.fancybox').fancybox();\n"; $indicia_templates['taxon_label'] = 'return \'<div class="taxon-cell">' . '<a href="' . data_entry_helper::$base_url . 'upload/{image_path}" class="fancybox" >' . '<img alt="{taxon}" src="' . data_entry_helper::$base_url . 'upload/med-{image_path}" width="250"/></a>' . '<div>{taxon}</div></div>' . '<div class="taxon-desc"><ul><li>\'.str_replace("\\n", "</li><li>","{description_in_list}").\'</li></ul>' . '<a href="http://www.marine-life.org.uk/northeastcetaceans/?q=\'. strtolower(str_replace(array(" ", "\\\'"), array("-", ""), "{taxon}")). \'" target="_blank" class="ui-state-default ui-corner-all indicia-button">' . lang::get('More Info') . '...</a></div>\';'; // Template the taxon label cell $indicia_templates['taxon_label_cell'] = "\n<td class='scTaxonCell'>{content}</td>"; // Also template the attribute controls to show the label in place. $indicia_templates['attribute_cell'] = "\n<td class='scOccAttrCell'><label>{label}:</label><br/>{content}</td>"; $r .= data_entry_helper::species_checklist($species_list_args); if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => $user->uid == 0 ? 'middle' : 'first')); } $r .= "</fieldset>"; // --Place tab-- $r .= "<fieldset id=\"place\">\n"; if ($args['interface'] == 'one_page') { $r .= '<legend>' . lang::get('where was it') . '</legend>'; } $r .= data_entry_helper::radio_group(array('label' => 'Where were you when you made the sighting?', 'fieldname' => 'smpAttr:' . $args['platform_attr_id'], 'table' => 'termlists_term', 'captionField' => 'term', 'valueField' => 'id', 'extraParams' => $readAuth + array('termlist_id' => $args['platform_termlist_id']), 'sep' => '<br />', 'labelClass' => 'auto', 'class' => 'inline sighting-platform', 'validation' => array('required'))); $r .= '<div id="place_wrapper" class="hidden">'; // Some instructions only visible when entering data from a boat $r .= '<p class="boat_mode page-notice ui-state-highlight ui-corner-all">' . lang::get('Instructions for when on boat') . '</p>'; // Some instructions only visible when entering data from the shore $r .= '<p class="shore_mode page-notice ui-state-highlight ui-corner-all">' . lang::get('Instructions for clicking on map') . '</p>'; $r .= '<div class="boat_mode">'; // Add help examples to the lat and long boxes $indicia_templates['sref_textbox_latlong'] = '<label for="{idLat}">{labelLat}:</label>' . '<input type="text" id="{idLat}" name="{fieldnameLat}" {class} {disabled} value="{default}" /> <p class="helpText">e.g. 55:12.345N</p>' . '<label for="{idLong}">{labelLong}:</label>' . '<input type="text" id="{idLong}" name="{fieldnameLong}" {class} {disabled} value="{default}" /> <p class="helpText">e.g. 0:45.678W</p>' . '<input type="hidden" id="imp-geom" name="{table}:geom" value="{defaultGeom}" />' . '<input type="text" id="{id}" name="{fieldname}" style="display:none" value="{default}" />'; $r .= data_entry_helper::sref_and_system(array('systems' => array(4326 => lang::get('Latitude, Longitude')), 'splitLatLong' => true, 'helpText' => lang::get('Instructions for latlong'))); $r .= '</div>'; // Initially, we hide the map. Only show it when the user selects the sighting was from the shore, // as a click on the map for boat recordings will not be accurate. $r .= '<div class="shore_mode">'; $options = iform_map_get_map_options($args, $readAuth); $olOptions = iform_map_get_ol_options($args); $options['maxZoom'] = 9; // Switch to degrees and decimal minutes for lat long. $options['latLongFormat'] = 'DM'; $r .= data_entry_helper::map_panel($options, $olOptions); // Now, add some JavaScript to show or hide the map. Show it for when the sighting was from the shore. // Hide it for boat based sightings as we want a GPS coordinate in this case. The JavaScript looks for the // checked radio button to see the value data_entry_helper::$javascript .= 'jQuery(".sighting-platform input").click( function() { var platformId = jQuery("input[name=smpAttr\\\\:' . $args['platform_attr_id'] . ']:checked").val(); if (platformId == ' . $args['platform_mapped_term_id'] . ') { jQuery("#place_wrapper").removeClass("hidden"); jQuery(".shore_mode").removeClass("hidden"); jQuery(".boat_mode").addClass("hidden"); } else { jQuery("#place_wrapper").removeClass("hidden"); jQuery(".shore_mode").addClass("hidden"); jQuery(".boat_mode").removeClass("hidden"); } } );' . "\n"; // Force existing setting of the radio buttons to reload when showign page after validation failure data_entry_helper::$onload_javascript .= ' jQuery("input[name=smpAttr\\\\:' . $args['platform_attr_id'] . ']:checked").trigger("click"); '; $r .= '</div></div>'; if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls')); } $r .= '</fieldset>'; // --Other information tab-- $r .= "<fieldset id=\"other\">\n"; // Get authorisation tokens to update and read from the Warehouse. $r .= data_entry_helper::get_auth($args['website_id'], $args['password']); $r .= "<input type=\"hidden\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n"; $r .= "<input type=\"hidden\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n"; $r .= "<input type=\"hidden\" name=\"occurrence:record_status\" value=\"C\" />\n"; if ($args['interface'] == 'one_page') { $r .= '<legend>' . lang::get('other information') . '</legend>'; } $r .= data_entry_helper::date_picker(array('label' => lang::get('Sighting Date'), 'fieldname' => 'sample:date')); $indicia_templates['timeFormat'] = '<label>hh:mm</label><br/>'; $r .= data_entry_helper::text_input(array('label' => lang::get('Sighting Time'), 'fieldname' => 'smpAttr:' . $args['sample_time_attr_id'], 'class' => 'control-width-1', 'suffixTemplate' => 'timeFormat')); $r .= data_entry_helper::textarea(array('label' => lang::get('Any other information'), 'fieldname' => 'sample:comment', 'class' => 'control-width-6', 'helpText' => lang::get('Instructions for any other info'))); $r .= '<div class="footer">' . data_entry_helper::checkbox(array('label' => lang::get('happy for contact'), 'labelClass' => 'auto', 'fieldname' => 'smpAttr:' . $args['contact_attr_id'])) . '</div>'; if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => 'last')); } else { $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"Save\" />\n"; } $r .= "</fieldset></div>"; $r .= "</form>"; $r .= data_entry_helper::loading_block_end(); return $r; }
/** * Return the generated output for the main sample tab. * @param array $args List of parameter values passed through to the form depending on how the form has been configured. * This array always contains a value for language. * @param integer $nid The Drupal node object's ID. * @param object $auth The full read-write authorisation. * @return HTML. */ private static function get_sample_tab($args, $nid, $auth, $attributes, &$packageAttr) { global $user; 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'); } // are there any option overrides for the custom attributes? if (isset($args['custom_attribute_options']) && $args['custom_attribute_options']) { $blockOptions = get_attr_options_array_with_user_data($args['custom_attribute_options']); } else { $blockOptions = array(); } $systems = array(); $list = explode(',', str_replace(' ', '', $args['spatial_systems'])); foreach ($list as $system) { $systems[$system] = lang::get("sref:{$system}"); } $options = iform_map_get_map_options($args, $auth['read']); $olOptions = iform_map_get_ol_options($args); if (!empty(data_entry_helper::$entity_to_load['sample:wkt'])) { $options['initialFeatureWkt'] = data_entry_helper::$entity_to_load['sample:wkt']; } if (!isset($options['standardControls'])) { $options['standardControls'] = array('layerSwitcher', 'panZoomBar'); } $options['tabDiv'] = 'sample'; // we pass through the read auth. This makes it possible for the get_submission method to authorise against the warehouse // without an additional (expensive) warehouse call, so it can get subsample details. $r = '<div id="sample">' . '<input type="hidden" name="website_id" value="' . $args['website_id'] . '"/>' . get_user_profile_hidden_inputs($attributes, $args, isset(data_entry_helper::$entity_to_load['sample:id']), $auth['read']) . data_entry_helper::text_input(array('label' => lang::get('Location Name'), 'fieldname' => 'sample:location_name', 'class' => 'control-width-5', 'validation' => array('required'))) . data_entry_helper::date_picker(array('label' => lang::get('Date'), 'fieldname' => 'sample:date')) . self::_build_package_control($args, $packageAttr) . get_attribute_html($attributes, $args, array('extraParams' => $auth['read']), null, $blockOptions) . data_entry_helper::textarea(array('fieldname' => 'sample:comment', 'label' => lang::get('Overall comment'))) . data_entry_helper::sref_and_system(array('label' => lang::get('Grid Reference'), 'systems' => $systems)) . '<p class="ui-state-highlight page-notice ui-corner-all">' . t('Use the search box to find a nearby town or village, then drag the map to pan and click on the map to set the centre grid reference of the transect. ' . 'Alternatively if you know the grid reference you can enter it in the Grid Ref box above: this will then be drawn automatically on the map.') . '</p>' . (isset(data_entry_helper::$entity_to_load['sample:id']) ? '' : data_entry_helper::georeference_lookup(array('label' => lang::get('Search for place'), 'driver' => $args['georefDriver'], 'georefPreferredArea' => $args['georefPreferredArea'], 'georefCountry' => $args['georefCountry'], 'georefLang' => $args['language'], 'readAuth' => $auth['read']))) . map_helper::map_panel($options, $olOptions) . (self::$readOnly ? '' : '<br/><input type="submit" value="' . lang::get('Save') . '" title="' . lang::get('Saves any data entered across all the tabs.') . '" />') . '</div>'; return $r; }
/** * Survey control that supports multiple surveys each with a date */ protected static function get_control_surveys($auth, $args, $tabalias, $options) { //Get the Delete icon for the Surveys Grid $imgPath = empty(data_entry_helper::$images_path) ? data_entry_helper::relative_client_helper_path() . "../media/images/" : data_entry_helper::$images_path; $deleteIcon = $imgPath . "delete.png"; //Pass the delete icon to javascript data_entry_helper::$javascript .= "indiciaData.deleteImagePath='" . $deleteIcon . "';\n"; if (!empty($_GET['parent_id'])) { $countUnitId = $_GET['parent_id']; } else { $countUnitId = $_GET['location_id']; } //Get the data for all surveys that are relevant $surveysData = data_entry_helper::get_population_data(array('table' => 'survey', 'extraParams' => $auth['read'], 'nocache' => true, 'sharing' => $sharing)); //If we are in edit mode, then collect the data relating to the previously selected surveys, the ID and Date are //held as JSON, so we need to decode it. if ($countUnitId) { $selectedSurveysData = data_entry_helper::get_population_data(array('table' => 'location_attribute_value', 'extraParams' => $auth['read'] + array('location_attribute_id' => $args['surveys_attribute_id'], 'location_id' => $countUnitId), 'nocache' => true, 'sharing' => $sharing)); if (!empty($selectedSurveysData)) { foreach ($selectedSurveysData as $idx => $theSurveyData) { $decodedSavedSurvey[$idx] = json_decode($theSurveyData['raw_value']); $decodedSavedSurveyIds[$idx] = $decodedSavedSurvey[$idx][0]; } } } //We need to populate the surveys drop-down but not include items that are already on the grid. $r = '<div id="surveys-control">'; $r .= '<h3>Surveys</h3>'; $r .= '<label>Surveys: </label><select id = "survey-select">'; $r .= '<option id="please-select-surveys-item">Please Select</option>'; if (!empty($surveysData)) { foreach ($surveysData as $surveyData) { if (empty($decodedSavedSurveyIds) || !in_array($surveyData['id'], $decodedSavedSurveyIds)) { $r .= '<option id="survey-select-' . $surveyData['id'] . '" value="' . $surveyData['id'] . '">' . $surveyData['title'] . '</option>'; } //Get the names of the survey items in the grid and save them in an array where the ids are the keys - for use in a minute if (!empty($decodedSavedSurveyIds)) { if (in_array($surveyData['id'], $decodedSavedSurveyIds)) { $surveyNameInGrid[$surveyData['id']]['title'] = $surveyData['title']; } } } } $r .= '</select><br>'; $r .= data_entry_helper::date_picker(array_merge(array('label' => lang::get('LANG_Location_Surveys_Date'), 'fieldname' => 'survey:date'), $options)); $r .= '</br>'; $r .= '<input type="button" id="select-surveys-add" value="Add" onclick="select_survey_and_date();"><br>'; $r .= '<table id="surveys-table" id="surveys-table" border="3">' . '<tr>' . '<th>Survey Id</th>' . '<th>Survey Name</th>' . '<th>Date</th>' . '<th>Remove</th>' . '<th style="display:none;">Existing Attribute Id</th>' . '<th style="display:none;" type="hidden">Deleted</th></tr>' . '<tr>' . '</tr>'; if ($countUnitId) { if (!empty($selectedSurveysData)) { foreach ($selectedSurveysData as $idx => $theSurveyData) { //Add a row to the grid of Selected Suveys and Dates for each existing survey that has been saved against the Count Unit //Note we use the Survey Id on the end of the various html ids. The fields that will be used in submission also have a //"name" otherwise they won't show in the submission $values variable $r .= "\r\n <tr id='" . "selected-survey-row-" . $decodedSavedSurvey[$idx][0] . "'>\r\n <td>\r\n <input style='border: none;' id='" . "selected-survey-id-" . $decodedSavedSurvey[$idx][0] . "' name='" . "selected-survey-id-" . $decodedSavedSurvey[$idx][0] . "' value='" . $decodedSavedSurvey[$idx][0] . "' readonly>\r\n </td>\r\n <td>\r\n <input style='border: none;' id='" . "selected-survey-name-" . $decodedSavedSurvey[$idx][0] . "' value='" . $surveyNameInGrid[$decodedSavedSurvey[$idx][0]]['title'] . "' readonly>\r\n </td>\r\n <td>\r\n <input id='" . "selected-survey-date-" . $decodedSavedSurvey[$idx][0] . "' name='" . "selected-survey-date-" . $decodedSavedSurvey[$idx][0] . "' value='" . $decodedSavedSurvey[$idx][1] . "'>\r\n </td>\r\n <td>\r\n <img class=\"action-button\" src=\"{$deleteIcon}\" onclick=\"remove_survey_selection(" . $decodedSavedSurvey[$idx][0] . ",'" . $surveyNameInGrid[$decodedSavedSurvey[$idx][0]]['title'] . "');\" title=\"Delete Survey Selection\">\r\n </td>\r\n <td style='display:none;'>\r\n <input id='" . "selected-survey-existing-" . $decodedSavedSurvey[$idx][0] . "' name='" . "selected-survey-existing-" . $decodedSavedSurvey[$idx][0] . "' value='" . $theSurveyData['id'] . "'>\r\n </td>\r\n <td style='display:none;'>\r\n <input id='" . "selected-survey-deleted-" . $decodedSavedSurvey[$idx][0] . "' name='" . "selected-survey-deleted-" . $decodedSavedSurvey[$idx][0] . "' value='false'>\r\n </td>\r\n </tr>"; } } } $r .= '</table>'; $r .= '</div>'; return $r; }